gnucash stable: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Mon Mar 27 00:53:43 EDT 2023
Updated via https://github.com/Gnucash/gnucash/commit/bdf79f77 (commit)
via https://github.com/Gnucash/gnucash/commit/6c5f9052 (commit)
via https://github.com/Gnucash/gnucash/commit/b3553b13 (commit)
via https://github.com/Gnucash/gnucash/commit/dd0d65d8 (commit)
from https://github.com/Gnucash/gnucash/commit/f3c0665c (commit)
commit bdf79f7721262b873aaa78c3a1fce24688b521e2
Merge: b3553b13d3 6c5f905260
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Mon Mar 27 12:48:52 2023 +0800
Merge branch 'master-fileopen-filter' into stable #1576
commit 6c5f9052602d8e01cbf244c6e526bf131d969655
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Wed Mar 15 00:25:44 2023 +0800
[2/2] [dialog-file-access] File/Open shows *.gnucash by default
Initially File/Open should show *.gnucash files, excluding the
backup *.gnucash.*.gnucash files.
diff --git a/gnucash/gnome-utils/dialog-file-access.c b/gnucash/gnome-utils/dialog-file-access.c
index 01ba3bdec8..e0ce32fe59 100644
--- a/gnucash/gnome-utils/dialog-file-access.c
+++ b/gnucash/gnome-utils/dialog-file-access.c
@@ -22,6 +22,7 @@
* Boston, MA 02110-1301, USA gnu at gnu.org *
\********************************************************************/
+#include <stdbool.h>
#include <config.h>
#include <gtk/gtk.h>
@@ -33,6 +34,7 @@
#include "dialog-utils.h"
#include "dialog-file-access.h"
#include "gnc-file.h"
+#include "gnc-filepath-utils.h"
#include "gnc-plugin-file-history.h"
#include "gnc-session.h"
@@ -243,6 +245,15 @@ get_default_database( void )
return default_db;
}
+typedef bool (*CharToBool)(const char*);
+
+static bool datafile_filter (const GtkFileFilterInfo* filter_info,
+ CharToBool filename_checker)
+{
+ return filter_info && filter_info->filename &&
+ filename_checker (filter_info->filename);
+}
+
static void free_file_access_window (FileAccessWindow *faw)
{
g_free (faw->starting_dir);
@@ -340,6 +351,31 @@ gnc_ui_file_access (GtkWindow *parent, int type)
faw->fileChooser = GTK_FILE_CHOOSER(fileChooser);
gtk_box_pack_start( GTK_BOX(file_chooser), GTK_WIDGET(fileChooser), TRUE, TRUE, 6 );
+ /* set up .gnucash filters for Datafile operations */
+ GtkFileFilter *filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("All files"));
+ gtk_file_filter_add_pattern (filter, "*");
+ gtk_file_chooser_add_filter (faw->fileChooser, filter);
+
+ filter = gtk_file_filter_new ();
+ /* Translators: *.gnucash and *.xac are file patterns and must not
+ be translated*/
+ gtk_file_filter_set_name (filter, _("Datafiles only (*.gnucash, *.xac)"));
+ gtk_file_filter_add_custom (filter, GTK_FILE_FILTER_FILENAME,
+ (GtkFileFilterFunc)datafile_filter,
+ gnc_filename_is_datafile, NULL);
+ gtk_file_chooser_add_filter (faw->fileChooser, filter);
+ gtk_file_chooser_set_filter (faw->fileChooser, filter);
+
+ filter = gtk_file_filter_new ();
+ /* Translators: *.gnucash.*.gnucash, *.xac.*.xac are file
+ patterns and must not be translated*/
+ gtk_file_filter_set_name (filter, _("Backups only (*.gnucash.*.gnucash, *.xac.*.xac)"));
+ gtk_file_filter_add_custom (filter, GTK_FILE_FILTER_FILENAME,
+ (GtkFileFilterFunc)datafile_filter,
+ gnc_filename_is_backup, NULL);
+ gtk_file_chooser_add_filter (faw->fileChooser, filter);
+
/* Set the default directory */
if (type == FILE_ACCESS_OPEN || type == FILE_ACCESS_SAVE_AS)
{
commit b3553b13d34cd8ddb435d5b2433a570acd4780fa
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Mon Mar 27 11:52:11 2023 +0800
[dialog-search.c] if result, select first one. also grab focus.
Addendum to bug 355498 to select the result. This allows faster
keyboard navigation -- Find Customer, input search string, press
ENTER, use up/down to select desired object, press ENTER to open
object.
diff --git a/gnucash/gnome-search/dialog-search.c b/gnucash/gnome-search/dialog-search.c
index 9d07ca63e1..3c67c85626 100644
--- a/gnucash/gnome-search/dialog-search.c
+++ b/gnucash/gnome-search/dialog-search.c
@@ -368,13 +368,14 @@ gnc_search_dialog_display_results (GNCSearchWindow *sw)
if (gnc_query_view_get_num_entries(GNC_QUERY_VIEW(sw->result_view)) < max_count)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (sw->new_rb), TRUE);
- /* If there is only one item then select it */
- if (gnc_query_view_get_num_entries (GNC_QUERY_VIEW(sw->result_view)) == 1)
+ /* If there are results then select the first, and grab focus */
+ if (gnc_query_view_get_num_entries (GNC_QUERY_VIEW(sw->result_view)) > 0)
{
GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(sw->result_view));
GtkTreePath *path = gtk_tree_path_new_first ();
gtk_tree_selection_select_path (selection, path);
gtk_tree_path_free (path);
+ gtk_widget_grab_focus (sw->result_view);
}
}
commit dd0d65d861991dc2d8c198c7ef22b813a39e8fdf
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Thu Mar 16 09:36:38 2023 +0800
[1/2] [gnc-filepath-utils.cpp] gnc_filename_is_backup|datafile
uses std::regex to test filename
diff --git a/libgnucash/core-utils/gnc-filepath-utils.cpp b/libgnucash/core-utils/gnc-filepath-utils.cpp
index c613640c36..28f6b57acd 100644
--- a/libgnucash/core-utils/gnc-filepath-utils.cpp
+++ b/libgnucash/core-utils/gnc-filepath-utils.cpp
@@ -66,6 +66,7 @@
#include "gnc-locale-utils.hpp"
#include <boost/filesystem.hpp>
#include <boost/locale.hpp>
+#include <regex>
#include <iostream>
#include <numeric>
@@ -1326,4 +1327,21 @@ gnc_list_all_paths (void)
return std::accumulate (paths.rbegin(), paths.rend(), (GList*) nullptr, accum);
}
+static const std::regex
+backup_regex (".*[.](?:xac|gnucash)[.][0-9]{14}[.](?:xac|gnucash)$");
+
+gboolean gnc_filename_is_backup (const char *filename)
+{
+ return std::regex_match (filename, backup_regex);
+}
+
+static const std::regex
+datafile_regex (".*[.](?:xac|gnucash)$");
+
+gboolean gnc_filename_is_datafile (const char *filename)
+{
+ return !gnc_filename_is_backup (filename) &&
+ std::regex_match (filename, datafile_regex);
+}
+
/* =============================== END OF FILE ========================== */
diff --git a/libgnucash/core-utils/gnc-filepath-utils.h b/libgnucash/core-utils/gnc-filepath-utils.h
index 1f5ca8bae0..fd10e186be 100644
--- a/libgnucash/core-utils/gnc-filepath-utils.h
+++ b/libgnucash/core-utils/gnc-filepath-utils.h
@@ -194,6 +194,10 @@ typedef struct
*/
GList *gnc_list_all_paths (void);
+gboolean gnc_filename_is_backup (const char *filename);
+
+gboolean gnc_filename_is_datafile (const char *filename);
+
#ifdef __cplusplus
}
#endif
diff --git a/libgnucash/core-utils/test/gtest-path-utilities.cpp b/libgnucash/core-utils/test/gtest-path-utilities.cpp
index 14792dfcab..3f6f8459dd 100644
--- a/libgnucash/core-utils/test/gtest-path-utilities.cpp
+++ b/libgnucash/core-utils/test/gtest-path-utilities.cpp
@@ -121,3 +121,14 @@ TEST_F(PathTest, gnc_path_get_sysconfdir)
g_free(sysconfpath);
#endif
}
+
+TEST_F (PathTest, gnc_filename_is_backup)
+{
+ EXPECT_EQ (gnc_filename_is_backup (""), false);
+ EXPECT_EQ (gnc_filename_is_backup ("a.gnucash"), false);
+ EXPECT_EQ (gnc_filename_is_backup ("a.gnucash.20201131010203.gnucash"), true);
+
+ EXPECT_EQ (gnc_filename_is_datafile (""), false);
+ EXPECT_EQ (gnc_filename_is_datafile ("a.gnucash"), true);
+ EXPECT_EQ (gnc_filename_is_datafile ("a.gnucash.20201131010203.gnucash"), false);
+}
Summary of changes:
gnucash/gnome-search/dialog-search.c | 5 +--
gnucash/gnome-utils/dialog-file-access.c | 36 ++++++++++++++++++++++
libgnucash/core-utils/gnc-filepath-utils.cpp | 18 +++++++++++
libgnucash/core-utils/gnc-filepath-utils.h | 4 +++
.../core-utils/test/gtest-path-utilities.cpp | 11 +++++++
5 files changed, 72 insertions(+), 2 deletions(-)
More information about the gnucash-changes
mailing list