From: Soren Stoutner Date: Sat, 20 Jan 2024 00:33:20 +0000 (-0700) Subject: Disable the current folder in the edit folder dialog. https://redmine.stoutner.com... X-Git-Tag: v0.6~10 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=cc59ec7b2c1ad4d7832b2c05f7245e8387379e66;p=PrivacyBrowserPC.git Disable the current folder in the edit folder dialog. https://redmine.stoutner.com/issues/1092 --- diff --git a/src/dialogs/EditFolderDialog.cpp b/src/dialogs/EditFolderDialog.cpp index 950e502..cabcf5d 100644 --- a/src/dialogs/EditFolderDialog.cpp +++ b/src/dialogs/EditFolderDialog.cpp @@ -50,11 +50,11 @@ EditFolderDialog::EditFolderDialog(QWidget *parentWidgetPointer, const int datab QDialogButtonBox *dialogButtonBoxPointer = editFolderDialogUi.dialogButtonBox; saveButtonPointer = dialogButtonBoxPointer->button(QDialogButtonBox::Save); - // Get the bookmark struct. - bookmarkStructPointer = BookmarksDatabase::getBookmark(databaseId); + // Get the folder bookmark struct. + folderBookmarkStructPointer = BookmarksDatabase::getBookmark(databaseId); // Set the folder icons. - currentFolderIconRadioButtonPointer->setIcon(bookmarkStructPointer->favoriteIcon); + currentFolderIconRadioButtonPointer->setIcon(folderBookmarkStructPointer->favoriteIcon); currentWebsiteFavoriteIconRadioButtonPointer->setIcon(currentWebsiteFavoriteIcon); // Instantiate a folder helper. @@ -81,17 +81,17 @@ EditFolderDialog::EditFolderDialog(QWidget *parentWidgetPointer, const int datab parentFolderTreeWidgetPointer->addTopLevelItem(bookmarksTreeWidgetItemPointer); // Select the root bookmarks folder if it is the initial parent folder. - if (bookmarkStructPointer->parentFolderId == 0) + if (folderBookmarkStructPointer->parentFolderId == 0) bookmarksTreeWidgetItemPointer->setSelected(true); // Populate the subfolders, except for the one being edited. - folderHelperPointer->populateSubfoldersExcept(databaseId, bookmarksTreeWidgetItemPointer, bookmarkStructPointer->parentFolderId); + folderHelperPointer->populateSubfoldersExcept(databaseId, bookmarksTreeWidgetItemPointer, folderBookmarkStructPointer->parentFolderId); // Open all the folders. parentFolderTreeWidgetPointer->expandAll(); // Populate the line edits. - folderNameLineEditPointer->setText(bookmarkStructPointer->name); + folderNameLineEditPointer->setText(folderBookmarkStructPointer->name); // Focus the folder name line edit. folderNameLineEditPointer->setFocus(); @@ -136,11 +136,14 @@ void EditFolderDialog::save() // Get the parent folder ID. double parentFolderId = selectedFolderPointer->text(folderHelperPointer->FOLDER_ID_COLUMN).toDouble(); + // Determine if it has moved to a new folder. + bool movedToNewFolder = parentFolderId != folderBookmarkStructPointer->parentFolderId; + // Get the original display order. - int displayOrder = bookmarkStructPointer->displayOrder; + int displayOrder = folderBookmarkStructPointer->displayOrder; // Get the new display order if the parent folder has changed. - if (parentFolderId != bookmarkStructPointer->parentFolderId) + if (movedToNewFolder) displayOrder = BookmarksDatabase::getFolderItemCount(parentFolderId); // Create a favorite icon. @@ -167,8 +170,9 @@ void EditFolderDialog::save() // Update the folder. BookmarksDatabase::updateBookmark(updatedBookmarkStructPointer); - // Update the display order of all the items in the previous folder. - BookmarksDatabase::updateFolderContentsDisplayOrder(bookmarkStructPointer->parentFolderId); + // Update the display order of all the items in the previous folder if it has moved to a new folder. + if (movedToNewFolder) + BookmarksDatabase::updateFolderContentsDisplayOrder(folderBookmarkStructPointer->parentFolderId); // Emit the folder saved signal. emit folderSaved(); diff --git a/src/dialogs/EditFolderDialog.h b/src/dialogs/EditFolderDialog.h index 8f38324..d585b15 100644 --- a/src/dialogs/EditFolderDialog.h +++ b/src/dialogs/EditFolderDialog.h @@ -52,10 +52,10 @@ private: FolderHelper *folderHelperPointer; // The private widgets. - BookmarkStruct *bookmarkStructPointer; QRadioButton *currentFolderIconRadioButtonPointer; QRadioButton *currentWebsiteFavoriteIconRadioButtonPointer; QRadioButton *customFolderIconRadioButtonPointer; + BookmarkStruct *folderBookmarkStructPointer; int folderDatabaseId; QLineEdit *folderNameLineEditPointer; QTreeWidget *parentFolderTreeWidgetPointer; diff --git a/src/helpers/FolderHelper.cpp b/src/helpers/FolderHelper.cpp index 01a45da..01e1b22 100644 --- a/src/helpers/FolderHelper.cpp +++ b/src/helpers/FolderHelper.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2023 Soren Stoutner . + * Copyright 2023-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -61,26 +61,29 @@ void FolderHelper::populateSubfoldersExcept(const double exceptSubfolderDatabase // Populate each subfolder. for (BookmarkStruct bookmarkStruct : *subfoldersList) { - // Only populate the subfolder if it is not excepted. - if (bookmarkStruct.databaseId != exceptSubfolderDatabaseId) - { - // Create a tree widget item. - QTreeWidgetItem *subfolderWidgetItemPointer = new QTreeWidgetItem(); - - // Populate the tree widget item. - subfolderWidgetItemPointer->setText(FOLDER_NAME_COLUMN, bookmarkStruct.name); - subfolderWidgetItemPointer->setIcon(FOLDER_NAME_COLUMN, bookmarkStruct.favoriteIcon); - subfolderWidgetItemPointer->setText(FOLDER_ID_COLUMN, QString::number(bookmarkStruct.folderId, 'f', 0)); // Format the folder ID as a floating point with no trailing zeros. - - // Add the subfolder to the tree widget item. - treeWidgetItemPointer->addChild(subfolderWidgetItemPointer); - - // Select the folder if it is the initial parent folder. - if (bookmarkStruct.folderId == initialParentFolderId) - subfolderWidgetItemPointer->setSelected(true); - - // Add any subfolders. - populateSubfoldersExcept(exceptSubfolderDatabaseId, subfolderWidgetItemPointer, initialParentFolderId); - } + // Determine if this is an excepted folder. + bool exceptedFolder = bookmarkStruct.databaseId == exceptSubfolderDatabaseId; + + // Create a tree widget item. + QTreeWidgetItem *subfolderWidgetItemPointer = new QTreeWidgetItem(); + + // Populate the tree widget item. + subfolderWidgetItemPointer->setText(FOLDER_NAME_COLUMN, bookmarkStruct.name); + subfolderWidgetItemPointer->setIcon(FOLDER_NAME_COLUMN, bookmarkStruct.favoriteIcon); + subfolderWidgetItemPointer->setText(FOLDER_ID_COLUMN, QString::number(bookmarkStruct.folderId, 'f', 0)); // Format the folder ID as a floating point with no trailing zeros. + + // Disable the folder widget if it is excepted. All subfolders will automatically be disabled. + if (exceptedFolder) + subfolderWidgetItemPointer->setDisabled(true); + + // Add the subfolder to the tree widget item. + treeWidgetItemPointer->addChild(subfolderWidgetItemPointer); + + // Select the folder if it is the initial parent folder. + if (bookmarkStruct.folderId == initialParentFolderId) + subfolderWidgetItemPointer->setSelected(true); + + // Add any subfolders. + populateSubfoldersExcept(exceptSubfolderDatabaseId, subfolderWidgetItemPointer, initialParentFolderId); } }