Skip to content

Commit

Permalink
refactor: adjust codegeex position
Browse files Browse the repository at this point in the history
Log:
Change-Id: I04b8c6d7e64b8161df1cf6d7e874677cb21c223e
  • Loading branch information
deepin-mozart committed Nov 27, 2023
1 parent 025acb4 commit 36c82d8
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 37 deletions.
6 changes: 5 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions src/plugins/codeeditor/codeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
48 changes: 34 additions & 14 deletions src/plugins/codeeditor/mainframe/naveditmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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<DWidget*>(treeWidget->qWidget());
qTabWidgetWorkspace->addTab(qTreeWidget, title);

adjustWorkspaceItemOrder();
}

void NavEditMainWindow::addWorkspaceArea(const QString &title, AbstractWidget *widget)
{
auto qWidget = static_cast<DWidget*>(widget->qWidget());
if (qWidget) {
qDockWidgetWorkspace->setWindowTitle(title);
qDockWidgetWorkspace->setWidget(qWidget);
workspaceWidgets.insert(title, qWidget);
}
}

if (qTabWidgetWorkspace) {
auto qTreeWidget = static_cast<DWidget*>(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)
Expand Down
38 changes: 23 additions & 15 deletions src/plugins/codeeditor/mainframe/naveditmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QString> 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
Expand All @@ -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<QString, DWidget*> workspaceWidgets;
QList<QString> contextList;
QMutex mutex;

DWidget *topToolBarWidget{nullptr};
};

#endif // NAVEDITMAINWINDOW_H
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 5 additions & 6 deletions src/plugins/codegeex/codegeex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QAction>
#include <QIcon>

using namespace dpfservice;
void CodeGeex::initialize()
{
}
Expand All @@ -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()));
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/plugins/codegeex/codegeex.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
<file>images/chat_icon_new_hover.png</file>
<file>images/copy.png</file>
</qresource>
<qresource prefix="/icons/deepin/">
<file>builtin/actions/codegeex-navigation_20px.svg</file>
</qresource>
</RCC>
25 changes: 25 additions & 0 deletions src/plugins/core/mainframe/windowkeeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QTranslator>
#include <QScreen>
#include <QStandardPaths>
#include <DDockWidget>

static WindowKeeper *ins{nullptr};
using namespace dpfservice;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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<QHBoxLayout*>(d->window->titlebar()->layout());
Expand All @@ -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__;
Expand Down Expand Up @@ -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>(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);
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/core/mainframe/windowkeeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ 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);
void addAction(const QString &menuName, AbstractAction *action);
void removeActions(const QString &menuName);
void addOpenProjectAction(const QString &name, AbstractAction *action);
void initUserWidget();
void switchWidgetNavigation(const QString &navName);

void setTopToolBarWidget(AbstractWidget *widget);

Expand Down
1 change: 1 addition & 0 deletions src/services/window/windowelement.h
Original file line number Diff line number Diff line change
Expand Up @@ -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++" };
Expand Down
4 changes: 4 additions & 0 deletions src/services/window/windowservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit 36c82d8

Please sign in to comment.