Skip to content

Commit 3247910

Browse files
committed
Added a confirmation prompt when deleting items such as port and device
1 parent d9122e2 commit 3247910

File tree

3 files changed

+84
-26
lines changed

3 files changed

+84
-26
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,5 @@
7575

7676
* When you click `Insert` in the `DataView` window, the new value is added to the list,
7777
but taking into account the address and size of the element format above.
78+
* Added insert/delete hotkeys for port/device/actions elements (copy/paste for actions)
79+
* Added a confirmation prompt when deleting items such as port and device

src/client/gui/client_ui.cpp

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <QBuffer>
2828
#include <QClipboard>
2929
#include <QLabel>
30+
#include <QMessageBox>
3031

3132
#include <client.h>
3233

@@ -273,9 +274,22 @@ void mbClientUi::menuSlotPortDelete()
273274
if (port)
274275
{
275276
if (port->deviceCount())
277+
{
278+
QMessageBox::information(this,
279+
QStringLiteral("Delete Port"),
280+
QString("Can't delete '%1' because it has a device(s)!").arg(port->name()),
281+
QMessageBox::Ok);
276282
return;
277-
project->portRemove(port);
278-
delete port;
283+
}
284+
QMessageBox::StandardButton res = QMessageBox::question(this,
285+
QStringLiteral("Delete Port"),
286+
QString("Are you sure you want to delete '%1'?").arg(port->name()),
287+
QMessageBox::Yes|QMessageBox::No);
288+
if (res == QMessageBox::Yes)
289+
{
290+
project->portRemove(port);
291+
delete port;
292+
}
279293
}
280294
}
281295
}
@@ -309,12 +323,20 @@ void mbClientUi::menuSlotPortClearAllDevice()
309323
QList<mbClientDevice*> devices = port->devices();
310324
if (devices.count())
311325
{
312-
Q_FOREACH(mbClientDevice* d, devices)
313-
port->deviceRemove(d);
314-
mbClientProject* project = core()->project();
315-
Q_FOREACH(mbClientDevice* d, devices)
316-
project->deviceRemove(d);
317-
qDeleteAll(devices);
326+
QMessageBox::StandardButton res = QMessageBox::question(this,
327+
QStringLiteral("Clear All Devices"),
328+
QString("Are you sure you want to clear all devices for port '%1'?").arg(port->name()),
329+
QMessageBox::Yes|QMessageBox::No);
330+
if (res == QMessageBox::Yes)
331+
{
332+
333+
Q_FOREACH(mbClientDevice* d, devices)
334+
port->deviceRemove(d);
335+
mbClientProject* project = core()->project();
336+
Q_FOREACH(mbClientDevice* d, devices)
337+
project->deviceRemove(d);
338+
qDeleteAll(devices);
339+
}
318340
}
319341
}
320342
}
@@ -385,11 +407,18 @@ void mbClientUi::menuSlotDeviceDelete()
385407
mbClientDevice *d = projectUi()->currentDevice();
386408
if (d)
387409
{
388-
mbClientPort *port = d->port();
389-
if (port)
390-
port->deviceRemove(d);
391-
prj->deviceRemove(d);
392-
delete d;
410+
QMessageBox::StandardButton res = QMessageBox::question(this,
411+
QStringLiteral("Delete Device"),
412+
QString("Are you sure you want to delete '%1'?").arg(d->name()),
413+
QMessageBox::Yes|QMessageBox::No);
414+
if (res == QMessageBox::Yes)
415+
{
416+
mbClientPort *port = d->port();
417+
if (port)
418+
port->deviceRemove(d);
419+
prj->deviceRemove(d);
420+
delete d;
421+
}
393422
}
394423
}
395424
}

src/server/gui/server_ui.cpp

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <QComboBox>
3131
#include <QMdiArea>
3232
#include <QMdiSubWindow>
33+
#include <QMessageBox>
3334

3435
#include <project/server_project.h>
3536
#include <project/server_port.h>
@@ -49,7 +50,6 @@
4950
#include "device/server_deviceui.h"
5051

5152
#include "dataview/server_dataviewmanager.h"
52-
#include "dataview/server_dataviewui.h"
5353

5454
#include "actions/server_actionsui.h"
5555

@@ -357,7 +357,7 @@ void mbServerUi::menuSlotEditDelete()
357357
{
358358
if (m_projectUi->selectedDeviceCore())
359359
{
360-
menuSlotDeviceDelete();
360+
menuSlotPortDeviceDelete();
361361
return;
362362
}
363363
if (m_projectUi->selectedPortCore())
@@ -426,9 +426,22 @@ void mbServerUi::menuSlotPortDelete()
426426
if (port)
427427
{
428428
if (port->deviceCount())
429+
{
430+
QMessageBox::information(this,
431+
QStringLiteral("Delete Port"),
432+
QString("Can't delete '%1' because it has a device(s)!").arg(port->name()),
433+
QMessageBox::Ok);
429434
return;
430-
project->portRemove(port);
431-
delete port;
435+
}
436+
QMessageBox::StandardButton res = QMessageBox::question(this,
437+
QStringLiteral("Delete Port"),
438+
QString("Are you sure you want to delete '%1'?").arg(port->name()),
439+
QMessageBox::Yes|QMessageBox::No);
440+
if (res == QMessageBox::Yes)
441+
{
442+
project->portRemove(port);
443+
delete port;
444+
}
432445
}
433446
}
434447
}
@@ -522,9 +535,16 @@ void mbServerUi::menuSlotPortDeviceDelete()
522535
mbServerDeviceRef *device = projectUi()->currentDeviceRef();
523536
if (!device)
524537
return;
525-
mbServerPort *port = device->port();
526-
port->deviceRemove(device);
527-
delete device;
538+
QMessageBox::StandardButton res = QMessageBox::question(this,
539+
QStringLiteral("Delete Device"),
540+
QString("Are you sure you want to delete '%1' from port?").arg(device->name()),
541+
QMessageBox::Yes|QMessageBox::No);
542+
if (res == QMessageBox::Yes)
543+
{
544+
mbServerPort *port = device->port();
545+
port->deviceRemove(device);
546+
delete device;
547+
}
528548
}
529549

530550
void mbServerUi::menuSlotDeviceNew()
@@ -558,13 +578,20 @@ void mbServerUi::menuSlotDeviceDelete()
558578
mbServerProject *project = core()->project();
559579
if (!project)
560580
return;
561-
mbServerDevice *d = m_deviceManager->activeDevice();
562-
if (!d)
581+
mbServerDevice *device = m_deviceManager->activeDevice();
582+
if (!device)
563583
return;
564-
Q_FOREACH(mbServerPort *port, project->ports())
565-
port->deviceRemove(d);
566-
project->deviceRemove(d);
567-
delete d;
584+
QMessageBox::StandardButton res = QMessageBox::question(this,
585+
QStringLiteral("Delete Device"),
586+
QString("Are you sure you want to delete '%1'?").arg(device->name()),
587+
QMessageBox::Yes|QMessageBox::No);
588+
if (res == QMessageBox::Yes)
589+
{
590+
Q_FOREACH(mbServerPort *port, project->ports())
591+
port->deviceRemove(device);
592+
project->deviceRemove(device);
593+
delete device;
594+
}
568595
}
569596

570597
void mbServerUi::menuSlotDeviceImport()

0 commit comments

Comments
 (0)