now the root note folder cannot be removed in the note subfolder tree and did some refactoring

This commit is contained in:
Patrizio Bekerle 2016-07-17 09:44:52 +02:00
parent 284ac527ac
commit 06d9dfa066
4 changed files with 33 additions and 15 deletions

View file

@ -8,6 +8,8 @@
- note subfolders deeper than 2nd level can now be used
(for [Issue #246](https://github.com/pbek/QOwnNotes/issues/246))
- note subfolders can now be renamed in the note subfolder tree
- now the root note folder cannot be removed in the note subfolder tree
(for [Issue #246](https://github.com/pbek/QOwnNotes/issues/246))
## 16.07.7
- fixed a possible crash after removing the last script in the settings dialog

View file

@ -103,14 +103,14 @@ QString NoteSubFolder::relativePath() {
}
/**
* Gets the relative path name of the note sub folder
* Gets the full path of the note sub folder
*/
QString NoteSubFolder::fullPath() {
return Note::getFullNoteFilePathForFile(relativePath());
}
/**
* Gets the relative path name of the note sub folder
* Gets the full path of the note sub folder as QDir
*/
QDir NoteSubFolder::dir() {
return QDir(fullPath());
@ -162,10 +162,11 @@ bool NoteSubFolder::remove() {
}
/**
* Removes the directory recursivley from the file system
* Removes the directory recursively from the file system
*/
bool NoteSubFolder::removeFromFileSystem() {
QDir dir(fullPath());
QDir dir = this->dir();
if (dir.exists()) {
return dir.removeRecursively();
}
@ -173,6 +174,24 @@ bool NoteSubFolder::removeFromFileSystem() {
return false;
}
/**
* Renames the note subfolder in the file system
*/
bool NoteSubFolder::rename(QString newName) {
QDir dir = this->dir();
if (dir.exists() && !newName.isEmpty()) {
QString oldPath = fullPath();
setName(newName);
QString newPath = fullPath();
// rename the note subfolder
return dir.rename(oldPath, newPath);
}
return false;
}
NoteSubFolder NoteSubFolder::noteSubFolderFromQuery(QSqlQuery query) {
NoteSubFolder noteSubFolder;
noteSubFolder.fillFromQuery(query);

View file

@ -80,6 +80,8 @@ public:
QDir dir();
bool rename(QString newName);
protected:
int id;
int parentId;

View file

@ -2754,8 +2754,10 @@ void MainWindow::removeSelectedNoteSubFolders() {
ui->noteSubFolderTreeWidget->selectedItems()) {
int id = item->data(0, Qt::UserRole).toInt();
NoteSubFolder noteSubFolder = NoteSubFolder::fetch(id);
noteSubFolder.removeFromFileSystem();
qDebug() << "Removed folder " << noteSubFolder.getName();
if (noteSubFolder.isFetched()) {
noteSubFolder.removeFromFileSystem();
qDebug() << "Removed folder " << noteSubFolder.getName();
}
}
}
}
@ -6426,15 +6428,8 @@ void MainWindow::on_noteSubFolderTreeWidget_itemChanged(
if (noteSubFolder.isFetched()) {
QString name = item->text(0);
if (!name.isEmpty()) {
QString oldPath = noteSubFolder.fullPath();
noteSubFolder.setName(name);
noteSubFolder.store();
QString newPath = noteSubFolder.fullPath();
// rename the note subfolder
noteSubFolder.dir().rename(oldPath, newPath);
}
// rename the note subfolder in the file system
noteSubFolder.rename(name);
// reload tags, note subfolder and notes
on_action_Reload_note_folder_triggered();