Skip to content

Commit

Permalink
feat: [controller] modified interface of windowService
Browse files Browse the repository at this point in the history
change the way of show dockWidget at right position

Log: as title
  • Loading branch information
LiHua000 authored and deepin-mozart committed Oct 31, 2024
1 parent d4e5594 commit 7c6c655
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 43 deletions.
30 changes: 3 additions & 27 deletions src/plugins/codegeex/codegeex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,9 @@ bool CodeGeex::start()
{
auto windowService = dpfGetService(dpfservice::WindowService);
if (windowService) {
auto codeGeex = new CodeGeeXWidget;
auto codeGeexImpl = new AbstractWidget(codeGeex);
windowService->registerWidget(MWNA_CODEGEEX, codeGeexImpl);
windowService->deleteDockHeader(MWNA_CODEGEEX); // do not hide by header.
DToolButton *button = new DToolButton(codeGeex);
button->setIcon(QIcon::fromTheme("codegeex-navigation"));
button->setToolTip(MWNA_CODEGEEX);
button->setCheckable(true);
windowService->addStatusBarItem(button);
auto scAction = new QAction(tr("Quick Open CodeGeeX"), codeGeex);
auto cmd = ActionManager::instance()->registerAction(scAction, "CodeGeeX.Quick.Open");
cmd->setDefaultKeySequence(QKeySequence(Qt::ALT + Qt::Key_L));

connect(scAction, &QAction::triggered, button, &DToolButton::clicked);
connect(button, &DToolButton::clicked, this, [=]() {
if (codeGeex->isVisible()) {
windowService->hideWidget(MWNA_CODEGEEX);
button->setChecked(false);
} else {
windowService->showWidgetAtPosition(MWNA_CODEGEEX, Position::Right, false);
button->setChecked(true);
}
}, Qt::DirectConnection);
connect(CodeGeeXCallProxy::instance(), &CodeGeeXCallProxy::switchToWidget, this, [=](const QString &name){
if (button->isChecked())
QMetaObject::invokeMethod(windowService, [=]() { windowService->showWidgetAtPosition(MWNA_CODEGEEX, Position::Right, false);});
}, Qt::DirectConnection);
auto codeGeex = new CodeGeeXWidget;
auto codeGeexImpl = new AbstractWidget(codeGeex);
windowService->addWidgetRightspace(MWNA_CODEGEEX, codeGeexImpl, "");
}

auto optionService = dpfGetService(dpfservice::OptionService);
Expand Down
9 changes: 9 additions & 0 deletions src/plugins/core/builtin/texts/uc_left_show_16px.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/plugins/core/builtin/texts/uc_right_show_16px.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/plugins/core/core.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<file>builtin/texts/hide_dock_16px.svg</file>
<file>builtin/texts/docks_manager_16px.svg</file>
<file>builtin/texts/context_widget_16px.svg</file>
<file>builtin/texts/uc_left_show_16px.svg</file>
<file>builtin/texts/uc_right_show_16px.svg</file>
<file>builtin/texts/default_dock_16px.svg</file>
<file>builtin/light/icons/notification_info_20px.svg</file>
<file>builtin/light/icons/notification_warning_20px.svg</file>
Expand Down
82 changes: 78 additions & 4 deletions src/plugins/core/uicontroller/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ class ControllerPrivate
{
MainWindow *mainWindow { nullptr };
loadingWidget *loadingwidget { nullptr };
WorkspaceWidget *workspace { nullptr };
WorkspaceWidget *workspace { nullptr }; // left default dock widget
WorkspaceWidget *rightspace { nullptr }; // right default dock widget

DWidget *navigationToolBar { nullptr };
NavigationBar *navigationBar { nullptr };
Expand All @@ -144,6 +145,8 @@ class ControllerPrivate
QHBoxLayout *contextButtonLayout { nullptr };

WindowStatusBar *statusBar { nullptr };
DToolButton *showContextBtn { nullptr };
DToolButton *showRightspaceBtn { nullptr };

QStringList validModeList { CM_EDIT, CM_DEBUG, CM_RECENT };
QMap<QString, QString> modePluginMap { { CM_EDIT, MWNA_EDIT }, { CM_RECENT, MWNA_RECENT }, { CM_DEBUG, MWNA_DEBUG } };
Expand Down Expand Up @@ -183,6 +186,7 @@ Controller::Controller(QObject *parent)
initMainWindow();
initNavigationBar();
initStatusBar();
initRightspaceWidget();
initContextWidget();
initWorkspaceWidget();
initTopToolBar();
Expand Down Expand Up @@ -311,9 +315,18 @@ void Controller::registerService()
if (!windowService->addWidgetWorkspace) {
windowService->addWidgetWorkspace = std::bind(&WorkspaceWidget::addWorkspaceWidget, d->workspace, _1, _2, _3);
}
if (!windowService->addWidgetRightspace) {
windowService->addWidgetRightspace = std::bind(&WorkspaceWidget::addWorkspaceWidget, d->rightspace, _1, _2, _3);
}
if (!windowService->registerToolBtnToWorkspaceWidget) {
windowService->registerToolBtnToWorkspaceWidget = std::bind(&WorkspaceWidget::registerToolBtnToWidget, d->workspace, _1, _2);
}
if (!windowService->registerToolBtnToRightspaceWidget) {
windowService->registerToolBtnToRightspaceWidget = std::bind(&WorkspaceWidget::registerToolBtnToWidget, d->rightspace, _1, _2);
}
if (!windowService->showWidgetAtRightspace) {
windowService->showWidgetAtRightspace = std::bind(&WorkspaceWidget::switchWidgetWorkspace, d->rightspace, _1);
}
if (!windowService->registerWidgetToDockHeader) {
windowService->registerWidgetToDockHeader = std::bind(&Controller::registerWidgetToDockHeader, this, _1, _2);
}
Expand Down Expand Up @@ -400,6 +413,7 @@ void Controller::raiseMode(const QString &mode)

showTopToolBar();
showContextWidget();
showRightspace();

d->mode = mode;
uiController.modeRaised(mode);
Expand Down Expand Up @@ -711,6 +725,38 @@ void Controller::showContextWidget()
d->currentDocks.append(WN_CONTEXTWIDGET);
}

void Controller::showRightspace()
{
auto &rightSpaceInfo = d->allWidgets[WN_RIGHTSPACE];
if (!rightSpaceInfo.created) {
createDockWidget(d->allWidgets[WN_RIGHTSPACE]);
d->mainWindow->showWidget(WN_RIGHTSPACE);
d->mainWindow->resizeDock(WN_RIGHTSPACE, QSize(300, 300));

for (auto btn : d->rightspace->getAllToolBtn())
d->mainWindow->addWidgetToDockHeader(WN_RIGHTSPACE, btn);

auto titles = d->rightspace->allWidgetTitles();
QList<QAction *> headers;
for (auto title : titles) {
QAction *action = new QAction(title, d->rightspace);
connect(action, &QAction::triggered, this, [=]() { d->rightspace->switchWidgetWorkspace(title); });
headers.append(action);
}
d->mainWindow->setDockHeaderList(WN_RIGHTSPACE, headers);
d->mainWindow->setDockHeaderName(WN_RIGHTSPACE, d->rightspace->currentTitle());

d->rightspace->addedToController = true;
connect(d->rightspace, &WorkspaceWidget::workSpaceWidgeSwitched, this, [=](const QString &title) {
d->mainWindow->setDockHeaderName(WN_RIGHTSPACE, title);
});
connect(rightSpaceInfo.dockWidget, &QDockWidget::visibilityChanged, d->showRightspaceBtn, [=](bool visible){ d->showRightspaceBtn->setChecked(visible); });
} else if (!rightSpaceInfo.hiddenByManual) {
d->mainWindow->showWidget(WN_RIGHTSPACE);
}
d->currentDocks.append(WN_RIGHTSPACE);
}

bool Controller::hasContextWidget(const QString &title)
{
return d->contextWidgets.contains(title);
Expand Down Expand Up @@ -956,9 +1002,9 @@ void Controller::initContextWidget()
info.icon = QIcon::fromTheme("context_widget");

if (d->statusBar) {
auto btn = createDockButton(info);
btn->setChecked(true);
d->statusBar->insertPermanentWidget(0, btn);
d->showContextBtn = createDockButton(info);
d->showContextBtn->setChecked(true);
d->statusBar->insertPermanentWidget(0, d->showContextBtn);
}

d->allWidgets.insert(WN_CONTEXTWIDGET, info);
Expand All @@ -970,6 +1016,7 @@ void Controller::initStatusBar()
return;
d->statusBar = new WindowStatusBar(d->mainWindow);
d->statusBar->hide();

d->mainWindow->setStatusBar(d->statusBar);
}

Expand All @@ -988,6 +1035,31 @@ void Controller::initWorkspaceWidget()
d->allWidgets.insert(WN_WORKSPACE, info);
}

void Controller::initRightspaceWidget()
{
if (d->rightspace)
return;

d->rightspace = new WorkspaceWidget(d->mainWindow);

WidgetInfo info;
info.name = WN_RIGHTSPACE;
info.setWidget(d->rightspace);
info.defaultPos = Position::Right;
info.replace = true;
info.icon = QIcon::fromTheme("uc_right_show");
d->allWidgets.insert(WN_RIGHTSPACE, info);

d->showRightspaceBtn = createDockButton(info);
d->showRightspaceBtn->setChecked(true);
auto scAction = new QAction(tr("Open rightspace"), d->rightspace);
auto cmd = ActionManager::instance()->registerAction(scAction, "Core.Open.Rightspace");
cmd->setDefaultKeySequence(QKeySequence(Qt::ALT + Qt::Key_L));
connect(scAction, &QAction::triggered, d->showRightspaceBtn, &DToolButton::clicked);

d->statusBar->insertPermanentWidget(0, d->showRightspaceBtn);
}

void Controller::initTopToolBar()
{
d->leftTopToolBar = new DWidget(d->mainWindow);
Expand Down Expand Up @@ -1276,6 +1348,8 @@ DToolButton *Controller::createDockButton(const WidgetInfo &info)
btn->setCheckable(true);
connect(btn, &DToolButton::clicked, this, [=]() {
auto &dockInfo = d->allWidgets[info.name];
if (!dockInfo.dockWidget)
return;
if (dockInfo.dockWidget->isVisible()) {
d->mainWindow->hideWidget(dockInfo.name);
btn->setChecked(false);
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/core/uicontroller/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public slots:
//workspace
void switchWorkspace(const QString &titleName);

void showRightspace();
void showCurrentDocksManager();

private:
Expand All @@ -99,6 +100,7 @@ public slots:
void initContextWidget();
void initStatusBar();
void initWorkspaceWidget();
void initRightspaceWidget();
void initTopToolBar();
void initModules();
void initDocksManager();
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/core/uicontroller/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void MainWindow::setDockHeaderName(const QString &dockName, const QString &heade

void MainWindow::setDockHeaderList(const QString &dockName, const QList<QAction *> &actions)
{
if (!d->dockList.contains(dockName))
if (!d->dockList.contains(dockName) || actions.isEmpty())
return;

auto dock = d->dockList[dockName];
Expand Down
14 changes: 4 additions & 10 deletions src/plugins/debugger/debuggerplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

using namespace dpfservice;
inline constexpr char mainWindow[] = "debugMainWindow";
inline constexpr char localsPane[] = "debuggerWatcher";

void DebuggerPlugin::initialize()
{
Expand Down Expand Up @@ -55,22 +54,17 @@ bool DebuggerPlugin::start()
windowService->bindWidgetToNavigation(mainWindow, actionImpl);
windowService->setDockHeaderName(mainWindow, tr("debug"));
auto localsPaneImpl = new AbstractWidget(debugManager->getLocalsPane());
localsPaneImpl->setDisplayIcon(QIcon::fromTheme("variable_watchers"));
windowService->registerWidget(localsPane, localsPaneImpl);
windowService->deleteDockHeader(localsPane);
QString variablesPane = tr("Variables Watcher");
windowService->addWidgetRightspace(variablesPane, localsPaneImpl, "");
connect(action, &QAction::triggered, this, [=]() {
if (debugManager->getRunState() != AbstractDebugger::kNoRun)
windowService->showWidgetAtPosition(localsPane, Position::Right, false);
windowService->showWidgetAtRightspace(variablesPane);
}, Qt::DirectConnection);
connect(debugManager, &DebugManager::debugStarted, this, [=](){
uiController.doSwitch(MWNA_DEBUG);
windowService->showWidgetAtPosition(localsPane, Position::Right, false);
windowService->deleteDockHeader(localsPane);
windowService->showWidgetAtRightspace(variablesPane);
uiController.switchContext(tr("&Application Output"));
}, Qt::DirectConnection);
connect(debugManager, &DebugManager::debugStopped, this, [=](){
windowService->hideWidget(localsPane);
}, Qt::DirectConnection);
}

return true;
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 @@ -30,6 +30,7 @@ inline const QString MWTG_DEBUG { "Debug" };
// WN = window name
inline const QString WN_CONTEXTWIDGET = "contextWidget";
inline const QString WN_WORKSPACE = "workspaceWidget";
inline const QString WN_RIGHTSPACE = "rightspaceWidget";

// MWM = MW menu
// MWMFA = MWM File Action
Expand Down
4 changes: 3 additions & 1 deletion src/services/window/windowservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,12 @@ class WindowService final : public dpf::PluginService, dpf::AutoServiceRegister<
* \param widget
*/
DPF_INTERFACE(void, addWidgetWorkspace, const QString &title, AbstractWidget *widget, const QString &iconName);
DPF_INTERFACE(void, addWidgetRightspace, const QString &title, AbstractWidget *widget, const QString &iconName);
DPF_INTERFACE(void, registerWidgetToDockHeader,const QString &dockName, QWidget *widget);
DPF_INTERFACE(void, registerToolBtnToWorkspaceWidget, Dtk::Widget::DToolButton *btn, const QString &title);
DPF_INTERFACE(void, registerToolBtnToRightspaceWidget, Dtk::Widget::DToolButton *btn, const QString &title);

DPF_INTERFACE(void, switchWorkspaceArea, const QString &title);
DPF_INTERFACE(void, showWidgetAtRightspace, const QString &title);

DPF_INTERFACE(QWidget *, createFindPlaceHolder, QWidget *owner, AbstractDocumentFind *docFind);

Expand Down

0 comments on commit 7c6c655

Please sign in to comment.