@@ -2100,30 +2100,42 @@ bool MainWindow::changeNoteFolder(const int noteFolderId, const bool forceChange
21002100
21012101 QString folderName = noteFolder.getLocalPath ();
21022102 const QString oldPath = this ->notesPath ;
2103-
2104- // Switch the active note folder first so all subsequent refresh steps
2105- // (including combo/menu rebuilding) use the correct current folder.
2106- noteFolder.setAsCurrent ();
2107-
21082103 const bool notesPathChanged = (oldPath != folderName);
21092104
21102105 // reload notes if notes folder was changed
21112106 if (notesPathChanged) {
2107+ // Store everything before changing folder
2108+ storeUpdatedNotesToDisk ();
2109+
2110+ if (Note::hasDirtyNotes ()) {
2111+ loadNoteFolderListMenu ();
2112+ QMessageBox::warning (
2113+ this , tr (" Could not switch note folder" ),
2114+ tr (" Modified notes could not be written to disk. Please resolve the problem and "
2115+ " try switching note folders again." ));
2116+ return false ;
2117+ }
2118+
21122119 const QSignalBlocker blocker2 (this ->ui ->searchLineEdit );
21132120 {
21142121 Q_UNUSED (blocker2)
21152122 ui->searchLineEdit ->clear ();
21162123 }
21172124
2118- // store everything before changing folder
2119- storeUpdatedNotesToDisk ();
2120-
21212125 // commit the changes in the current note folder to git
21222126 gitCommitCurrentNoteFolder ();
21232127
21242128 // update the recent note folder list
21252129 storeRecentNoteFolder (this ->notesPath , folderName);
21262130
2131+ // Switch the active note folder only after all pending writes for the
2132+ // current folder were flushed to disk.
2133+ noteFolder.setAsCurrent ();
2134+
2135+ // Rebuild the selector and menu after switching so the newly active
2136+ // note folder stays selected in the UI.
2137+ loadNoteFolderListMenu ();
2138+
21272139 // change notes path
21282140 this ->notesPath = folderName;
21292141
@@ -2139,6 +2151,8 @@ bool MainWindow::changeNoteFolder(const int noteFolderId, const bool forceChange
21392151 // switching to another note folder
21402152 unsetCurrentNote ();
21412153 } else {
2154+ noteFolder.setAsCurrent ();
2155+
21422156 // Keep selector and Note -> Note folders menu in sync when switching
21432157 // between folders that share the same path.
21442158 loadNoteFolderListMenu ();
0 commit comments