]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Disable the current folder in the edit folder dialog. https://redmine.stoutner.com...
authorSoren Stoutner <soren@stoutner.com>
Sat, 20 Jan 2024 00:33:20 +0000 (17:33 -0700)
committerSoren Stoutner <soren@stoutner.com>
Sat, 20 Jan 2024 00:33:20 +0000 (17:33 -0700)
src/dialogs/EditFolderDialog.cpp
src/dialogs/EditFolderDialog.h
src/helpers/FolderHelper.cpp

index 950e502a7790db72eba97e633dd0e2d09b9bb2cf..cabcf5dce6b838ca3315c5bfcddbf61b5a191447 100644 (file)
@@ -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();
index 8f3832417fe8a77c490aa4a48bb08e29d8f612a7..d585b1545809364dde2993f6bcc1574eb324c1a7 100644 (file)
@@ -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;
index 01a45da1f33b08490f6554e2afba8072b41944f4..01e1b229a69f425fd2d1057be61941cfbee1c239 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2023 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2023-2024 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser PC <https://www.stoutner.com/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);
     }
 }