New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No automatic sort when manually renaming a note #450

Closed
dwu opened this Issue Jan 2, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@dwu
Contributor

dwu commented Jan 2, 2017

Manually renaming a note when "Allow note file name to be different from headline" and alphabetical sort order are activated does currently not automatically trigger sorting the note tree. This means that the renamed note might end up in the wrong position. It would be great if sorting could happen automatically after renaming.

As renaming a note does not seem to change currentNoteLastEdited I assume that sorting is only required if sortAlphabetically is enabled. In this case the easiest solution to get the desired behavior would probably be to do something along the lines of:

diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 2d36779..e78addb 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -7534,8 +7534,11 @@ void MainWindow::on_noteTreeWidget_itemChanged(QTreeWidgetItem *item,
                 // handle the replacing of all note urls if a note was renamed
                 Note::handleNoteRenaming(oldNoteName, newNoteName);
 
-                // reload the directory list if note name has changed
-//                loadNoteDirectoryList();
+                // sort notes if note name has changed
+                if (sortAlphabetically) {
+                    ui->noteTreeWidget->sortItems(0, Qt::AscendingOrder);
+                    ui->noteTreeWidget->scrollToItem(item);
+                }
             }
         }

However, as there's currently a commented out call to loadNoteDirectoryList in on_noteTreeWidget_itemChanged it seems that it was originally intended to completely reload the note tree here. If that's still desired the following (with the call to loadNoteDirectoryList moved after the last access to item to make sure item still points to the original object) might probably be a better solution:

diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 2d36779..71882db 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -7506,6 +7506,8 @@ void MainWindow::on_noteTreeWidget_customContextMenuRequested(
  */
 void MainWindow::on_noteTreeWidget_itemChanged(QTreeWidgetItem *item,
                                                int column) {
+    bool noteRenamed = false;
+
     Q_UNUSED(column);
     if (item == NULL || !Note::allowDifferentFileName()) {
         return;
@@ -7534,8 +7536,7 @@ void MainWindow::on_noteTreeWidget_itemChanged(QTreeWidgetItem *item,
                 // handle the replacing of all note urls if a note was renamed
                 Note::handleNoteRenaming(oldNoteName, newNoteName);
 
-                // reload the directory list if note name has changed
-//                loadNoteDirectoryList();
+                noteRenamed = true;
             }
         }
 
@@ -7545,6 +7546,11 @@ void MainWindow::on_noteTreeWidget_itemChanged(QTreeWidgetItem *item,
         // set old name back in case the renaming failed or the file name got
         // altered in the renaming process
         item->setText(0, note.getName());
+
+        // reload the directory list if note name has changed
+        if (noteRenamed) {
+            loadNoteDirectoryList();
+        }
     }
 }

@pbek pbek added the enhancement label Jan 2, 2017

@pbek

This comment has been minimized.

Owner

pbek commented Jan 2, 2017

loadNoteDirectoryList() should currently not be called (since it was commented out). 😃
Can you please make a pull request with your proposed changes, so I can take a look and test them.

@pbek pbek added this to the 17.01.0 milestone Jan 3, 2017

@pbek

This comment has been minimized.

Owner

pbek commented Jan 3, 2017

17.01.0

  • notes in the note list are now resorted if they were sorted alphabetically
    and a note was manually renamed in the note list (thank you @dwu)
@pbek

This comment has been minimized.

Owner

pbek commented Jan 3, 2017

There now is a new release, could you please test it and report if it works for you?

@dwu

This comment has been minimized.

Contributor

dwu commented Jan 3, 2017

Tested and working fine. Thanks!

@dwu dwu closed this Jan 3, 2017

@pbek

This comment has been minimized.

Owner

pbek commented Jan 3, 2017

Thank you for testing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment