Skip to content

Commit

Permalink
Add keybindings to the tooltip of control buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
xusheng6 committed Dec 14, 2022
1 parent 5372a0f commit 2d387a9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
34 changes: 29 additions & 5 deletions ui/controlswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,48 +39,61 @@ DebugControlsWidget::DebugControlsWidget(QWidget* parent, const std::string name
auto red = getThemeColor(RedStandardHighlightColor);
auto white = getThemeColor(WhiteStandardHighlightColor);

m_actionRun = addAction(getColoredIcon(":/debugger_icons/icons/run.svg", red), "Run", [this]() {
m_actionRun = addAction(getColoredIcon(":/debugger_icons/icons/run.svg", red), "Launch", [this]() {
performLaunch();
});
m_actionRun->setToolTip(getToolTip("Launch"));

m_actionPause = addAction(getColoredIcon(":/debugger_icons/icons/pause.svg", white), "Pause", [this]() {
performPause();
});
m_actionPause->setToolTip(getToolTip("Pause"));

m_actionResume = addAction(getColoredIcon(":/debugger_icons/icons/resume.svg", green), "Resume", [this]() {
performResume();
});
m_actionResume->setToolTip(getToolTip("Resume"));

// m_actionRun->setVisible(true);
m_actionPause->setVisible(false);
m_actionResume->setVisible(false);

// TODO: we need a different icon here
m_actionAttachPid = addAction(getColoredIcon(":/debugger_icons/icons/connect.svg", white), "Attach to PID", [this]() {
m_actionAttachPid = addAction(getColoredIcon(":/debugger_icons/icons/connect.svg", white), "Attach To Process...", [this]() {
performAttachPID();
});
m_actionAttachPid->setToolTip(getToolTip("Attach To Process..."));

m_actionDetach = addAction(getColoredIcon(":/debugger_icons/icons/disconnect.svg", red), "Detach", [this]() {
performDetach();
});
m_actionDetach->setVisible(false);
m_actionDetach->setToolTip(getToolTip("Detach"));

m_actionRestart = addAction(getColoredIcon(":/debugger_icons/icons/restart.svg", red), "Restart", [this]() {
performRestart();
});
m_actionQuit = addAction(getColoredIcon(":/debugger_icons/icons/cancel.svg", red), "Quit", [this]() {
m_actionRestart->setToolTip(getToolTip("Restart"));

m_actionQuit = addAction(getColoredIcon(":/debugger_icons/icons/cancel.svg", red), "Kill", [this]() {
performQuit();
});
m_actionQuit->setToolTip(getToolTip("Kill"));
addSeparator();

m_actionStepInto = addAction(getColoredIcon(":/debugger_icons/icons/stepinto.svg", cyan), "Step Into", [this]() {
performStepInto();
});
m_actionStepInto->setToolTip(getToolTip("Step Into"));

m_actionStepOver = addAction(getColoredIcon(":/debugger_icons/icons/stepover.svg", cyan), "Step Over", [this]() {
performStepOver();
});
m_actionStepReturn = addAction(getColoredIcon(":/debugger_icons/icons/stepout.svg", cyan), "Step Out", [this]() {
m_actionStepOver->setToolTip(getToolTip("Step Over"));

m_actionStepReturn = addAction(getColoredIcon(":/debugger_icons/icons/stepout.svg", cyan), "Step Return", [this]() {
performStepReturn();
});
m_actionStepReturn->setToolTip(getToolTip("Step Return"));

updateButtons();
}
Expand All @@ -99,6 +112,17 @@ QIcon DebugControlsWidget::getColoredIcon(const QString& iconPath, const QColor&
}


QString DebugControlsWidget::getToolTip(const QString& name)
{
QString result = name;
auto keyBinding = UIAction::getKeyBinding(name);
if (!keyBinding.isEmpty())
result += (QString(" (") + keyBinding[0].toString() + ")");

return result;
}


void DebugControlsWidget::performLaunch()
{
QString text = QString(
Expand Down
1 change: 1 addition & 0 deletions ui/controlswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class DebugControlsWidget : public QToolBar
bool canConnect();

QIcon getColoredIcon(const QString& iconPath, const QColor& color);
QString getToolTip(const QString& name);

public:
DebugControlsWidget(QWidget* parent, const std::string name, BinaryViewRef data);
Expand Down
2 changes: 1 addition & 1 deletion ui/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void GlobalDebuggerUI::SetupMenu(UIContext* context)
Menu::setMainMenuOrder("Debugger", MENU_ORDER_LATE);
debuggerMenu->addAction("Debug Adapter Settings...", "Settings", MENU_ORDER_FIRST);

UIAction::registerAction("Launch");
UIAction::registerAction("Launch", QKeySequence(Qt::Key_F6));
context->globalActions()->bindAction("Launch",
UIAction(
[=](const UIActionContext& ctxt) {
Expand Down

0 comments on commit 2d387a9

Please sign in to comment.