]> www.fi.muni.cz Git - evince.git/commitdiff
new functions to help with implementation of sensitivity code Fix
authorDave Malcolm <dmalcolm@redhat.com>
Fri, 14 Jan 2005 05:26:54 +0000 (05:26 +0000)
committerDavid Malcolm <dave_malcolm@src.gnome.org>
Fri, 14 Jan 2005 05:26:54 +0000 (05:26 +0000)
2005-01-14  Dave Malcolm  <dmalcolm@redhat.com>

* shell/ev-view.h:
* shell/ev-view.c (ev_view_can_go_back), (ev_view_can_go_forward):
new functions to help with implementation of sensitivity code
* shell/ev-window.c (update_action_sensitivity): Fix sensitivity
of all actions that might require it.  Fixes a crash when you
click on the Zoom actions in a window lacking a document.

ChangeLog
shell/ev-view.c
shell/ev-view.h
shell/ev-window.c

index 6aca2db29bc5dd91cb5eae49b7d02a6512cd5c4d..6a4f9174eae12a86df0e1e94a1b7e8751c77d738 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,16 @@
+2005-01-14  Dave Malcolm  <dmalcolm@redhat.com>
+
+       * shell/ev-view.h:
+       * shell/ev-view.c (ev_view_can_go_back), (ev_view_can_go_forward):      
+       new functions to help with implementation of sensitivity code
+       * shell/ev-window.c (update_action_sensitivity): Fix sensitivity
+       of all actions that might require it.  Fixes a crash when you
+       click on the Zoom actions in a window lacking a document.
+
 2005-01-13  Dave Malcolm  <dmalcolm@redhat.com>
 
-       * shell/ev-window.c (Module): Fix sensitivity of the Find action
+       * shell/ev-window.c (update_action_sensitivity): Fix sensitivity
+       of the Find action
 
 2005-01-13  Marco Pesenti Gritti  <marco@gnome.org>
 
index 41bf94b60e96550d83fe15040bf92760d57f0ebe..8e18ec48bbbcd4a1dc85466124d9971bbcf3ab43 100644 (file)
@@ -1123,6 +1123,23 @@ go_to_index (EvView *view, int index)
        go_to_link (view, link);
 }
 
+gboolean
+ev_view_can_go_back (EvView *view)
+{
+       int index, n;
+
+       g_return_val_if_fail (EV_IS_HISTORY (view->history), FALSE);
+
+       index = ev_history_get_current_index (view->history);
+       n = ev_history_get_n_links (view->history);
+
+       if (n > 0) {
+               return index != MAX (0, index - 1);
+       } else {
+               return FALSE;
+       }
+}
+
 void
 ev_view_go_back        (EvView *view)
 {
@@ -1139,6 +1156,23 @@ ev_view_go_back  (EvView *view)
        }
 }
 
+gboolean
+ev_view_can_go_forward (EvView *view)
+{
+       int index, n;
+
+       g_return_val_if_fail (EV_IS_HISTORY (view->history), FALSE);
+
+       index = ev_history_get_current_index (view->history);
+       n = ev_history_get_n_links (view->history);
+
+       if (n > 0) {
+               return  index != MIN (n - 1, index + 1);
+       } else {
+               return FALSE;
+       }
+}
+
 void
 ev_view_go_forward (EvView *view)
 {
index 0e7237de96a92867e20e237e339bba4168af90b3..e57371aa4da698f59b854e8038cb427e71f79165 100644 (file)
@@ -47,7 +47,9 @@ void          ev_view_copy            (EvView     *view);
 void           ev_view_select_all      (EvView     *view);
 
 /* Navigation */
+gboolean       ev_view_can_go_back     (EvView     *view);
 void           ev_view_go_back         (EvView     *view);
+gboolean       ev_view_can_go_forward  (EvView     *view);
 void           ev_view_go_forward      (EvView     *view);
 void           ev_view_go_to_link      (EvView     *view,
                                         EvLink     *link);
index a1bb4db28fc1689dd49eefffd24a4ade5f6f3bcf..0b8679cb3d63bb605cd4d5ab20fdeb099d1aefb2 100644 (file)
@@ -178,29 +178,71 @@ static void
 update_action_sensitivity (EvWindow *ev_window)
 {
        EvDocument *document;
-       int n_pages;
-       int page;
+       EvView *view;
+
+       gboolean can_go_back = FALSE;
+       gboolean can_go_forward = FALSE;
 
        document = ev_window->priv->document;
 
-       if (document)
-               n_pages = ev_document_get_n_pages (document);
-       else
-               n_pages = 1;
+       view = EV_VIEW (ev_window->priv->view);
 
-       page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
+       if (document) {
+               can_go_back = ev_view_can_go_back (view);
+               can_go_forward = ev_view_can_go_forward (view);
+       }
+
+       /* File menu */
+       /* "FileOpen": always sensitive */
+       set_action_sensitive (ev_window, "FileSaveAs", document!=NULL);
+       set_action_sensitive (ev_window, "FilePrint", document!=NULL);
+       /* "FileCloseWindow": always sensitive */
 
-       set_action_sensitive (ev_window, "GoFirstPage", page > 1);
-       set_action_sensitive (ev_window, "GoPageDown", page > 1);
-       set_action_sensitive (ev_window, "GoPageUp", page < n_pages);
-       set_action_sensitive (ev_window, "GoLastPage", page < n_pages);
+        /* Edit menu */
+       set_action_sensitive (ev_window, "EditCopy", document!=NULL);
+       set_action_sensitive (ev_window, "EditSelectAll", document!=NULL);
 
        if (document)
                set_action_sensitive (ev_window, "EditFind", EV_IS_DOCUMENT_FIND (document));
        else
                set_action_sensitive (ev_window, "EditFind", FALSE);
 
-       
+        /* View menu */
+       set_action_sensitive (ev_window, "ViewZoomIn", document!=NULL);
+       set_action_sensitive (ev_window, "ViewZoomOut", document!=NULL);
+       set_action_sensitive (ev_window, "ViewNormalSize", document!=NULL);
+       set_action_sensitive (ev_window, "ViewBestFit", document!=NULL);
+       set_action_sensitive (ev_window, "ViewPageWidth", document!=NULL);
+
+        /* Go menu */
+       set_action_sensitive (ev_window, "GoBack", can_go_back);
+       set_action_sensitive (ev_window, "GoForward", can_go_forward);
+       if (document) {
+               int n_pages;
+               int page;
+
+               page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
+               n_pages = ev_document_get_n_pages (document);
+
+               set_action_sensitive (ev_window, "GoPageDown", page > 1);
+               set_action_sensitive (ev_window, "GoPageUp", page < n_pages);
+               set_action_sensitive (ev_window, "GoFirstPage", page > 1);
+               set_action_sensitive (ev_window, "GoLastPage", page < n_pages);
+       } else {
+               set_action_sensitive (ev_window, "GoFirstPage", FALSE);
+               set_action_sensitive (ev_window, "GoPageDown", FALSE);
+               set_action_sensitive (ev_window, "GoPageUp", FALSE);
+               set_action_sensitive (ev_window, "GoLastPage", FALSE);
+       }
+        
+       /* Help menu */
+       /* "HelpContents": always sensitive */
+       /* "HelpAbout": always sensitive */
+
+       /* Toolbar-specific actions: */
+       set_action_sensitive (ev_window, NAVIGATION_BACK_ACTION, can_go_back);
+       set_action_sensitive (ev_window, NAVIGATION_FORWARD_ACTION, can_go_forward);
+       set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, document!=NULL);
 }
 
 void