From acbbae24c6d90d619ee43e0bbc6b94ff099871d6 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 8 Feb 2022 16:36:20 +0800 Subject: [PATCH] - enhancement: remove / rename / create new folder in the files view --- NEWS.md | 1 + RedPandaIDE/mainwindow.cpp | 61 +++++++++++++++++++++++++++++++++++++- RedPandaIDE/mainwindow.h | 5 ++++ RedPandaIDE/mainwindow.ui | 10 +++++-- RedPandaIDE/project.cpp | 1 - 5 files changed, 74 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 3b27856f..dbcbc22a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ Red Panda C++ Version 0.14.2 - enhancement: file system view mode for project + - enhancement: remove / rename / create new folder in the files view Red Panda C++ Version 0.14.1 - enhancement: custom theme diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 7ccea5f7..213ef44d 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -285,7 +285,7 @@ MainWindow::MainWindow(QWidget *parent) //files view ui->treeFiles->setModel(&mFileSystemModel); - mFileSystemModel.setReadOnly(true); + mFileSystemModel.setReadOnly(false); setFilesViewRoot(pSettings->environment().currentFolder()); for (int i=1;itreeFiles->hideColumn(i); @@ -2649,6 +2649,18 @@ void MainWindow::buildContextMenus() ui->treeFiles->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->treeFiles,&QWidget::customContextMenuRequested, this, &MainWindow::onFilesViewContextMenu); + + mFilesView_CreateFolder = createActionFor( + tr("New Folder"), + ui->treeFiles); + connect(mFilesView_CreateFolder, &QAction::triggered, + this, &MainWindow::onFilesViewCreateFolder); + mFilesView_RemoveFile = createActionFor( + tr("Delete"), + ui->treeFiles); + mFilesView_RemoveFile->setShortcut(Qt::Key_Delete); + connect(mFilesView_RemoveFile, &QAction::triggered, + this, &MainWindow::onFilesViewRemoveFile); mFilesView_Open = createActionFor( tr("Open in Editor"), ui->treeFiles); @@ -3019,6 +3031,8 @@ void MainWindow::onFilesViewContextMenu(const QPoint &pos) QMenu menu(this); menu.addAction(ui->actionOpen_Folder); menu.addSeparator(); + menu.addAction(mFilesView_CreateFolder); + menu.addSeparator(); menu.addAction(mFilesView_Open); menu.addAction(mFilesView_OpenWithExternal); menu.addSeparator(); @@ -3295,6 +3309,51 @@ void MainWindow::onShowInsertCodeSnippetMenu() } +void MainWindow::onFilesViewCreateFolder() +{ + QModelIndex index = ui->treeFiles->currentIndex(); + QDir dir; + if (index.isValid()) { + if (mFileSystemModel.isDir(index)) + dir = QDir(mFileSystemModel.fileInfo(index).absoluteFilePath()); + else + dir = mFileSystemModel.fileInfo(index).absoluteDir(); + } else { + dir = mFileSystemModel.rootDirectory(); + } + QString folderName = tr("New Folder"); + int count = 0; + while (dir.exists(folderName)) { + count++; + folderName = tr("New Folder").arg(count); + } + mFileSystemModel.mkdir(index,folderName); +} + +void MainWindow::onFilesViewRemoveFile() +{ + QModelIndex index = ui->treeFiles->currentIndex(); + if (!index.isValid()) + return; + if (QMessageBox::question(ui->treeFiles,tr("Delete") + ,tr("Do you really want to delete %1?").arg(mFileSystemModel.fileName(index)), + QMessageBox::Yes | QMessageBox::No, QMessageBox::No)!=QMessageBox::Yes) + return; + if (mFileSystemModel.isDir(index)) { + QDir dir(mFileSystemModel.fileInfo(index).absoluteFilePath()); + if (!dir.isEmpty() && + QMessageBox::question(ui->treeFiles + ,tr("Delete") + ,tr("Folder %1 is not empty.").arg(mFileSystemModel.fileName(index)) + + tr("Do you really want to delete it?"), + QMessageBox::Yes | QMessageBox::No, QMessageBox::No)!=QMessageBox::Yes) + return; + dir.removeRecursively(); + } else { + QFile::remove(mFileSystemModel.filePath(index)); + } +} + void MainWindow::onEditorContextMenu(const QPoint& pos) { Editor * editor = mEditorList->getEditor(); diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 28e6f6de..aa1a6be7 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -274,6 +274,9 @@ private slots: void onShowInsertCodeSnippetMenu(); + void onFilesViewCreateFolder(); + void onFilesViewRemoveFile(); + void on_actionNew_triggered(); void on_EditorTabsLeft_tabCloseRequested(int index); @@ -667,6 +670,8 @@ private: QAction * mFilesView_OpenInTerminal; QAction * mFilesView_OpenInExplorer; QWidget * mFilesViewToolbar; + QAction * mFilesView_CreateFolder; + QAction * mFilesView_RemoveFile; //action for debug console QAction * mDebugConsole_ShowDetailLog; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 2d773bb6..257f4952 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -85,7 +85,7 @@ QTabWidget::West - 2 + 3 true @@ -258,8 +258,14 @@ QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked + + true + - QAbstractItemView::DragOnly + QAbstractItemView::DragDrop + + + Qt::CopyAction diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index 914b3806..631d818d 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -311,7 +311,6 @@ Editor *Project::openUnit(int index) void Project::rebuildNodes() { - qDebug()<<(int)mOptions.modelType; mModel.beginUpdate(); // Delete everything mRootNode->children.clear();