diff --git a/ChangeLog b/ChangeLog index 290c50a..77d2ada 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1935,3 +1935,9 @@ Mon Jan 31 17:51:43 EST 2000 (Christian) E-Mixer didn't cleanup. +------------------------------------------------------------------------------- + +Tue Feb 1 12:26:41 PST 2000 +(KainX) + +Patches and an icon from Jerome De Greef . diff --git a/epplets/E-Exec.c b/epplets/E-Exec.c index dbe00dc..494cc56 100644 --- a/epplets/E-Exec.c +++ b/epplets/E-Exec.c @@ -6,159 +6,291 @@ #define MAX_HIST_LEN 15 +#define TRUE 1 +#define FALSE 0 + Epplet_gadget textbox = NULL; Epplet_gadget history_popup = NULL; char *command_history[MAX_HIST_LEN]; int current_command = 0; int num_commands = 0; +int save_history = TRUE, delete_history = FALSE; +Window config_win = None; static void cb_close(void *data); static void run_contents(void *data); static void change_textbox(void *data); +static void hist_last(void *data); +static void hist_next(void *data); +static void empty_popup(void); +static void fill_popup(void); +static void cb_ok(void *data); +static void cb_cancel(void *data); +static void cb_configure(void *data); static void cb_close(void *data) { - Epplet_cleanup(); - Epplet_unremember(); - exit(0); - data = NULL; + Epplet_cleanup(); + Epplet_unremember(); + exit(0); + data = NULL; } static void run_contents(void *data) { - char *command = Epplet_textbox_contents(textbox); - int i; + char *command = Epplet_textbox_contents(textbox); + int i; + int command_exists, num_results; + char **results; - if (command && strlen(command)) - { + if (!Epplet_popup_entry_get_data(history_popup, 0)) + Epplet_remove_popup_entry(history_popup, 0); - if (num_commands < MAX_HIST_LEN) - command_history[num_commands++] = strdup(command); - else - { - free(command_history[0]); - Epplet_remove_popup_entry(history_popup, 1); + if (command && strlen(command)) + { + command_exists = FALSE; + for (i = 0; i < num_commands; i++) + { + if (!strcmp(command_history[i], command)) + { + command_exists = TRUE; + } + } + if (!command_exists) + { + if (num_commands < MAX_HIST_LEN) + command_history[num_commands++] = strdup(command); + else + { + free(command_history[0]); + Epplet_remove_popup_entry(history_popup, 1); - for (i = 0; i < MAX_HIST_LEN; i++) + for (i = 0; i < MAX_HIST_LEN; i++) command_history[i] = command_history[i + 1]; - command_history[MAX_HIST_LEN - 1] = strdup(command); - } + command_history[MAX_HIST_LEN - 1] = strdup(command); + } - current_command = num_commands; + current_command = num_commands; - Epplet_add_popup_entry(history_popup, command, NULL, change_textbox, - strdup(command)); - Epplet_spawn_command(command); - Epplet_reset_textbox(textbox); - } + Epplet_add_popup_entry(history_popup, command, NULL, change_textbox, + strdup(command)); + } - return; - data = NULL; + if (save_history) + Epplet_modify_multi_config("Command", command_history, num_commands); + + Epplet_spawn_command(command); + Epplet_reset_textbox(textbox); + } + return; + data = NULL; } static void change_textbox(void *data) { - char *s = (char *)data; + char *s = (char *)data; - Epplet_change_textbox(textbox, s); + Epplet_change_textbox(textbox, s); } static void hist_last(void *data) { - if (current_command == 0) - { - current_command = num_commands; - Epplet_reset_textbox(textbox); - } - else - { - Epplet_change_textbox(textbox, command_history[--current_command]); - } + if (current_command == 0) + { + current_command = num_commands; + Epplet_reset_textbox(textbox); + } + else + { + Epplet_change_textbox(textbox, command_history[--current_command]); + } - return; - data = NULL; + return; + data = NULL; } static void hist_next(void *data) { - if (current_command == num_commands - 1) - { - current_command++; - Epplet_reset_textbox(textbox); - return; - } - else if (current_command >= num_commands) - { - current_command = 0; - } - else - { - current_command++; - } - Epplet_change_textbox(textbox, command_history[current_command]); + if (current_command == num_commands - 1) + { + current_command++; + Epplet_reset_textbox(textbox); + return; + } + else if (current_command >= num_commands) + { + current_command = 0; + } + else + { + current_command++; + } + Epplet_change_textbox(textbox, command_history[current_command]); - return; - data = NULL; + return; + data = NULL; +} + +static void +empty_popup(void) +{ + int i, num_popup_entries; + + num_popup_entries = Epplet_popup_entry_num(history_popup); + for (i = num_popup_entries; i > 0; i--) + { + Epplet_remove_popup_entry(history_popup, i - 1); + } + + for (i = 0; i < num_commands; i++) + { + free(command_history[i]); + command_history[i] = NULL; + } + num_commands = 0; + + if (atoi(Epplet_query_config_def("Save_History", "1"))) + Epplet_modify_multi_config("Command", command_history, num_commands); + + Epplet_add_popup_entry(history_popup, "-Empty-", NULL, NULL, NULL); + return; +} + +static void +fill_popup(void) +{ + int num_results, i; + char **results; + + results = Epplet_query_multi_config("Command", &num_results); + if (results) + { + for (i = 0; i < num_results; i++) + { + Epplet_add_popup_entry(history_popup, results[i], NULL, change_textbox, + strdup(results[i])); + command_history[i] = strdup(results[i]); + num_commands = i + 1; + } + } + else + Epplet_add_popup_entry(history_popup, "-Empty-", NULL, NULL, NULL); + + free(results); + return; +} + +static void +cb_ok(void *data) +{ + char buff[2]; + + Epplet_window_destroy(config_win); + config_win = None; + + if (delete_history) + empty_popup(); + + sprintf(buff, "%d", save_history); + Epplet_modify_config("Save_History", buff); + + return; + data = NULL; +} + +static void +cb_cancel(void *data) +{ + Epplet_window_destroy(config_win); + config_win = None; + return; + data = NULL; +} + +static void +cb_configure(void *data) +{ + if (config_win) + return; + + delete_history = FALSE; + config_win = Epplet_create_window_config(220, 60, "E-Exec Configuration", cb_ok, NULL, NULL, NULL, cb_cancel, NULL); + Epplet_gadget_show(Epplet_create_togglebutton(NULL, NULL, 6, 6, 12, 12, &save_history, NULL, NULL)); + Epplet_gadget_show(Epplet_create_label(22, 6, "Save command history?", 2)); + Epplet_gadget_show(Epplet_create_togglebutton(NULL, NULL, 6, 22, 12, 12, &delete_history, NULL, NULL)); + Epplet_gadget_show(Epplet_create_label(22, 22, "Empty command popup now?", 2)); + Epplet_window_show(config_win); + Epplet_window_pop_context(); + return; } int main(int argc, char *argv[]) { - atexit(Epplet_cleanup); + atexit(Epplet_cleanup); - if ((argc > 1) && (!strcmp("--proper-size", argv[1]))) - { - Epplet_Init(EPPLET_NAME, EPPLET_VERSION, EPPLET_INFO, 6, 3, argc, argv, - 0); + if ((argc > 1) && (!strcmp("--proper-size", argv[1]))) + { + Epplet_Init(EPPLET_NAME, EPPLET_VERSION, EPPLET_INFO, 6, 3, argc, argv, + 0); - Epplet_gadget_show(Epplet_create_label(-12, 2, "E-Exec", 2)); + Epplet_gadget_show(Epplet_create_label(-10, 2, "E-Exec", 2)); - textbox = - Epplet_create_textbox(NULL, NULL, 2, 32, 92, 14, 2, run_contents, - NULL); - } - else - { - Epplet_Init(EPPLET_NAME, EPPLET_VERSION, EPPLET_INFO, 5, 3, argc, argv, - 0); - Epplet_gadget_show(Epplet_create_label(-12, 2, "E-Exec", 2)); + textbox = + Epplet_create_textbox(NULL, NULL, 2, 32, 92, 14, 2, run_contents, + NULL); + } + else + { + Epplet_Init(EPPLET_NAME, EPPLET_VERSION, EPPLET_INFO, 5, 3, argc, argv, + 0); + Epplet_gadget_show(Epplet_create_label(-10, 2, "E-Exec", 2)); - textbox = - Epplet_create_textbox(NULL, NULL, 2, 32, 76, 14, 2, run_contents, - NULL); - } - Epplet_gadget_show(Epplet_create_button(NULL, NULL, 2, 2, - 12, 12, "CLOSE", 0, NULL, - cb_close, NULL)); + textbox = + Epplet_create_textbox(NULL, NULL, 2, 32, 76, 14, 2, run_contents, + NULL); + } - Epplet_gadget_show(Epplet_create_button(NULL, NULL, 2, 16, - 12, 12, "PREVIOUS", 0, NULL, - hist_last, NULL)); + Epplet_load_config(); - Epplet_gadget_show(Epplet_create_button(NULL, NULL, 16, 16, - 12, 12, "NEXT", 0, NULL, - hist_next, NULL)); + save_history = atoi(Epplet_query_config_def("Save_History", "1")); - Epplet_gadget_show(Epplet_create_button(NULL, NULL, 60, 16, - 12, 12, "PLAY", 0, NULL, - run_contents, NULL)); + Epplet_gadget_show(Epplet_create_button(NULL, NULL, 2, 2, + 12, 12, "CLOSE", 0, NULL, + cb_close, NULL)); - history_popup = Epplet_create_popup(); - Epplet_add_popup_entry(history_popup, "-NeverMind-", NULL, NULL, NULL); + Epplet_gadget_show(Epplet_create_button(NULL, NULL, 16, 2, + 12, 12, "CONFIGURE", 0, NULL, + cb_configure, NULL)); - Epplet_gadget_show(Epplet_create_popupbutton(NULL, NULL, 30, 16, - 12, 12, "ARROW_UP", - history_popup)); + Epplet_gadget_show(Epplet_create_button(NULL, NULL, 2, 16, + 12, 12, "PREVIOUS", 0, NULL, + hist_last, NULL)); - Epplet_gadget_show(textbox); + Epplet_gadget_show(Epplet_create_button(NULL, NULL, 16, 16, + 12, 12, "NEXT", 0, NULL, + hist_next, NULL)); - Epplet_show(); - Epplet_Loop(); - return 0; + Epplet_gadget_show(Epplet_create_button(NULL, NULL, 60, 16, + 12, 12, "PLAY", 0, NULL, + run_contents, NULL)); + + history_popup = Epplet_create_popup(); + fill_popup(); + + Epplet_gadget_show(Epplet_create_popupbutton(NULL, NULL, 30, 16, + 12, 12, "ARROW_UP", + history_popup)); + + Epplet_gadget_show(textbox); + + Epplet_show(); + Epplet_Loop(); + return 0; } diff --git a/epplets/icons/E-Exec.icon b/epplets/icons/E-Exec.icon new file mode 100644 index 0000000..c6c38d1 Binary files /dev/null and b/epplets/icons/E-Exec.icon differ