Skip to content

Commit

Permalink
Use new sidebar API instead of global area widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
D0ntPanic committed Feb 2, 2024
1 parent 318e612 commit 799f77c
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 25 deletions.
7 changes: 6 additions & 1 deletion ui/moduleswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ void DebugModulesWithFilter::updateFonts()


GlobalDebugModulesContainer::GlobalDebugModulesContainer(const QString& title) :
GlobalAreaWidget(title), m_currentFrame(nullptr), m_consoleStack(new QStackedWidget)
SidebarWidget(title), m_currentFrame(nullptr), m_consoleStack(new QStackedWidget)
{
auto* layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
Expand Down Expand Up @@ -720,3 +720,8 @@ bool DebugModulesFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelI
}
return false;
}


DebugModulesSidebarWidgetType::DebugModulesSidebarWidgetType() :
SidebarWidgetType(QImage(":/letters/images/letter-icons/letter-M.png"), "Debugger Modules")
{}
12 changes: 11 additions & 1 deletion ui/moduleswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class DebugModulesWithFilter : public QWidget
};


class GlobalDebugModulesContainer : public GlobalAreaWidget
class GlobalDebugModulesContainer : public SidebarWidget
{
ViewFrame* m_currentFrame;
QHash<ViewFrame*, DebugModulesWithFilter*> m_widgetMap;
Expand All @@ -215,3 +215,13 @@ class GlobalDebugModulesContainer : public GlobalAreaWidget
void notifyViewChanged(ViewFrame*) override;
void notifyFontChanged() override;
};


class DebugModulesSidebarWidgetType : public SidebarWidgetType
{
public:
DebugModulesSidebarWidgetType();
SidebarWidgetLocation defaultLocation() const override { return SidebarWidgetLocation::RightBottom; }
SidebarContextSensitivity contextSensitivity() const override { return SelfManagedSidebarContext; }
bool hideIfNoContent() const override { return true; }
};
7 changes: 6 additions & 1 deletion ui/threadframes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ void ThreadFramesWidget::onDoubleClicked()


GlobalThreadFramesContainer::GlobalThreadFramesContainer(const QString& title) :
GlobalAreaWidget(title), m_currentFrame(nullptr), m_consoleStack(new QStackedWidget)
SidebarWidget(title), m_currentFrame(nullptr), m_consoleStack(new QStackedWidget)
{
auto* layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
Expand Down Expand Up @@ -840,3 +840,8 @@ void GlobalThreadFramesContainer::notifyFontChanged()
it.value()->updateFonts();
}
}


ThreadFramesSidebarWidgetType::ThreadFramesSidebarWidgetType() :
SidebarWidgetType(QImage(":/letters/images/letter-icons/letter-T.png"), "Stack Trace")
{}
12 changes: 11 additions & 1 deletion ui/threadframes.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private slots:
void copy();
};

class GlobalThreadFramesContainer : public GlobalAreaWidget
class GlobalThreadFramesContainer : public SidebarWidget
{
ViewFrame* m_currentFrame;
QHash<ViewFrame*, ThreadFramesWidget*> m_consoleMap;
Expand All @@ -208,3 +208,13 @@ class GlobalThreadFramesContainer : public GlobalAreaWidget
void notifyViewChanged(ViewFrame*) override;
void notifyFontChanged() override;
};


class ThreadFramesSidebarWidgetType : public SidebarWidgetType
{
public:
ThreadFramesSidebarWidgetType();
SidebarWidgetLocation defaultLocation() const override { return SidebarWidgetLocation::RightBottom; }
SidebarContextSensitivity contextSensitivity() const override { return SelfManagedSidebarContext; }
bool hideIfNoContent() const override { return true; }
};
42 changes: 21 additions & 21 deletions ui/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ void GlobalDebuggerUI::SetupMenu(UIContext* context)
// }));
// debuggerMenu->addAction("Activate Debug Adapter", "Launch");

QString showAreaWidgets = "Show Debugger Global Area Widgets";
QString showAreaWidgets = "Show Debugger Sidebar Widgets";
UIAction::registerAction(showAreaWidgets);

context->globalActions()->bindAction(showAreaWidgets, UIAction([](const UIActionContext& ctxt) {
Expand Down Expand Up @@ -882,8 +882,8 @@ void GlobalDebuggerUI::SetDisplayingGlobalAreaWidgets(bool display)

void GlobalDebuggerUI::CreateGlobalAreaWidgets(UIContext* context)
{
auto globalArea = context->globalArea();
if (!globalArea)
auto sidebar = context->sidebar();
if (!sidebar)
return;

// Hacky way to create the Debugger Console. Note, since MainWindow internally keeps a list of scripting consoles,
Expand All @@ -893,52 +893,50 @@ void GlobalDebuggerUI::CreateGlobalAreaWidgets(UIContext* context)
// emulate what happens when the user clicks the "Create Debugger Console" item.
if (context->contentActionHandler())
{
auto widget = globalArea->widget("Debugger Console");
if (!widget)
if (!sidebar->hasWidgetWithTitle("Console", "Debugger"))
context->contentActionHandler()->executeAction("Create Debugger Console");

widget = globalArea->widget("Target Console");
if (!widget)
if (!sidebar->hasWidgetWithTitle("Console", "Target"))
context->contentActionHandler()->executeAction("Create Target Console");
}

auto widget = globalArea->widget("Stack Trace");
auto widget = sidebar->widget("Stack Trace");
if (!widget)
{
auto* globalThreadFramesContainer = new GlobalThreadFramesContainer("Stack Trace");
globalArea->addWidget(globalThreadFramesContainer);
sidebar->addWidget("Stack Trace", globalThreadFramesContainer);
}

widget = globalArea->widget("Debugger Modules");
widget = sidebar->widget("Debugger Modules");
if (!widget)
{
auto* globalDebugModulesContainer = new GlobalDebugModulesContainer("Debugger Modules");
globalArea->addWidget(globalDebugModulesContainer);
sidebar->addWidget("Debugger Modules", globalDebugModulesContainer);
}
}


void GlobalDebuggerUI::CloseGlobalAreaWidgets(UIContext* context)
{
auto globalArea = context->globalArea();
if (!globalArea)
auto sidebar = context->sidebar();
if (!sidebar)
return;

auto widget = globalArea->widget("Stack Trace");
auto widget = sidebar->widget("Stack Trace");
if (widget)
globalArea->closeTab(widget);
sidebar->removeWidget("Stack Trace", widget);

widget = globalArea->widget("Debugger Modules");
widget = sidebar->widget("Debugger Modules");
if (widget)
globalArea->closeTab(widget);
sidebar->removeWidget("Debugger Modules", widget);

widget = globalArea->widget("Debugger Console");
widget = sidebar->widgetWithTitle("Console", "Debugger");
if (widget)
globalArea->closeTab(widget);
sidebar->removeWidget("Console", widget);

widget = globalArea->widget("Target Console");
widget = sidebar->widgetWithTitle("Console", "Target");
if (widget)
globalArea->closeTab(widget);
sidebar->removeWidget("Console", widget);
}


Expand Down Expand Up @@ -1451,6 +1449,8 @@ static bool ConnectedAndRunning(BinaryView* view, uint64_t addr)
void GlobalDebuggerUI::InitializeUI()
{
Sidebar::addSidebarWidgetType(new DebuggerWidgetType(QImage(":/debugger_icons/icons/debugger.svg"), "Debugger"));
Sidebar::addSidebarWidgetType(new DebugModulesSidebarWidgetType());
Sidebar::addSidebarWidgetType(new ThreadFramesSidebarWidgetType());

// We must use the sequence of these four calls to do the job, otherwise the keybinding does not work.
// Though it really should be the case where I can specify the keybinding in the first registerAction() call.
Expand Down

0 comments on commit 799f77c

Please sign in to comment.