[patch] "Save" menu/toolbar action is greyed out when file unchanged
Douglas Burke <[email protected]>
| Newsgroups | gmane.editors.conglomerate.devel |
|---|---|
| Message-ID | <Pine.GSO.4.58.0410171756120.22582@lagado> |
The attached patch makes the "Save" menu item and toolbar icon insensitive if the file has not been modified. It's not 100% foolproof (add a space and then delete it [ie no use of the undo]) and it doesn't recognise the file is unchanged. Doug
save.patch
(text/plain, 3.8 KB)
Index: src/ChangeLog =================================================================== RCS file: /cvs/gnome/conglomerate/src/ChangeLog,v retrieving revision 1.736 diff -u -r1.736 ChangeLog --- src/ChangeLog 15 Oct 2004 16:01:40 -0000 1.736 +++ src/ChangeLog 17 Oct 2004 21:54:53 -0000 @@ -1,3 +1,11 @@ +2004-10-17 Douglas Burke <[email protected]> + + * cong-document.c, cong-file-open.c: + + The "Save" menu and toolbar items are now inactive when the file + has not changed. It's not 100% foolproof (add a space and then delete + it and it still thinks the file has changed). + 2004-10-15 Douglas Burke <[email protected]> * cong-attribute-editor-cdata.c, cong-attribute-editor-cdata.h, cong-attribute-editor-enumeration.c, cong-attribute-editor-lang.c, cong-attribute-editor-lang.h, cong-attribute-editor-nmtoken.c, cong-attribute-editor-nmtoken.h, cong-attribute-editor.c, cong-attribute-editor.h, cong-attribute-wrapper-check-button.c, cong-attribute-wrapper-check-button.h, cong-attribute-wrapper-radio-button.c, cong-attribute-wrapper-radio-button.h, cong-attribute-wrapper.c, cong-attribute-wrapper.h, cong-glade.c: Index: src/cong-document.c =================================================================== RCS file: /cvs/gnome/conglomerate/src/cong-document.c,v retrieving revision 1.111 diff -u -r1.111 cong-document.c --- src/cong-document.c 13 Oct 2004 20:15:21 -0000 1.111 +++ src/cong-document.c 17 Oct 2004 21:54:53 -0000 @@ -89,6 +89,10 @@ #undef PRIVATE #define PRIVATE(x) ((x)->private) +/* taken from cong-menus.c */ +#define SET_ACTION_SENSITIVE(action_name, sens) \ + g_object_set (G_OBJECT (gtk_action_group_get_action (cong_primary_window_get_action_group (primary_window, CONG_ACTION_GROUP_DOCUMENT), action_name)), "sensitive", sens, NULL) + enum { BEGIN_EDIT, END_EDIT, @@ -374,6 +378,7 @@ PRIVATE(doc)->url = g_strdup(url); g_get_current_time(&PRIVATE(doc)->time_of_last_save); + PRIVATE(doc)->modified = FALSE; #if TEST_VIEW { @@ -825,18 +830,23 @@ * * TODO: Write me */ + void cong_document_set_modified(CongDocument *doc, gboolean modified) { g_return_if_fail(doc); if (PRIVATE(doc)->modified != modified) { + CongPrimaryWindow *primary_window = PRIVATE(doc)->primary_window; PRIVATE(doc)->modified = modified; - /* get at primary window; set title */ - if (PRIVATE(doc)->primary_window) { - cong_primary_window_update_title(PRIVATE(doc)->primary_window); + if (primary_window) { + /* set title */ + cong_primary_window_update_title (primary_window); + + /* change the menu/toolbar Save action */ + SET_ACTION_SENSITIVE("Save",modified); } } } Index: src/cong-file-open.c =================================================================== RCS file: /cvs/gnome/conglomerate/src/cong-file-open.c,v retrieving revision 1.22 diff -u -r1.22 cong-file-open.c --- src/cong-file-open.c 16 Jul 2004 03:31:34 -0000 1.22 +++ src/cong-file-open.c 17 Oct 2004 21:54:53 -0000 @@ -14,6 +14,10 @@ #include "cong-vfs.h" #include "cong-file-selection.h" +/* taken from cong-menus.c */ +#define SET_ACTION_SENSITIVE(action_name, sens) \ + g_object_set (G_OBJECT (gtk_action_group_get_action (cong_primary_window_get_action_group (primary_window, CONG_ACTION_GROUP_DOCUMENT), action_name)), "sensitive", sens, NULL) + /* Data and callback for handling the forced loading of a file, autogenerating a dispspec: */ struct force_dialog { @@ -190,6 +194,14 @@ g_assert(cong_doc); cong_primary_window_new(cong_doc); + + /* now we have a primary window we can set the "Save" menu item */ + { + CongPrimaryWindow *primary_window = cong_document_get_primary_window(cong_doc); + g_assert (primary_window); + SET_ACTION_SENSITIVE("Save",FALSE); + } + g_object_unref( G_OBJECT(cong_doc)); }