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;
41 update_menubar (TboWindow *tbo)
45 char *actions[20] = {"FlipHObj", "FlipVObj", "OrderUpObj", "OrderDownObj", "DeleteObj", "CloneObj"};
47 int obj_n_elements = 4;
48 gboolean activated = FALSE;
53 TboDrawing *drawing = TBO_DRAWING (tbo->drawing);
54 TboToolSelector *selector = TBO_TOOL_SELECTOR (tbo->toolbar->tools[TBO_TOOLBAR_SELECTOR]);
55 TboObjectBase *obj = selector->selected_object;
56 Frame *frame = selector->selected_frame;
58 if (!MENU_ACTION_GROUP)
61 if (tbo_drawing_get_current_frame (drawing) && obj)
63 for (i=0; i<elements; i++)
65 action = gtk_action_group_get_action (MENU_ACTION_GROUP, actions[i]);
66 gtk_action_set_sensitive (action, TRUE);
69 else if (!tbo_drawing_get_current_frame (drawing) && frame)
71 for (i=obj_n_elements; i<elements; i++)
73 action = gtk_action_group_get_action (MENU_ACTION_GROUP, actions[i]);
74 gtk_action_set_sensitive (action, TRUE);
79 for (i=0; i<elements; i++)
81 action = gtk_action_group_get_action (MENU_ACTION_GROUP, actions[i]);
82 gtk_action_set_sensitive (action, FALSE);
88 clone_obj_cb (GtkWidget *widget, TboWindow *tbo)
90 TboToolSelector *selector = TBO_TOOL_SELECTOR (tbo->toolbar->tools[TBO_TOOLBAR_SELECTOR]);
91 TboObjectBase *obj = selector->selected_object;
92 Frame *frame = selector->selected_frame;
93 Page *page = tbo_comic_get_current_page (tbo->comic);
94 TboDrawing *drawing = TBO_DRAWING (tbo->drawing);
96 if (!tbo_drawing_get_current_frame (drawing) && frame)
98 Frame *cloned_frame = tbo_frame_clone (frame);
99 cloned_frame->x += 10;
100 cloned_frame->y -= 10;
101 tbo_page_add_frame (page, cloned_frame);
102 tbo_toolbar_set_selected_tool (tbo->toolbar, TBO_TOOLBAR_SELECTOR);
103 tbo_tool_selector_set_selected (selector, cloned_frame);
105 else if (obj && tbo_drawing_get_current_frame (drawing))
107 TboObjectBase *cloned_obj = obj->clone (obj);
110 tbo_frame_add_obj (frame, cloned_obj);
111 tbo_toolbar_set_selected_tool (tbo->toolbar, TBO_TOOLBAR_SELECTOR);
112 tbo_tool_selector_set_selected_obj (selector, cloned_obj);
114 tbo_drawing_update (TBO_DRAWING (tbo->drawing));
119 delete_obj_cb (GtkWidget *widget, TboWindow *tbo)
121 TboToolSelector *selector = TBO_TOOL_SELECTOR (tbo->toolbar->tools[TBO_TOOLBAR_SELECTOR]);
122 TboObjectBase *obj = selector->selected_object;
123 Frame *frame = selector->selected_frame;
124 Page *page = tbo_comic_get_current_page (tbo->comic);
125 TboDrawing *drawing = TBO_DRAWING (tbo->drawing);
127 if (obj && tbo_drawing_get_current_frame (drawing))
129 tbo_frame_del_obj (frame, obj);
130 tbo_tool_selector_set_selected_obj (selector, NULL);
132 else if (!tbo_drawing_get_current_frame (drawing) && frame)
134 tbo_page_del_frame (page, frame);
135 tbo_tool_selector_set_selected (selector, NULL);
137 tbo_drawing_update (TBO_DRAWING (tbo->drawing));
142 flip_v_cb (GtkWidget *widget, TboWindow *tbo)
144 TboToolSelector *selector = TBO_TOOL_SELECTOR (tbo->toolbar->tools[TBO_TOOLBAR_SELECTOR]);
145 TboObjectBase *obj = selector->selected_object;
147 tbo_object_base_flipv (obj);
148 tbo_drawing_update (TBO_DRAWING (tbo->drawing));
153 flip_h_cb (GtkWidget *widget, TboWindow *tbo)
155 TboToolSelector *selector = TBO_TOOL_SELECTOR (tbo->toolbar->tools[TBO_TOOLBAR_SELECTOR]);
156 TboObjectBase *obj = selector->selected_object;
158 tbo_object_base_fliph (obj);
159 tbo_drawing_update (TBO_DRAWING (tbo->drawing));
164 order_up_cb (GtkWidget *widget, TboWindow *tbo)
166 TboToolSelector *selector = TBO_TOOL_SELECTOR (tbo->toolbar->tools[TBO_TOOLBAR_SELECTOR]);
167 TboObjectBase *obj = selector->selected_object;
168 Frame *current_frame = selector->selected_frame;
170 tbo_object_base_order_up (obj, current_frame);
171 tbo_drawing_update (TBO_DRAWING (tbo->drawing));
176 order_down_cb (GtkWidget *widget, TboWindow *tbo)
178 TboToolSelector *selector = TBO_TOOL_SELECTOR (tbo->toolbar->tools[TBO_TOOLBAR_SELECTOR]);
179 TboObjectBase *obj = selector->selected_object;
180 Frame *current_frame = selector->selected_frame;
182 tbo_object_base_order_down (obj, current_frame);
183 tbo_drawing_update (TBO_DRAWING (tbo->drawing));
187 gboolean close_cb (GtkWidget *widget, TboWindow *tbo)
189 tbo_window_free_cb (widget, NULL, tbo);
194 tutorial_cb (GtkWidget *widget, TboWindow *tbo){
195 char *filename = DATA_DIR "/tut.tbo";
196 tbo_comic_open (tbo, filename);
197 tbo_window_set_path (tbo, filename);
198 tbo_drawing_update (TBO_DRAWING (tbo->drawing));
199 tbo_window_update_status (tbo, 0, 0);
204 about_cb (GtkWidget *widget, TboWindow *tbo){
205 const gchar *authors[] = {"danigm <dani@danigm.net>", NULL};
206 const gchar *artists[] = {"danigm <dani@danigm.net>",
208 "Arcadia http://www.arcadiaproject.org :",
209 "Samuel Navas Portillo",
210 "Daniel Pavón Pérez",
211 "Juan Jesús Pérez Luna",
217 "Rafael García <bladecoder@gmail.com>",
220 "VIcente Pons <simpons@gmail.com>",
223 gtk_show_about_dialog (GTK_WINDOW (tbo->window),
224 "name", _("TBO comic editor"),
228 "website", "http://trac.danigm.net/tbo",
229 "translator-credits", _("translator-credits"),
236 tbo_menu_export (GtkWidget *widget, TboWindow *tbo)
242 static const GtkActionEntry tbo_menu_entries [] = {
245 { "File", NULL, N_("_File") },
246 { "Edit", NULL, N_("_Edit") },
247 { "Help", NULL, N_("Help") },
251 { "NewFile", GTK_STOCK_NEW, N_("_New"), "<control>N",
252 N_("Create a new file"),
253 G_CALLBACK (tbo_comic_new_dialog) },
255 { "OpenFile", GTK_STOCK_OPEN, N_("_Open"), "<control>O",
256 N_("Open a new file"),
257 G_CALLBACK (tbo_comic_open_dialog) },
259 { "SaveFile", GTK_STOCK_SAVE, N_("_Save"), "<control>S",
260 N_("Save current document"),
261 G_CALLBACK (tbo_comic_save_dialog) },
263 { "SaveFileAs", GTK_STOCK_SAVE_AS, N_("_Save as"), "",
264 N_("Save current document as ..."),
265 G_CALLBACK (tbo_comic_saveas_dialog) },
267 { "ToPNG", GTK_STOCK_FILE, N_("Export as..."), "",
268 N_("Save current document as..."),
269 G_CALLBACK (tbo_menu_export) },
271 { "Quit", GTK_STOCK_QUIT, N_("_Quit"), "<control>Q",
273 G_CALLBACK (close_cb) },
277 { "CloneObj", GTK_STOCK_COPY, N_("Clone"), "<control>d",
279 G_CALLBACK (clone_obj_cb) },
280 { "DeleteObj", GTK_STOCK_DELETE, N_("Delete"), "Delete",
282 G_CALLBACK (delete_obj_cb) },
283 { "FlipHObj", NULL, N_("Horizontal flip"), "h",
284 N_("Horizontal flip"),
285 G_CALLBACK (flip_h_cb) },
286 { "FlipVObj", NULL, N_("Vertical flip"), "v",
288 G_CALLBACK (flip_v_cb) },
289 { "OrderUpObj", NULL, N_("Move to front"), "Page_Up",
291 G_CALLBACK ( order_up_cb ) },
292 { "OrderDownObj", NULL, N_("Move to back"), "Page_Down",
294 G_CALLBACK ( order_down_cb ) },
297 { "Tutorial", NULL, N_("Tutorial"), "",
299 G_CALLBACK (tutorial_cb) },
301 { "About", GTK_STOCK_ABOUT, N_("About"), "",
303 G_CALLBACK (about_cb) },
306 GtkWidget *generate_menu (TboWindow *window){
308 GtkUIManager *manager;
309 GtkAccelGroup *accel;
310 GError *error = NULL;
312 manager = gtk_ui_manager_new ();
313 gtk_ui_manager_add_ui_from_file (manager, DATA_DIR "/ui/tbo-menu-ui.xml", &error);
316 g_warning (_("Could not merge tbo-menu-ui.xml: %s"), error->message);
317 g_error_free (error);
320 MENU_ACTION_GROUP = gtk_action_group_new ("MenuActions");
321 gtk_action_group_set_translation_domain (MENU_ACTION_GROUP, NULL);
322 gtk_action_group_add_actions (MENU_ACTION_GROUP, tbo_menu_entries,
323 G_N_ELEMENTS (tbo_menu_entries), window);
325 gtk_ui_manager_insert_action_group (manager, MENU_ACTION_GROUP, 0);
327 menu = gtk_ui_manager_get_widget (manager, "/menubar");
329 accel = gtk_ui_manager_get_accel_group (manager);
330 gtk_window_add_accel_group (GTK_WINDOW (window->window), accel);