Skip to content

Commit

Permalink
Rename editor after renaming a file
Browse files Browse the repository at this point in the history
  • Loading branch information
SimLV committed May 7, 2024
1 parent 08a04c9 commit 45fcfcb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/NotepadNext/docks/FolderAsWorkspaceDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ FolderAsWorkspaceDock::FolderAsWorkspaceDock(MainWindow *parent) :
}
});
connect(ui->treeView, &QTreeView::customContextMenuRequested, this, &FolderAsWorkspaceDock::onCustomContextMenu);
connect(model, &QFileSystemModel::fileRenamed, this, &FolderAsWorkspaceDock::onFileRenamed);

ApplicationSettings settings;
setRootPath(settings.get(rootPathSetting));
Expand Down Expand Up @@ -138,6 +139,19 @@ void FolderAsWorkspaceDock::on_actionRename_triggered()
ui->treeView->edit(lastSelectedItem);
}

void FolderAsWorkspaceDock::onFileRenamed(const QString &path, const QString &oldName, const QString &newName)
{
QDir dir(path);
QString fileName = dir.absoluteFilePath(oldName);
for(auto &&editor : window->editors())
{
if (editor->isFile() && (editor->getFilePath() == fileName))
{
editor->setName(newName);
}
}
}

void FolderAsWorkspaceDock::on_actionDelete_triggered()
{
bool ret;
Expand Down
1 change: 1 addition & 0 deletions src/NotepadNext/docks/FolderAsWorkspaceDock.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private slots:
void on_actionDelete_triggered();

void onCustomContextMenu(const QPoint &point);
void onFileRenamed(const QString &path, const QString &oldName, const QString &newName);

private:
Ui::FolderAsWorkspaceDock *ui;
Expand Down

0 comments on commit 45fcfcb

Please sign in to comment.