00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <basis/byte_array.h>
00021 #include <basis/istring.h>
00022 #include <opsystem/application_shell.h>
00023 #include <opsystem/byte_filer.h>
00024 #include <loggers/console_logger.h>
00025 #include <opsystem/application_shell.h>
00026 #include <opsystem/ini_config.h>
00027 #include <data_struct/static_memory_gremlin.h>
00028 #include <textual/byte_format.h>
00029 #include <textual/parser_bits.h>
00030
00031 #ifdef __WIN32__
00032 #include <mfc_ext/list_dialog.h>
00033 #include <mfc_ext/tiny_app.cpp>
00034 #include <mfc_ext/tiny_shell.h>
00035 #endif
00036
00037 #ifdef __WIN32__
00038 #define base_implementation tiny_shell
00039 #else
00040 #define base_implementation application_shell
00041 #endif
00042
00043 class list_chooser : public base_implementation
00044 {
00045 public:
00046 list_chooser();
00047
00048 IMPLEMENT_CLASS_NAME("list_chooser");
00049
00050 int execute();
00051
00052 };
00053
00054 list_chooser::list_chooser()
00055 #ifdef __WIN32__
00056 : base_implementation("List Chooser", "list_chooser")
00057 #else
00058 : base_implementation("list_chooser")
00059 #endif
00060 {}
00061
00062 int list_chooser::execute()
00063 {
00064 #ifdef __WIN32__
00065
00066 ShowWindow(SW_HIDE);
00067
00068
00069 istring ini_name = portable::env_string("TEMP") + "/" + "list_chooser.ini";
00070 ini_configurator ini(ini_name, configurator::RETURN_ONLY);
00071 ini.put("answer", "okay", "0");
00072 ini.put("answer", "choice", "");
00073
00074 if (__argc < 4) {
00075 log("This program needs two parameters. The first is the caption that will be used");
00076 log("in the list box. The second is the number of lines to skip in the input file.");
00077 log("The third parameter is the filename from which to load the options that will");
00078 log("be shown in the list.");
00079 PostMessage(WM_CLOSE);
00080
00081 return 34;
00082 }
00083
00084 istring caption = __argv[1];
00085 int skip_count = istring(__argv[2]).convert(0);
00086 istring filename = __argv[3];
00087
00088 byte_filer option_file(filename, "rb");
00089 if (!option_file.good()) {
00090 log(istring("Could not open the file named: ") + filename);
00091 PostMessage(WM_CLOSE);
00092
00093 return 35;
00094 }
00095
00096 list_dialog list(this, caption);
00097
00098 int skippy = 0;
00099 while (true) {
00100 istring next_option;
00101 int chars_read = option_file.getline(next_option, 255);
00102 if (!chars_read) break;
00103 skippy++;
00104 if (skippy <= skip_count) continue;
00105
00106 next_option.shrink();
00107 while (next_option[0] == ' ') {
00108 next_option.zap(0, 0);
00109 }
00110 while (parser_bits::is_eol(next_option[next_option.end()])
00111 || (next_option[next_option.end()] == ' ') ) {
00112 next_option.zap(next_option.end(), next_option.end());
00113 }
00114
00115 list.add_string(next_option.s(), true);
00116 }
00117 option_file.close();
00118
00119 list.SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
00120
00121 if (list.DoModal() != IDOK) {
00122 PostMessage(WM_CLOSE);
00123 return 36;
00124 }
00125
00126 istring curr;
00127 list.get_current(curr);
00128
00129 while (parser_bits::is_eol(curr[curr.end()])) {
00130 curr.zap(curr.end(), curr.end());
00131 }
00132
00133 ini.put("answer", "choice", curr);
00134 ini.put("answer", "okay", "1");
00135
00136 PostMessage(WM_CLOSE);
00137
00138 #endif //win32
00139
00140 return 0;
00141 }
00142
00143 HOOPLE_MAIN(list_chooser, )
00144