Updated Spanish translation
[anjuta-git-plugin.git] / libegg / test-actions.c
blob9a08c1454f5f824efb6e382196ffe2f5bd599fc7
1 #include <config.h>
2 #include <gtk/gtk.h>
3 #include <string.h>
4 #include <libegg/menu/egg-combo-action.h>
5 #include <libegg/menu/egg-recent-action.h>
6 //#include <libegg/menu/egg-markup.h>
8 #ifndef _
9 # define _(String) (String)
10 # define N_(String) (String)
11 #endif
13 static GtkActionGroup *action_group = NULL;
14 static GtkToolbar *toolbar = NULL;
15 static GtkUIManager *menu_merge = NULL;
17 static void
18 activate_action (GtkAction *action)
20 const gchar *name;
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);
28 static void
29 changed_action (GtkAction *action)
31 const gchar *name;
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 =
50 "<ui>\n"
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"
57 " </toolbar>\n"
58 "</ui>\n";
60 static void
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);
74 enum {
75 COL_PIX, COL_NAME, COL_LINE, N_COLS
78 static GtkTreeModel *
79 create_model ()
81 GtkTreeIter iter, *parent;
82 gchar *strs[] = {"string 1", "string 2", "string 3", NULL};
83 GtkTreeStore *store;
84 gchar **idx;
86 parent = NULL;
87 store = gtk_tree_store_new (N_COLS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_INT);
88 idx = strs;
89 while (*idx)
91 GdkPixbuf *pixbuf;
92 pixbuf = gdk_pixbuf_new_from_file_at_size (PACKAGE_PIXMAPS_DIR"/anjuta.png",
93 16, 16, NULL);
94 gtk_tree_store_append (store, &iter, NULL);
95 gtk_tree_store_set (store, &iter,
96 COL_PIX, pixbuf,
97 COL_NAME, *idx,
98 COL_LINE, 23, -1);
99 g_object_unref (pixbuf);
100 //if (parent)
101 //gtk_tree_iter_free (parent);
102 //parent = gtk_tree_iter_copy (&iter);
103 idx++;
105 return GTK_TREE_MODEL (store);
109 static EggRecentModel *
110 create_recent_model ()
112 EggRecentModel *model;
113 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,
117 "anjuta", NULL);
118 return EGG_RECENT_MODEL (model);
122 main (int argc, char **argv)
124 GList *strs;
125 GtkAction *action;
126 GtkWidget *window;
127 GtkWidget *box;
128 GError *error = NULL;
129 GtkTreeModel *model;
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,
144 NULL);
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);
153 /* recent action */
154 action = g_object_new (EGG_TYPE_RECENT_ACTION,
155 "name", "ActionRecent",
156 "label", _("Open _Recent"),
157 "tooltip", _("Open recent files"),
158 "stock_id", NULL,
159 NULL);
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);
186 if (error != NULL)
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 */
194 gtk_main ();
196 // g_object_unref (action_group);
198 gtk_accel_map_save("accels");
200 return 0;