gnucash maint: Multiple changes pushed

Geert Janssens gjanssens at code.gnucash.org
Fri Dec 11 06:07:07 EST 2015


Updated	 via  https://github.com/Gnucash/gnucash/commit/f46ab3b9 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/bfce5d84 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/38c0cc94 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/cb0ae9ee (commit)
	from  https://github.com/Gnucash/gnucash/commit/35b5d944 (commit)



commit f46ab3b98bd40773ccc22efb1f2fc2c901aa00e0
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Fri Dec 11 12:06:18 2015 +0100

    Improve the revert action
    
    - Move it's implementation to gnc-file with the rest of the file actions
    - Ask user confirmation
    - Don't ask to save before reverting

diff --git a/src/gnome-utils/gnc-file.c b/src/gnome-utils/gnc-file.c
index 6c8bba2..cde782b 100644
--- a/src/gnome-utils/gnc-file.c
+++ b/src/gnome-utils/gnc-file.c
@@ -1564,6 +1564,29 @@ gnc_file_do_save_as (const char* filename)
 }
 
 void
+gnc_file_revert (void)
+{
+    QofSession *session;
+    const gchar *fileurl, *filename, *tmp;
+    const gchar *title = _("Reverting will discard all unsaved changes to %s. Are you sure you want to proceed ?");
+
+    if (!gnc_main_window_all_finish_pending())
+        return;
+
+    session = gnc_get_current_session();
+    fileurl = qof_session_get_url(session);
+    if (fileurl == NULL)
+        fileurl = _("<unknown>");
+    if ((tmp = strrchr(fileurl, '/')) != NULL)
+        filename = tmp + 1;
+
+    if (!gnc_verify_dialog (NULL, FALSE, title, filename))
+        return;
+
+    qof_book_mark_session_saved (qof_session_get_book (session));
+    gnc_file_open_file (fileurl, qof_book_is_readonly(gnc_get_current_book()));}
+
+void
 gnc_file_quit (void)
 {
     QofSession *session;
diff --git a/src/gnome-utils/gnc-file.h b/src/gnome-utils/gnc-file.h
index 57353a7..538096f 100644
--- a/src/gnome-utils/gnc-file.h
+++ b/src/gnome-utils/gnc-file.h
@@ -34,7 +34,7 @@
  *
  * These GUI utilities implement and maintain a single global "session"
  * that defines the currently edited account group.  In a sense, these
- * functions provide the GUI for the xaccSession object.  The session
+ * functions provide the GUI for the qof_session object.  The session
  * is essentially a file that is open for editing, with locks on it
  * to prevent other readers and writers from accessing it as long as its
  * open.
@@ -92,6 +92,9 @@
  *    case it is up to the user to try again, or to pick
  *    a different filename).
  *
+ * The gnc_file_revert() routine will discard any changes since the last
+ * time the session was saved (but only after user confirmation).
+ *
  * The gnc_file_open_file() routine behaves much like the gnc_file_open()
  *    routine, except that the new file to open is passed as a char *
  *    argument.
@@ -130,6 +133,7 @@ void gnc_file_save (void);
 void gnc_file_save_as (void);
 void gnc_file_do_export(const char* filename);
 void gnc_file_do_save_as(const char* filename);
+void gnc_file_revert (void);
 
 /** Tell the user about errors in the backends
 
diff --git a/src/gnome/gnc-plugin-basic-commands.c b/src/gnome/gnc-plugin-basic-commands.c
index e34ce9a..40089d9 100644
--- a/src/gnome/gnc-plugin-basic-commands.c
+++ b/src/gnome/gnc-plugin-basic-commands.c
@@ -494,20 +494,19 @@ gnc_main_window_cmd_file_save_as (GtkAction *action, GncMainWindowActionData *da
 static void
 gnc_main_window_cmd_file_revert (GtkAction *action, GncMainWindowActionData *data)
 {
+    GtkWidget *dialog;
+    QofSession *session;
+    QofBook *book;
+    const gchar *filename, *tmp;
+    const gchar *title = _("Reverting will discard all unsaved changes to %s. Are you sure you want to proceed ?");
+
     g_return_if_fail (data != NULL);
 
     if (!gnc_main_window_all_finish_pending())
         return;
 
     gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
-
-    {
-        gchar *filename = gnc_history_get_last();
-        // And actually open the current file again
-        gnc_file_open_file (filename, qof_book_is_readonly(gnc_get_current_book()));
-        g_free(filename);
-    }
-
+    gnc_file_revert();
     gnc_window_set_progressbar_window (NULL);
 }
 

commit bfce5d840d990f2d762d26a61eb4d915f310f813
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Fri Dec 11 12:05:15 2015 +0100

    Have a more generic mechanism to set Save action's sensitivity and use it for Revert action as well
    
    So far the Save actions was more or less treated as an exception.
    The new code enables/disables selected actions based on the dirty
    state of the book.

diff --git a/src/gnome-utils/gnc-main-window.c b/src/gnome-utils/gnc-main-window.c
index 4c7913c..712f11b 100644
--- a/src/gnome-utils/gnc-main-window.c
+++ b/src/gnome-utils/gnc-main-window.c
@@ -1468,26 +1468,13 @@ gnc_main_window_generate_title (GncMainWindow *window)
     const gchar *readonly_text = NULL;
     gchar *readonly;
     gchar *title;
-    GtkAction* action;
 
-    /* The save action is sensitive if the book is dirty */
-    action = gnc_main_window_find_action (window, "FileSaveAction");
-    if (action != NULL)
-    {
-        gtk_action_set_sensitive(action, FALSE);
-    }
     if (gnc_current_session_exist())
     {
         book_id = qof_session_get_url (gnc_get_current_session ());
         book = gnc_get_current_book();
         if (qof_book_session_not_saved (book))
-        {
             dirty = "*";
-            if (action != NULL)
-            {
-                gtk_action_set_sensitive(action, TRUE);
-            }
-        }
         if (qof_book_is_readonly(book))
         {
             /* Translators: This string is shown in the window title if this
@@ -1538,6 +1525,8 @@ gnc_main_window_generate_title (GncMainWindow *window)
     gnc_plugin_update_actions(priv->action_group,
                               immutable_page_actions,
                               "sensitive", !immutable);
+    /* Trigger sensitivity updtates of other actions such as Save/Revert */
+    g_signal_emit_by_name (window, "page_changed", page);
     g_free( filename );
     g_free(readonly);
 
diff --git a/src/gnome/gnc-plugin-basic-commands.c b/src/gnome/gnc-plugin-basic-commands.c
index 4db3a04..e34ce9a 100644
--- a/src/gnome/gnc-plugin-basic-commands.c
+++ b/src/gnome/gnc-plugin-basic-commands.c
@@ -224,16 +224,29 @@ static const gchar *gnc_plugin_important_actions[] =
     NULL,
 };
 
-/** These actions, plus FileSaveAction, are made not sensitive (i.e.,
+/** These actions are made not sensitive (i.e.,
  * their toolbar and menu items are grayed out and do not send events
  * when clicked) when the current book is "Read Only".
  */
-static const gchar *readonly_inactive_actions[] =
+static const gchar *readwrite_only_active_actions[] =
 {
     "ToolsBookCloseAction",
     NULL
 };
 
+/** These actions are made not sensitive (i.e.,
+ * their toolbar and menu items are grayed out and do not send events
+ * when clicked) when the current book is not dirty. As a read only book
+ * can't be dirty this implies they will be disabled for a read only book
+ * as well.
+ */
+static const gchar *dirty_only_active_actions[] =
+{
+    "FileSaveAction",
+    "FileRevertAction",
+    NULL
+};
+
 /** The instance private data structure for an basic commands
  *  plugin. */
 typedef struct GncPluginBasicCommandsPrivate
@@ -323,7 +336,6 @@ static void update_inactive_actions(GncPluginPage *plugin_page)
 {
     GncMainWindow  *window;
     GtkActionGroup *action_group;
-    GtkAction *file_save_action;
 
     // We are readonly - so we have to switch particular actions to inactive.
     gboolean is_readwrite = !qof_book_is_readonly(gnc_get_current_book());
@@ -339,12 +351,10 @@ static void update_inactive_actions(GncPluginPage *plugin_page)
     g_return_if_fail(GTK_IS_ACTION_GROUP(action_group));
 
     /* Set the action's sensitivity */
-    gnc_plugin_update_actions (action_group, readonly_inactive_actions,
+    gnc_plugin_update_actions (action_group, readwrite_only_active_actions,
                                "sensitive", is_readwrite);
-    /* FileSaveAction needs to be set separately because it has *two* conditions */
-    file_save_action = gtk_action_group_get_action (action_group,
-                       "FileSaveAction");
-    gtk_action_set_sensitive (file_save_action, is_readwrite && is_dirty);
+    gnc_plugin_update_actions (action_group, dirty_only_active_actions,
+                               "sensitive", is_dirty);
 }
 
 static void

commit 38c0cc94515f5936620fabcc4eace778b337e33f
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Fri Dec 11 11:57:50 2015 +0100

    Remove a couple of obsolete FIXME comments

diff --git a/src/gnome/gnc-plugin-basic-commands.c b/src/gnome/gnc-plugin-basic-commands.c
index 5440850..4db3a04 100644
--- a/src/gnome/gnc-plugin-basic-commands.c
+++ b/src/gnome/gnc-plugin-basic-commands.c
@@ -432,7 +432,6 @@ gnc_main_window_cmd_file_new (GtkAction *action, GncMainWindowActionData *data)
         return;
 
     gnc_file_new ();
-    /* FIXME GNOME 2 Port (update the title etc.) */
 }
 
 static void
@@ -463,7 +462,6 @@ gnc_main_window_cmd_file_save (GtkAction *action, GncMainWindowActionData *data)
     gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
     gnc_file_save ();
     gnc_window_set_progressbar_window (NULL);
-    /* FIXME GNOME 2 Port (update the title etc.) */
 }
 
 static void
@@ -481,7 +479,6 @@ gnc_main_window_cmd_file_save_as (GtkAction *action, GncMainWindowActionData *da
     gnc_file_save_as ();
 #endif
     gnc_window_set_progressbar_window (NULL);
-    /* FIXME GNOME 2 Port (update the title etc.) */
 }
 
 static void
@@ -516,8 +513,6 @@ gnc_main_window_cmd_file_export_accounts (GtkAction *action, GncMainWindowAction
     gnc_file_export ();
 #endif
     gnc_window_set_progressbar_window (NULL);
-    /* FIXME GNOME 2 Port (update the title etc.) */
-    /* gnc_refresh_main_window_info (); */
 }
 
 static void

commit cb0ae9ee8d0b9b475b10d2ab42b1197023b58b3f
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Thu Dec 10 22:14:35 2015 +0100

    Make dirty handling as currently defined by qof_alt_dirty_mode the only dirty handling mode

diff --git a/src/engine/gnc-engine.c b/src/engine/gnc-engine.c
index 24d34db..6ba252b 100644
--- a/src/engine/gnc-engine.c
+++ b/src/engine/gnc-engine.c
@@ -60,7 +60,6 @@ gnc_engine_init_part1()
 
     /* initialize QOF */
     qof_init();
-    qof_set_alt_dirty_mode(TRUE);
 
     /* Now register our core types */
     cashobjects_register();
diff --git a/src/libqof/qof/qofid.c b/src/libqof/qof/qofid.c
index 116082b..e9509e6 100644
--- a/src/libqof/qof/qofid.c
+++ b/src/libqof/qof/qofid.c
@@ -31,7 +31,6 @@
 #include "qofid-p.h"
 
 static QofLogModule log_module = QOF_MOD_ENGINE;
-static gboolean qof_alt_dirty_mode = FALSE;
 
 struct QofCollection_s
 {
@@ -44,20 +43,6 @@ struct QofCollection_s
 
 /* =============================================================== */
 
-gboolean
-qof_get_alt_dirty_mode (void)
-{
-    return qof_alt_dirty_mode;
-}
-
-void
-qof_set_alt_dirty_mode (gboolean enabled)
-{
-    qof_alt_dirty_mode = enabled;
-}
-
-/* =============================================================== */
-
 QofCollection *
 qof_collection_new (QofIdType type)
 {
@@ -102,8 +87,6 @@ qof_collection_remove_entity (QofInstance *ent)
     if (!col) return;
     guid = qof_instance_get_guid(ent);
     g_hash_table_remove (col->hash_of_entities, guid);
-    if (!qof_alt_dirty_mode)
-        qof_collection_mark_dirty(col);
     qof_instance_set_collection(ent, NULL);
 }
 
@@ -118,8 +101,6 @@ qof_collection_insert_entity (QofCollection *col, QofInstance *ent)
     g_return_if_fail (col->e_type == ent->e_type);
     qof_collection_remove_entity (ent);
     g_hash_table_insert (col->hash_of_entities, (gpointer)guid, ent);
-    if (!qof_alt_dirty_mode)
-        qof_collection_mark_dirty(col);
     qof_instance_set_collection(ent, col);
 }
 
@@ -146,8 +127,6 @@ qof_collection_add_entity (QofCollection *coll, QofInstance *ent)
         return FALSE;
     }
     g_hash_table_insert (coll->hash_of_entities, (gpointer)guid, ent);
-    if (!qof_alt_dirty_mode)
-        qof_collection_mark_dirty(coll);
     return TRUE;
 }
 
diff --git a/src/libqof/qof/qofid.h b/src/libqof/qof/qofid.h
index ae1624d..670b2d5 100644
--- a/src/libqof/qof/qofid.h
+++ b/src/libqof/qof/qofid.h
@@ -140,24 +140,6 @@ print error message if its bad  */
 
 */
 
-/** Is QOF operating in "alternate" dirty mode?
- *
- * In normal mode, whenever an instance is dirtied, the collection
- * (and therefore the book) is immediately marked as dirty.  In
- * alternate mode, the collection is only marked dirty when a dirty
- * instance is committed.  If a dirty instance is freed instead of
- * committed, the dirty state of collection (and therefore the book)
- * is never changed. */
-gboolean qof_get_alt_dirty_mode (void);
-
-/** Set QOF into "alternate" dirty mode.  In normal mode, whenever an
- *  instance is dirtied, the collection (and therefore the book) is
- *  immediately marked as dirty.  In alternate mode, the collection is
- *  only marked dirty when a dirty instance is committed.  If a dirty
- *  instance is freed instead of committed, the dirty state of
- *  collection (and therefore the book) is never changed. */
-void qof_set_alt_dirty_mode (gboolean enabled);
-
 /** @name Collections of Entities
  @{ */
 
diff --git a/src/libqof/qof/qofinstance.c b/src/libqof/qof/qofinstance.c
index f61d107..30121db 100644
--- a/src/libqof/qof/qofinstance.c
+++ b/src/libqof/qof/qofinstance.c
@@ -716,15 +716,7 @@ qof_instance_get_dirty (QofInstance *inst)
     }
 
     priv = GET_PRIVATE(inst);
-    if (qof_get_alt_dirty_mode())
-        return priv->dirty;
-    coll = priv->collection;
-    if (qof_collection_is_dirty(coll))
-    {
-        return priv->dirty;
-    }
-    priv->dirty = FALSE;
-    return FALSE;
+    return priv->dirty;
 }
 
 void
@@ -735,11 +727,6 @@ qof_instance_set_dirty(QofInstance* inst)
 
     priv = GET_PRIVATE(inst);
     priv->dirty = TRUE;
-    if (!qof_get_alt_dirty_mode())
-    {
-        coll = priv->collection;
-        qof_collection_mark_dirty(coll);
-    }
 }
 
 gboolean
@@ -1002,7 +989,7 @@ qof_commit_edit_part2(QofInstance *inst,
 
     priv = GET_PRIVATE(inst);
 
-    if (priv->dirty && qof_get_alt_dirty_mode() &&
+    if (priv->dirty &&
         !(priv->infant && priv->do_free)) {
       qof_collection_mark_dirty(priv->collection);
       qof_book_mark_session_dirty(priv->book);
diff --git a/src/libqof/qof/test/test-qofinstance.c b/src/libqof/qof/test/test-qofinstance.c
index a47a8ad..9b50680 100644
--- a/src/libqof/qof/test/test-qofinstance.c
+++ b/src/libqof/qof/test/test-qofinstance.c
@@ -345,24 +345,7 @@ test_instance_get_set_dirty( Fixture *fixture, gconstpointer pData )
     g_test_message( "Test get_dirty on empty instance returns false" );
     g_assert( qof_instance_get_dirty( NULL ) == FALSE );
 
-    g_test_message( "Test dirty in normal mode" );
-    g_assert( !qof_get_alt_dirty_mode() );
-    g_assert( !qof_instance_get_dirty_flag( fixture->inst ) );
-    g_assert( !qof_collection_is_dirty( col ) );
-    g_assert( !qof_instance_get_dirty( fixture->inst ) );
-    qof_instance_set_dirty( fixture->inst );
-    g_assert( qof_instance_get_dirty_flag( fixture->inst ) );
-    g_assert( qof_collection_is_dirty( col ) );
-    g_assert( qof_instance_get_dirty( fixture->inst ) );
-
-
-    g_test_message( "Test dirty in alternate mode" );
-    qof_set_alt_dirty_mode ( TRUE );
-    /* restore */
-    qof_collection_mark_clean( col );
-    qof_instance_set_dirty_flag( fixture->inst, FALSE );
-
-    g_assert( qof_get_alt_dirty_mode() );
+    g_test_message( "Test dirty" );
     g_assert( !qof_instance_get_dirty_flag( fixture->inst ) );
     g_assert( !qof_collection_is_dirty( col ) );
     g_assert( !qof_instance_get_dirty( fixture->inst ) );



Summary of changes:
 src/engine/gnc-engine.c                |  1 -
 src/gnome-utils/gnc-file.c             | 23 +++++++++++++++++
 src/gnome-utils/gnc-file.h             |  6 ++++-
 src/gnome-utils/gnc-main-window.c      | 15 ++---------
 src/gnome/gnc-plugin-basic-commands.c  | 46 ++++++++++++++++++----------------
 src/libqof/qof/qofid.c                 | 21 ----------------
 src/libqof/qof/qofid.h                 | 18 -------------
 src/libqof/qof/qofinstance.c           | 17 ++-----------
 src/libqof/qof/test/test-qofinstance.c | 19 +-------------
 9 files changed, 58 insertions(+), 108 deletions(-)



More information about the gnucash-changes mailing list