4 #include <libegg/menu/egg-combo-action.h>
5 #include <libegg/menu/egg-recent-action.h>
6 //#include <libegg/menu/egg-markup.h>
9 # define _(String) (String)
10 # define N_(String) (String)
13 static GtkActionGroup
*action_group
= NULL
;
14 static GtkToolbar
*toolbar
= NULL
;
15 static GtkUIManager
*menu_merge
= NULL
;
18 activate_action (GtkAction
*action
)
22 g_object_get (G_OBJECT (action
), "name", &name
, NULL
);
23 const gchar
*typename
= G_OBJECT_TYPE_NAME (action
);
25 g_print ("Action %s (type=%s) activated", name
, typename
);
29 changed_action (GtkAction
*action
)
33 g_object_get (G_OBJECT (action
), "name", &name
, NULL
);
34 const gchar
*typename
= G_OBJECT_TYPE_NAME (action
);
36 g_print ("Action %s (type=%s) changed activated", name
, typename
);
39 /* convenience functions for declaring actions */
40 static GtkActionEntry entries
[] = {
41 {"ActionList", GTK_STOCK_JUMP_TO
, "List", NULL
, "List box",
42 G_CALLBACK (activate_action
)}
45 static guint n_entries
= G_N_ELEMENTS (entries
);
47 /* XML description of the menus for the test app. The parser understands
48 * a subset of the Bonobo UI XML format, and uses GMarkup for parsing */
49 static const gchar
*ui_info
=
51 " <toolbar name=\"toolbar\">\n"
52 " <toolitem name=\"recent\" action=\"ActionRecent\" />\n"
53 " <toolitem name=\"button\" action=\"ActionList\" />\n"
54 " <toolitem name=\"combo\" action=\"ActionCombo\" />\n"
55 " <toolitem name=\"combo2\" action=\"ActionCombo\" />\n"
56 " <toolitem name=\"recent2\" action=\"ActionRecent\" />\n"
61 on_add_merge_widget (GtkWidget
*merge
, GtkWidget
*widget
,
62 GtkWidget
*ui_container
)
64 // g_message("got widget %s of type %s", name ? name : "(null)", type);
65 gtk_container_add (GTK_CONTAINER (ui_container
), widget
);
66 gtk_widget_show(widget
);
68 if (GTK_IS_TOOLBAR (widget
)) {
69 toolbar
= GTK_TOOLBAR (widget
);
70 gtk_toolbar_set_show_arrow (toolbar
, TRUE
);
75 COL_PIX
, COL_NAME
, COL_LINE
, N_COLS
81 GtkTreeIter iter
, *parent
;
82 gchar
*strs
[] = {"string 1", "string 2", "string 3", NULL
};
87 store
= gtk_tree_store_new (N_COLS
, GDK_TYPE_PIXBUF
, G_TYPE_STRING
, G_TYPE_INT
);
92 pixbuf
= gdk_pixbuf_new_from_file_at_size (PACKAGE_PIXMAPS_DIR
"/anjuta.png",
94 gtk_tree_store_append (store
, &iter
, NULL
);
95 gtk_tree_store_set (store
, &iter
,
99 g_object_unref (pixbuf
);
101 //gtk_tree_iter_free (parent);
102 //parent = gtk_tree_iter_copy (&iter);
105 return GTK_TREE_MODEL (store
);
109 static EggRecentModel
*
110 create_recent_model ()
112 EggRecentModel
*model
;
114 egg_recent_model_new (EGG_RECENT_MODEL_SORT_MRU
);
115 egg_recent_model_set_limit (model
, 15);
116 egg_recent_model_set_filter_groups (model
,
118 return EGG_RECENT_MODEL (model
);
122 main (int argc
, char **argv
)
128 GError
*error
= NULL
;
130 EggRecentModel
*rmodel
;
132 gtk_init (&argc
, &argv
);
134 if (g_file_test("accels", G_FILE_TEST_IS_REGULAR
))
135 gtk_accel_map_load("accels");
137 action_group
= gtk_action_group_new ("TestActions");
138 gtk_action_group_add_actions (action_group
, entries
, n_entries
, NULL
);
139 action
= g_object_new (EGG_TYPE_COMBO_ACTION
,
140 "name", "ActionCombo",
141 "label", _("Search"),
142 "tooltip", _("Incremental search"),
143 "stock_id", GTK_STOCK_JUMP_TO
,
145 g_assert (EGG_IS_COMBO_ACTION (action
));
146 g_signal_connect (action
, "activate",
147 G_CALLBACK (activate_action
), NULL
);
148 gtk_action_group_add_action (action_group
, action
);
150 model
= create_model ();
151 egg_combo_action_set_model (EGG_COMBO_ACTION (action
), model
);
152 g_object_unref (model
);
154 action
= g_object_new (EGG_TYPE_RECENT_ACTION
,
155 "name", "ActionRecent",
156 "label", _("Open _Recent"),
157 "tooltip", _("Open recent files"),
160 g_assert (EGG_IS_RECENT_ACTION (action
));
161 //g_signal_connect (action, "activate",
162 // G_CALLBACK (activate_action), NULL);
163 gtk_action_group_add_action (action_group
, action
);
164 rmodel
= create_recent_model ();
165 egg_recent_action_add_model (EGG_RECENT_ACTION (action
), rmodel
);
166 egg_recent_action_add_model (EGG_RECENT_ACTION (action
), rmodel
);
167 egg_recent_action_add_model (EGG_RECENT_ACTION (action
), rmodel
);
168 g_object_unref (rmodel
);
170 window
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
171 gtk_widget_show (window
);
172 gtk_window_set_title (GTK_WINDOW (window
), "Action Test");
173 //gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
174 g_signal_connect (window
, "destroy", G_CALLBACK (gtk_main_quit
), NULL
);
175 // gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
177 box
= gtk_vbox_new (FALSE
, 0);
178 gtk_container_add (GTK_CONTAINER (window
), box
);
179 gtk_widget_show (box
);
181 menu_merge
= gtk_ui_manager_new ();
182 g_signal_connect (G_OBJECT (menu_merge
), "add_widget",
183 G_CALLBACK (on_add_merge_widget
), box
);
184 gtk_ui_manager_insert_action_group (menu_merge
, action_group
, 0);
185 gtk_ui_manager_add_ui_from_string (menu_merge
, ui_info
, strlen(ui_info
), &error
);
188 g_warning ("building menus failed: %s", error
->message
);
189 g_error_free (error
);
192 // g_object_unref(accel_group); /* window holds ref to accel group */
196 // g_object_unref (action_group);
198 gtk_accel_map_save("accels");