From 023a2f4458cdce47ddf1bba8a6594b7d288de6b1 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 13 Jan 2022 23:47:41 -0500 Subject: [PATCH] V2022.1.3 - Added keyboard shortcuts --- CMakeLists.txt | 2 +- UpdateConfig.json | 2 +- controls/headerbar.cpp | 7 +++ controls/headerbar.h | 2 + views/mainwindow.cpp | 121 +++++++++++++++++++++++++++++++++++- views/mainwindow.h | 39 ++++++++++++ views/settingsdialog.cpp | 3 + views/shortcutswindow.cpp | 51 +++++++++++++++ views/shortcutswindow.h | 30 +++++++++ views/transactiondialog.cpp | 1 - 10 files changed, 252 insertions(+), 6 deletions(-) create mode 100644 views/shortcutswindow.cpp create mode 100644 views/shortcutswindow.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6dfb25f6e..103590176 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(MODELS models/configuration.h models/configuration.cpp models/update/version.h models/update/version.cpp models/update/updateconfig.h models/update/updateconfig.cpp models/update/updater.h models/update/updater.cpp models/transaction.h models/transaction.cpp models/account.h models/account.cpp models/datatransactionscolumns.h models/datatransactionscolumns.cpp) set(CONTROLS controls/headerbar.h controls/headerbar.cpp controls/infobar.h controls/infobar.cpp controls/progressdialog.h controls/progressdialog.cpp) -set(VIEWS views/mainwindow.h views/mainwindow.cpp views/settingsdialog.h views/settingsdialog.cpp views/transactiondialog.h views/transactiondialog.cpp) +set(VIEWS views/mainwindow.h views/mainwindow.cpp views/settingsdialog.h views/settingsdialog.cpp views/shortcutswindow.h views/shortcutswindow.cpp views/transactiondialog.h views/transactiondialog.cpp) add_executable(NickvisionMoney main.cpp ${MODELS} ${CONTROLS} ${VIEWS}) diff --git a/UpdateConfig.json b/UpdateConfig.json index 12dbe7d42..ac2ffceee 100644 --- a/UpdateConfig.json +++ b/UpdateConfig.json @@ -1 +1 @@ -{"LatestVersion":"2022.1.2","Changelog":"- Fixed issue with date handling","LinkToExe":"https://github.com/nlogozzo/NickvisionMoney/releases/download/2022.1.2/NickvisionMoney"} +{"LatestVersion":"2022.1.3","Changelog":"- Added keyboard shortcuts","LinkToExe":"https://github.com/nlogozzo/NickvisionMoney/releases/download/2022.1.3/NickvisionMoney"} diff --git a/controls/headerbar.cpp b/controls/headerbar.cpp index 8f63f43bb..c4fb78e21 100644 --- a/controls/headerbar.cpp +++ b/controls/headerbar.cpp @@ -60,6 +60,7 @@ namespace NickvisionMoney::Controls m_actionGitHubRepo = m_actionHelp->add_action("gitHubRepo"); m_actionReportABug = m_actionHelp->add_action("reportABug"); m_actionSettings = m_actionHelp->add_action("settings"); + m_actionShortcuts = m_actionHelp->add_action("shortcuts"); m_actionChangelog = m_actionHelp->add_action("changelog"); m_actionAbout = m_actionHelp->add_action("about"); insert_action_group("help", m_actionHelp); @@ -71,6 +72,7 @@ namespace NickvisionMoney::Controls m_menuHelpLinks->append("Report a Bug", "help.reportABug"); m_menuHelpActions = Gio::Menu::create(); m_menuHelpActions->append("Settings", "help.settings"); + m_menuHelpActions->append("Keyboard Shortcuts", "help.shortcuts"); m_menuHelpActions->append("Changelog", "help.changelog"); m_menuHelpActions->append("About Money", "help.about"); m_menuHelp->append_section(m_menuHelpUpdate); @@ -178,6 +180,11 @@ namespace NickvisionMoney::Controls return m_actionSettings; } + const std::shared_ptr& HeaderBar::getActionShortcuts() const + { + return m_actionShortcuts; + } + const std::shared_ptr& HeaderBar::getActionChangelog() const { return m_actionChangelog; diff --git a/controls/headerbar.h b/controls/headerbar.h index 27a044e3b..f3009c9de 100644 --- a/controls/headerbar.h +++ b/controls/headerbar.h @@ -26,6 +26,7 @@ namespace NickvisionMoney::Controls const std::shared_ptr& getActionGitHubRepo() const; const std::shared_ptr& getActionReportABug() const; const std::shared_ptr& getActionSettings() const; + const std::shared_ptr& getActionShortcuts() const; const std::shared_ptr& getActionChangelog() const; const std::shared_ptr& getActionAbout() const; @@ -63,6 +64,7 @@ namespace NickvisionMoney::Controls std::shared_ptr m_actionGitHubRepo; std::shared_ptr m_actionReportABug; std::shared_ptr m_actionSettings; + std::shared_ptr m_actionShortcuts; std::shared_ptr m_actionChangelog; std::shared_ptr m_actionAbout; std::shared_ptr m_menuHelp; diff --git a/views/mainwindow.cpp b/views/mainwindow.cpp index 06a5c64d9..dba707f14 100644 --- a/views/mainwindow.cpp +++ b/views/mainwindow.cpp @@ -2,6 +2,7 @@ #include #include "../models/configuration.h" #include "../controls/progressdialog.h" +#include "shortcutswindow.h" #include "settingsdialog.h" #include "transactiondialog.h" @@ -10,7 +11,7 @@ namespace NickvisionMoney::Views using namespace NickvisionMoney::Models; using namespace NickvisionMoney::Controls; - MainWindow::MainWindow() : m_opened(false), m_updater("https://raw.githubusercontent.com/nlogozzo/NickvisionMoney/main/UpdateConfig.json", { "2022.1.2" }), m_account(std::nullopt) + MainWindow::MainWindow() : m_opened(false), m_updater("https://raw.githubusercontent.com/nlogozzo/NickvisionMoney/main/UpdateConfig.json", { "2022.1.3" }), m_account(std::nullopt) { //==Settings==// set_default_size(800, 600); @@ -31,6 +32,7 @@ namespace NickvisionMoney::Views m_headerBar.getActionGitHubRepo()->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::gitHubRepo)); m_headerBar.getActionReportABug()->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::reportABug)); m_headerBar.getActionSettings()->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::settings)); + m_headerBar.getActionShortcuts()->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::shortcuts)); m_headerBar.getActionChangelog()->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::changelog)); m_headerBar.getActionAbout()->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::about)); m_headerBar.getActionCloseAccount()->set_enabled(false); @@ -101,6 +103,109 @@ namespace NickvisionMoney::Views m_scrollDataTransactions.set_child(m_dataTransactions); m_scrollDataTransactions.set_margin(6); m_scrollDataTransactions.set_expand(true); + //==Shortcuts==// + m_shortcutController = Gtk::ShortcutController::create(); + m_shortcutController->set_scope(Gtk::ShortcutScope::GLOBAL); + //New Account + m_shortcutNewAccountTrigger = Gtk::KeyvalTrigger::create(GDK_KEY_N, Gdk::ModifierType::CONTROL_MASK); + m_shortcutNewAccountAction = Gtk::CallbackAction::create([&](Gtk::Widget& widget, const Glib::VariantBase& args) + { + newAccount(args); + return true; + }); + m_shortcutNewAccount = Gtk::Shortcut::create(m_shortcutNewAccountTrigger, m_shortcutNewAccountAction); + m_shortcutController->add_shortcut(m_shortcutNewAccount); + //Open Account + m_shortcutOpenAccountTrigger = Gtk::KeyvalTrigger::create(GDK_KEY_O, Gdk::ModifierType::CONTROL_MASK); + m_shortcutOpenAccountAction = Gtk::CallbackAction::create([&](Gtk::Widget& widget, const Glib::VariantBase& args) + { + openAccount(args); + return true; + }); + m_shortcutOpenAccount = Gtk::Shortcut::create(m_shortcutOpenAccountTrigger, m_shortcutOpenAccountAction); + m_shortcutController->add_shortcut(m_shortcutOpenAccount); + //Close Account + m_shortcutCloseAccountTrigger = Gtk::KeyvalTrigger::create(GDK_KEY_W, Gdk::ModifierType::CONTROL_MASK); + m_shortcutCloseAccountAction = Gtk::CallbackAction::create([&](Gtk::Widget& widget, const Glib::VariantBase& args) + { + if(m_account.has_value()) + { + closeAccount(args); + } + return true; + }); + m_shortcutCloseAccount = Gtk::Shortcut::create(m_shortcutCloseAccountTrigger, m_shortcutCloseAccountAction); + m_shortcutController->add_shortcut(m_shortcutCloseAccount); + //Backup Account + m_shortcutBackupAccountTrigger = Gtk::KeyvalTrigger::create(GDK_KEY_B, Gdk::ModifierType::CONTROL_MASK | Gdk::ModifierType::SHIFT_MASK); + m_shortcutBackupAccountAction = Gtk::CallbackAction::create([&](Gtk::Widget& widget, const Glib::VariantBase& args) + { + if(m_account.has_value()) + { + backupAccount(); + } + return true; + }); + m_shortcutBackupAccount = Gtk::Shortcut::create(m_shortcutBackupAccountTrigger, m_shortcutBackupAccountAction); + m_shortcutController->add_shortcut(m_shortcutBackupAccount); + //Restore Account + m_shortcutRestoreAccountTrigger = Gtk::KeyvalTrigger::create(GDK_KEY_R, Gdk::ModifierType::CONTROL_MASK | Gdk::ModifierType::SHIFT_MASK); + m_shortcutRestoreAccountAction = Gtk::CallbackAction::create([&](Gtk::Widget& widget, const Glib::VariantBase& args) + { + if(m_account.has_value()) + { + restoreAccount(); + } + return true; + }); + m_shortcutRestoreAccount = Gtk::Shortcut::create(m_shortcutRestoreAccountTrigger, m_shortcutRestoreAccountAction); + m_shortcutController->add_shortcut(m_shortcutRestoreAccount); + //New Transaction + m_shortcutNewTransactionTrigger = Gtk::KeyvalTrigger::create(GDK_KEY_N, Gdk::ModifierType::CONTROL_MASK | Gdk::ModifierType::SHIFT_MASK); + m_shortcutNewTransactionAction = Gtk::CallbackAction::create([&](Gtk::Widget& widget, const Glib::VariantBase& args) + { + if(m_account.has_value()) + { + newTransaction(); + } + return true; + }); + m_shortcutNewTransaction = Gtk::Shortcut::create(m_shortcutNewTransactionTrigger, m_shortcutNewTransactionAction); + m_shortcutController->add_shortcut(m_shortcutNewTransaction); + //Edit Transaction + m_shortcutEditTransactionTrigger = Gtk::KeyvalTrigger::create(GDK_KEY_O, Gdk::ModifierType::CONTROL_MASK | Gdk::ModifierType::SHIFT_MASK); + m_shortcutEditTransactionAction = Gtk::CallbackAction::create([&](Gtk::Widget& widget, const Glib::VariantBase& args) + { + if(m_dataTransactions.get_selection()->get_selected_rows().size() == 1) + { + editTransaction(); + } + return true; + }); + m_shortcutEditTransaction = Gtk::Shortcut::create(m_shortcutEditTransactionTrigger, m_shortcutEditTransactionAction); + m_shortcutController->add_shortcut(m_shortcutEditTransaction); + //Delete Transaction + m_shortcutDeleteTransactionTrigger = Gtk::KeyvalTrigger::create(GDK_KEY_Delete); + m_shortcutDeleteTransactionAction = Gtk::CallbackAction::create([&](Gtk::Widget& widget, const Glib::VariantBase& args) + { + if(m_dataTransactions.get_selection()->get_selected_rows().size() == 1) + { + m_headerBar.getPopDeleteTransaction().popup(); + } + return true; + }); + m_shortcutDeleteTransaction = Gtk::Shortcut::create(m_shortcutDeleteTransactionTrigger, m_shortcutDeleteTransactionAction); + m_shortcutController->add_shortcut(m_shortcutDeleteTransaction); + //About + m_shortcutAboutTrigger = Gtk::KeyvalTrigger::create(GDK_KEY_F1); + m_shortcutAboutAction = Gtk::CallbackAction::create([&](Gtk::Widget& widget, const Glib::VariantBase& args) + { + about(args); + return true; + }); + m_shortcutAbout = Gtk::Shortcut::create(m_shortcutAboutTrigger, m_shortcutAboutAction); + m_shortcutController->add_shortcut(m_shortcutAbout); + add_controller(m_shortcutController); //==Layout==// m_mainBox.set_orientation(Gtk::Orientation::VERTICAL); m_mainBox.append(m_infoBar); @@ -387,10 +492,20 @@ namespace NickvisionMoney::Views settingsDialog->show(); } + void MainWindow::shortcuts(const Glib::VariantBase& args) + { + ShortcutsWindow* shortcutsWindow = new ShortcutsWindow(*this); + shortcutsWindow->signal_hide().connect(sigc::bind([](ShortcutsWindow* window) + { + delete window; + }, shortcutsWindow)); + shortcutsWindow->show(); + } + void MainWindow::changelog(const Glib::VariantBase& args) { Gtk::MessageDialog* changelogDialog = new Gtk::MessageDialog(*this, "What's New?", false, Gtk::MessageType::INFO, Gtk::ButtonsType::OK, true); - changelogDialog->set_secondary_text("\n- Fixed issue with date handling"); + changelogDialog->set_secondary_text("\n- Added keyboard shortcuts"); changelogDialog->signal_response().connect(sigc::bind([](int response, Gtk::MessageDialog* dialog) { delete dialog; @@ -405,7 +520,7 @@ namespace NickvisionMoney::Views aboutDialog->set_modal(true); aboutDialog->set_hide_on_close(true); aboutDialog->set_program_name("Nickvision Money"); - aboutDialog->set_version("2022.1.2"); + aboutDialog->set_version("2022.1.3"); aboutDialog->set_comments("A personal finance manager."); aboutDialog->set_copyright("(C) Nickvision 2021-2022"); aboutDialog->set_license_type(Gtk::License::GPL_3_0); diff --git a/views/mainwindow.h b/views/mainwindow.h index 01b1e90bd..89f69d260 100644 --- a/views/mainwindow.h +++ b/views/mainwindow.h @@ -37,6 +37,44 @@ namespace NickvisionMoney::Views Gtk::TreeView m_dataTransactions; NickvisionMoney::Models::DataTransactionsColumns m_dataTransactionsColumns; std::shared_ptr m_dataTransactionsModel; + //==Shortcuts==// + std::shared_ptr m_shortcutController; + //New Account + std::shared_ptr m_shortcutNewAccount; + std::shared_ptr m_shortcutNewAccountTrigger; + std::shared_ptr m_shortcutNewAccountAction; + //Open Account + std::shared_ptr m_shortcutOpenAccount; + std::shared_ptr m_shortcutOpenAccountTrigger; + std::shared_ptr m_shortcutOpenAccountAction; + //Close Account + std::shared_ptr m_shortcutCloseAccount; + std::shared_ptr m_shortcutCloseAccountTrigger; + std::shared_ptr m_shortcutCloseAccountAction; + //Backup Account + std::shared_ptr m_shortcutBackupAccount; + std::shared_ptr m_shortcutBackupAccountTrigger; + std::shared_ptr m_shortcutBackupAccountAction; + //Restore Account + std::shared_ptr m_shortcutRestoreAccount; + std::shared_ptr m_shortcutRestoreAccountTrigger; + std::shared_ptr m_shortcutRestoreAccountAction; + //New Transaction + std::shared_ptr m_shortcutNewTransaction; + std::shared_ptr m_shortcutNewTransactionTrigger; + std::shared_ptr m_shortcutNewTransactionAction; + //Edit Transaction + std::shared_ptr m_shortcutEditTransaction; + std::shared_ptr m_shortcutEditTransactionTrigger; + std::shared_ptr m_shortcutEditTransactionAction; + //Delete Transaction + std::shared_ptr m_shortcutDeleteTransaction; + std::shared_ptr m_shortcutDeleteTransactionTrigger; + std::shared_ptr m_shortcutDeleteTransactionAction; + //About + std::shared_ptr m_shortcutAbout; + std::shared_ptr m_shortcutAboutTrigger; + std::shared_ptr m_shortcutAboutAction; //==Slots==// void onShow(); void newAccount(const Glib::VariantBase& args); @@ -51,6 +89,7 @@ namespace NickvisionMoney::Views void gitHubRepo(const Glib::VariantBase& args); void reportABug(const Glib::VariantBase& args); void settings(const Glib::VariantBase& args); + void shortcuts(const Glib::VariantBase& args); void changelog(const Glib::VariantBase& args); void about(const Glib::VariantBase& args); void onRowDoubleClick(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column); diff --git a/views/settingsdialog.cpp b/views/settingsdialog.cpp index 8696966a7..3c76e8532 100644 --- a/views/settingsdialog.cpp +++ b/views/settingsdialog.cpp @@ -21,6 +21,9 @@ namespace NickvisionMoney::Views m_chkRememberLastOpenedAccount.set_tooltip_text("If checked, Money will remember the last opened account and automatically open it again when the application starts again."); m_listGeneral.append(m_chkRememberLastOpenedAccount); //==Layout==// + Gtk::Button* btnSave = add_button("Save", Gtk::ResponseType::CLOSE); + btnSave->get_style_context()->add_class("suggested-action"); + btnSave->signal_clicked().connect(sigc::mem_fun(*this, &Gtk::Dialog::hide)); m_mainBox.set_orientation(Gtk::Orientation::VERTICAL); m_mainBox.append(m_lblGeneral); m_mainBox.append(m_listGeneral); diff --git a/views/shortcutswindow.cpp b/views/shortcutswindow.cpp new file mode 100644 index 000000000..fb48295e1 --- /dev/null +++ b/views/shortcutswindow.cpp @@ -0,0 +1,51 @@ +#include "shortcutswindow.h" + +namespace NickvisionMoney::Views +{ + ShortcutsWindow::ShortcutsWindow(Gtk::Window& parent) + { + //==Settings==// + set_title("Shortcuts"); + set_transient_for(parent); + set_modal(true); + set_hide_on_close(true); + //==Account==// + m_grpAccount.property_title().set_value("Account"); + m_shortNewAccount.property_accelerator().set_value("N"); + m_shortNewAccount.property_title().set_value("New Account"); + m_shortOpenAccount.property_accelerator().set_value("O"); + m_shortOpenAccount.property_title().set_value("Open Account"); + m_shortCloseAccount.property_accelerator().set_value("W"); + m_shortCloseAccount.property_title().set_value("Close Account"); + m_shortBackupAccount.property_accelerator().set_value("B"); + m_shortBackupAccount.property_title().set_value("Backup Account"); + m_shortRestoreAccount.property_accelerator().set_value("R"); + m_shortRestoreAccount.property_title().set_value("Restore Account"); + m_grpAccount.append(m_shortNewAccount); + m_grpAccount.append(m_shortOpenAccount); + m_grpAccount.append(m_shortCloseAccount); + m_grpAccount.append(m_shortBackupAccount); + m_grpAccount.append(m_shortRestoreAccount); + m_section.append(m_grpAccount); + //==Transaction==// + m_grpTransaction.property_title().set_value("Transaction"); + m_shortNewTransaction.property_accelerator().set_value("N"); + m_shortNewTransaction.property_title().set_value("New Transaction"); + m_shortEditTransaction.property_accelerator().set_value("O"); + m_shortEditTransaction.property_title().set_value("Edit Transaction"); + m_shortDeleteTransaction.property_accelerator().set_value("Delete"); + m_shortDeleteTransaction.property_title().set_value("Delete Transaction"); + m_grpTransaction.append(m_shortNewTransaction); + m_grpTransaction.append(m_shortEditTransaction); + m_grpTransaction.append(m_shortDeleteTransaction); + m_section.append(m_grpTransaction); + //==Application==// + m_grpApplication.property_title().set_value("Application"); + m_shortAbout.property_accelerator().set_value("F1"); + m_shortAbout.property_title().set_value("About"); + m_grpApplication.append(m_shortAbout); + m_section.append(m_grpApplication); + //==Layout==// + set_child(m_section); + } +} diff --git a/views/shortcutswindow.h b/views/shortcutswindow.h new file mode 100644 index 000000000..102f07760 --- /dev/null +++ b/views/shortcutswindow.h @@ -0,0 +1,30 @@ +#ifndef SHORTCUTSWINDOW_H +#define SHORTCUTSWINDOW_H + +#include + +namespace NickvisionMoney::Views +{ + class ShortcutsWindow : public Gtk::ShortcutsWindow + { + public: + ShortcutsWindow(Gtk::Window& parent); + + private: + Gtk::ShortcutsSection m_section; + Gtk::ShortcutsGroup m_grpAccount; + Gtk::ShortcutsShortcut m_shortNewAccount; + Gtk::ShortcutsShortcut m_shortOpenAccount; + Gtk::ShortcutsShortcut m_shortCloseAccount; + Gtk::ShortcutsShortcut m_shortBackupAccount; + Gtk::ShortcutsShortcut m_shortRestoreAccount; + Gtk::ShortcutsGroup m_grpTransaction; + Gtk::ShortcutsShortcut m_shortNewTransaction; + Gtk::ShortcutsShortcut m_shortEditTransaction; + Gtk::ShortcutsShortcut m_shortDeleteTransaction; + Gtk::ShortcutsGroup m_grpApplication; + Gtk::ShortcutsShortcut m_shortAbout; + }; +} + +#endif // SHORTCUTSWINDOW_H diff --git a/views/transactiondialog.cpp b/views/transactiondialog.cpp index c650344cf..b728c4400 100644 --- a/views/transactiondialog.cpp +++ b/views/transactiondialog.cpp @@ -8,7 +8,6 @@ namespace NickvisionMoney::Views { //==Settings==// set_resizable(false); - set_deletable(false); //==Buttons==// Gtk::Button* btnCancel = add_button("_Cancel", Gtk::ResponseType::CANCEL); Gtk::Button* btnSave = add_button("_Save", Gtk::ResponseType::NONE);