From c5706a6ff3fbc42418e60b79fbe3f5c19396f7d2 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Wed, 27 Mar 2024 16:03:36 -0700 Subject: [PATCH] Add a default folder icon to the edit folder dialog. https://redmine.stoutner.com/issues/1179 --- src/dialogs/EditFolderDialog.cpp | 3 ++ src/dialogs/EditFolderDialog.h | 1 + src/uis/EditFolderDialog.ui | 28 +++++++++++++++--- src/windows/BrowserWindow.cpp | 51 ++++++++++++++++++-------------- src/windows/BrowserWindow.h | 4 +-- 5 files changed, 58 insertions(+), 29 deletions(-) diff --git a/src/dialogs/EditFolderDialog.cpp b/src/dialogs/EditFolderDialog.cpp index cabcf5d..bae0965 100644 --- a/src/dialogs/EditFolderDialog.cpp +++ b/src/dialogs/EditFolderDialog.cpp @@ -42,6 +42,7 @@ EditFolderDialog::EditFolderDialog(QWidget *parentWidgetPointer, const int datab // Get handles for the widgets. currentFolderIconRadioButtonPointer = editFolderDialogUi.currentFolderIconRadioButton; + defaultFolderIconRadioButtonPointer = editFolderDialogUi.defaultFolderIconRadioButton; currentWebsiteFavoriteIconRadioButtonPointer = editFolderDialogUi.currentWebsiteFavoriteIconRadioButton; customFolderIconRadioButtonPointer = editFolderDialogUi.customFolderIconRadioButton; parentFolderTreeWidgetPointer = editFolderDialogUi.parentFolderTreeWidget; @@ -152,6 +153,8 @@ void EditFolderDialog::save() // Get the favorite icon. if (currentFolderIconRadioButtonPointer->isChecked()) // The current folder icon is checked. favoriteIcon = currentFolderIconRadioButtonPointer->icon(); + else if (defaultFolderIconRadioButtonPointer->isChecked()) // The default folder icon is checked. + favoriteIcon = defaultFolderIconRadioButtonPointer->icon(); else if (currentWebsiteFavoriteIconRadioButtonPointer->isChecked()) // The current website favorite icon is checked. favoriteIcon = currentWebsiteFavoriteIconRadioButtonPointer->icon(); else // The custom favorite icon is checked. diff --git a/src/dialogs/EditFolderDialog.h b/src/dialogs/EditFolderDialog.h index d585b15..899d5af 100644 --- a/src/dialogs/EditFolderDialog.h +++ b/src/dialogs/EditFolderDialog.h @@ -55,6 +55,7 @@ private: QRadioButton *currentFolderIconRadioButtonPointer; QRadioButton *currentWebsiteFavoriteIconRadioButtonPointer; QRadioButton *customFolderIconRadioButtonPointer; + QRadioButton *defaultFolderIconRadioButtonPointer; BookmarkStruct *folderBookmarkStructPointer; int folderDatabaseId; QLineEdit *folderNameLineEditPointer; diff --git a/src/uis/EditFolderDialog.ui b/src/uis/EditFolderDialog.ui index 545ed3c..efebd2a 100644 --- a/src/uis/EditFolderDialog.ui +++ b/src/uis/EditFolderDialog.ui @@ -1,7 +1,7 @@ + + + + + Default folder icon + + + + + + + + + 32 + 32 + + + + + + @@ -69,7 +89,7 @@ - + diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index f0cd4df..fe3b593 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -543,12 +543,12 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) // Add a separator to the bookmarks menu. bookmarksMenuPointer->addSeparator(); - // Initialize the current bookmarks lists. - finalBookmarkFolderMenuActionList = QList *>(); + // Initialize the bookmark action lists. + bookmarkFolderFinalActionList = QList *>(); bookmarksMenuActionList = QList *>(); bookmarksMenuSubmenuList = QList *>(); bookmarksToolBarActionList = QList(); - bookmarksToolBarSubfolderActionList = QList *>(); + bookmarksToolBarSubfolderActionList = QList *>(); // Set the bookmarks toolbar context menu policy. bookmarksToolBarPointer->setContextMenuPolicy(Qt::CustomContextMenu); @@ -580,7 +580,8 @@ BrowserWindow::BrowserWindow(bool firstWindow, QString *initialUrlStringPointer) } } -void BrowserWindow::addFinalBookmarkFolderMenuActions(QMenu *menuPointer, double folderId) +// If actions are part of a context menu they do not need to be added to the list as they will be deleted automatically when the context menu closes. +void BrowserWindow::addBookmarkFolderFinalActions(QMenu *menuPointer, const double folderId, const bool addToList) { // Get the database ID. int folderDatabaseId = BookmarksDatabase::getFolderDatabaseId(folderId); @@ -688,8 +689,9 @@ void BrowserWindow::addFinalBookmarkFolderMenuActions(QMenu *menuPointer, double } ); - // Add the action to the beginning of the final bookmark folder menu action list. - finalBookmarkFolderMenuActionList.prepend(new QPair(menuPointer, editFolderActionPointer)); + // Add the action to the beginning of the bookmark folder final action list if requsted. + if (addToList) + bookmarkFolderFinalActionList.prepend(new QPair(menuPointer, editFolderActionPointer)); } // Add the delete folder action to the menu. @@ -760,13 +762,15 @@ void BrowserWindow::addFinalBookmarkFolderMenuActions(QMenu *menuPointer, double actionCollectionPointer->setDefaultShortcut(addFolderActionPointer, metaFKeySequence); } - // Add the actions to the beginning of the final bookmark folder menu action list. - finalBookmarkFolderMenuActionList.prepend(new QPair(menuPointer, addBookmarkActionPointer)); - finalBookmarkFolderMenuActionList.prepend(new QPair(menuPointer, addFolderActionPointer)); - finalBookmarkFolderMenuActionList.prepend(new QPair(menuPointer, openFolderInNewTabsActionPointer)); - finalBookmarkFolderMenuActionList.prepend(new QPair(menuPointer, openFolderInBackgroundTabsActionPointer)); - finalBookmarkFolderMenuActionList.prepend(new QPair(menuPointer, openFolderInNewWindowActionPointer)); - finalBookmarkFolderMenuActionList.prepend(new QPair(menuPointer, deleteFolderActionPointer)); + // Add the actions to the beginning of the bookmark folder final action list if requested. + if (addToList) { + bookmarkFolderFinalActionList.prepend(new QPair(menuPointer, addBookmarkActionPointer)); + bookmarkFolderFinalActionList.prepend(new QPair(menuPointer, addFolderActionPointer)); + bookmarkFolderFinalActionList.prepend(new QPair(menuPointer, openFolderInNewTabsActionPointer)); + bookmarkFolderFinalActionList.prepend(new QPair(menuPointer, openFolderInBackgroundTabsActionPointer)); + bookmarkFolderFinalActionList.prepend(new QPair(menuPointer, openFolderInNewWindowActionPointer)); + bookmarkFolderFinalActionList.prepend(new QPair(menuPointer, deleteFolderActionPointer)); + } } void BrowserWindow::addOrEditDomainSettings() @@ -1091,10 +1095,10 @@ void BrowserWindow::populateBookmarksInAllWindows() const void BrowserWindow::populateBookmarksInThisWindow() { // Remove all the final bookmark folder menu actions. - for (QPair *finalBookmarkFolderMenuActionPair : finalBookmarkFolderMenuActionList) + for (QPair *bookmarkFolderFinalActionPairPointer : bookmarkFolderFinalActionList) { // Remove the action. - finalBookmarkFolderMenuActionPair->first->removeAction(finalBookmarkFolderMenuActionPair->second); + bookmarkFolderFinalActionPairPointer->first->removeAction(bookmarkFolderFinalActionPairPointer->second); } // Remove all the current menu bookmarks. @@ -1125,11 +1129,12 @@ void BrowserWindow::populateBookmarksInThisWindow() bookmarksToolBarPointer->removeAction(bookmarkAction); } - // Clear the current bookmark lists. + // Clear the action lists. + bookmarkFolderFinalActionList.clear(); bookmarksMenuActionList.clear(); bookmarksMenuSubmenuList.clear(); - bookmarksToolBarActionList.clear(); bookmarksToolBarSubfolderActionList.clear(); + bookmarksToolBarActionList.clear(); // Populate the bookmarks subfolders, beginning with the root folder (`0`); populateBookmarksMenuSubfolders(0, bookmarksMenuPointer); @@ -1189,8 +1194,8 @@ void BrowserWindow::populateBookmarksMenuSubfolders(const double folderId, QMenu } } - // Add the extra items at the bottom of the menu. - addFinalBookmarkFolderMenuActions(menuPointer, folderId); + // Add the extra items at the bottom of the menu. `true` adds them to the list of actions to be deleted on repopulate. + addBookmarkFolderFinalActions(menuPointer, folderId, true); } void BrowserWindow::populateBookmarksToolBar() @@ -1252,8 +1257,8 @@ void BrowserWindow::populateBookmarksToolBar() // Add the extra items to the toolbar folder menus. The first item in the pair is the menu pointer. The second is the folder ID. for (QPair *menuAndFolderIdPairPointer : bookmarksToolBarMenuList) { - // Populate the final bookmarks menu entries. - addFinalBookmarkFolderMenuActions(menuAndFolderIdPairPointer->first, menuAndFolderIdPairPointer->second); + // Populate the final bookmarks menu entries. `true` adds them to the list of actions to be deleted on repopulate. + addBookmarkFolderFinalActions(menuAndFolderIdPairPointer->first, menuAndFolderIdPairPointer->second, true); } } @@ -1346,8 +1351,8 @@ void BrowserWindow::showBookmarkContextMenu(const QPoint &point) // Create the menu according to the type. if (BookmarksDatabase::isFolder(databaseId)) // A folder was clicked. { - // Populate the final bookmarks menu entries. - addFinalBookmarkFolderMenuActions(bookmarkContextMenuPointer, BookmarksDatabase::getFolderId(databaseId)); + // Populate the final bookmarks menu entries. `false` does not add the actions to the delete list, as they will be automatically deleted when the menu closes. + addBookmarkFolderFinalActions(bookmarkContextMenuPointer, BookmarksDatabase::getFolderId(databaseId), false); } else // A bookmark was clicked. { diff --git a/src/windows/BrowserWindow.h b/src/windows/BrowserWindow.h index 29c8d60..85af5a2 100644 --- a/src/windows/BrowserWindow.h +++ b/src/windows/BrowserWindow.h @@ -112,6 +112,7 @@ private: // The private variables. KActionCollection *actionCollectionPointer; QAction *bookmarkedActionPointer; + QList *> bookmarkFolderFinalActionList; QList *> bookmarksMenuActionList; QMenu *bookmarksMenuPointer; QList *> bookmarksMenuSubmenuList; @@ -130,7 +131,6 @@ private: double defaultZoomFactorDouble; QAction *developerToolsActionPointer; QAction *domStorageActionPointer; - QList *> finalBookmarkFolderMenuActionList; QAction *findCaseSensitiveActionPointer; QAction *findNextActionPointer; QAction *findPreviousActionPointer; @@ -182,7 +182,7 @@ private: QPushButton *zoomPlusButtonPointer; // The private functions. - void addFinalBookmarkFolderMenuActions(QMenu *menuPointer, double folderId); + void addBookmarkFolderFinalActions(QMenu *menuPointer, const double folderId, const bool addToList); int calculateSettingsInt(const bool settingCurrentlyEnabled, const bool settingEnabledByDefault) const; void populateBookmarksMenuSubfolders(const double folderId, QMenu *menuPointer); void populateBookmarksToolBar(); -- 2.45.2