From 7b904bf803b24e5e7ff9c7dcfe6bc9d93e98cb8e Mon Sep 17 00:00:00 2001 From: vsonnier Date: Fri, 12 Jan 2018 19:17:04 +0100 Subject: [PATCH] Add a Reset Bookmarks menu (empty the bookmarks), similar to Reset Session --- src/AppFrame.cpp | 22 ++++++++++++++++------ src/AppFrame.h | 7 ++++--- src/BookmarkMgr.cpp | 11 +++++++++++ src/BookmarkMgr.h | 2 ++ 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 96ed628..078482c 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -418,9 +418,11 @@ AppFrame::AppFrame() : menu->AppendSeparator(); menu->Append(wxID_RESET, "&Reset Session"); menu->AppendSeparator(); - menu->Append(wxID_OPEN_BOOKMARK, "Open Bookmark"); - menu->Append(wxID_SAVE_BOOKMARK, "Save Bookmark"); - menu->Append(wxID_SAVEAS_BOOKMARK, "Save Bookmark As.."); + menu->Append(wxID_OPEN_BOOKMARKS, "Open Bookmarks"); + menu->Append(wxID_SAVE_BOOKMARKS, "Save Bookmarks"); + menu->Append(wxID_SAVEAS_BOOKMARKS, "Save Bookmarks As.."); + menu->AppendSeparator(); + menu->Append(wxID_RESET_BOOKMARKS, "Reset Bookmarks"); #ifndef __APPLE__ menu->AppendSeparator(); @@ -1407,7 +1409,7 @@ bool AppFrame::actionOnMenuLoadSave(wxCommandEvent& event) { } //save mecanic for bookmark files - else if (event.GetId() == wxID_SAVE_BOOKMARK) { + else if (event.GetId() == wxID_SAVE_BOOKMARKS) { if (!currentBookmarkFile.empty()) { wxGetApp().getBookmarkMgr().saveToFile(currentBookmarkFile, false, true); @@ -1434,7 +1436,7 @@ bool AppFrame::actionOnMenuLoadSave(wxCommandEvent& event) { return true; } - else if (event.GetId() == wxID_OPEN_BOOKMARK) { + else if (event.GetId() == wxID_OPEN_BOOKMARKS) { wxFileDialog openFileDialog(this, _("Open XML Bookmark file"), "", "", "XML files (*.xml)|*.xml", wxFD_OPEN | wxFD_FILE_MUST_EXIST); if (openFileDialog.ShowModal() == wxID_CANCEL) { @@ -1454,7 +1456,7 @@ bool AppFrame::actionOnMenuLoadSave(wxCommandEvent& event) { return true; } - else if (event.GetId() == wxID_SAVEAS_BOOKMARK) { + else if (event.GetId() == wxID_SAVEAS_BOOKMARKS) { wxFileDialog saveFileDialog(this, _("Save XML Bookmark file"), "", "", "XML files (*.xml)|*.xml", wxFD_SAVE | wxFD_OVERWRITE_PROMPT); if (saveFileDialog.ShowModal() == wxID_CANCEL) { @@ -1476,6 +1478,14 @@ bool AppFrame::actionOnMenuLoadSave(wxCommandEvent& event) { return true; } + else if (event.GetId() == wxID_RESET_BOOKMARKS) { + + wxGetApp().getBookmarkMgr().resetBookmarks(); + wxGetApp().getBookmarkMgr().updateBookmarks(); + wxGetApp().getBookmarkMgr().updateActiveList(); + + return true; + } return false; } diff --git a/src/AppFrame.h b/src/AppFrame.h index f81541a..5ea0fe5 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -43,9 +43,10 @@ #define wxID_SET_DB_OFFSET 2012 #define wxID_ABOUT_CUBICSDR 2013 -#define wxID_OPEN_BOOKMARK 2020 -#define wxID_SAVE_BOOKMARK 2021 -#define wxID_SAVEAS_BOOKMARK 2022 +#define wxID_OPEN_BOOKMARKS 2020 +#define wxID_SAVE_BOOKMARKS 2021 +#define wxID_SAVEAS_BOOKMARKS 2022 +#define wxID_RESET_BOOKMARKS 2023 #define wxID_MAIN_SPLITTER 2050 #define wxID_VIS_SPLITTER 2051 diff --git a/src/BookmarkMgr.cpp b/src/BookmarkMgr.cpp index 8cb4d5c..eec5d6f 100644 --- a/src/BookmarkMgr.cpp +++ b/src/BookmarkMgr.cpp @@ -238,6 +238,17 @@ bool BookmarkMgr::loadFromFile(std::string bookmarkFn, bool backup, bool useFull return loadStatusOk; } +void BookmarkMgr::resetBookmarks() { + + // Clear any active data + bmData.clear(); + clearRecents(); + clearRanges(); + bmDataSorted.clear(); + + wxGetApp().getAppFrame()->getBookmarkView()->loadDefaultRanges(); + +} bool BookmarkMgr::hasLastLoad(std::string bookmarkFn) { wxFileName lastLoaded(wxGetApp().getConfig()->getConfigDir(), bookmarkFn + ".lastloaded"); diff --git a/src/BookmarkMgr.h b/src/BookmarkMgr.h index 272c1b9..0560a67 100644 --- a/src/BookmarkMgr.h +++ b/src/BookmarkMgr.h @@ -83,6 +83,8 @@ public: void saveToFile(std::string bookmarkFn, bool backup = true, bool useFullpath = false); bool loadFromFile(std::string bookmarkFn, bool backup = true, bool useFullpath = false); + void resetBookmarks(); + bool hasLastLoad(std::string bookmarkFn); bool hasBackup(std::string bookmarkFn);