Fix crash

This commit is contained in:
Joey Yakimowich-Payne 2026-01-30 12:49:47 -07:00
commit 07a151ebdf
3 changed files with 49 additions and 5 deletions

View file

@ -496,6 +496,12 @@ void GraphEditorWidget::scheduleSaveLayout() {
}
}
GraphEditorWidget::~GraphEditorWidget() {
if (m_client) {
m_client->SetChangeCallback(nullptr);
}
}
int GraphEditorWidget::nodeCount() const {
return static_cast<int>(m_model->allNodeIds().size());
}
@ -712,6 +718,13 @@ void GraphEditorWidget::showNodeContextMenu(const QPoint &screenPos,
deleteAction->setShortcut(QKeySequence::Delete);
}
QAction *createRuleAction = nullptr;
if (type == WarpNodeType::kApplication) {
menu.addSeparator();
createRuleAction = menu.addAction(QStringLiteral("Create Rule..."));
}
menu.addSeparator();
QAction *pasteAction = menu.addAction(QStringLiteral("Paste"));
pasteAction->setShortcut(QKeySequence::Paste);
pasteAction->setEnabled(!m_clipboardJson.isEmpty() ||
@ -732,6 +745,10 @@ void GraphEditorWidget::showNodeContextMenu(const QPoint &screenPos,
deleteSelection();
} else if (chosen == pasteAction) {
pasteSelection(QPointF(0, 0));
} else if (chosen == createRuleAction) {
showAddRuleDialog(data->info.application_name,
data->info.process_binary,
data->info.media_role);
}
}
@ -1476,14 +1493,14 @@ void GraphEditorWidget::rebuildRulesList() {
infoLayout->addWidget(matchLabel);
auto *targetLabel = new QLabel(
QStringLiteral("\xe2\x86\x92 ") +
QString(QChar(0x2192)) + QStringLiteral(" ") +
QString::fromStdString(rule.target_node));
targetLabel->setStyleSheet(labelStyle);
infoLayout->addWidget(targetLabel);
cardLayout->addLayout(infoLayout, 1);
auto *delBtn = new QPushButton(QStringLiteral("\xe2\x9c\x95"));
auto *delBtn = new QPushButton(QString(QChar(0x2715)));
delBtn->setFixedSize(24, 24);
delBtn->setStyleSheet(delBtnStyle);
warppipe::RuleId ruleId = rule.id;
@ -1500,13 +1517,15 @@ void GraphEditorWidget::rebuildRulesList() {
auto *addBtn = new QPushButton(QStringLiteral("Add Rule..."));
addBtn->setStyleSheet(btnStyle);
connect(addBtn, &QPushButton::clicked, this,
&GraphEditorWidget::showAddRuleDialog);
[this]() { showAddRuleDialog(); });
layout->addWidget(addBtn);
static_cast<QVBoxLayout *>(layout)->addStretch();
}
void GraphEditorWidget::showAddRuleDialog() {
void GraphEditorWidget::showAddRuleDialog(const std::string &prefillApp,
const std::string &prefillBin,
const std::string &prefillRole) {
if (!m_client)
return;
@ -1529,14 +1548,20 @@ void GraphEditorWidget::showAddRuleDialog() {
auto *appNameEdit = new QLineEdit();
appNameEdit->setPlaceholderText(QStringLiteral("e.g. Firefox"));
if (!prefillApp.empty())
appNameEdit->setText(QString::fromStdString(prefillApp));
form->addRow(QStringLiteral("Application Name:"), appNameEdit);
auto *processBinEdit = new QLineEdit();
processBinEdit->setPlaceholderText(QStringLiteral("e.g. firefox"));
if (!prefillBin.empty())
processBinEdit->setText(QString::fromStdString(prefillBin));
form->addRow(QStringLiteral("Process Binary:"), processBinEdit);
auto *mediaRoleEdit = new QLineEdit();
mediaRoleEdit->setPlaceholderText(QStringLiteral("e.g. Music"));
if (!prefillRole.empty())
mediaRoleEdit->setText(QString::fromStdString(prefillRole));
form->addRow(QStringLiteral("Media Role:"), mediaRoleEdit);
auto *targetCombo = new QComboBox();