Hello, I write a patch to migrate the pop-up-menu from GtkItemFactory (witch is deprecated since Gtk 2.4) to GtkUIManager.
Why don't use GtkUIManager and GtkAction to manage the menubar toolbar and accelerator. This permit to use CheckMenuItem (ex : to active rubber-band and magnetic net) and RadioMenuItem (ex : to select colour theme) in the menu. -- Camille Delbegue
diff --git a/gschem/include/globals.h b/gschem/include/globals.h index 8fbeb75..38c81d4 100644 --- a/gschem/include/globals.h +++ b/gschem/include/globals.h @@ -88,12 +88,6 @@ extern SCM new_page_hook; #define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__) #endif /* GCC_VERSION */ -#if GCC_VERSION > 2007 -#define ATTRIBUTE_UNUSED __attribute__((unused)) -#else -#define ATTRIBUTE_UNUSED -#endif - /*EK* used by prototype.h */ #include "../include/x_states.h" diff --git a/gschem/include/gschem_struct.h b/gschem/include/gschem_struct.h index c4754cf..b453c88 100644 --- a/gschem/include/gschem_struct.h +++ b/gschem/include/gschem_struct.h @@ -12,6 +12,9 @@ struct st_gschem_toplevel { /* main window widgets */ /* ------------------- */ GtkWidget *main_window; + + GtkUIManager *ui_manager; + GtkActionGroup *action_group; GtkWidget *drawing_area; GtkWidget *menubar; diff --git a/gschem/include/prototype.h b/gschem/include/prototype.h index 5948c74..2ec8900 100644 --- a/gschem/include/prototype.h +++ b/gschem/include/prototype.h @@ -321,17 +321,17 @@ void i_callback_edit_undo(gpointer data, guint callback_action, GtkWidget *widge void i_callback_toolbar_edit_undo(GtkWidget *widget, gpointer data); void i_callback_edit_redo(gpointer data, guint callback_action, GtkWidget *widget); void i_callback_toolbar_edit_redo(GtkWidget *widget, gpointer data); -void i_callback_edit_select(gpointer data, guint callback_action, GtkWidget *widget); +void i_callback_edit_select(GtkAction *action, gpointer data); void i_callback_toolbar_edit_select(GtkWidget *widget, gpointer data); -void i_callback_edit_copy(gpointer data, guint callback_action, GtkWidget *widget); +void i_callback_edit_copy(GtkAction *action, gpointer data); void i_callback_edit_copy_hotkey(gpointer data, guint callback_action, GtkWidget *widget); void i_callback_edit_mcopy(gpointer data, guint callback_action, GtkWidget *widget); void i_callback_edit_mcopy_hotkey(gpointer data, guint callback_action, GtkWidget *widget); -void i_callback_edit_move(gpointer data, guint callback_action, GtkWidget *widget); +void i_callback_edit_move(GtkAction *action, gpointer data); void i_callback_edit_move_hotkey(gpointer data, guint callback_action, GtkWidget *widget); -void i_callback_edit_delete(gpointer data, guint callback_action, GtkWidget *widget); -void i_callback_edit_edit(gpointer data, guint callback_action, GtkWidget *widget); -void i_callback_edit_pin_type(gpointer data, guint callback_action, GtkWidget *widget); +void i_callback_edit_delete(GtkAction *action, gpointer data); +void i_callback_edit_edit(GtkAction *action, gpointer data); +void i_callback_edit_pin_type(GtkAction *action, gpointer data); void i_callback_edit_text(gpointer data, guint callback_action, GtkWidget *widget); void i_callback_edit_slot(gpointer data, guint callback_action, GtkWidget *widget); void i_callback_edit_color(gpointer data, guint callback_action, GtkWidget *widget); @@ -355,12 +355,12 @@ void i_callback_edit_autonumber_text(gpointer data, guint callback_action, GtkWi void i_callback_edit_linetype(gpointer data, guint callback_action, GtkWidget *widget); void i_callback_edit_filltype(gpointer data, guint callback_action, GtkWidget *widget); void i_callback_view_redraw(gpointer data, guint callback_action, GtkWidget *widget); -void i_callback_view_zoom_full(gpointer data, guint callback_action, GtkWidget *widget); -void i_callback_view_zoom_extents(gpointer data, guint callback_action, GtkWidget *widget); -void i_callback_view_zoom_box(gpointer data, guint callback_action, GtkWidget *widget); +void i_callback_view_zoom_full(GtkAction *action, gpointer data); +void i_callback_view_zoom_extents(GtkAction *action, gpointer data); +void i_callback_view_zoom_box(GtkAction *action, gpointer data); void i_callback_view_zoom_box_hotkey(gpointer data, guint callback_action, GtkWidget *widget); -void i_callback_view_zoom_in(gpointer data, guint callback_action, GtkWidget *widget); -void i_callback_view_zoom_out(gpointer data, guint callback_action, GtkWidget *widget); +void i_callback_view_zoom_in(GtkAction *action, gpointer data); +void i_callback_view_zoom_out(GtkAction *action, gpointer data); void i_callback_view_zoom_in_hotkey(gpointer data, guint callback_action, GtkWidget *widget); void i_callback_view_zoom_out_hotkey(gpointer data, guint callback_action, GtkWidget *widget); void i_callback_view_pan(gpointer data, guint callback_action, GtkWidget *widget); @@ -404,17 +404,17 @@ void i_callback_buffer_paste2_hotkey(gpointer data, guint callback_action, GtkWi void i_callback_buffer_paste3_hotkey(gpointer data, guint callback_action, GtkWidget *widget); void i_callback_buffer_paste4_hotkey(gpointer data, guint callback_action, GtkWidget *widget); void i_callback_buffer_paste5_hotkey(gpointer data, guint callback_action, GtkWidget *widget); -void i_callback_add_component(gpointer data, guint callback_action, GtkWidget *widget); +void i_callback_add_component(GtkAction *action, gpointer data); void i_callback_toolbar_add_component(GtkWidget *widget, gpointer data); -void i_callback_add_attribute(gpointer data, guint callback_action, GtkWidget *widget); +void i_callback_add_attribute(GtkAction *action, gpointer data); void i_callback_add_attribute_hotkey(gpointer data, guint callback_action, GtkWidget *widget); -void i_callback_add_net(gpointer data, guint callback_action, GtkWidget *widget); +void i_callback_add_net(GtkAction *action, gpointer data); void i_callback_add_net_hotkey(gpointer data, guint callback_action, GtkWidget *widget); void i_callback_toolbar_add_net(GtkWidget *widget, gpointer data); -void i_callback_add_bus(gpointer data, guint callback_action, GtkWidget *widget); +void i_callback_add_bus(GtkAction *action, gpointer data); void i_callback_add_bus_hotkey(gpointer data, guint callback_action, GtkWidget *widget); void i_callback_toolbar_add_bus(GtkWidget *widget, gpointer data); -void i_callback_add_text(gpointer data, guint callback_action, GtkWidget *widget); +void i_callback_add_text(GtkAction *action, gpointer data); void i_callback_toolbar_add_text(GtkWidget *widget, gpointer data); void i_callback_add_line(gpointer data, guint callback_action, GtkWidget *widget); void i_callback_add_line_hotkey(gpointer data, guint callback_action, GtkWidget *widget); @@ -428,9 +428,9 @@ void i_callback_add_arc(gpointer data, guint callback_action, GtkWidget *widget) void i_callback_add_arc_hotkey(gpointer data, guint callback_action, GtkWidget *widget); void i_callback_add_pin(gpointer data, guint callback_action, GtkWidget *widget); void i_callback_add_pin_hotkey(gpointer data, guint callback_action, GtkWidget *widget); -void i_callback_hierarchy_down_schematic(gpointer data, guint callback_action, GtkWidget *widget); -void i_callback_hierarchy_down_symbol(gpointer data, guint callback_action, GtkWidget *widget); -void i_callback_hierarchy_up(gpointer data, guint callback_action, GtkWidget *widget); +void i_callback_hierarchy_down_schematic(GtkAction *action, gpointer data); +void i_callback_hierarchy_down_symbol(GtkAction *action, gpointer data); +void i_callback_hierarchy_up(GtkAction *action, gpointer data); void i_callback_hierarchy_documentation(gpointer data, guint callback_action, GtkWidget *widget); void i_callback_attributes_attach(gpointer data, guint callback_action, GtkWidget *widget); void i_callback_attributes_detach(gpointer data, guint callback_action, GtkWidget *widget); @@ -823,10 +823,10 @@ void x_log_message (const gchar *log_domain, const gchar *message); /* x_menus.c */ GtkWidget *get_main_menu(GSCHEM_TOPLEVEL *w_current); -GtkWidget *get_main_popup(GSCHEM_TOPLEVEL *w_current); +void x_menus_create_ui_manager (GSCHEM_TOPLEVEL *w_current); gint do_popup(GSCHEM_TOPLEVEL *w_current, GdkEventButton *event); +void x_menus_set_action_sensitivity (GSCHEM_TOPLEVEL *w_current, const gchar *action_name, gboolean flag); void x_menus_sensitivity(GSCHEM_TOPLEVEL *w_current, const char *buf, int flag); -void x_menus_popup_sensitivity(GSCHEM_TOPLEVEL *w_current, const char *buf, int flag); void x_menu_attach_recent_files_submenu(GSCHEM_TOPLEVEL *w_current); void recent_files_load(); void recent_files_save(gpointer user_data); diff --git a/gschem/lib/Makefile.am b/gschem/lib/Makefile.am index 37dd5db..39e5b58 100644 --- a/gschem/lib/Makefile.am +++ b/gschem/lib/Makefile.am @@ -1,8 +1,10 @@ rcdatadir = $(GEDARCDIR) +datadir = $(GEDADATADIR) rcdata_DATA = system-gschemrc gschem-gtkrc gschem-colormap-lightbg gschem-colormap-darkbg gschem-colormap-bw +data_DATA = gschem-ui.xml -EXTRA_DIST = system-gschemrc.in gschem-gtkrc gschem-colormap-lightbg gschem-colormap-darkbg gschem-colormap-bw +EXTRA_DIST = system-gschemrc.in gschem-gtkrc gschem-colormap-lightbg gschem-colormap-darkbg gschem-colormap-bw gschem-ui.xml MOSTLYCLEANFILES = *.log *~ CLEANFILES = *.log *~ diff --git a/gschem/lib/gschem-ui.xml b/gschem/lib/gschem-ui.xml new file mode 100644 index 0000000..35f1c28 --- /dev/null +++ b/gschem/lib/gschem-ui.xml @@ -0,0 +1,48 @@ +<!-- + * gEDA - GPL Electronic Design Automation + * gschem - gEDA Schematic Capture + * Copyright (C) 1998-2010 Ales Hvezda + * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA +--> +<ui> + <popup name="MainPopup"> + <menu action="PopupmenuAdd"> + <menuitem action="AddNet"/> + <menuitem action="AddAttribute"/> + <menuitem action="AddComponent"/> + <menuitem action="AddBus"/> + <menuitem action="AddText"/> + </menu> + <separator/> + <menuitem action="ZoomBox"/> + <menuitem action="ZoomIn"/> + <menuitem action="ZoomOut"/> + <menuitem action="ZoomFit"/> + <separator/> + <menuitem action="Select"/> + <menuitem action="Edit"/> + <menuitem action="EditPinType"/> + <menuitem action="Move"/> + <menuitem action="Copy"/> + <menuitem action="Delete"/> + <separator/> + <menuitem action="DownSchematic"/> + <menuitem action="DownSymbol"/> + <menuitem action="Up"/> + </popup> + +</ui> diff --git a/gschem/src/g_keys.c b/gschem/src/g_keys.c index 67c46be..3f3f132 100644 --- a/gschem/src/g_keys.c +++ b/gschem/src/g_keys.c @@ -189,6 +189,14 @@ SCM g_keys_ ## name(SCM rest) \ return SCM_BOOL_T; \ } +#define DEFINE_G_KEYS_NG(name) \ +SCM g_keys_ ## name(SCM rest) \ +{ \ + g_timeout_add(400, clear_keyaccel_string, global_window_current); \ + i_callback_ ## name(NULL, global_window_current); \ + return SCM_BOOL_T; \ +} + /*! \brief test-comment * test-comment */ @@ -222,22 +230,16 @@ DEFINE_G_KEYS(file_quit) /* Select also does not update the middle button shortcut */ DEFINE_G_KEYS(edit_undo) DEFINE_G_KEYS(edit_redo) -DEFINE_G_KEYS(edit_select) -DEFINE_G_KEYS(edit_copy) DEFINE_G_KEYS(edit_copy_hotkey) DEFINE_G_KEYS(edit_mcopy) DEFINE_G_KEYS(edit_mcopy_hotkey) -DEFINE_G_KEYS(edit_move) DEFINE_G_KEYS(edit_move_hotkey) -DEFINE_G_KEYS(edit_delete) DEFINE_G_KEYS(edit_rotate_90) DEFINE_G_KEYS(edit_rotate_90_hotkey) DEFINE_G_KEYS(edit_mirror) DEFINE_G_KEYS(edit_mirror_hotkey) DEFINE_G_KEYS(edit_slot) DEFINE_G_KEYS(edit_color) -DEFINE_G_KEYS(edit_edit) -DEFINE_G_KEYS(edit_pin_type) DEFINE_G_KEYS(edit_text) DEFINE_G_KEYS(edit_lock) DEFINE_G_KEYS(edit_unlock) @@ -255,6 +257,13 @@ DEFINE_G_KEYS(edit_show_text) DEFINE_G_KEYS(edit_hide_text) DEFINE_G_KEYS(edit_autonumber_text) +DEFINE_G_KEYS_NG(edit_select) +DEFINE_G_KEYS_NG(edit_copy) +DEFINE_G_KEYS_NG(edit_edit) +DEFINE_G_KEYS_NG(edit_pin_type) +DEFINE_G_KEYS_NG(edit_move) +DEFINE_G_KEYS_NG(edit_delete) + DEFINE_G_KEYS(clipboard_copy) DEFINE_G_KEYS(clipboard_cut) DEFINE_G_KEYS(clipboard_paste) @@ -287,14 +296,8 @@ DEFINE_G_KEYS(view_redraw) /* for these functions, repeat middle shortcut would get into the way * of what user is try to do */ -DEFINE_G_KEYS(view_zoom_full) -DEFINE_G_KEYS(view_zoom_extents) -DEFINE_G_KEYS(view_zoom_in) -DEFINE_G_KEYS(view_zoom_out) DEFINE_G_KEYS(view_zoom_in_hotkey) DEFINE_G_KEYS(view_zoom_out_hotkey) - -DEFINE_G_KEYS(view_zoom_box) DEFINE_G_KEYS(view_zoom_box_hotkey) DEFINE_G_KEYS(view_pan) DEFINE_G_KEYS(view_pan_left) @@ -313,14 +316,9 @@ DEFINE_G_KEYS(page_close) DEFINE_G_KEYS(page_revert) DEFINE_G_KEYS(page_discard) DEFINE_G_KEYS(page_print) -DEFINE_G_KEYS(add_component) -DEFINE_G_KEYS(add_attribute) DEFINE_G_KEYS(add_attribute_hotkey) -DEFINE_G_KEYS(add_net) DEFINE_G_KEYS(add_net_hotkey) -DEFINE_G_KEYS(add_bus) DEFINE_G_KEYS(add_bus_hotkey) -DEFINE_G_KEYS(add_text) DEFINE_G_KEYS(add_line) DEFINE_G_KEYS(add_line_hotkey) DEFINE_G_KEYS(add_box) @@ -333,9 +331,6 @@ DEFINE_G_KEYS(add_arc) DEFINE_G_KEYS(add_arc_hotkey) DEFINE_G_KEYS(add_pin) DEFINE_G_KEYS(add_pin_hotkey) -DEFINE_G_KEYS(hierarchy_down_schematic) -DEFINE_G_KEYS(hierarchy_down_symbol) -DEFINE_G_KEYS(hierarchy_up) DEFINE_G_KEYS(hierarchy_documentation) DEFINE_G_KEYS(attributes_attach) DEFINE_G_KEYS(attributes_detach) @@ -344,6 +339,20 @@ DEFINE_G_KEYS(attributes_show_value) DEFINE_G_KEYS(attributes_show_both) DEFINE_G_KEYS(attributes_visibility_toggle) +DEFINE_G_KEYS_NG(add_net) +DEFINE_G_KEYS_NG(add_attribute) +DEFINE_G_KEYS_NG(add_component) +DEFINE_G_KEYS_NG(add_bus) +DEFINE_G_KEYS_NG(add_text) +DEFINE_G_KEYS_NG(view_zoom_in) +DEFINE_G_KEYS_NG(view_zoom_out) +DEFINE_G_KEYS_NG(view_zoom_full) +DEFINE_G_KEYS_NG(view_zoom_extents) +DEFINE_G_KEYS_NG(view_zoom_box) +DEFINE_G_KEYS_NG(hierarchy_down_schematic) +DEFINE_G_KEYS_NG(hierarchy_down_symbol) +DEFINE_G_KEYS_NG(hierarchy_up) + /* i_callback_script_console is not currently implemented */ DEFINE_G_KEYS(script_console) diff --git a/gschem/src/gschem_toplevel.c b/gschem/src/gschem_toplevel.c index 6bfda7a..1c8e306 100644 --- a/gschem/src/gschem_toplevel.c +++ b/gschem/src/gschem_toplevel.c @@ -33,6 +33,8 @@ GSCHEM_TOPLEVEL *gschem_toplevel_new () /* main window widgets */ /* ------------------- */ w_current->main_window = NULL; + w_current->ui_manager = NULL; + w_current->action_group = NULL; w_current->drawing_area = NULL; w_current->menubar = NULL; w_current->popup_menu = NULL; diff --git a/gschem/src/i_basic.c b/gschem/src/i_basic.c index c43f3be..f3a64dc 100644 --- a/gschem/src/i_basic.c +++ b/gschem/src/i_basic.c @@ -433,9 +433,9 @@ void i_update_menus(GSCHEM_TOPLEVEL *w_current) x_menus_sensitivity(w_current, "A_ttributes/_Toggle Visibility", TRUE); /* Menu items for hierarchy added by SDB 1.9.2005. */ - x_menus_popup_sensitivity(w_current, "/Down Schematic", TRUE); - x_menus_popup_sensitivity(w_current, "/Down Symbol", TRUE); - /* x_menus_popup_sensitivity(w_current, "/Up", TRUE); */ + x_menus_set_action_sensitivity (w_current, "DownSchematic", TRUE); + x_menus_set_action_sensitivity (w_current, "DownSymbol", TRUE); + /* x_menus_set_action_sensitivity (w_current, "Up", TRUE); */ } else { /* Nothing is selected, grey these out */ @@ -480,9 +480,9 @@ void i_update_menus(GSCHEM_TOPLEVEL *w_current) x_menus_sensitivity(w_current, "A_ttributes/_Toggle Visibility", FALSE); /* Menu items for hierarchy added by SDB 1.9.2005. */ - x_menus_popup_sensitivity(w_current, "/Down Schematic", FALSE); - x_menus_popup_sensitivity(w_current, "/Down Symbol", FALSE); - /* x_menus_popup_sensitivity(w_current, "/Up", FALSE); */ + x_menus_set_action_sensitivity (w_current, "DownSchematic", FALSE); + x_menus_set_action_sensitivity (w_current, "DownSymbol", FALSE); + /* x_menus_set_action_sensitivity (w_current, "Up", FALSE); */ } x_menus_sensitivity(w_current, "_Buffer/Paste from 1", (object_buffer[0] != NULL)); diff --git a/gschem/src/i_callbacks.c b/gschem/src/i_callbacks.c index bcc3525..97352b0 100644 --- a/gschem/src/i_callbacks.c +++ b/gschem/src/i_callbacks.c @@ -497,7 +497,7 @@ void i_callback_toolbar_edit_redo(GtkWidget* widget, gpointer data) * \note * Select also does not update the middle button shortcut. */ -DEFINE_I_CALLBACK(edit_select) +void i_callback_edit_select(GtkAction *action, gpointer data) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; o_redraw_cleanstates(w_current); @@ -526,7 +526,7 @@ void i_callback_toolbar_edit_select(GtkWidget* widget, gpointer data) if (!o_invalidate_rubber (w_current)) { i_callback_cancel(w_current, 0, NULL); } - i_callback_edit_select(data, 0, NULL); + i_callback_edit_select(NULL, data); } } @@ -535,7 +535,7 @@ void i_callback_toolbar_edit_select(GtkWidget* widget, gpointer data) * \par Function Description * */ -DEFINE_I_CALLBACK(edit_copy) +void i_callback_edit_copy(GtkAction *action, gpointer data) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; @@ -625,7 +625,7 @@ DEFINE_I_CALLBACK(edit_mcopy_hotkey) * \par Function Description * */ -DEFINE_I_CALLBACK(edit_move) +void i_callback_edit_move(GtkAction *action, gpointer data) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; @@ -669,7 +669,7 @@ DEFINE_I_CALLBACK(edit_move_hotkey) * \par Function Description * */ -DEFINE_I_CALLBACK(edit_delete) +void i_callback_edit_delete(GtkAction *action, gpointer data) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; @@ -694,7 +694,7 @@ DEFINE_I_CALLBACK(edit_delete) * \par Function Description * */ -DEFINE_I_CALLBACK(edit_edit) +void i_callback_edit_edit(GtkAction *action, gpointer data) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; @@ -709,7 +709,7 @@ DEFINE_I_CALLBACK(edit_edit) * \par Function Description * */ -DEFINE_I_CALLBACK(edit_pin_type) +void i_callback_edit_pin_type(GtkAction *action, gpointer data) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; @@ -1291,7 +1291,7 @@ DEFINE_I_CALLBACK(view_redraw) * \note * repeat middle shortcut would get into the way of what user is try to do */ -DEFINE_I_CALLBACK(view_zoom_full) +void i_callback_view_zoom_full(GtkAction *action, gpointer data) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; @@ -1312,7 +1312,7 @@ DEFINE_I_CALLBACK(view_zoom_full) * \note * repeat middle shortcut would get into the way of what user is try to do */ -DEFINE_I_CALLBACK(view_zoom_extents) +void i_callback_view_zoom_extents(GtkAction *action, gpointer data) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; @@ -1333,7 +1333,7 @@ DEFINE_I_CALLBACK(view_zoom_extents) * \note * repeat middle shortcut would get into the way of what user is try to do */ -DEFINE_I_CALLBACK(view_zoom_box) +void i_callback_view_zoom_box(GtkAction *action, gpointer data) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; @@ -1373,7 +1373,7 @@ DEFINE_I_CALLBACK(view_zoom_box_hotkey) * \note * repeat middle shortcut would get into the way of what user is try to do */ -DEFINE_I_CALLBACK(view_zoom_in) +void i_callback_view_zoom_in(GtkAction *action, gpointer data) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; @@ -1393,7 +1393,7 @@ DEFINE_I_CALLBACK(view_zoom_in) * \note * repeat middle shortcut would get into the way of what user is try to do */ -DEFINE_I_CALLBACK(view_zoom_out) +void i_callback_view_zoom_out(GtkAction *action, gpointer data) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; @@ -2305,7 +2305,7 @@ DEFINE_I_CALLBACK(buffer_paste5_hotkey) * \par Function Description * */ -DEFINE_I_CALLBACK(add_component) +void i_callback_add_component(GtkAction *action, gpointer data) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; @@ -2335,7 +2335,7 @@ void i_callback_toolbar_add_component(GtkWidget* widget, gpointer data) exit_if_null(w_current); if (!w_current->window) return; - i_callback_add_component(data, 0, NULL); + i_callback_add_component(NULL, data); } /*! \todo Finish function documentation!!! @@ -2343,7 +2343,7 @@ void i_callback_toolbar_add_component(GtkWidget* widget, gpointer data) * \par Function Description * */ -DEFINE_I_CALLBACK(add_attribute) +void i_callback_add_attribute(GtkAction *action, gpointer data) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; @@ -2381,7 +2381,7 @@ DEFINE_I_CALLBACK(add_attribute_hotkey) * \par Function Description * */ -DEFINE_I_CALLBACK(add_net) +void i_callback_add_net(GtkAction *action, gpointer data) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; @@ -2444,7 +2444,7 @@ void i_callback_toolbar_add_net(GtkWidget* widget, gpointer data) if (!w_current->window) return; if (GTK_TOGGLE_BUTTON (widget)->active) { - i_callback_add_net(data, 0, NULL); + i_callback_add_net(NULL, data); } } @@ -2453,7 +2453,7 @@ void i_callback_toolbar_add_net(GtkWidget* widget, gpointer data) * \par Function Description * */ -DEFINE_I_CALLBACK(add_bus) +void i_callback_add_bus (GtkAction *action, gpointer data) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; @@ -2515,7 +2515,7 @@ void i_callback_toolbar_add_bus(GtkWidget* widget, gpointer data) if (!w_current->window) return; if (GTK_TOGGLE_BUTTON (widget)->active) { - i_callback_add_bus(data, 0, NULL); + i_callback_add_bus(NULL, data); } } @@ -2524,7 +2524,7 @@ void i_callback_toolbar_add_bus(GtkWidget* widget, gpointer data) * \par Function Description * */ -DEFINE_I_CALLBACK(add_text) +void i_callback_add_text(GtkAction *action, gpointer data) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; @@ -2554,7 +2554,7 @@ void i_callback_toolbar_add_text(GtkWidget* widget, gpointer data) exit_if_null(w_current); if (!w_current->window) return; - i_callback_add_text(data, 0, NULL); + i_callback_add_text(NULL, data); } /*! \todo Finish function documentation!!! @@ -2823,7 +2823,7 @@ DEFINE_I_CALLBACK(add_pin_hotkey) * \par Function Description * */ -DEFINE_I_CALLBACK(hierarchy_down_schematic) +void i_callback_hierarchy_down_schematic(GtkAction *action, gpointer data) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; char *attrib=NULL; @@ -2949,7 +2949,7 @@ DEFINE_I_CALLBACK(hierarchy_down_schematic) * \par Function Description * \bug may cause problems with non-directory symbols */ -DEFINE_I_CALLBACK(hierarchy_down_symbol) +void i_callback_hierarchy_down_symbol(GtkAction *action, gpointer data) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; OBJECT *object; @@ -2988,7 +2988,7 @@ DEFINE_I_CALLBACK(hierarchy_down_symbol) * \par Function Description * */ -DEFINE_I_CALLBACK(hierarchy_up) +void i_callback_hierarchy_up(GtkAction *action, gpointer data) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; PAGE *up_page; diff --git a/gschem/src/x_menus.c b/gschem/src/x_menus.c index 63fe5a6..b87b6ad 100644 --- a/gschem/src/x_menus.c +++ b/gschem/src/x_menus.c @@ -32,32 +32,35 @@ #include <dmalloc.h> #endif -static GtkItemFactoryEntry popup_items[] = { - { N_("/Add Net"), NULL, i_callback_add_net, 0, NULL}, - { N_("/Add Attribute..."), NULL, i_callback_add_attribute, 0, NULL}, - { N_("/Add Component..."), NULL, i_callback_add_component, 0, NULL}, - { N_("/Add Bus"), NULL, i_callback_add_bus, 0, NULL}, - { N_("/Add Text"), NULL, i_callback_add_text, 0, NULL}, - { "/sep1", NULL, NULL, 0, "<Separator>"}, - { N_("/Zoom In"), NULL, i_callback_view_zoom_in, 0, NULL}, - { N_("/Zoom Out"), NULL, i_callback_view_zoom_out, 0, NULL}, - { N_("/Zoom Box"), NULL, i_callback_view_zoom_box, 0, NULL}, - { N_("/Zoom Extents"), NULL, i_callback_view_zoom_extents, 0, NULL}, - { "/sep1", NULL, NULL, 0, "<Separator>"}, - { N_("/Select"), NULL, i_callback_edit_select, 0, NULL}, - { N_("/Edit..."), NULL, i_callback_edit_edit, 0, NULL}, - { N_("/Edit pin type..."), NULL, i_callback_edit_pin_type, 0, NULL}, - { N_("/Copy"), NULL, i_callback_edit_copy, 0, NULL}, - { N_("/Move"), NULL, i_callback_edit_move, 0, NULL}, - { N_("/Delete"), NULL, i_callback_edit_delete, 0, NULL}, - /* Menu items for hierarchy added by SDB 1.9.2005. */ - {"/sep1", NULL, NULL, 0, "<Separator>"}, - {N_("/Down Schematic"), NULL, i_callback_hierarchy_down_schematic, 0, NULL}, - {N_("/Down Symbol"), NULL, i_callback_hierarchy_down_symbol, 0, NULL}, - {N_("/Up"), NULL, i_callback_hierarchy_up, 0, NULL}, -}; - -int npopup_items = sizeof(popup_items) / sizeof(popup_items[0]); +static GtkActionEntry popup_menu_items[] = { + {"PopupmenuAdd", GTK_STOCK_ADD, NULL, "", "", NULL}, + + /* Add menu */ + {"AddNet", NULL, N_("_Net"), "", "", G_CALLBACK (i_callback_add_net) }, + {"AddAttribute", NULL, N_("_Attribute"), "", "", G_CALLBACK (i_callback_add_attribute) }, + {"AddComponent", NULL, N_("_Component"), "", "", G_CALLBACK (i_callback_add_component) }, + {"AddBus", NULL, N_("B_us"), "", "", G_CALLBACK (i_callback_add_bus) }, + {"AddText", NULL, N_("_Text"), "", "", G_CALLBACK (i_callback_add_text) }, + + /* View menu */ + {"ZoomIn", GTK_STOCK_ZOOM_IN, NULL, "", "", G_CALLBACK (i_callback_view_zoom_in) }, + {"ZoomOut", GTK_STOCK_ZOOM_OUT, NULL, "", "", G_CALLBACK (i_callback_view_zoom_out) }, + {"ZoomFit", GTK_STOCK_ZOOM_FIT, NULL, "", "", G_CALLBACK (i_callback_view_zoom_extents) }, + {"ZoomBox", NULL, N_("Zoom _Box"), "", "", G_CALLBACK (i_callback_view_zoom_box) }, + + /* Edit menu */ + {"Select", NULL, N_("Select"), "", "", G_CALLBACK (i_callback_edit_select) }, + {"Edit", NULL, N_("Edit..."), "", "", G_CALLBACK (i_callback_edit_edit) }, + {"EditPinType", NULL, N_("Edit pin type..."), "", "", G_CALLBACK (i_callback_edit_pin_type) }, + {"Move", NULL, N_("Move"), "", "", G_CALLBACK (i_callback_edit_move) }, + {"Copy", GTK_STOCK_COPY, NULL, "", "", G_CALLBACK (i_callback_edit_copy) }, + {"Delete", GTK_STOCK_DELETE, NULL, "", "", G_CALLBACK (i_callback_edit_delete) }, + + /* Hierarchy menu*/ + {"DownSchematic", NULL, N_("_Down Schematic"), "", "", G_CALLBACK (i_callback_hierarchy_down_schematic) }, + {"DownSymbol", NULL, N_("Down _Symbol"), "", "", G_CALLBACK (i_callback_hierarchy_down_symbol) }, + {"Up", GTK_STOCK_GO_UP, NULL, "", "", G_CALLBACK (i_callback_hierarchy_up) }, +}; /*! \todo Finish function documentation!!! * \brief @@ -225,49 +228,44 @@ get_main_menu(GSCHEM_TOPLEVEL *w_current) return menu_bar; } -/*! \todo Finish function documentation!!! - * \brief - * \par Function Description + +/*! \brief Create the UI Manager + * \par Create the UI Manager to manage the popup menu + * + * \param w_current A pointer to the main window * */ -static gchar* gettext_fn(const gchar *path, - gpointer func_data ATTRIBUTE_UNUSED) +void x_menus_create_ui_manager (GSCHEM_TOPLEVEL *w_current) { - return gettext(path); -} - -GtkWidget *get_main_popup(GSCHEM_TOPLEVEL *w_current) -{ - static GtkItemFactory *item_factory; - GtkAccelGroup *accel_group; - GtkWidget *menu; - - accel_group = gtk_accel_group_new(); - - /* This function initializes the item factory. - Param 1: The type of menu - can be GTK_TYPE_MENU_BAR, GTK_TYPE_MENU, or GTK_TYPE_OPTION_MENU. - Param 2: The path of the menu. - Param 3: A pointer to a gtk_accel_group. The item factory sets up - the accelerator table while generating menus. - */ - item_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<popup>", - accel_group); - gtk_item_factory_set_translate_func (item_factory, - gettext_fn, - NULL, NULL); - /* This function creates the pop-up menu itself & attaches it to the - GtkItemFactory. Pass the item factory, - the number of items in the array, the array itself, and any - callback data for the the menu items. Note that npopup_items is - a static var declared in this file above; popup_items is also a - static var declared above. - */ - gtk_item_factory_create_items(item_factory, npopup_items, popup_items, w_current); - - /* Finally, return the actual menu created by the item factory. */ - menu = (GtkWidget *) gtk_item_factory_get_widget(item_factory, "<popup>"); - return (menu); - + gchar *ui_file = NULL; + GtkActionGroup *action_group = NULL; + GError *error = NULL; + + /* Create and fill the action group object */ + action_group = gtk_action_group_new ("PopupMenuAction"); + + gtk_action_group_set_translation_domain (action_group, NULL); + + gtk_action_group_add_actions (action_group, popup_menu_items, + G_N_ELEMENTS (popup_menu_items), + w_current); + + w_current->action_group = action_group; + + /* Create the UI manager object */ + w_current->ui_manager = gtk_ui_manager_new (); + + gtk_ui_manager_insert_action_group (w_current->ui_manager, action_group, 0); + + ui_file = g_build_filename (s_path_sys_data (), "gschem-ui.xml", NULL); + + if (!gtk_ui_manager_add_ui_from_file (w_current->ui_manager, ui_file, &error)) + { + g_warning ("Could not merge \"%s\" : %s\n", ui_file, error->message); + g_error_free (error); + } + + g_free (ui_file); } /*! \todo Finish function documentation!!! @@ -295,6 +293,36 @@ gint do_popup (GSCHEM_TOPLEVEL *w_current, GdkEventButton *event) return FALSE; } +/*! \brief Sets the sensitivity of an action use by GtkUIManager + * + * \par Sets the sensitivity of an action use by GtkUIManager + * + * \param [in] w_current A pointer to the current window + * \param [in] action_name + * \param [in] flag New sensitivity of the action + */ +void x_menus_set_action_sensitivity (GSCHEM_TOPLEVEL *w_current, const gchar *action_name, gboolean flag) +{ + GtkAction *action = NULL; + + if (action_name != NULL) + { + if (w_current->action_group == NULL) + g_warning ("action_group doesn't exist!\n"); + else + { + action = gtk_action_group_get_action (w_current->action_group, + action_name); + + if (action != NULL) + gtk_action_set_sensitive(action, flag); + else + g_warning ("Tried to set sensitivity on a non-existent action : %s\n", action_name); + } + } + +} + /*! \todo Finish function documentation!!! * \brief * \par Function Description @@ -323,42 +351,6 @@ void x_menus_sensitivity (GSCHEM_TOPLEVEL *w_current, const char *buf, int flag) } -/*! \todo Finish function documentation!!! - * \brief - * \par Function Description - * This function sets the sensitivity of the items in the right button - * popup. - * - * \note - * 1.9.2005 -- SDB. - */ -void x_menus_popup_sensitivity (GSCHEM_TOPLEVEL *w_current, const char *buf, int flag) -{ - GtkWidget *menu_item; - GtkItemFactory *menu_item_factory; - - if (!buf) { - return; - } - - if (!w_current->popup_menu) { - s_log_message(_("Popup_menu_item_factory doesn't exist!\n")); - return; - } - - /* - * first get entire item factory from popup, then get the individual - * menu item indexed by buf. - */ - menu_item_factory = (GtkItemFactory *)gtk_item_factory_from_widget(w_current->popup_menu); - menu_item = (GtkWidget *) gtk_item_factory_get_widget(menu_item_factory, buf); - if (menu_item) { - gtk_widget_set_sensitive(GTK_WIDGET(menu_item), flag); - } else { - s_log_message(_("Tried to set the sensitivity on a non-existent popup menu_item\n")); - } -} - /* The list of recently loaded files. */ static GList *recent_files = NULL; diff --git a/gschem/src/x_window.c b/gschem/src/x_window.c index 07beb6e..6eb621a 100644 --- a/gschem/src/x_window.c +++ b/gschem/src/x_window.c @@ -278,6 +278,9 @@ void x_window_create_main(GSCHEM_TOPLEVEL *w_current) gtk_signal_connect (GTK_OBJECT (w_current->main_window), "delete_event", GTK_SIGNAL_FUNC (i_callback_close_wm), w_current); + + /* Try to create GtkUIManager */ + x_menus_create_ui_manager (w_current); /* Containers first */ main_box = gtk_vbox_new(FALSE, 1); @@ -285,13 +288,7 @@ void x_window_create_main(GSCHEM_TOPLEVEL *w_current) gtk_container_add(GTK_CONTAINER(w_current->main_window), main_box); menubar = get_main_menu (w_current); - if (w_current->handleboxes) { - handlebox = gtk_handle_box_new (); - gtk_box_pack_start(GTK_BOX(main_box), handlebox, FALSE, FALSE, 0); - gtk_container_add (GTK_CONTAINER (handlebox), menubar); - } else { - gtk_box_pack_start(GTK_BOX(main_box), menubar, FALSE, FALSE, 0); - } + gtk_box_pack_start(GTK_BOX(main_box), menubar, FALSE, FALSE, 0); w_current->menubar = menubar; gtk_widget_realize (w_current->main_window); @@ -402,11 +399,10 @@ void x_window_create_main(GSCHEM_TOPLEVEL *w_current) gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w_current->toolbar_select), TRUE); - } - - - /* Try to create popup menu (appears in right mouse button */ - w_current->popup_menu = (GtkWidget *) get_main_popup(w_current); + } + + /* Try to create main popup menu (appears in right mouse button */ + w_current->popup_menu = gtk_ui_manager_get_widget(w_current->ui_manager, "/ui/MainPopup/"); drawbox = gtk_hbox_new(FALSE, 0); gtk_container_border_width(GTK_CONTAINER(drawbox), 0);
_______________________________________________ geda-user mailing list geda-user@moria.seul.org http://www.seul.org/cgi-bin/mailman/listinfo/geda-user