Revision: 1036 http://svn.sourceforge.net/geany/?rev=1036&view=rev Author: ntrel Date: 2006-11-29 02:29:34 -0800 (Wed, 29 Nov 2006)
Log Message: ----------- Make stop button only apply for killing running programs. Disable build commands when building is in progress. Make build_menu_update() detect how to call set_stop_button(). Make build_menu_update() also update the LaTeX build menu. Make build keybindings only active when the equivalent menu item is also active.
Modified Paths: -------------- trunk/ChangeLog trunk/src/build.c trunk/src/build.h trunk/src/filetypes.c trunk/src/filetypes.h trunk/src/keybindings.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2006-11-28 20:04:20 UTC (rev 1035) +++ trunk/ChangeLog 2006-11-29 10:29:34 UTC (rev 1036) @@ -1,3 +1,15 @@ +2006-11-29 Nick Treleaven nick.treleaven@btinternet.com + + * src/build.c, src/build.h, src/keybindings.c, src/filetypes.c, + src/filetypes.h: + Make stop button only apply for killing running programs. + Disable build commands when building is in progress. + Make build_menu_update() detect how to call set_stop_button(). + Make build_menu_update() also update the LaTeX build menu. + Make build keybindings only active when the equivalent menu item + is also active. + + 2006-11-27 Nick Treleaven nick.treleaven@btinternet.com
* src/build.c:
Modified: trunk/src/build.c =================================================================== --- trunk/src/build.c 2006-11-28 20:04:20 UTC (rev 1035) +++ trunk/src/build.c 2006-11-29 10:29:34 UTC (rev 1036) @@ -48,6 +48,12 @@
BuildInfo build_info = {GBO_COMPILE, 0, NULL, GEANY_FILETYPES_ALL, NULL};
+static struct +{ + GPid pid; + gint file_type_id; +} run_info = {0, GEANY_FILETYPES_ALL}; + enum { LATEX_CMD_TO_DVI, @@ -65,9 +71,11 @@ static void on_make_target_entry_activate(GtkEntry *entry, gpointer user_data); static void set_stop_button(gboolean stop); static void build_exit_cb(GPid child_pid, gint status, gpointer user_data); +static void run_exit_cb(GPid child_pid, gint status, gpointer user_data); static void free_pointers(gpointer first, ...); + #ifndef G_OS_WIN32 -static void kill_process(gint pid); +static void kill_process(GPid *pid); #endif
void build_finalize() @@ -116,8 +124,7 @@
if (idx < 0 || doc_list[idx].file_name == NULL) return (GPid) 1;
- build_info.file_type_id = GEANY_FILETYPES_LATEX; - build_info.type = GBO_RUN; + run_info.file_type_id = GEANY_FILETYPES_LATEX;
#ifdef G_OS_WIN32 script_name = g_strdup("./geany_run_script.bat"); @@ -206,7 +213,7 @@
if (! g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, - NULL, NULL, &(build_info.pid), NULL, NULL, NULL, &error)) + NULL, NULL, &(run_info.pid), NULL, NULL, NULL, &error)) { geany_debug("g_spawn_async_with_pipes() failed: %s", error->message); msgwin_status_add(_("Process failed (%s)"), error->message); @@ -220,11 +227,11 @@ return (GPid) 0; }
- if (build_info.pid > 0) + if (run_info.pid > 0) { //setpgid(0, getppid()); - g_child_watch_add(build_info.pid, (GChildWatchFunc) build_exit_cb, NULL); - set_stop_button(TRUE); + g_child_watch_add(run_info.pid, (GChildWatchFunc) run_exit_cb, NULL); + build_menu_update(idx); }
free_pointers(executable, view_file, locale_filename, cmd_string, locale_cmd_string, @@ -232,7 +239,7 @@ g_strfreev(argv); g_strfreev(term_argv);
- return build_info.pid; + return run_info.pid; }
@@ -439,7 +446,7 @@ if (build_info.pid > 0) { g_child_watch_add(build_info.pid, (GChildWatchFunc) build_exit_cb, NULL); - set_stop_button(TRUE); + build_menu_update(idx); }
// use GIOChannels to monitor stdout and stderr @@ -479,8 +486,7 @@
if (! DOC_IDX_VALID(idx) || doc_list[idx].file_name == NULL) return (GPid) 1;
- build_info.file_type_id = FILETYPE_ID(doc_list[idx].file_type); - build_info.type = GBO_RUN; + run_info.file_type_id = FILETYPE_ID(doc_list[idx].file_type);
#ifdef G_OS_WIN32 script_name = g_strdup("./geany_run_script.bat"); @@ -599,7 +605,7 @@ argv[term_argv_len + 2] = NULL;
if (! g_spawn_async_with_pipes(working_dir, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, - NULL, NULL, &(build_info.pid), NULL, NULL, NULL, &error)) + NULL, NULL, &(run_info.pid), NULL, NULL, NULL, &error)) { geany_debug("g_spawn_async_with_pipes() failed: %s", error->message); msgwin_status_add(_("Process failed (%s)"), error->message); @@ -610,11 +616,11 @@ goto free_strings; }
- result_id = build_info.pid; // g_spawn was successful, result is child process id - if (build_info.pid > 0) + result_id = run_info.pid; // g_spawn was successful, result is child process id + if (run_info.pid > 0) { - g_child_watch_add(build_info.pid, (GChildWatchFunc) build_exit_cb, NULL); - set_stop_button(TRUE); + g_child_watch_add(run_info.pid, (GChildWatchFunc) run_exit_cb, NULL); + build_menu_update(idx); }
free_strings: @@ -705,35 +711,42 @@
static void build_exit_cb(GPid child_pid, gint status, gpointer user_data) { - if (build_info.type != GBO_RUN) // not necessary when executing a file - { #ifdef G_OS_UNIX - gboolean failure = FALSE; + gboolean failure = FALSE;
- if (WIFEXITED(status)) - { - if (WEXITSTATUS(status) != EXIT_SUCCESS) - failure = TRUE; - } - else if (WIFSIGNALED(status)) - { - // the terminating signal: WTERMSIG (status)); + if (WIFEXITED(status)) + { + if (WEXITSTATUS(status) != EXIT_SUCCESS) failure = TRUE; - } - else - { // any other failure occured - failure = TRUE; - } - show_build_result_message(failure); + } + else if (WIFSIGNALED(status)) + { + // the terminating signal: WTERMSIG (status)); + failure = TRUE; + } + else + { // any other failure occured + failure = TRUE; + } + show_build_result_message(failure); #endif - }
- if (build_info.type != GBO_RUN) utils_beep(); + utils_beep(); g_spawn_close_pid(child_pid);
build_info.pid = 0; + // enable build items again + build_menu_update(-1); +} + + +static void run_exit_cb(GPid child_pid, gint status, gpointer user_data) +{ + g_spawn_close_pid(child_pid); + + run_info.pid = 0; // reset the stop button and menu item to the original meaning - set_stop_button(FALSE); + build_menu_update(-1); }
@@ -922,6 +935,7 @@ gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image); g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_tex_activate), GINT_TO_POINTER(LATEX_CMD_TO_DVI)); + ft->menu_items->item_compile = item;
// PDF item = gtk_image_menu_item_new_with_mnemonic(_("LaTeX -> PDF")); @@ -936,6 +950,7 @@ gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image); g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_tex_activate), GINT_TO_POINTER(LATEX_CMD_TO_PDF)); + ft->menu_items->item_link = item;
if (item != NULL) { @@ -1003,6 +1018,7 @@ gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image); g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_execute_activate), GINT_TO_POINTER(LATEX_CMD_VIEW_PDF)); + ft->menu_items->item_exec2 = item;
// separator separator = gtk_separator_menu_item_new(); @@ -1022,7 +1038,8 @@ image = gtk_image_new_from_stock("gtk-preferences", GTK_ICON_SIZE_MENU); gtk_widget_show(image); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image); - g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_tex_arguments_activate), NULL); + g_signal_connect((gpointer) item, "activate", + G_CALLBACK(on_build_arguments_activate), ft);
gtk_window_add_accel_group(GTK_WINDOW(app->window), accel_group);
@@ -1045,9 +1062,13 @@ void build_menu_update(gint idx) { filetype *ft; - gboolean have_path; + gboolean have_path, can_build, can_make;
- if (idx == -1 || doc_list[idx].file_type == NULL) + if (idx == -1) + idx = document_get_cur_idx(); + if (idx == -1 || + (FILETYPE_ID(doc_list[idx].file_type) == GEANY_FILETYPES_ALL && + doc_list[idx].file_name == NULL)) { gtk_widget_set_sensitive(lookup_widget(app->window, "menu_build1"), FALSE); gtk_menu_item_remove_submenu(GTK_MENU_ITEM(lookup_widget(app->window, "menu_build1"))); @@ -1066,61 +1087,107 @@ ft->menu_items->can_link = FALSE; #endif
- gtk_menu_item_remove_submenu(GTK_MENU_ITEM(lookup_widget(app->window, "menu_build1"))); - if (ft->menu_items->menu == NULL) { ft->menu_items->menu = (ft->id == GEANY_FILETYPES_LATEX) ? create_build_menu_tex() : create_build_menu_gen(idx); g_object_ref((gpointer)ft->menu_items->menu); // to hold it after removing } + /* Note: don't remove the submenu first because it can now cause an X hang if + * the menu is already open when called from build_exit_cb(). */ gtk_menu_item_set_submenu(GTK_MENU_ITEM(lookup_widget(app->window, "menu_build1")), ft->menu_items->menu);
have_path = (doc_list[idx].file_name != NULL); - // update the Make items - if (ft->menu_items->item_make_all != NULL) - gtk_widget_set_sensitive(ft->menu_items->item_make_all, have_path); - if (ft->menu_items->item_make_custom != NULL) - gtk_widget_set_sensitive(ft->menu_items->item_make_custom, have_path); - if (ft->menu_items->item_make_object != NULL) - gtk_widget_set_sensitive(ft->menu_items->item_make_object, have_path);
- switch (ft->id) + can_make = have_path && build_info.pid <= 1; + + // disable compile and link for C/C++ header files + if (ft->id == GEANY_FILETYPES_C || ft->id == GEANY_FILETYPES_CPP) + can_build = can_make && ! is_c_header(doc_list[idx].file_name); + else + can_build = can_make; + + if (ft->menu_items->can_compile) + gtk_widget_set_sensitive(ft->menu_items->item_compile, can_build); + if (ft->menu_items->can_link) + gtk_widget_set_sensitive(ft->menu_items->item_link, can_build); + if (ft->menu_items->item_make_all) + gtk_widget_set_sensitive(ft->menu_items->item_make_all, can_make); + if (ft->menu_items->item_make_custom) + gtk_widget_set_sensitive(ft->menu_items->item_make_custom, can_make); + if (ft->menu_items->item_make_object) + gtk_widget_set_sensitive(ft->menu_items->item_make_object, can_make); + if (ft->menu_items->can_exec) { - case GEANY_FILETYPES_LATEX: + gboolean can_run = have_path && run_info.pid <= 1; + + /* can_run only applies item_exec2 + * item_exec is enabled for both run and stop commands */ + if (ft->menu_items->item_exec) + gtk_widget_set_sensitive(ft->menu_items->item_exec, have_path); + if (ft->menu_items->item_exec2) + gtk_widget_set_sensitive(ft->menu_items->item_exec2, can_run); + } + + gtk_widget_set_sensitive(app->compile_button, can_build && ft->menu_items->can_compile); + gtk_widget_set_sensitive(app->run_button, have_path && ft->menu_items->can_exec); + + // show the stop command if a program is running, otherwise show run command + set_stop_button(run_info.pid > 1); +} + + +// Call build_menu_update() instead of calling this directly. +static void set_stop_button(gboolean stop) +{ + GtkStockItem sitem; + GtkWidget *menuitem = + filetypes[run_info.file_type_id]->menu_items->item_exec; + + if (stop && utils_str_equal( + gtk_tool_button_get_stock_id(GTK_TOOL_BUTTON(app->run_button)), "gtk-stop")) return; + if (! stop && utils_str_equal( + gtk_tool_button_get_stock_id(GTK_TOOL_BUTTON(app->run_button)), "gtk-execute")) return; + + // use the run button also as stop button + if (stop) + { + gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(app->run_button), "gtk-stop"); + + if (menuitem != NULL) { - gtk_widget_set_sensitive(app->compile_button, have_path && ft->menu_items->can_compile); - gtk_widget_set_sensitive(app->run_button, have_path && ft->menu_items->can_exec); - break; + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), + gtk_image_new_from_stock("gtk-stop", GTK_ICON_SIZE_MENU)); + gtk_stock_lookup("gtk-stop", &sitem); + gtk_label_set_text_with_mnemonic(GTK_LABEL(gtk_bin_get_child(GTK_BIN(menuitem))), + sitem.label); } - case GEANY_FILETYPES_C: // intended fallthrough, C and C++ behave equal - case GEANY_FILETYPES_CPP: + } + else + { + gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(app->run_button), "gtk-execute"); + + if (menuitem != NULL) { - if (ft->menu_items->can_exec) - gtk_widget_set_sensitive(ft->menu_items->item_exec, have_path); - gtk_widget_set_sensitive(app->run_button, have_path && ft->menu_items->can_exec); + // LaTeX hacks ;-( + if (run_info.file_type_id == GEANY_FILETYPES_LATEX) + { + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), + gtk_image_new_from_stock("gtk-find", GTK_ICON_SIZE_MENU)); + gtk_label_set_text_with_mnemonic(GTK_LABEL(gtk_bin_get_child(GTK_BIN(menuitem))), + LATEX_VIEW_DVI_LABEL); + } + else + { + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), + gtk_image_new_from_stock("gtk-execute", GTK_ICON_SIZE_MENU));
- // compile and link are disabled for header files - have_path = have_path && ! is_c_header(doc_list[idx].file_name); - gtk_widget_set_sensitive(app->compile_button, have_path && ft->menu_items->can_compile); - if (ft->menu_items->can_compile) - gtk_widget_set_sensitive(ft->menu_items->item_compile, have_path); - if (ft->menu_items->can_link) - gtk_widget_set_sensitive(ft->menu_items->item_link, have_path); - break; + gtk_stock_lookup("gtk-execute", &sitem); + gtk_label_set_text_with_mnemonic(GTK_LABEL(gtk_bin_get_child(GTK_BIN(menuitem))), + sitem.label); + } } - default: - { - gtk_widget_set_sensitive(app->compile_button, have_path && ft->menu_items->can_compile); - gtk_widget_set_sensitive(app->run_button, have_path && ft->menu_items->can_exec); - if (ft->menu_items->can_compile) - gtk_widget_set_sensitive(ft->menu_items->item_compile, have_path); - if (ft->menu_items->can_link) - gtk_widget_set_sensitive(ft->menu_items->item_link, have_path); - if (ft->menu_items->can_exec) - gtk_widget_set_sensitive(ft->menu_items->item_exec, have_path); - } } }
@@ -1219,11 +1286,11 @@ gint idx = document_get_cur_idx();
// make the process "stopable" - if (build_info.pid > (GPid) 1) + if (run_info.pid > (GPid) 1) { // on Windows there is no PID returned (resp. it is a handle), currently unsupported #ifndef G_OS_WIN32 - kill_process(build_info.pid); + kill_process(&run_info.pid); #endif return; } @@ -1261,18 +1328,13 @@ on_build_arguments_activate (GtkMenuItem *menuitem, gpointer user_data) { - dialogs_show_includes_arguments_gen(); + if (user_data && FILETYPE_ID((filetype*) user_data) == GEANY_FILETYPES_LATEX) + dialogs_show_includes_arguments_tex(); + else + dialogs_show_includes_arguments_gen(); }
-void -on_build_tex_arguments_activate (GtkMenuItem *menuitem, - gpointer user_data) -{ - dialogs_show_includes_arguments_tex(); -} - - static void on_make_target_dialog_response (GtkDialog *dialog, gint response, @@ -1301,57 +1363,8 @@ }
-static void set_stop_button(gboolean stop) -{ - GtkStockItem sitem; - GtkWidget *menuitem = - filetypes[build_info.file_type_id]->menu_items->item_exec; - - // use the run button also as stop button - if (stop) - { - gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(app->run_button), "gtk-stop"); - gtk_widget_set_sensitive(app->compile_button, FALSE); - if (menuitem != NULL) - { - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), - gtk_image_new_from_stock("gtk-stop", GTK_ICON_SIZE_MENU)); - gtk_stock_lookup("gtk-stop", &sitem); - gtk_label_set_text_with_mnemonic(GTK_LABEL(gtk_bin_get_child(GTK_BIN(menuitem))), - sitem.label); - } - } - else - { - gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(app->run_button), "gtk-execute"); - gtk_widget_set_sensitive(app->compile_button, TRUE); - - if (menuitem != NULL) - { - // LaTeX hacks ;-( - if (build_info.file_type_id == GEANY_FILETYPES_LATEX) - { - gtk_label_set_text_with_mnemonic(GTK_LABEL(gtk_bin_get_child(GTK_BIN(menuitem))), - LATEX_VIEW_DVI_LABEL); - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), - gtk_image_new_from_stock("gtk-find", GTK_ICON_SIZE_MENU)); - } - else - { - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), - gtk_image_new_from_stock("gtk-execute", GTK_ICON_SIZE_MENU)); - - gtk_stock_lookup("gtk-execute", &sitem); - gtk_label_set_text_with_mnemonic(GTK_LABEL(gtk_bin_get_child(GTK_BIN(menuitem))), - sitem.label); - } - } - } -} - - #ifndef G_OS_WIN32 -static void kill_process(gint pid) +static void kill_process(GPid *pid) { /* SIGQUIT is not the best signal to use because it causes a core dump (this should not * perforce necessary for just killing a process). But we must use a signal which we can @@ -1360,15 +1373,15 @@ gint resultpg, result;
// sent SIGQUIT to all the processes to the processes' own process group - result = kill(pid, SIGQUIT); + result = kill(*pid, SIGQUIT); resultpg = killpg(0, SIGQUIT);
if (result != 0 || resultpg != 0) msgwin_status_add(_("Process could not be stopped (%s)."), g_strerror(errno)); else { - build_info.pid = 0; - set_stop_button(FALSE); + *pid = 0; + build_menu_update(-1); } } #endif
Modified: trunk/src/build.h =================================================================== --- trunk/src/build.h 2006-11-28 20:04:20 UTC (rev 1035) +++ trunk/src/build.h 2006-11-29 10:29:34 UTC (rev 1036) @@ -30,8 +30,7 @@ GBO_BUILD, GBO_MAKE_ALL, GBO_MAKE_CUSTOM, - GBO_MAKE_OBJECT, - GBO_RUN + GBO_MAKE_OBJECT } build_type;
typedef struct @@ -87,8 +86,4 @@ on_build_arguments_activate (GtkMenuItem *menuitem, gpointer user_data);
-void -on_build_tex_arguments_activate (GtkMenuItem *menuitem, - gpointer user_data); - #endif
Modified: trunk/src/filetypes.c =================================================================== --- trunk/src/filetypes.c 2006-11-28 20:04:20 UTC (rev 1035) +++ trunk/src/filetypes.c 2006-11-29 10:29:34 UTC (rev 1036) @@ -867,20 +867,7 @@ if (filetypes[i]->menu_items->menu != NULL && GTK_IS_WIDGET(filetypes[i]->menu_items->menu)) gtk_widget_destroy(filetypes[i]->menu_items->menu); - /// TODO not necessary because they got freed with the menu? -/* if (filetypes[i]->menu_items->item_compile != NULL && - GTK_IS_WIDGET(filetypes[i]->menu_items->item_compile)) - gtk_widget_destroy(filetypes[i]->menu_items->item_compile); - if (filetypes[i]->menu_items->item_link != NULL && - GTK_IS_WIDGET(filetypes[i]->menu_items->item_link)) - gtk_widget_destroy(filetypes[i]->menu_items->item_link); - if (filetypes[i]->menu_items->item_exec != NULL && - GTK_IS_WIDGET(filetypes[i]->menu_items->item_exec)) - gtk_widget_destroy(filetypes[i]->menu_items->item_exec); - if (filetypes[i]->menu_items->item_make_object != NULL && - GTK_IS_WIDGET(filetypes[i]->menu_items->item_make_object)) - gtk_widget_destroy(filetypes[i]->menu_items->item_make_object); -*/ g_free(filetypes[i]->menu_items); + g_free(filetypes[i]->menu_items);
g_strfreev(filetypes[i]->pattern); g_free(filetypes[i]);
Modified: trunk/src/filetypes.h =================================================================== --- trunk/src/filetypes.h 2006-11-28 20:04:20 UTC (rev 1035) +++ trunk/src/filetypes.h 2006-11-29 10:29:34 UTC (rev 1036) @@ -75,6 +75,7 @@ GtkWidget *item_compile; GtkWidget *item_link; GtkWidget *item_exec; + GtkWidget *item_exec2; GtkWidget *item_make_all; GtkWidget *item_make_custom; GtkWidget *item_make_object;
Modified: trunk/src/keybindings.c =================================================================== --- trunk/src/keybindings.c 2006-11-28 20:04:20 UTC (rev 1035) +++ trunk/src/keybindings.c 2006-11-29 10:29:34 UTC (rev 1036) @@ -74,13 +74,7 @@ static void cb_func_menu_replacetabs(guint key_id); static void cb_func_menu_foldall(guint key_id); static void cb_func_menu_unfoldall(guint key_id); -static void cb_func_build_compile(guint key_id); -static void cb_func_build_link(guint key_id); -static void cb_func_build_make(guint key_id); -static void cb_func_build_makeowntarget(guint key_id); -static void cb_func_build_makeobject(guint key_id); -static void cb_func_build_run(guint key_id); -static void cb_func_build_run2(guint key_id); +static void cb_func_build_action(guint key_id); static void cb_func_build_options(guint key_id); static void cb_func_reloadtaglist(guint key_id); static void cb_func_switch_editor(guint key_id); @@ -163,20 +157,20 @@ 0, 0, "menu_foldall", _("Fold all")); keys[GEANY_KEYS_MENU_UNFOLDALL] = fill(cb_func_menu_unfoldall, 0, 0, "menu_unfoldall", _("Unfold all")); - keys[GEANY_KEYS_BUILD_COMPILE] = fill(cb_func_build_compile, + keys[GEANY_KEYS_BUILD_COMPILE] = fill(cb_func_build_action, GDK_F8, 0, "build_compile", _("Compile")); - keys[GEANY_KEYS_BUILD_LINK] = fill(cb_func_build_link, + keys[GEANY_KEYS_BUILD_LINK] = fill(cb_func_build_action, GDK_F9, 0, "build_link", _("Build")); - keys[GEANY_KEYS_BUILD_MAKE] = fill(cb_func_build_make, + keys[GEANY_KEYS_BUILD_MAKE] = fill(cb_func_build_action, GDK_F9, GDK_SHIFT_MASK, "build_make", _("Make all")); - keys[GEANY_KEYS_BUILD_MAKEOWNTARGET] = fill(cb_func_build_makeowntarget, + keys[GEANY_KEYS_BUILD_MAKEOWNTARGET] = fill(cb_func_build_action, GDK_F9, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "build_makeowntarget", _("Make custom target")); - keys[GEANY_KEYS_BUILD_MAKEOBJECT] = fill(cb_func_build_makeobject, + keys[GEANY_KEYS_BUILD_MAKEOBJECT] = fill(cb_func_build_action, 0, 0, "build_makeobject", _("Make object")); - keys[GEANY_KEYS_BUILD_RUN] = fill(cb_func_build_run, + keys[GEANY_KEYS_BUILD_RUN] = fill(cb_func_build_action, GDK_F5, 0, "build_run", _("Run")); - keys[GEANY_KEYS_BUILD_RUN2] = fill(cb_func_build_run2, + keys[GEANY_KEYS_BUILD_RUN2] = fill(cb_func_build_action, 0, 0, "build_run2", _("Run (alternative command)")); keys[GEANY_KEYS_BUILD_OPTIONS] = fill(cb_func_build_options, 0, 0, "build_options", _("Build options")); @@ -571,71 +565,70 @@ document_unfold_all(idx); }
-static void cb_func_build_compile(G_GNUC_UNUSED guint key_id) +static void cb_func_build_action(guint key_id) { gint idx = document_get_cur_idx(); - if (idx == -1 || ! doc_list[idx].is_valid) return; - if (doc_list[idx].file_type->menu_items->can_compile && doc_list[idx].file_name != NULL) - on_build_compile_activate(NULL, NULL); -} + GtkWidget *item; + filetype *ft;
-static void cb_func_build_link(G_GNUC_UNUSED guint key_id) -{ - gint idx = document_get_cur_idx(); - if (idx == -1 || ! doc_list[idx].is_valid) return; - if (doc_list[idx].file_type->menu_items->can_link && doc_list[idx].file_name != NULL) - on_build_build_activate(NULL, NULL); -} + if (! DOC_IDX_VALID(idx)) return;
-static void cb_func_build_make(G_GNUC_UNUSED guint key_id) -{ - gint idx = document_get_cur_idx(); - if (idx == -1 || ! doc_list[idx].is_valid) return; - if (doc_list[idx].file_name != NULL) - on_build_make_activate(NULL, GINT_TO_POINTER(GBO_MAKE_ALL)); -} + ft = doc_list[idx].file_type; + if (! ft || ! ft->menu_items) return;
-static void cb_func_build_makeowntarget(G_GNUC_UNUSED guint key_id) -{ - gint idx = document_get_cur_idx(); - if (idx == -1 || ! doc_list[idx].is_valid) return; - if (doc_list[idx].file_name != NULL) - on_build_make_activate(NULL, GINT_TO_POINTER(GBO_MAKE_CUSTOM)); -} + switch (key_id) + { + case GEANY_KEYS_BUILD_COMPILE: + item = ft->menu_items->item_compile; + break;
-static void cb_func_build_makeobject(G_GNUC_UNUSED guint key_id) -{ - gint idx = document_get_cur_idx(); - if (idx == -1 || ! doc_list[idx].is_valid) return; - if (doc_list[idx].file_name != NULL) - on_build_make_activate(NULL, GINT_TO_POINTER(GBO_MAKE_OBJECT)); -} + case GEANY_KEYS_BUILD_LINK: + item = ft->menu_items->item_link; + break;
-static void cb_func_build_run(G_GNUC_UNUSED guint key_id) -{ - gint idx = document_get_cur_idx(); - if (idx == -1 || ! doc_list[idx].is_valid) return; - if (doc_list[idx].file_type->menu_items->can_exec && doc_list[idx].file_name != NULL) - on_build_execute_activate(NULL, GINT_TO_POINTER(0)); -} + case GEANY_KEYS_BUILD_MAKE: + item = ft->menu_items->item_make_all; + break;
-static void cb_func_build_run2(G_GNUC_UNUSED guint key_id) -{ - gint idx = document_get_cur_idx(); - if (idx == -1 || ! doc_list[idx].is_valid) return; - if (doc_list[idx].file_type->menu_items->can_exec && doc_list[idx].file_name != NULL) - on_build_execute_activate(NULL, GINT_TO_POINTER(1)); + case GEANY_KEYS_BUILD_MAKEOWNTARGET: + item = ft->menu_items->item_make_custom; + break; + + case GEANY_KEYS_BUILD_MAKEOBJECT: + item = ft->menu_items->item_make_object; + break; + + case GEANY_KEYS_BUILD_RUN: + item = ft->menu_items->item_exec; + break; + + case GEANY_KEYS_BUILD_RUN2: + item = ft->menu_items->item_exec2; + break; + + default: + item = NULL; + } + if (item && GTK_WIDGET_IS_SENSITIVE(item)) + gtk_menu_item_activate(GTK_MENU_ITEM(item)); }
static void cb_func_build_options(G_GNUC_UNUSED guint key_id) { gint idx = document_get_cur_idx(); - if (idx == -1 || ! doc_list[idx].is_valid) return; - if ((doc_list[idx].file_type->menu_items->can_compile || - doc_list[idx].file_type->menu_items->can_link || - doc_list[idx].file_type->menu_items->can_exec) && - doc_list[idx].file_name != NULL) - on_build_arguments_activate(NULL, NULL); + document *doc; + filetype *ft; + + if (! DOC_IDX_VALID(idx)) return; + doc = &doc_list[idx]; + ft = doc->file_type; + if (! ft || ! ft->menu_items) return; + if ((ft->menu_items->can_compile || + ft->menu_items->can_link || + ft->menu_items->can_exec) && + (doc->file_name != NULL || + FILETYPE_ID(ft) != GEANY_FILETYPES_ALL)) + on_build_arguments_activate(NULL, ft); }
static void cb_func_reloadtaglist(G_GNUC_UNUSED guint key_id)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.