Skip to content

Commit 66dc593

Browse files
committed
Improve the AdapterSettingsDialog UI
1 parent a9563b0 commit 66dc593

File tree

3 files changed

+44
-57
lines changed

3 files changed

+44
-57
lines changed

ui/adaptersettings.cpp

Lines changed: 41 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616

1717
#include "adaptersettings.h"
1818
#include "uicontext.h"
19+
#include "qfiledialog.h"
1920

2021
using namespace BinaryNinjaDebuggerAPI;
2122
using namespace BinaryNinja;
@@ -33,11 +34,6 @@ AdapterSettingsDialog::AdapterSettingsDialog(QWidget* parent, DebuggerController
3334
QVBoxLayout* layout = new QVBoxLayout;
3435
layout->setSpacing(0);
3536

36-
QLabel* titleLabel = new QLabel("Adapter Settings");
37-
QHBoxLayout* titleLayout = new QHBoxLayout;
38-
titleLayout->setContentsMargins(0, 0, 0, 0);
39-
titleLayout->addWidget(titleLabel);
40-
4137
m_adapterEntry = new QComboBox(this);
4238
for (const std::string& adapter: DebugAdapterType::GetAvailableAdapters(m_controller->GetData()))
4339
{
@@ -55,20 +51,49 @@ AdapterSettingsDialog::AdapterSettingsDialog(QWidget* parent, DebuggerController
5551
connect(m_adapterEntry, &QComboBox::currentTextChanged, this, &AdapterSettingsDialog::selectAdapter);
5652

5753
m_pathEntry = new QLineEdit(this);
54+
m_pathEntry->setMinimumWidth(800);
5855
m_argumentsEntry = new QLineEdit(this);
5956
m_workingDirectoryEntry = new QLineEdit(this);
60-
m_addressEntry = new QLineEdit(this);
61-
m_portEntry = new QLineEdit(this);
6257
m_terminalEmulator = new QCheckBox(this);
6358

64-
QFormLayout* formLayout = new QFormLayout;
65-
formLayout->addRow("Adapter Type", m_adapterEntry);
66-
formLayout->addRow("Executable Path", m_pathEntry);
67-
formLayout->addRow("Working Directory", m_workingDirectoryEntry);
68-
formLayout->addRow("Command Line Arguments", m_argumentsEntry);
69-
formLayout->addRow("Run In Separate Terminal", m_terminalEmulator);
70-
formLayout->addRow("Address", m_addressEntry);
71-
formLayout->addRow("Port", m_portEntry);
59+
auto* pathSelector = new QPushButton("...", this);
60+
pathSelector->setMaximumWidth(30);
61+
connect(pathSelector, &QPushButton::clicked, [&](){
62+
auto fileName = QFileDialog::getOpenFileName(this, "Select Executable Path", m_workingDirectoryEntry->text());
63+
if (!fileName.isEmpty())
64+
m_pathEntry->setText(fileName);
65+
});
66+
67+
auto* workingDirSelector = new QPushButton("...", this);
68+
workingDirSelector->setMaximumWidth(30);
69+
connect(workingDirSelector, &QPushButton::clicked, [&](){
70+
auto pathName = QFileDialog::getExistingDirectory(this, "Specify Working Directory",
71+
m_workingDirectoryEntry->text(),
72+
QFileDialog::ShowDirsOnly| QFileDialog::DontResolveSymlinks);
73+
if (!pathName.isEmpty())
74+
m_workingDirectoryEntry->setText(pathName);
75+
});
76+
77+
auto pathEntryLayout = new QHBoxLayout;
78+
pathEntryLayout->addWidget(m_pathEntry);
79+
pathEntryLayout->addWidget(pathSelector);
80+
81+
auto workingDirLayout = new QHBoxLayout;
82+
workingDirLayout->addWidget(m_workingDirectoryEntry);
83+
workingDirLayout->addWidget(workingDirSelector);
84+
85+
QVBoxLayout* contentLayout = new QVBoxLayout;
86+
contentLayout->setSpacing(10);
87+
contentLayout->addWidget(new QLabel("Adapter Type"));
88+
contentLayout->addWidget(m_adapterEntry);
89+
contentLayout->addWidget(new QLabel("Executable Path"));
90+
contentLayout->addLayout(pathEntryLayout);
91+
contentLayout->addWidget(new QLabel("Working Directory"));
92+
contentLayout->addLayout(workingDirLayout);
93+
contentLayout->addWidget(new QLabel("Command Line Arguments"));
94+
contentLayout->addWidget(m_argumentsEntry);
95+
contentLayout->addWidget(new QLabel("Run In Separate Terminal"));
96+
contentLayout->addWidget(m_terminalEmulator);
7297

7398
QHBoxLayout* buttonLayout = new QHBoxLayout;
7499
buttonLayout->setContentsMargins(0, 0, 0, 0);
@@ -83,16 +108,12 @@ AdapterSettingsDialog::AdapterSettingsDialog(QWidget* parent, DebuggerController
83108
buttonLayout->addWidget(cancelButton);
84109
buttonLayout->addWidget(acceptButton);
85110

86-
layout->addLayout(titleLayout);
87-
layout->addSpacing(10);
88-
layout->addLayout(formLayout);
111+
layout->addLayout(contentLayout);
89112
layout->addStretch(1);
90113
layout->addSpacing(10);
91114
layout->addLayout(buttonLayout);
92115
setLayout(layout);
93116

94-
m_addressEntry->setText(QString::fromStdString(m_controller->GetRemoteHost()));
95-
m_portEntry->setText(QString::number(m_controller->GetRemotePort()));
96117
m_pathEntry->setText(QString::fromStdString(m_controller->GetExecutablePath()));
97118
m_terminalEmulator->setChecked(m_controller->GetRequestTerminalEmulator());
98119
m_argumentsEntry->setText(QString::fromStdString(m_controller->GetCommandLineArguments()));
@@ -120,17 +141,6 @@ void AdapterSettingsDialog::selectAdapter(const QString& adapter)
120141
m_argumentsEntry->setEnabled(false);
121142
m_terminalEmulator->setEnabled(false);
122143
}
123-
124-
if (adapterType->CanConnect(m_controller->GetData()))
125-
{
126-
m_addressEntry->setEnabled(true);
127-
m_portEntry->setEnabled(true);
128-
}
129-
else
130-
{
131-
m_addressEntry->setEnabled(false);
132-
m_portEntry->setEnabled(false);
133-
}
134144
}
135145

136146

@@ -161,27 +171,6 @@ void AdapterSettingsDialog::apply()
161171
data = new Metadata(workingDir);
162172
m_controller->GetData()->StoreMetadata("debugger.working_directory", data);
163173

164-
std::string host = m_addressEntry->text().toStdString();
165-
m_controller->SetRemoteHost(host);
166-
data = new Metadata(host);
167-
m_controller->GetData()->StoreMetadata("debugger.remote_host", data);
168-
169-
std::string portString = m_portEntry->text().toStdString();
170-
uint64_t port;
171-
try
172-
{
173-
port = stoull(portString);
174-
175-
}
176-
catch(const std::exception&)
177-
{
178-
port = 31337;
179-
}
180-
181-
m_controller->SetRemotePort(port);
182-
data = new Metadata(port);
183-
m_controller->GetData()->StoreMetadata("debugger.remote_port", data);
184-
185174
bool requestTerminal = m_terminalEmulator->isChecked();
186175
m_controller->SetRequestTerminalEmulator(requestTerminal);
187176
data = new Metadata(requestTerminal);

ui/adaptersettings.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ class AdapterSettingsDialog: public QDialog
4040
QLineEdit* m_pathEntry;
4141
QLineEdit* m_workingDirectoryEntry;
4242
QLineEdit* m_argumentsEntry;
43-
QLineEdit* m_addressEntry;
44-
QLineEdit* m_portEntry;
4543
QCheckBox* m_terminalEmulator;
4644

4745
public:

ui/ui.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ void GlobalDebuggerUI::SetupMenu(UIContext* context)
236236
return !controller->IsConnectedToDebugServer();
237237
};
238238

239-
UIAction::registerAction("Launch/Connect Settings...");
240-
context->globalActions()->bindAction("Launch/Connect Settings...", UIAction([=](const UIActionContext& ctxt) {
239+
UIAction::registerAction("Debug Adapter Settings...");
240+
context->globalActions()->bindAction("Debug Adapter Settings...", UIAction([=](const UIActionContext& ctxt) {
241241
if (!ctxt.binaryView)
242242
return;
243243
auto controller = DebuggerController::GetController(ctxt.binaryView);
@@ -253,7 +253,7 @@ void GlobalDebuggerUI::SetupMenu(UIContext* context)
253253

254254
Menu* debuggerMenu = Menu::mainMenu("Debugger");
255255
Menu::setMainMenuOrder("Debugger", MENU_ORDER_LATE);
256-
debuggerMenu->addAction("Launch/Connect Settings...", "Settings", MENU_ORDER_FIRST);
256+
debuggerMenu->addAction("Debug Adapter Settings...", "Settings", MENU_ORDER_FIRST);
257257

258258
UIAction::registerAction("Launch");
259259
context->globalActions()->bindAction("Launch", UIAction([=](const UIActionContext& ctxt) {

0 commit comments

Comments
 (0)