From 36c82d863c2c4e892465941d32fbf315221f04a4 Mon Sep 17 00:00:00 2001 From: Lu Zhen Date: Fri, 24 Nov 2023 18:04:43 +0800 Subject: [PATCH] refactor: adjust codegeex position Log: Change-Id: I04b8c6d7e64b8161df1cf6d7e874677cb21c223e --- debian/control | 6 ++- src/plugins/codeeditor/codeeditor.cpp | 8 ++++ .../mainframe/naveditmainwindow.cpp | 48 +++++++++++++------ .../codeeditor/mainframe/naveditmainwindow.h | 38 +++++++++------ .../actions/codegeex-navigation_20px.svg | 7 +++ src/plugins/codegeex/codegeex.cpp | 11 ++--- src/plugins/codegeex/codegeex.qrc | 3 ++ src/plugins/core/mainframe/windowkeeper.cpp | 25 ++++++++++ src/plugins/core/mainframe/windowkeeper.h | 4 +- src/services/window/windowelement.h | 1 + src/services/window/windowservice.h | 4 ++ 11 files changed, 118 insertions(+), 37 deletions(-) create mode 100644 src/plugins/codegeex/builtin/actions/codegeex-navigation_20px.svg diff --git a/debian/control b/debian/control index 4c5d3777d..068fd4f5e 100644 --- a/debian/control +++ b/debian/control @@ -31,7 +31,11 @@ Build-Depends: qtscript5-dev, libqt5scripttools5, clang, - doxygen + doxygen, + libdtkgui-dev, + libdtkwidget-dev, + libdtkcore-dev, + libdtkcore5-bin Standards-version: 3.9.8 Homepage: http://www.deepin.org diff --git a/src/plugins/codeeditor/codeeditor.cpp b/src/plugins/codeeditor/codeeditor.cpp index 37ac0b270..95a35c3eb 100644 --- a/src/plugins/codeeditor/codeeditor.cpp +++ b/src/plugins/codeeditor/codeeditor.cpp @@ -96,6 +96,14 @@ bool CodeEditor::start() windowService->showFindToolBar = std::bind(&NavEditMainWindow::showFindToolBar, navEditWindow); } + if (!windowService->addWorkspaceArea) { + windowService->addWorkspaceArea = std::bind(&NavEditMainWindow::addWorkspaceArea, navEditWindow, _1, _2); + } + + if (!windowService->switchWorkspaceArea) { + windowService->switchWorkspaceArea = std::bind(&NavEditMainWindow::switchWorkspaceArea, navEditWindow, _1); + } + auto sep = new QAction(); sep->setSeparator(true); windowService->addAction(MWM_FILE, new AbstractAction(sep)); diff --git a/src/plugins/codeeditor/mainframe/naveditmainwindow.cpp b/src/plugins/codeeditor/mainframe/naveditmainwindow.cpp index b781347a8..1fa4f0e11 100644 --- a/src/plugins/codeeditor/mainframe/naveditmainwindow.cpp +++ b/src/plugins/codeeditor/mainframe/naveditmainwindow.cpp @@ -83,6 +83,20 @@ NavEditMainWindow::NavEditMainWindow(QWidget *parent, Qt::WindowFlags flags) topToolBarWidget = new DWidget(); QHBoxLayout *toolBarLayout = new QHBoxLayout(topToolBarWidget); toolBarLayout->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); + + // initialize space area. + qDockWidgetWorkspace = new AutoHideDockWidget(DDockWidget::tr("Workspace"), this); + qDockWidgetWorkspace->setFeatures(DDockWidget::DockWidgetMovable); + qDockWidgetWorkspace->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + addDockWidget(Qt::DockWidgetArea::LeftDockWidgetArea, qDockWidgetWorkspace); + setCorner(Qt::BottomLeftCorner, Qt::DockWidgetArea::LeftDockWidgetArea); + + qTabWidgetWorkspace = new DTabWidget(); + qTabWidgetWorkspace->setMinimumHeight(300); + qTabWidgetWorkspace->setTabPosition(DTabWidget::West); + workspaceWidgets.insert(DDockWidget::tr("Workspace"), qTabWidgetWorkspace); + + qDockWidgetWorkspace->setWidget(qTabWidgetWorkspace); } NavEditMainWindow::~NavEditMainWindow() @@ -102,23 +116,29 @@ QStringList NavEditMainWindow::contextWidgetTitles() const void NavEditMainWindow::addWidgetWorkspace(const QString &title, AbstractWidget *treeWidget) { - if (!qDockWidgetWorkspace) { - qTabWidgetWorkspace = new DTabWidget(); - qTabWidgetWorkspace->setMinimumHeight(300); - qTabWidgetWorkspace->setTabPosition(DTabWidget::West); - qDockWidgetWorkspace = new AutoHideDockWidget(DDockWidget::tr("Workspace"), this); - qDockWidgetWorkspace->setFeatures(DDockWidget::DockWidgetMovable); - qDockWidgetWorkspace->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - addDockWidget(Qt::DockWidgetArea::LeftDockWidgetArea, qDockWidgetWorkspace); - setCorner(Qt::BottomLeftCorner, Qt::DockWidgetArea::LeftDockWidgetArea); - qDockWidgetWorkspace->setWidget(qTabWidgetWorkspace); + auto qTreeWidget = static_cast(treeWidget->qWidget()); + qTabWidgetWorkspace->addTab(qTreeWidget, title); + + adjustWorkspaceItemOrder(); +} + +void NavEditMainWindow::addWorkspaceArea(const QString &title, AbstractWidget *widget) +{ + auto qWidget = static_cast(widget->qWidget()); + if (qWidget) { + qDockWidgetWorkspace->setWindowTitle(title); + qDockWidgetWorkspace->setWidget(qWidget); + workspaceWidgets.insert(title, qWidget); } +} - if (qTabWidgetWorkspace) { - auto qTreeWidget = static_cast(treeWidget->qWidget()); - qTabWidgetWorkspace->addTab(qTreeWidget, title); +void NavEditMainWindow::switchWorkspaceArea(const QString &title) +{ + auto widget = workspaceWidgets.value(title); + if (widget) { + qDockWidgetWorkspace->setWindowTitle(title); + qDockWidgetWorkspace->setWidget(widget); } - adjustWorkspaceItemOrder(); } DWidget *NavEditMainWindow::setWidgetEdit(AbstractCentral *editWidget) diff --git a/src/plugins/codeeditor/mainframe/naveditmainwindow.h b/src/plugins/codeeditor/mainframe/naveditmainwindow.h index 61e9bd15e..06211cf70 100644 --- a/src/plugins/codeeditor/mainframe/naveditmainwindow.h +++ b/src/plugins/codeeditor/mainframe/naveditmainwindow.h @@ -25,28 +25,17 @@ class ToolBarManager; class NavEditMainWindow : public DMainWindow { Q_OBJECT - AutoHideDockWidget *qDockWidgetWorkspace{nullptr}; - AutoHideDockWidget *qDockWidgetContext{nullptr}; - AutoHideDockWidget *qDockWidgetWatch{nullptr}; - AutoHideDockWidget *qDockWidgetFindToolBar{nullptr}; - AutoHideDockWidget *qDockWidgetValgrindBar{nullptr}; - AutoHideDockWidget *qDockWidgetTools{nullptr}; - DWidget *qWidgetEdit{nullptr}; - DWidget *qWidgetWatch{nullptr}; - DTabWidget *qTabWidgetContext{nullptr}; - DTabWidget *qTabWidgetWorkspace{nullptr}; - DTabWidget *qTabWidgetTools{nullptr}; - ToolBarManager *mainToolBar{nullptr}; - QList contextList; - QMutex mutex; - DWidget *topToolBarWidget{nullptr}; public: static NavEditMainWindow *instance(); explicit NavEditMainWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); virtual ~NavEditMainWindow(); QStringList contextWidgetTitles() const; + void addWidgetWorkspace(const QString &title, AbstractWidget *treeWidget); + void addWorkspaceArea(const QString &title, AbstractWidget *widget); + void switchWorkspaceArea(const QString &title); + // return old edit widget DWidget *setWidgetEdit(AbstractCentral *editWidget); // return old watch widget @@ -68,8 +57,27 @@ class NavEditMainWindow : public DMainWindow void setToolBarItemDisable(const QString &id, bool disable); DWidget *getTopToolBarWidget(); + private: void adjustWorkspaceItemOrder(); + + AutoHideDockWidget *qDockWidgetWorkspace{nullptr}; + AutoHideDockWidget *qDockWidgetContext{nullptr}; + AutoHideDockWidget *qDockWidgetWatch{nullptr}; + AutoHideDockWidget *qDockWidgetFindToolBar{nullptr}; + AutoHideDockWidget *qDockWidgetValgrindBar{nullptr}; + AutoHideDockWidget *qDockWidgetTools{nullptr}; + DWidget *qWidgetEdit{nullptr}; + DWidget *qWidgetWatch{nullptr}; + DTabWidget *qTabWidgetContext{nullptr}; + DTabWidget *qTabWidgetWorkspace{nullptr}; + DTabWidget *qTabWidgetTools{nullptr}; + ToolBarManager *mainToolBar{nullptr}; + QMap workspaceWidgets; + QList contextList; + QMutex mutex; + + DWidget *topToolBarWidget{nullptr}; }; #endif // NAVEDITMAINWINDOW_H diff --git a/src/plugins/codegeex/builtin/actions/codegeex-navigation_20px.svg b/src/plugins/codegeex/builtin/actions/codegeex-navigation_20px.svg new file mode 100644 index 000000000..7f2d76a0e --- /dev/null +++ b/src/plugins/codegeex/builtin/actions/codegeex-navigation_20px.svg @@ -0,0 +1,7 @@ + + + ICON / sidebar /codegee + + + + \ No newline at end of file diff --git a/src/plugins/codegeex/codegeex.cpp b/src/plugins/codegeex/codegeex.cpp index d358f95bc..8c898a6b7 100644 --- a/src/plugins/codegeex/codegeex.cpp +++ b/src/plugins/codegeex/codegeex.cpp @@ -21,6 +21,7 @@ #include #include +using namespace dpfservice; void CodeGeex::initialize() { } @@ -29,15 +30,13 @@ bool CodeGeex::start() { auto windowService = dpfGetService(dpfservice::WindowService); if (windowService) { - QString title = "CodeGeex"; - // Add widget to left bar if (windowService->addCentralNavigation) { -// auto askPage = new AskPage(); -// windowService->addWidgetWorkspace(title, new AbstractWidget(askPage)); + auto editWidget = windowService->getCentralNavigation(MWNA_EDIT); + windowService->addNavigation(MWNA_CODEGEEX, "codegeex-navigation"); + windowService->addCentralNavigation(MWNA_CODEGEEX, editWidget); - auto codeGeeXWidget = new CodeGeeXWidget(); - windowService->addWidgetWorkspace(title, new AbstractWidget(codeGeeXWidget)); + windowService->addWorkspaceArea(MWNA_CODEGEEX, new AbstractWidget(new CodeGeeXWidget())); } } diff --git a/src/plugins/codegeex/codegeex.qrc b/src/plugins/codegeex/codegeex.qrc index 1c3c72933..c13b65117 100644 --- a/src/plugins/codegeex/codegeex.qrc +++ b/src/plugins/codegeex/codegeex.qrc @@ -12,4 +12,7 @@ images/chat_icon_new_hover.png images/copy.png + + builtin/actions/codegeex-navigation_20px.svg + diff --git a/src/plugins/core/mainframe/windowkeeper.cpp b/src/plugins/core/mainframe/windowkeeper.cpp index 93981abc5..ab79a8287 100644 --- a/src/plugins/core/mainframe/windowkeeper.cpp +++ b/src/plugins/core/mainframe/windowkeeper.cpp @@ -30,6 +30,7 @@ #include #include #include +#include static WindowKeeper *ins{nullptr}; using namespace dpfservice; @@ -303,6 +304,10 @@ WindowKeeper::WindowKeeper(QObject *parent) if (!windowService->setTopToolBarWidget) { windowService->setTopToolBarWidget = std::bind(&WindowKeeper::setTopToolBarWidget, this, _1); } + + if (!windowService->getCentralNavigation) { + windowService->getCentralNavigation = std::bind(&WindowKeeper::getCentralNavigation, this, _1); + } } WindowKeeper::~WindowKeeper() @@ -330,8 +335,11 @@ void WindowKeeper::addCentralNavigation(const QString &navName, AbstractCentral if(!central || !inputWidget || navName.isEmpty()) return; + // use same widget is allowed +#if 0 if (d->centrals.values().contains(inputWidget)) return; +#endif if (navName == MWNA_EDIT) { QHBoxLayout *titleBarLayout = static_cast(d->window->titlebar()->layout()); @@ -345,6 +353,11 @@ void WindowKeeper::addCentralNavigation(const QString &navName, AbstractCentral d->centrals.insert(navName, inputWidget); } +AbstractCentral *WindowKeeper::getCentralNavigation(const QString &navName) +{ + return new AbstractCentral(d->centrals.value(navName)); +} + void WindowKeeper::addMenu(AbstractMenu *menu) { qInfo() << __FUNCTION__; @@ -512,9 +525,21 @@ void WindowKeeper::switchWidgetNavigation(const QString &navName) d->topToolBar->hide(); d->window->titlebar()->setTitle(QString(tr("Deepin Union Code"))); + auto &ctx = dpfInstance.serviceContext(); + WindowService *windowService = ctx.service(WindowService::name()); + if (!windowService) + return; + if (navName == MWNA_EDIT) { d->topToolBar->show(); d->window->titlebar()->setTitle(QString()); + if (windowService->switchWorkspaceArea) { + windowService->switchWorkspaceArea(DDockWidget::tr("Workspace")); + } + } else if (navName == MWNA_CODEGEEX) { + if (windowService->switchWorkspaceArea) { + windowService->switchWorkspaceArea(navName); + } } setNavActionChecked(navName, true); diff --git a/src/plugins/core/mainframe/windowkeeper.h b/src/plugins/core/mainframe/windowkeeper.h index 2eed9ca49..cde5f4af1 100644 --- a/src/plugins/core/mainframe/windowkeeper.h +++ b/src/plugins/core/mainframe/windowkeeper.h @@ -48,6 +48,9 @@ class WindowKeeper final :public QObject public slots: void addNavigation(const QString &navName, const QString &iconName); void addCentralNavigation(const QString &navName, AbstractCentral *central); + AbstractCentral *getCentralNavigation(const QString &navName); + void switchWidgetNavigation(const QString &navName); + void addMenu(AbstractMenu *menu); void insertAction(const QString &menuName, const QString &beforActionName, AbstractAction *action); @@ -55,7 +58,6 @@ public slots: void removeActions(const QString &menuName); void addOpenProjectAction(const QString &name, AbstractAction *action); void initUserWidget(); - void switchWidgetNavigation(const QString &navName); void setTopToolBarWidget(AbstractWidget *widget); diff --git a/src/services/window/windowelement.h b/src/services/window/windowelement.h index f341fba56..f99c7670b 100644 --- a/src/services/window/windowelement.h +++ b/src/services/window/windowelement.h @@ -23,6 +23,7 @@ inline const QString MWNA_DEBUG { QObject::tr("Debug") }; inline const QString MWNA_GIT { QObject::tr("Git") }; inline const QString MWNA_SVN { QObject::tr("Svn") }; inline const QString MWNA_RUNTIME { QObject::tr("Runtime") }; +inline const QString MWNA_CODEGEEX { QObject::tr("CodeGeeX") }; inline const QString MWM_FILE { QMenu::tr("&File") }; inline const QString MWMFA_CXX { "C/C++" }; diff --git a/src/services/window/windowservice.h b/src/services/window/windowservice.h index fd89a7a04..5ebdabba8 100644 --- a/src/services/window/windowservice.h +++ b/src/services/window/windowservice.h @@ -181,6 +181,10 @@ class WindowService final : public dpf::PluginService, dpf::AutoServiceRegister< DPF_INTERFACE(void, setTopToolBarWidget, AbstractWidget *widget); + DPF_INTERFACE(AbstractCentral *, getCentralNavigation, const QString &navName); + + DPF_INTERFACE(void, addWorkspaceArea, const QString &title, AbstractWidget *widget); + DPF_INTERFACE(void, switchWorkspaceArea, const QString &title); signals: