]> git.sur5r.net Git - glabels/blobdiff - glabels2/src/ui.c
2009-09-17 Jim Evins <evins@snaught.com>
[glabels] / glabels2 / src / ui.c
index 53727197cea1765e9f75b1a5f00bdd8b263fe5e3..62b67d4ecc56a87d56b837be2da05e7f1172e8c6 100644 (file)
@@ -1,34 +1,31 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-
-/**
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  ui.c:  GLabels ui module
+/*
+ *  ui.c
+ *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
  *
- *  Copyright (C) 2001-2002  Jim Evins <evins@snaught.com>.
+ *  This file is part of gLabels.
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  gLabels is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
- *  This program is distributed in the hope that it will be useful,
+ *  gLabels is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
  */
+
 #include <config.h>
 
 #include "ui.h"
 
 #include <glib/gi18n.h>
 #include <gconf/gconf-client.h>
-#include "recent-files/egg-recent-view.h"
-#include "recent-files/egg-recent-view-uimanager.h"
+#include <gtk/gtk.h>
+#include <string.h>
 
 #include "ui-util.h"
 #include "ui-commands.h"
 
 #include "debug.h"
 
+
 /*==========================================================================*/
 /* Private macros and constants.                                            */
 /*==========================================================================*/
 
+
 /*==========================================================================*/
 /* Private types.                                                           */
 /*==========================================================================*/
@@ -78,10 +77,6 @@ static void menu_item_select_cb            (GtkMenuItem     *proxy,
 static void menu_item_deselect_cb          (GtkMenuItem     *proxy,
                                            glWindow        *window);
 
-static char *recent_tooltip_func           (EggRecentItem   *item,
-                                           gpointer         user_data);
-
-
 
 /*==========================================================================*/
 /* Private globals                                                          */
@@ -91,7 +86,7 @@ static GtkActionEntry entries[] = {
 
        /* Menu entries. */
        { "FileMenu",                NULL, N_("_File") },
-       { "FileRecentsMenu",         NULL, N_("Recent _Files") },
+       { "FileRecentsMenu",         NULL, N_("Open Recent _Files") },
        { "EditMenu",                NULL, N_("_Edit") },
        { "ViewMenu",                NULL, N_("_View") },
        { "ViewMainToolBarMenu",     NULL, N_("Customize Main Toolbar") },
@@ -105,6 +100,9 @@ static GtkActionEntry entries[] = {
        { "ObjectsAlignVertMenu",    NULL, N_("Align _Vertical") },
        { "HelpMenu",                NULL, N_("_Help") },
 
+       /* Popup entries. */
+       { "ContextMenu", NULL, N_("Context Menu") },
+       { "EmptySelectionContextMenu", NULL, N_("Context Menu") },
 
        /* File action entries. */
        { "FileNew",
@@ -436,14 +434,6 @@ static GtkToggleActionEntry toggle_entries[] = {
          G_CALLBACK (gl_ui_cmd_view_property_bar_toggle),
          TRUE },
 
-       { "ViewPropertyToolBarToolTips",
-         NULL,
-         N_("Show tooltips"),
-         NULL,
-         N_("Show tooltips for property toolbar"),
-         G_CALLBACK (gl_ui_cmd_view_property_bar_tips_toggle),
-         TRUE },
-
        { "ViewGrid",
          NULL,
          N_("Grid"),
@@ -481,22 +471,6 @@ static GtkToggleActionEntry ui_toggle_entries[] = {
          G_CALLBACK (view_ui_item_toggled_cb),
          TRUE },
 
-       { "ViewMainToolBarToolTips",
-         NULL,
-         N_("Show tooltips"),
-         NULL,
-         N_("Show tooltips for main toolbar"),
-         G_CALLBACK (view_ui_item_toggled_cb),
-         TRUE },
-
-       { "ViewDrawingToolBarToolTips",
-         NULL,
-         N_("Show tooltips"),
-         NULL,
-         N_("Show tooltips for drawing toolbar"),
-         G_CALLBACK (view_ui_item_toggled_cb),
-         TRUE },
-
 };
 static guint n_ui_toggle_entries = G_N_ELEMENTS (ui_toggle_entries);
 
@@ -507,9 +481,7 @@ static const gchar *ui_info =
 "              <menu action='FileMenu'>"
 "                      <menuitem action='FileNew' />"
 "                      <menuitem action='FileOpen' />"
-"                       <menu action='FileRecentsMenu'>"
-"                              <placeholder name='FileRecentsPlaceHolder' />"
-"                       </menu>"
+"                      <menuitem action='FileRecentsMenu' />"
 "                      <separator />"
 "                      <menuitem action='FileSave' />"
 "                      <menuitem action='FileSaveAs' />"
@@ -538,16 +510,6 @@ static const gchar *ui_info =
 "                      <menuitem action='ViewDrawingToolBar' />"
 "                      <menuitem action='ViewPropertyToolBar' />"
 "                      <separator />"
-"                      <menu action='ViewMainToolBarMenu'>"
-"                              <menuitem action='ViewMainToolBarToolTips' />"
-"                      </menu>"
-"                      <menu action='ViewDrawingToolBarMenu'>"
-"                              <menuitem action='ViewDrawingToolBarToolTips' />"
-"                      </menu>"
-"                      <menu action='ViewPropertyToolBarMenu'>"
-"                              <menuitem action='ViewPropertyToolBarToolTips' />"
-"                      </menu>"
-"                      <separator />"
 "                      <menuitem action='ViewGrid' />"
 "                      <menuitem action='ViewMarkup' />"
 "                      <separator />"
@@ -628,6 +590,40 @@ static const gchar *ui_info =
 "              <toolitem action='ObjectsMergeProperties' />"
 "      </toolbar>"
 ""
+"      <popup action='ContextMenu'>"
+"              <menu action='ObjectsOrderMenu'>"
+"                      <menuitem action='ObjectsRaise' />"
+"                      <menuitem action='ObjectsLower' />"
+"              </menu>"
+"              <menu action='ObjectsRotateFlipMenu'>"
+"                      <menuitem action='ObjectsRotateLeft' />"
+"                      <menuitem action='ObjectsRotateRight' />"
+"                      <menuitem action='ObjectsFlipHorizontal' />"
+"                      <menuitem action='ObjectsFlipVertical' />"
+"              </menu>"
+"              <menu action='ObjectsAlignHorizMenu'>"
+"                      <menuitem action='ObjectsAlignLeft' />"
+"                      <menuitem action='ObjectsAlignHCenter' />"
+"                      <menuitem action='ObjectsAlignRight' />"
+"                      <menuitem action='ObjectsCenterHorizontal' />"
+"              </menu>"
+"              <menu action='ObjectsAlignVertMenu'>"
+"                      <menuitem action='ObjectsAlignTop' />"
+"                      <menuitem action='ObjectsAlignVCenter' />"
+"                      <menuitem action='ObjectsAlignBottom' />"
+"                      <menuitem action='ObjectsCenterVertical' />"
+"              </menu>"
+"              <separator />"
+"              <menuitem action='EditCut' />"
+"              <menuitem action='EditCopy' />"
+"              <menuitem action='EditPaste' />"
+"              <menuitem action='EditDelete' />"
+"      </popup>"
+""
+"      <popup action='EmptySelectionContextMenu'>"
+"              <menuitem action='EditPaste' />"
+"      </popup>"
+""
 "</ui>";
 
 
@@ -676,7 +672,7 @@ static gchar* doc_verbs [] = {
 };
 
 static gchar* doc_modified_verbs [] = {
-       "/ui/MenuBar/FileMenu/Save",
+       "/ui/MenuBar/FileMenu/FileSave",
 
        NULL
 };
@@ -724,7 +720,7 @@ gl_ui_new (glWindow *window)
        GtkUIManager            *ui;
        GtkActionGroup          *actions;
        GError                  *error = NULL;
-       EggRecentViewUIManager  *recent_view;
+       GtkWidget               *recent_menu;
 
        gl_debug (DEBUG_UI, "START");
 
@@ -740,6 +736,7 @@ gl_ui_new (glWindow *window)
                          G_CALLBACK (disconnect_proxy_cb), window);
 
        actions = gtk_action_group_new ("Actions");
+        gtk_action_group_set_translation_domain (actions, NULL);
        gtk_action_group_add_actions (actions, entries, n_entries, GTK_WINDOW (window));
        gtk_action_group_add_toggle_actions (actions, 
                                             toggle_entries, n_toggle_entries, 
@@ -751,6 +748,7 @@ gl_ui_new (glWindow *window)
        gtk_ui_manager_insert_action_group (ui, actions, 0);
        gtk_window_add_accel_group (GTK_WINDOW (window), gtk_ui_manager_get_accel_group (ui));
 
+       gl_debug (DEBUG_UI, "Creating ui from string");
        if (!gtk_ui_manager_add_ui_from_string (ui, ui_info, strlen (ui_info), &error)) {
                g_message ("building menus failed: %s", error->message);
                g_error_free (error);
@@ -763,16 +761,13 @@ gl_ui_new (glWindow *window)
        /* Set view grid and markup visibility according to prefs */
        set_view_style (ui);
                
-       /* add an eggRecentView */
-        recent_view  =
-               egg_recent_view_uimanager_new (ui,
-                                              "/ui/MenuBar/FileMenu/FileRecentsMenu/FileRecentsPlaceHolder",
-                                              G_CALLBACK (gl_ui_cmd_file_open_recent),
-                                              window);
-       egg_recent_view_uimanager_show_icons (recent_view, FALSE);
-       egg_recent_view_uimanager_set_tooltip_func (recent_view, recent_tooltip_func, NULL);
-       egg_recent_view_set_model (EGG_RECENT_VIEW (recent_view), gl_recent_get_model ());
-       g_object_set_data (G_OBJECT (ui), "recent-view", recent_view);
+       /* add an Open Recents Submenu */
+        recent_menu  = gl_recent_create_menu ();
+       g_signal_connect (G_OBJECT (recent_menu), "item-activated",
+                         G_CALLBACK (gl_ui_cmd_file_open_recent), window);
+       gtk_menu_item_set_submenu (GTK_MENU_ITEM (gtk_ui_manager_get_widget (ui, "/MenuBar/FileMenu/FileRecentsMenu")),
+                                  recent_menu);
+
 
        gl_ui_util_set_verb_list_sensitive (ui, doc_verbs, FALSE);
 
@@ -781,29 +776,23 @@ gl_ui_new (glWindow *window)
        return ui;
 }
 
+
 /*****************************************************************************/
 /** Unref wrapper.                                                           */
 /*****************************************************************************/
 void
 gl_ui_unref (GtkUIManager *ui)
 {
-       GObject *recent_view;
-
        gl_debug (DEBUG_UI, "START");
 
-       /* Pull out recent view to unreference. */
-       recent_view = g_object_get_data (G_OBJECT(ui), "recent-view");
-       if (recent_view) {
-               g_object_unref (recent_view);
-       }
-
        g_object_unref(ui);
 
        gl_debug (DEBUG_UI, "END");
 }
 
+
 /*****************************************************************************/
-/* Update all verbs of given UI component.                                   */
+/** Update all verbs of given UI component.                                  */
 /*****************************************************************************/
 void
 gl_ui_update_all (GtkUIManager *ui,
@@ -844,8 +833,9 @@ gl_ui_update_all (GtkUIManager *ui,
        gl_debug (DEBUG_UI, "END");
 }
 
+
 /*****************************************************************************/
-/* Update all verbs of given UI component to "no document" state.            */
+/** Update all verbs of given UI component to "no document" state.           */
 /*****************************************************************************/
 void
 gl_ui_update_nodoc (GtkUIManager *ui)
@@ -857,8 +847,9 @@ gl_ui_update_nodoc (GtkUIManager *ui)
        gl_debug (DEBUG_UI, "END");
 }
 
+
 /*****************************************************************************/
-/* Update label modified verbs of given UI component.                        */
+/** Update label modified verbs of given UI component.                       */
 /*****************************************************************************/
 void
 gl_ui_update_modified_verbs (GtkUIManager *ui,
@@ -873,8 +864,9 @@ gl_ui_update_modified_verbs (GtkUIManager *ui,
        gl_debug (DEBUG_UI, "END");
 }
 
+
 /*****************************************************************************/
-/* Update verbs associated with selection state of given UI component.       */
+/** Update verbs associated with selection state of given UI component.      */
 /*****************************************************************************/
 void
 gl_ui_update_selection_verbs (GtkUIManager *ui,
@@ -895,8 +887,9 @@ gl_ui_update_selection_verbs (GtkUIManager *ui,
        gl_debug (DEBUG_UI, "END");
 }
 
+
 /*****************************************************************************/
-/* Update verbs associated with zoom level of given UI component.            */
+/** Update verbs associated with zoom level of given UI component.           */
 /*****************************************************************************/
 void
 gl_ui_update_zoom_verbs (GtkUIManager *ui,
@@ -912,8 +905,9 @@ gl_ui_update_zoom_verbs (GtkUIManager *ui,
        gl_debug (DEBUG_UI, "END");
 }
 
+
 /*****************************************************************************/
-/* Update undo/redo verbs of given UI component.                             */
+/** Update undo/redo verbs of given UI component.                            */
 /*****************************************************************************/
 void
 gl_ui_update_undo_redo_verbs (GtkUIManager *ui,
@@ -930,8 +924,9 @@ gl_ui_update_undo_redo_verbs (GtkUIManager *ui,
        gl_debug (DEBUG_UI, "END");
 }
 
+
 /*---------------------------------------------------------------------------*/
-/* PRIVATE.  View menu item toggled callback.                                */
+/** PRIVATE.  View menu item toggled callback.                               */
 /*---------------------------------------------------------------------------*/
 static void
 view_ui_item_toggled_cb (GtkToggleAction *action,
@@ -956,13 +951,6 @@ view_ui_item_toggled_cb (GtkToggleAction *action,
                gl_prefs_model_save_settings (gl_prefs);
        }
 
-       if (strcmp (name, "ViewMainToolBarToolTips") == 0)
-       {
-               gl_prefs->main_toolbar_view_tooltips = state;
-               set_app_main_toolbar_style (ui);
-               gl_prefs_model_save_settings (gl_prefs);
-       }
-
        if (strcmp (name, "ViewDrawingToolBar") == 0)
        {
                gl_prefs->drawing_toolbar_visible = state;
@@ -970,18 +958,12 @@ view_ui_item_toggled_cb (GtkToggleAction *action,
                gl_prefs_model_save_settings (gl_prefs);
        }
 
-       if (strcmp (name, "ViewDrawingToolBarToolTips") == 0)
-       {
-               gl_prefs->drawing_toolbar_view_tooltips = state;
-               set_app_drawing_toolbar_style (ui);
-               gl_prefs_model_save_settings (gl_prefs);
-       }
-
        gl_debug (DEBUG_UI, "");
 }
 
+
 /*---------------------------------------------------------------------------*/
-/* PRIVATE.  Set main toolbar style.                                         */
+/** PRIVATE.  Set main toolbar style.                                        */
 /*---------------------------------------------------------------------------*/
 static void
 set_app_main_toolbar_style (GtkUIManager *ui)
@@ -996,18 +978,8 @@ set_app_main_toolbar_style (GtkUIManager *ui)
        gl_ui_util_set_verb_state (ui, "/ui/ViewMenu/ViewMainToolBar",
                                   gl_prefs->main_toolbar_visible);
 
-       gl_ui_util_set_verb_sensitive (ui, "/ui/ViewMenu/ViewMainToolBarToolTips",
-                                      gl_prefs->main_toolbar_visible);
-
-       gl_ui_util_set_verb_state (ui, "/ui/ViewMenu/ViewMainToolBarToolTips",
-                                  gl_prefs->main_toolbar_view_tooltips);
-
-       
        toolbar = gtk_ui_manager_get_widget (ui, "/MainToolBar");
 
-       gtk_toolbar_set_tooltips (GTK_TOOLBAR (toolbar),
-                                 gl_prefs->main_toolbar_view_tooltips);
-
        if (gl_prefs->main_toolbar_visible) {
                gtk_widget_show_all (toolbar);
        } else {
@@ -1019,7 +991,7 @@ set_app_main_toolbar_style (GtkUIManager *ui)
 
 
 /*---------------------------------------------------------------------------*/
-/* PRIVATE.  Set drawing toolbar style.                                      */
+/** PRIVATE.  Set drawing toolbar style.                                     */
 /*---------------------------------------------------------------------------*/
 static void
 set_app_drawing_toolbar_style (GtkUIManager *ui)
@@ -1034,18 +1006,8 @@ set_app_drawing_toolbar_style (GtkUIManager *ui)
        gl_ui_util_set_verb_state (ui, "/ui/MenuBar/ViewMenu/ViewDrawingToolBar",
                                   gl_prefs->drawing_toolbar_visible);
 
-       gl_ui_util_set_verb_sensitive (ui, "/ui/MenuBar/ViewMenu/ViewDrawingToolBarToolTips",
-                                      gl_prefs->drawing_toolbar_visible);
-
-       gl_ui_util_set_verb_state (ui, "/ui/MenuBar/ViewMenuDrawingToolBarToolTips",
-                                  gl_prefs->drawing_toolbar_view_tooltips);
-
-       
        toolbar = gtk_ui_manager_get_widget (ui, "/DrawingToolBar");
 
-       gtk_toolbar_set_tooltips (GTK_TOOLBAR (toolbar),
-                                 gl_prefs->drawing_toolbar_view_tooltips);
-
        gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS);
 
        if (gl_prefs->drawing_toolbar_visible) {
@@ -1057,8 +1019,9 @@ set_app_drawing_toolbar_style (GtkUIManager *ui)
        gl_debug (DEBUG_UI, "END");
 }
 
+
 /*---------------------------------------------------------------------------*/
-/* PRIVATE.  Set visibility of grid and markup.                              */
+/** PRIVATE.  Set visibility of grid and markup.                             */
 /*---------------------------------------------------------------------------*/
 static void
 set_view_style (GtkUIManager *ui)
@@ -1076,8 +1039,9 @@ set_view_style (GtkUIManager *ui)
        gl_debug (DEBUG_UI, "END");
 }
 
+
 /*---------------------------------------------------------------------------*/
-/* PRIVATE.  Connect proxy callback.                                         */
+/** PRIVATE.  Connect proxy callback.                                        */
 /*---------------------------------------------------------------------------*/
 static void
 connect_proxy_cb (GtkUIManager *ui,
@@ -1094,8 +1058,9 @@ connect_proxy_cb (GtkUIManager *ui,
        }
 }
 
+
 /*---------------------------------------------------------------------------*/
-/* PRIVATE.  Disconnect proxy callback.                                      */
+/** PRIVATE.  Disconnect proxy callback.                                     */
 /*---------------------------------------------------------------------------*/
 static void
 disconnect_proxy_cb (GtkUIManager *ui,
@@ -1112,8 +1077,9 @@ disconnect_proxy_cb (GtkUIManager *ui,
        }
 }
 
+
 /*---------------------------------------------------------------------------*/
-/* PRIVATE.  Menu item select callback.                                      */
+/** PRIVATE.  Menu item select callback.                                     */
 /*---------------------------------------------------------------------------*/
 static void
 menu_item_select_cb (GtkMenuItem *proxy,
@@ -1137,8 +1103,9 @@ menu_item_select_cb (GtkMenuItem *proxy,
        }
 }
 
+
 /*---------------------------------------------------------------------------*/
-/* PRIVATE.  Menu item deselect callback.                                    */
+/** PRIVATE.  Menu item deselect callback.                                   */
 /*---------------------------------------------------------------------------*/
 static void
 menu_item_deselect_cb (GtkMenuItem *proxy,
@@ -1151,23 +1118,13 @@ menu_item_deselect_cb (GtkMenuItem *proxy,
                           window->menu_tips_context_id);
 }
 
-/*---------------------------------------------------------------------------*/
-/* PRIVATE.  Tooltip function for recent file menu items.                    */
-/*---------------------------------------------------------------------------*/
-static char *
-recent_tooltip_func (EggRecentItem *item, gpointer user_data)
-{
-       char *tip;
-       char *uri_for_display;
-
-       uri_for_display = egg_recent_item_get_uri_for_display (item);
-       g_return_val_if_fail (uri_for_display != NULL, NULL);
-
-       tip = g_strdup_printf (_("Open '%s'"), uri_for_display);
-
-       g_free (uri_for_display);
-
-       return tip;
-}
 
 
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */