3 #include <libegg/menu/egg-combo-action.h>
4 #include <libegg/menu/egg-recent-action.h>
5 //#include <libegg/menu/egg-markup.h>
8 # define _(String) (String)
9 # define N_(String) (String)
12 static GtkActionGroup
*action_group
= NULL
;
13 static GtkToolbar
*toolbar
= NULL
;
14 static GtkUIManager
*menu_merge
= NULL
;
17 activate_action (GtkAction
*action
)
21 g_object_get (G_OBJECT (action
), "name", &name
, NULL
);
22 const gchar
*typename
= G_OBJECT_TYPE_NAME (action
);
24 g_print ("Action %s (type=%s) activated", name
, typename
);
28 changed_action (GtkAction
*action
)
32 g_object_get (G_OBJECT (action
), "name", &name
, NULL
);
33 const gchar
*typename
= G_OBJECT_TYPE_NAME (action
);
35 g_print ("Action %s (type=%s) changed activated", name
, typename
);
38 /* convenience functions for declaring actions */
39 static GtkActionEntry entries
[] = {
40 {"ActionList", GTK_STOCK_JUMP_TO
, "List", NULL
, "List box",
41 G_CALLBACK (activate_action
)}
44 static guint n_entries
= G_N_ELEMENTS (entries
);
46 /* XML description of the menus for the test app. The parser understands
47 * a subset of the Bonobo UI XML format, and uses GMarkup for parsing */
48 static const gchar
*ui_info
=
50 " <toolbar name=\"toolbar\">\n"
51 " <toolitem name=\"recent\" action=\"ActionRecent\" />\n"
52 " <toolitem name=\"button\" action=\"ActionList\" />\n"
53 " <toolitem name=\"combo\" action=\"ActionCombo\" />\n"
54 " <toolitem name=\"combo2\" action=\"ActionCombo\" />\n"
55 " <toolitem name=\"recent2\" action=\"ActionRecent\" />\n"
60 on_add_merge_widget (GtkWidget
*merge
, GtkWidget
*widget
,
61 GtkWidget
*ui_container
)
63 // g_message("got widget %s of type %s", name ? name : "(null)", type);
64 gtk_container_add (GTK_CONTAINER (ui_container
), widget
);
65 gtk_widget_show(widget
);
67 if (GTK_IS_TOOLBAR (widget
)) {
68 toolbar
= GTK_TOOLBAR (widget
);
69 gtk_toolbar_set_show_arrow (toolbar
, TRUE
);
74 COL_PIX
, COL_NAME
, COL_LINE
, N_COLS
80 GtkTreeIter iter
, *parent
;
81 gchar
*strs
[] = {"string 1", "string 2", "string 3", NULL
};
86 store
= gtk_tree_store_new (N_COLS
, GDK_TYPE_PIXBUF
, G_TYPE_STRING
, G_TYPE_INT
);
91 pixbuf
= gdk_pixbuf_new_from_file_at_size (PACKAGE_PIXMAPS_DIR
"/anjuta.png",
93 gtk_tree_store_append (store
, &iter
, NULL
);
94 gtk_tree_store_set (store
, &iter
,
98 g_object_unref (pixbuf
);
100 //gtk_tree_iter_free (parent);
101 //parent = gtk_tree_iter_copy (&iter);
104 return GTK_TREE_MODEL (store
);
108 static EggRecentModel
*
109 create_recent_model ()
111 EggRecentModel
*model
;
113 egg_recent_model_new (EGG_RECENT_MODEL_SORT_MRU
);
114 egg_recent_model_set_limit (model
, 15);
115 egg_recent_model_set_filter_groups (model
,
117 return EGG_RECENT_MODEL (model
);
121 main (int argc
, char **argv
)
127 GError
*error
= NULL
;
129 EggRecentModel
*rmodel
;
131 gtk_init (&argc
, &argv
);
133 if (g_file_test("accels", G_FILE_TEST_IS_REGULAR
))
134 gtk_accel_map_load("accels");
136 action_group
= gtk_action_group_new ("TestActions");
137 gtk_action_group_add_actions (action_group
, entries
, n_entries
, NULL
);
138 action
= g_object_new (EGG_TYPE_COMBO_ACTION
,
139 "name", "ActionCombo",
140 "label", _("Search"),
141 "tooltip", _("Incremental search"),
142 "stock_id", GTK_STOCK_JUMP_TO
,
144 g_assert (EGG_IS_COMBO_ACTION (action
));
145 g_signal_connect (action
, "activate",
146 G_CALLBACK (activate_action
), NULL
);
147 gtk_action_group_add_action (action_group
, action
);
149 model
= create_model ();
150 egg_combo_action_set_model (EGG_COMBO_ACTION (action
), model
);
151 g_object_unref (model
);
153 action
= g_object_new (EGG_TYPE_RECENT_ACTION
,
154 "name", "ActionRecent",
155 "label", _("Open _Recent"),
156 "tooltip", _("Open recent files"),
159 g_assert (EGG_IS_RECENT_ACTION (action
));
160 //g_signal_connect (action, "activate",
161 // G_CALLBACK (activate_action), NULL);
162 gtk_action_group_add_action (action_group
, action
);
163 rmodel
= create_recent_model ();
164 egg_recent_action_add_model (EGG_RECENT_ACTION (action
), rmodel
);
165 egg_recent_action_add_model (EGG_RECENT_ACTION (action
), rmodel
);
166 egg_recent_action_add_model (EGG_RECENT_ACTION (action
), rmodel
);
167 g_object_unref (rmodel
);
169 window
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
170 gtk_widget_show (window
);
171 gtk_window_set_title (GTK_WINDOW (window
), "Action Test");
172 //gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
173 g_signal_connect (window
, "destroy", G_CALLBACK (gtk_main_quit
), NULL
);
174 // gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
176 box
= gtk_vbox_new (FALSE
, 0);
177 gtk_container_add (GTK_CONTAINER (window
), box
);
178 gtk_widget_show (box
);
180 menu_merge
= gtk_ui_manager_new ();
181 g_signal_connect (G_OBJECT (menu_merge
), "add_widget",
182 G_CALLBACK (on_add_merge_widget
), box
);
183 gtk_ui_manager_insert_action_group (menu_merge
, action_group
, 0);
184 gtk_ui_manager_add_ui_from_string (menu_merge
, ui_info
, strlen(ui_info
), &error
);
187 g_warning ("building menus failed: %s", error
->message
);
188 g_error_free (error
);
191 // g_object_unref(accel_group); /* window holds ref to accel group */
195 // g_object_unref (action_group);
197 gtk_accel_map_save("accels");