[yelp] Adding "New Window" menu item, goes to document top



commit c1d0c3d380366d2272a1013b82c4738904ebb2be
Author: Shaun McCance <shaunm gnome org>
Date:   Fri Apr 2 09:42:06 2010 -0500

    Adding "New Window" menu item, goes to document top
    
    I think I'd actually prefer this to go to the root instead, but that
    involves inspecting the document. Right now, there's no difference
    in practice anyway.

 data/ui/yelp-ui.xml    |    3 ++-
 src/yelp-application.c |   35 +++++++++++++++++++++++++++++++----
 src/yelp-application.h |    2 ++
 src/yelp-window.c      |   23 ++++++++++++++++++++++-
 4 files changed, 57 insertions(+), 6 deletions(-)
---
diff --git a/data/ui/yelp-ui.xml b/data/ui/yelp-ui.xml
index 2daeba3..afaeb19 100644
--- a/data/ui/yelp-ui.xml
+++ b/data/ui/yelp-ui.xml
@@ -2,7 +2,8 @@
 <ui>
   <menubar>
     <menu action="PageMenu">
-      <menuitem action="Close"/>
+      <menuitem action="NewWindow"/>
+      <menuitem action="CloseWindow"/>
     </menu>
     <menu action="ViewMenu">
       <menuitem action="LargerText"/>
diff --git a/src/yelp-application.c b/src/yelp-application.c
index f428b48..dda2214 100644
--- a/src/yelp-application.c
+++ b/src/yelp-application.c
@@ -36,6 +36,8 @@
 #include "yelp-dbus.h"
 #include "yelp-window.h"
 
+#define DEFAULT_URI "ghelp:user-guide"
+
 static gboolean editor_mode = FALSE;
 
 static const GOptionEntry entries[] = {
@@ -47,6 +49,7 @@ typedef struct _YelpApplicationLoad YelpApplicationLoad;
 struct _YelpApplicationLoad {
     YelpApplication *app;
     guint timestamp;
+    gboolean new;
 };
 
 static void          yelp_application_init             (YelpApplication       *app);
@@ -227,7 +230,7 @@ yelp_application_run (YelpApplication  *app,
     if (argc > 1)
         uri = argv[1];
     else
-        uri = "ghelp:user-guide";
+        uri = DEFAULT_URI;
 
     proxy = dbus_g_proxy_new_for_name (priv->connection,
                                        DBUS_SERVICE_DBUS,
@@ -316,6 +319,25 @@ yelp_application_load_uri (YelpApplication  *app,
     return TRUE;
 }
 
+void
+yelp_application_new_window (YelpApplication  *app,
+                             const gchar      *uri)
+{
+    YelpApplicationLoad *data;
+    YelpUri *yuri;
+
+    data = g_new (YelpApplicationLoad, 1);
+    data->app = app;
+    data->new = TRUE;
+
+    yuri = yelp_uri_new (uri ? uri : DEFAULT_URI);
+
+    g_signal_connect (yuri, "resolved",
+                      G_CALLBACK (application_uri_resolved),
+                      data);
+    yelp_uri_resolve (yuri);
+}
+
 static void
 application_uri_resolved (YelpUri             *uri,
                           YelpApplicationLoad *data)
@@ -327,7 +349,10 @@ application_uri_resolved (YelpUri             *uri,
 
     doc_uri = yelp_uri_get_document_uri (uri);
 
-    window = g_hash_table_lookup (priv->windows_by_document, doc_uri);
+    if (data->new)
+        window = NULL;
+    else
+        window = g_hash_table_lookup (priv->windows_by_document, doc_uri);
 
     if (window == NULL) {
         GtkActionGroup *group;
@@ -342,8 +367,10 @@ application_uri_resolved (YelpUri             *uri,
                                       priv->show_text_cursor);
         priv->map_show_text_cursor = FALSE;
 
-        g_hash_table_insert (priv->windows_by_document, doc_uri, window);
-        g_object_set_data (G_OBJECT (window), "doc_uri", doc_uri);
+        if (!data->new) {
+            g_hash_table_insert (priv->windows_by_document, doc_uri, window);
+            g_object_set_data (G_OBJECT (window), "doc_uri", doc_uri);
+        }
         g_signal_connect (window, "delete-event",
                           G_CALLBACK (application_window_deleted), data->app);
     }
diff --git a/src/yelp-application.h b/src/yelp-application.h
index a6ebc0d..ed48bb0 100644
--- a/src/yelp-application.h
+++ b/src/yelp-application.h
@@ -53,6 +53,8 @@ gboolean          yelp_application_load_uri    (YelpApplication  *app,
                                                 const gchar      *uri,
                                                 guint             timestamp,
                                                 GError          **error);
+void              yelp_application_new_window  (YelpApplication  *app,
+                                                const gchar      *uri);
 
 void              yelp_application_adjust_font          (YelpApplication  *app,
                                                          gint              adjust);
diff --git a/src/yelp-window.c b/src/yelp-window.c
index 2a23f71..3934d8f 100644
--- a/src/yelp-window.c
+++ b/src/yelp-window.c
@@ -49,6 +49,8 @@ static void          yelp_window_set_property     (GObject            *object,
                                                    const GValue       *value,
                                                    GParamSpec         *pspec);
 
+static void          window_new                   (GtkAction          *action,
+                                                   YelpWindow         *window);
 static void          window_close                 (GtkAction          *action,
                                                    YelpWindow         *window);
 static void          window_open_location         (GtkAction          *action,
@@ -165,7 +167,12 @@ static const GtkActionEntry entries[] = {
     { "ViewMenu",      NULL, N_("_View")      },
     { "GoMenu",        NULL, N_("_Go")        },
 
-    { "Close", GTK_STOCK_CLOSE,
+    { "NewWindow", GTK_STOCK_NEW,
+      N_("_New Window"),
+      "<Control>N",
+      NULL,
+      G_CALLBACK (window_new) },
+    { "CloseWindow", GTK_STOCK_CLOSE,
       N_("_Close"),
       "<Control>W",
       NULL,
@@ -457,6 +464,20 @@ yelp_window_get_action_group (YelpWindow *window)
 /******************************************************************************/
 
 static void
+window_new (GtkAction *action, YelpWindow *window)
+{
+    gchar *uri = NULL;
+    YelpWindowPrivate *priv = GET_PRIV (window);
+
+    if (priv->back_list && priv->back_list->data)
+        uri = yelp_uri_get_document_uri (((YelpBackEntry *) priv->back_list->data)->uri);
+
+    yelp_application_new_window (priv->application, uri);
+
+    g_free (uri);
+}
+
+static void
 window_close (GtkAction *action, YelpWindow *window)
 {
     gboolean ret;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]