2 * This file is part of TBO, a gnome comic editor
3 * Copyright (C) 2010 Daniel Garcia Moreno <dani@danigm.net>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <glib/gi18n.h>
26 #include "comic-new-dialog.h"
27 #include "comic-saveas-dialog.h"
28 #include "comic-open-dialog.h"
29 #include "tbo-window.h"
30 #include "tbo-drawing.h"
32 #include "tbo-tool-selector.h"
36 #include "tbo-object-base.h"
38 static GtkActionGroup *MENU_ACTION_GROUP = NULL;
39 static GtkAccelGroup *ACCEL = NULL;
40 static gboolean ACCEL_SET = FALSE;
43 update_menubar (TboWindow *tbo)
47 char *actions[20] = {"FlipHObj", "FlipVObj", "OrderUpObj", "OrderDownObj", "DeleteObj", "CloneObj"};
49 int obj_n_elements = 4;
50 gboolean activated = FALSE;
55 TboDrawing *drawing = TBO_DRAWING (tbo->drawing);
56 TboToolSelector *selector = TBO_TOOL_SELECTOR (tbo->toolbar->tools[TBO_TOOLBAR_SELECTOR]);
57 TboObjectBase *obj = selector->selected_object;
58 Frame *frame = selector->selected_frame;
60 if (!MENU_ACTION_GROUP)
63 if (tbo_drawing_get_current_frame (drawing) && obj)
65 for (i=0; i<elements; i++)
67 action = gtk_action_group_get_action (MENU_ACTION_GROUP, actions[i]);
68 gtk_action_set_sensitive (action, TRUE);
71 else if (!tbo_drawing_get_current_frame (drawing) && frame)
73 for (i=obj_n_elements; i<elements; i++)
75 action = gtk_action_group_get_action (MENU_ACTION_GROUP, actions[i]);
76 gtk_action_set_sensitive (action, TRUE);
81 for (i=0; i<elements; i++)
83 action = gtk_action_group_get_action (MENU_ACTION_GROUP, actions[i]);
84 gtk_action_set_sensitive (action, FALSE);
90 clone_obj_cb (GtkWidget *widget, TboWindow *tbo)
92 TboToolSelector *selector = TBO_TOOL_SELECTOR (tbo->toolbar->tools[TBO_TOOLBAR_SELECTOR]);
93 TboObjectBase *obj = selector->selected_object;
94 Frame *frame = selector->selected_frame;
95 Page *page = tbo_comic_get_current_page (tbo->comic);
96 TboDrawing *drawing = TBO_DRAWING (tbo->drawing);
98 if (!tbo_drawing_get_current_frame (drawing) && frame)
100 Frame *cloned_frame = tbo_frame_clone (frame);
101 cloned_frame->x += 10;
102 cloned_frame->y -= 10;
103 tbo_page_add_frame (page, cloned_frame);
104 tbo_toolbar_set_selected_tool (tbo->toolbar, TBO_TOOLBAR_SELECTOR);
105 tbo_tool_selector_set_selected (selector, cloned_frame);
107 else if (obj && tbo_drawing_get_current_frame (drawing))
109 TboObjectBase *cloned_obj = obj->clone (obj);
112 tbo_frame_add_obj (frame, cloned_obj);
113 tbo_toolbar_set_selected_tool (tbo->toolbar, TBO_TOOLBAR_SELECTOR);
114 tbo_tool_selector_set_selected_obj (selector, cloned_obj);
116 tbo_drawing_update (TBO_DRAWING (tbo->drawing));
121 delete_obj_cb (GtkWidget *widget, TboWindow *tbo)
123 TboToolSelector *selector = TBO_TOOL_SELECTOR (tbo->toolbar->tools[TBO_TOOLBAR_SELECTOR]);
124 TboObjectBase *obj = selector->selected_object;
125 Frame *frame = selector->selected_frame;
126 Page *page = tbo_comic_get_current_page (tbo->comic);
127 TboDrawing *drawing = TBO_DRAWING (tbo->drawing);
129 if (obj && tbo_drawing_get_current_frame (drawing))
131 tbo_frame_del_obj (frame, obj);
132 tbo_tool_selector_set_selected_obj (selector, NULL);
134 else if (!tbo_drawing_get_current_frame (drawing) && frame)
136 tbo_page_del_frame (page, frame);
137 tbo_tool_selector_set_selected (selector, NULL);
139 tbo_drawing_update (TBO_DRAWING (tbo->drawing));
144 flip_v_cb (GtkWidget *widget, TboWindow *tbo)
146 TboToolSelector *selector = TBO_TOOL_SELECTOR (tbo->toolbar->tools[TBO_TOOLBAR_SELECTOR]);
147 TboObjectBase *obj = selector->selected_object;
149 tbo_object_base_flipv (obj);
150 tbo_drawing_update (TBO_DRAWING (tbo->drawing));
155 flip_h_cb (GtkWidget *widget, TboWindow *tbo)
157 TboToolSelector *selector = TBO_TOOL_SELECTOR (tbo->toolbar->tools[TBO_TOOLBAR_SELECTOR]);
158 TboObjectBase *obj = selector->selected_object;
160 tbo_object_base_fliph (obj);
161 tbo_drawing_update (TBO_DRAWING (tbo->drawing));
166 order_up_cb (GtkWidget *widget, TboWindow *tbo)
168 TboToolSelector *selector = TBO_TOOL_SELECTOR (tbo->toolbar->tools[TBO_TOOLBAR_SELECTOR]);
169 TboObjectBase *obj = selector->selected_object;
170 Frame *current_frame = selector->selected_frame;
172 tbo_object_base_order_up (obj, current_frame);
173 tbo_drawing_update (TBO_DRAWING (tbo->drawing));
178 order_down_cb (GtkWidget *widget, TboWindow *tbo)
180 TboToolSelector *selector = TBO_TOOL_SELECTOR (tbo->toolbar->tools[TBO_TOOLBAR_SELECTOR]);
181 TboObjectBase *obj = selector->selected_object;
182 Frame *current_frame = selector->selected_frame;
184 tbo_object_base_order_down (obj, current_frame);
185 tbo_drawing_update (TBO_DRAWING (tbo->drawing));
189 gboolean close_cb (GtkWidget *widget, TboWindow *tbo)
191 tbo_window_free_cb (widget, NULL, tbo);
196 tutorial_cb (GtkWidget *widget, TboWindow *tbo){
197 char *filename = DATA_DIR "/tut.tbo";
198 tbo_comic_open (tbo, filename);
199 tbo_window_set_path (tbo, filename);
200 tbo_drawing_update (TBO_DRAWING (tbo->drawing));
201 tbo_window_update_status (tbo, 0, 0);
206 about_cb (GtkWidget *widget, TboWindow *tbo){
207 const gchar *authors[] = {"danigm <dani@danigm.net>", NULL};
208 const gchar *artists[] = {"danigm <dani@danigm.net>",
210 "Arcadia http://www.arcadiaproject.org :",
211 "Samuel Navas Portillo",
212 "Daniel Pavón Pérez",
213 "Juan Jesús Pérez Luna",
219 "Rafael García <bladecoder@gmail.com>",
222 "VIcente Pons <simpons@gmail.com>",
225 gtk_show_about_dialog (GTK_WINDOW (tbo->window),
226 "name", _("TBO comic editor"),
230 "website", "http://trac.danigm.net/tbo",
231 "translator-credits", _("translator-credits"),
238 tbo_menu_export (GtkWidget *widget, TboWindow *tbo)
244 static const GtkActionEntry tbo_menu_entries [] = {
247 { "File", NULL, N_("_File") },
248 { "Edit", NULL, N_("_Edit") },
249 { "Help", NULL, N_("Help") },
253 { "NewFile", GTK_STOCK_NEW, N_("_New"), "<control>N",
254 N_("Create a new file"),
255 G_CALLBACK (tbo_comic_new_dialog) },
257 { "OpenFile", GTK_STOCK_OPEN, N_("_Open"), "<control>O",
258 N_("Open a new file"),
259 G_CALLBACK (tbo_comic_open_dialog) },
261 { "SaveFile", GTK_STOCK_SAVE, N_("_Save"), "<control>S",
262 N_("Save current document"),
263 G_CALLBACK (tbo_comic_save_dialog) },
265 { "SaveFileAs", GTK_STOCK_SAVE_AS, N_("_Save as"), "",
266 N_("Save current document as ..."),
267 G_CALLBACK (tbo_comic_saveas_dialog) },
269 { "ToPNG", GTK_STOCK_FILE, N_("Export as..."), "",
270 N_("Save current document as..."),
271 G_CALLBACK (tbo_menu_export) },
273 { "Quit", GTK_STOCK_QUIT, N_("_Quit"), "<control>Q",
275 G_CALLBACK (close_cb) },
279 { "CloneObj", GTK_STOCK_COPY, N_("Clone"), "<control>d",
281 G_CALLBACK (clone_obj_cb) },
282 { "DeleteObj", GTK_STOCK_DELETE, N_("Delete"), "Delete",
284 G_CALLBACK (delete_obj_cb) },
285 { "FlipHObj", NULL, N_("Horizontal flip"), "h",
286 N_("Horizontal flip"),
287 G_CALLBACK (flip_h_cb) },
288 { "FlipVObj", NULL, N_("Vertical flip"), "v",
290 G_CALLBACK (flip_v_cb) },
291 { "OrderUpObj", NULL, N_("Move to front"), "Page_Up",
293 G_CALLBACK ( order_up_cb ) },
294 { "OrderDownObj", NULL, N_("Move to back"), "Page_Down",
296 G_CALLBACK ( order_down_cb ) },
299 { "Tutorial", NULL, N_("Tutorial"), "",
301 G_CALLBACK (tutorial_cb) },
303 { "About", GTK_STOCK_ABOUT, N_("About"), "",
305 G_CALLBACK (about_cb) },
308 GtkWidget *generate_menu (TboWindow *window){
310 GtkUIManager *manager;
311 GError *error = NULL;
313 manager = gtk_ui_manager_new ();
314 gtk_ui_manager_add_ui_from_file (manager, DATA_DIR "/ui/tbo-menu-ui.xml", &error);
317 g_warning (_("Could not merge tbo-menu-ui.xml: %s"), error->message);
318 g_error_free (error);
321 MENU_ACTION_GROUP = gtk_action_group_new ("MenuActions");
322 gtk_action_group_set_translation_domain (MENU_ACTION_GROUP, NULL);
323 gtk_action_group_add_actions (MENU_ACTION_GROUP, tbo_menu_entries,
324 G_N_ELEMENTS (tbo_menu_entries), window);
326 gtk_ui_manager_insert_action_group (manager, MENU_ACTION_GROUP, 0);
328 menu = gtk_ui_manager_get_widget (manager, "/menubar");
330 ACCEL = gtk_ui_manager_get_accel_group (manager);
331 gtk_window_add_accel_group (GTK_WINDOW (window->window), ACCEL);
339 tbo_menu_enable_accel_keys (TboWindow *tbo)
341 if (ACCEL && !ACCEL_SET)
343 gtk_window_add_accel_group (GTK_WINDOW (tbo->window), ACCEL);
349 tbo_menu_disable_accel_keys (TboWindow *tbo)
351 if (ACCEL && ACCEL_SET)
353 gtk_window_remove_accel_group (GTK_WINDOW (tbo->window), ACCEL);