From f5358f16a7cf2463f9d31d8b6f2715717d84d89e Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Fri, 17 Sep 2021 22:58:58 +0800 Subject: [PATCH] - actions: rename project unit , add/remove/rename project folder --- RedPandaIDE/mainwindow.cpp | 76 ++++++++++++++++++++++++++++++++++++++ RedPandaIDE/mainwindow.h | 8 ++++ 2 files changed, 84 insertions(+) diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index f5533c01..9aaf8fd4 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -1468,6 +1468,35 @@ void MainWindow::buildContextMenus() [this](){ pMainWindow->debugger()->deleteBreakpoints(); }); + + //context menu signal for project view + ui->projectView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->projectView,&QWidget::customContextMenuRequested, + this, &MainWindow::onProjectViewContextMenu); + mProject_Rename_Unit = createActionFor( + tr("Rename File"), + ui->projectView); + connect(mProject_Rename_Unit, &QAction::triggered, + [this](){ + }); + mProject_Add_Folder = createActionFor( + tr("Add Folder"), + ui->projectView); + connect(mProject_Add_Folder, &QAction::triggered, + [this](){ + }); + mProject_Rename_Folder = createActionFor( + tr("Rename File"), + ui->projectView); + connect(mProject_Rename_Folder, &QAction::triggered, + [this](){ + }); + mProject_Remove_Folder = createActionFor( + tr("Rename File"), + ui->projectView); + connect(mProject_Remove_Folder, &QAction::triggered, + [this](){ + }); } void MainWindow::maximizeEditor() @@ -1571,6 +1600,53 @@ void MainWindow::onBreakpointsViewContextMenu(const QPoint &pos) menu.exec(ui->tblBreakpoints->mapToGlobal(pos)); } +void MainWindow::onProjectViewContextMenu(const QPoint &pos) +{ + if (!mProject) + return; + bool onFolder = false; + bool onUnit = false; + bool onRoot = false; + bool folderEmpty = false; + int unitIndex = -1; + QModelIndex current = ui->projectView->selectionModel()->currentIndex(); + if (current.isValid() && mProject) { + FolderNode * node = static_cast(current.internalPointer()); + PFolderNode pNode = mProject->pointerToNode(node); + if (pNode) { + unitIndex = pNode->unitIndex; + onFolder = (unitIndex<0); + onUnit = (unitIndex >= 0); + onRoot = (pNode == mProject->node()); + if (onFolder && !onRoot) { + folderEmpty = pNode->children.isEmpty(); + } + } + } + QMenu menu(this); + updateProjectActions(); + menu.addAction(ui->actionProject_New_File); + menu.addAction(ui->actionAdd_to_project); + menu.addAction(ui->actionRemove_from_project); + if (onUnit) { + menu.addAction(mProject_Rename_Unit); + } + menu.addSeparator(); + if (onFolder) { + menu.addAction(mProject_Add_Folder); + if (!onRoot) { + menu.addAction(mProject_Rename_Folder); + if (folderEmpty) { + menu.addAction(mProject_Remove_Folder); + } + } + menu.addSeparator(); + } + menu.addAction(ui->actionProject_options); + + menu.exec(ui->projectView->mapToGlobal(pos)); +} + void MainWindow::onEditorContextMenu(const QPoint &pos) { Editor * editor = mEditorList->getEditor(); diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 890f0bd2..c5b94cb4 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -154,6 +154,7 @@ private slots: void onTableIssuesContextMenu(const QPoint& pos); void onSearchViewContextMenu(const QPoint& pos); void onBreakpointsViewContextMenu(const QPoint& pos); + void onProjectViewContextMenu(const QPoint& pos); void on_actionNew_triggered(); @@ -387,6 +388,13 @@ private: QAction * mBreakpointViewPropertyAction; QAction * mBreakpointViewRemoveAllAction; + //actions for project view + QAction * mProject_Add_Folder; + QAction * mProject_Rename_Unit; + QAction * mProject_Rename_Folder; + QAction * mProject_Remove_Folder; + + // QWidget interface protected: void closeEvent(QCloseEvent *event) override;