Skip to content

Commit 45fcfcb

Browse files
committed
Rename editor after renaming a file
1 parent 08a04c9 commit 45fcfcb

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/NotepadNext/docks/FolderAsWorkspaceDock.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ FolderAsWorkspaceDock::FolderAsWorkspaceDock(MainWindow *parent) :
5050
}
5151
});
5252
connect(ui->treeView, &QTreeView::customContextMenuRequested, this, &FolderAsWorkspaceDock::onCustomContextMenu);
53+
connect(model, &QFileSystemModel::fileRenamed, this, &FolderAsWorkspaceDock::onFileRenamed);
5354

5455
ApplicationSettings settings;
5556
setRootPath(settings.get(rootPathSetting));
@@ -138,6 +139,19 @@ void FolderAsWorkspaceDock::on_actionRename_triggered()
138139
ui->treeView->edit(lastSelectedItem);
139140
}
140141

142+
void FolderAsWorkspaceDock::onFileRenamed(const QString &path, const QString &oldName, const QString &newName)
143+
{
144+
QDir dir(path);
145+
QString fileName = dir.absoluteFilePath(oldName);
146+
for(auto &&editor : window->editors())
147+
{
148+
if (editor->isFile() && (editor->getFilePath() == fileName))
149+
{
150+
editor->setName(newName);
151+
}
152+
}
153+
}
154+
141155
void FolderAsWorkspaceDock::on_actionDelete_triggered()
142156
{
143157
bool ret;

src/NotepadNext/docks/FolderAsWorkspaceDock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ private slots:
5151
void on_actionDelete_triggered();
5252

5353
void onCustomContextMenu(const QPoint &point);
54+
void onFileRenamed(const QString &path, const QString &oldName, const QString &newName);
5455

5556
private:
5657
Ui::FolderAsWorkspaceDock *ui;

0 commit comments

Comments
 (0)