From b4fbcbddb039cb49fa928c36609f8936f75572a2 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 25 Oct 2022 22:10:38 +0800 Subject: [PATCH] - enhancement: when create a new folder in the files view, auto select that folder and rename it --- RedPandaIDE/mainwindow.cpp | 35 ++++++++++++++++++++++++++++++++--- RedPandaIDE/mainwindow.h | 2 ++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 015836c4..942b3180 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -3838,6 +3838,25 @@ void MainWindow::onShowInsertCodeSnippetMenu() } +void MainWindow::onFilesViewCreateFolderFolderLoaded(const QString& path) +{ + + if (mFilesViewNewCreatedFolder.isEmpty()) + return; + + if (path!=extractFilePath(mFilesViewNewCreatedFolder)) + return; + + disconnect(&mFileSystemModel,&QFileSystemModel::directoryLoaded, + this,&MainWindow::onFilesViewCreateFolderFolderLoaded); + QModelIndex newIndex = mFileSystemModel.index(mFilesViewNewCreatedFolder); + if (newIndex.isValid()) { + ui->treeFiles->setCurrentIndex(newIndex); + ui->treeFiles->edit(newIndex); + } + mFilesViewNewCreatedFolder=""; +} + void MainWindow::onFilesViewCreateFolder() { QModelIndex index = ui->treeFiles->currentIndex(); @@ -3852,7 +3871,7 @@ void MainWindow::onFilesViewCreateFolder() dir = mFileSystemModel.fileInfo(index).absoluteDir(); parentIndex = mFileSystemModel.index(dir.absolutePath()); } - ui->treeFiles->expand(index); + //ui->treeFiles->expand(index); } else { dir = mFileSystemModel.rootDirectory(); parentIndex=mFileSystemModel.index(dir.absolutePath()); @@ -3864,8 +3883,18 @@ void MainWindow::onFilesViewCreateFolder() folderName = tr("New Folder %1").arg(count); } QModelIndex newIndex = mFileSystemModel.mkdir(parentIndex,folderName); - ui->treeFiles->setCurrentIndex(newIndex); - ui->treeFiles->edit(newIndex); + if (newIndex.isValid()) { + if (ui->treeFiles->isExpanded(parentIndex)) { + ui->treeFiles->setCurrentIndex(newIndex); + ui->treeFiles->edit(newIndex); + } else { + connect(&mFileSystemModel,&QFileSystemModel::directoryLoaded, + this,&MainWindow::onFilesViewCreateFolderFolderLoaded); + ui->treeFiles->expand(parentIndex); + mFilesViewNewCreatedFolder=mFileSystemModel.filePath(newIndex); + } + + } } void MainWindow::onFilesViewCreateFile() diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index d1e52071..d6b7fa26 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -329,6 +329,7 @@ private slots: void onShowInsertCodeSnippetMenu(); + void onFilesViewCreateFolderFolderLoaded(const QString& path); void onFilesViewCreateFolder(); void onFilesViewCreateFile(); void onFilesViewRemoveFiles(); @@ -777,6 +778,7 @@ private: int mOJProblemSetNameCounter; QString mClassBrowserCurrentStatement; + QString mFilesViewNewCreatedFolder; bool mCheckSyntaxInBack; bool mShouldRemoveAllSettings;