|
@@ -48,6 +48,7 @@ import java.awt.event.ActionEvent;
|
48
|
48
|
import java.awt.event.ActionListener;
|
49
|
49
|
import java.util.HashMap;
|
50
|
50
|
import java.util.Map;
|
|
51
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
51
|
52
|
|
52
|
53
|
import javax.swing.BorderFactory;
|
53
|
54
|
import javax.swing.DefaultListModel;
|
|
@@ -98,6 +99,8 @@ public final class ActionsManagerDialog extends StandardDialog implements
|
98
|
99
|
private ActionGroupSettingsPanel activeSettings;
|
99
|
100
|
/** Group panel. */
|
100
|
101
|
private JPanel groupPanel;
|
|
102
|
+ /** Are we saving? */
|
|
103
|
+ private AtomicBoolean saving = new AtomicBoolean(false);
|
101
|
104
|
|
102
|
105
|
/**
|
103
|
106
|
* Creates a new instance of ActionsManagerDialog.
|
|
@@ -167,10 +170,10 @@ public final class ActionsManagerDialog extends StandardDialog implements
|
167
|
170
|
*/
|
168
|
171
|
private void initComponents() {
|
169
|
172
|
orderButtons(new JButton(), new JButton());
|
170
|
|
- infoLabel = new TextLabel("Actions allow you to make DMDirc" +
|
171
|
|
- " intelligently respond to various events. Action groups are " +
|
172
|
|
- "there for you to organise groups, add or remove them " +
|
173
|
|
- "to suit your needs.");
|
|
173
|
+ infoLabel = new TextLabel("Actions allow you to make DMDirc"
|
|
174
|
+ + " intelligently respond to various events. Action groups are "
|
|
175
|
+ + "there for you to organise groups, add or remove them "
|
|
176
|
+ + "to suit your needs.");
|
174
|
177
|
groups = new JList(new SortedListModel<ActionGroup>(
|
175
|
178
|
new ActionGroupNameComparator()));
|
176
|
179
|
actions = new ActionsGroupPanel(this, null);
|
|
@@ -239,7 +242,8 @@ public final class ActionsManagerDialog extends StandardDialog implements
|
239
|
242
|
*/
|
240
|
243
|
private void layoutComponents() {
|
241
|
244
|
|
242
|
|
- getContentPane().setLayout(new MigLayout("fill, wrap 2, hidemode 3, wmax 800"));
|
|
245
|
+ getContentPane().setLayout(new MigLayout(
|
|
246
|
+ "fill, wrap 2, hidemode 3, wmax 800"));
|
243
|
247
|
|
244
|
248
|
getContentPane().add(infoLabel, "spanx 2, growx");
|
245
|
249
|
if (info.isVisible() && activeSettings.isVisible()) {
|
|
@@ -316,24 +320,29 @@ public final class ActionsManagerDialog extends StandardDialog implements
|
316
|
320
|
editGroup();
|
317
|
321
|
} else if (e.getSource() == delete) {
|
318
|
322
|
delGroup();
|
319
|
|
- } else if (e.getSource() == getOkButton() || e.getSource() ==
|
320
|
|
- getCancelButton()) {
|
321
|
|
- if (ActionEditorDialog.isOpen()) {
|
322
|
|
- if (JOptionPane.showConfirmDialog(this,
|
323
|
|
- "The action editor is currently open, do you want to cotinue and lose any unsaved changes?",
|
324
|
|
- "Confirm close?", JOptionPane.YES_NO_OPTION,
|
325
|
|
- JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
|
326
|
|
- ActionEditorDialog.getActionEditorDialog(this, "").dispose();
|
327
|
|
- } else {
|
328
|
|
- return;
|
|
323
|
+ } else if (e.getSource() == getOkButton() || e.getSource()
|
|
324
|
+ == getCancelButton()) {
|
|
325
|
+ if (!saving.get()) {
|
|
326
|
+ saving.set(true);
|
|
327
|
+ if (ActionEditorDialog.isOpen()) {
|
|
328
|
+ if (JOptionPane.showConfirmDialog(this,
|
|
329
|
+ "The action editor is currently open, do you want to cotinue and lose any unsaved changes?",
|
|
330
|
+ "Confirm close?", JOptionPane.YES_NO_OPTION,
|
|
331
|
+ JOptionPane.QUESTION_MESSAGE)
|
|
332
|
+ == JOptionPane.YES_OPTION) {
|
|
333
|
+ ActionEditorDialog.getActionEditorDialog(this, "").
|
|
334
|
+ dispose();
|
|
335
|
+ } else {
|
|
336
|
+ return;
|
|
337
|
+ }
|
329
|
338
|
}
|
|
339
|
+ for (ActionGroupSettingsPanel loopSettings : settings.values()) {
|
|
340
|
+ loopSettings.save();
|
|
341
|
+ }
|
|
342
|
+ IdentityManager.getConfigIdentity().setOption("dialogstate",
|
|
343
|
+ "actionsmanagerdialog", groups.getSelectedIndex());
|
|
344
|
+ dispose();
|
330
|
345
|
}
|
331
|
|
- for (ActionGroupSettingsPanel loopSettings : settings.values()) {
|
332
|
|
- loopSettings.save();
|
333
|
|
- }
|
334
|
|
- IdentityManager.getConfigIdentity().setOption("dialogstate",
|
335
|
|
- "actionsmanagerdialog", groups.getSelectedIndex());
|
336
|
|
- dispose();
|
337
|
346
|
}
|
338
|
347
|
}
|
339
|
348
|
|
|
@@ -358,16 +367,20 @@ public final class ActionsManagerDialog extends StandardDialog implements
|
358
|
367
|
/** {@inheritDoc} */
|
359
|
368
|
@Override
|
360
|
369
|
public boolean save() {
|
361
|
|
- if (getText() == null || getText().isEmpty() && !ActionManager.
|
362
|
|
- getGroups().
|
363
|
|
- containsKey(getText())) {
|
364
|
|
- return false;
|
365
|
|
- } else {
|
366
|
|
- final ActionGroup group =
|
367
|
|
- ActionManager.makeGroup(getText());
|
368
|
|
- reloadGroups(group);
|
369
|
|
- return true;
|
|
370
|
+ if (!saving.get()) {
|
|
371
|
+ saving.set(true);
|
|
372
|
+ if (getText() == null || getText().isEmpty() && !ActionManager.
|
|
373
|
+ getGroups().
|
|
374
|
+ containsKey(getText())) {
|
|
375
|
+ return false;
|
|
376
|
+ } else {
|
|
377
|
+ final ActionGroup group =
|
|
378
|
+ ActionManager.makeGroup(getText());
|
|
379
|
+ reloadGroups(group);
|
|
380
|
+ return true;
|
|
381
|
+ }
|
370
|
382
|
}
|
|
383
|
+ return false;
|
371
|
384
|
}
|
372
|
385
|
|
373
|
386
|
/** {@inheritDoc} */
|
|
@@ -403,13 +416,17 @@ public final class ActionsManagerDialog extends StandardDialog implements
|
403
|
416
|
/** {@inheritDoc} */
|
404
|
417
|
@Override
|
405
|
418
|
public boolean save() {
|
406
|
|
- if (getText() == null || getText().isEmpty()) {
|
407
|
|
- return false;
|
408
|
|
- } else {
|
409
|
|
- ActionManager.renameGroup(oldName, getText());
|
410
|
|
- reloadGroups();
|
411
|
|
- return true;
|
|
419
|
+ if (!saving.get()) {
|
|
420
|
+ saving.set(true);
|
|
421
|
+ if (getText() == null || getText().isEmpty()) {
|
|
422
|
+ return false;
|
|
423
|
+ } else {
|
|
424
|
+ ActionManager.renameGroup(oldName, getText());
|
|
425
|
+ reloadGroups();
|
|
426
|
+ return true;
|
|
427
|
+ }
|
412
|
428
|
}
|
|
429
|
+ return false;
|
413
|
430
|
}
|
414
|
431
|
|
415
|
432
|
/** {@inheritDoc} */
|
|
@@ -429,8 +446,8 @@ public final class ActionsManagerDialog extends StandardDialog implements
|
429
|
446
|
final String group =
|
430
|
447
|
((ActionGroup) groups.getSelectedValue()).getName();
|
431
|
448
|
final int response = JOptionPane.showConfirmDialog(this,
|
432
|
|
- "Are you sure you wish to delete the '" + group +
|
433
|
|
- "' group and all actions within it?",
|
|
449
|
+ "Are you sure you wish to delete the '" + group
|
|
450
|
+ + "' group and all actions within it?",
|
434
|
451
|
"Confirm deletion", JOptionPane.YES_NO_OPTION);
|
435
|
452
|
if (response == JOptionPane.YES_OPTION) {
|
436
|
453
|
int location =
|
|
@@ -457,8 +474,8 @@ public final class ActionsManagerDialog extends StandardDialog implements
|
457
|
474
|
}
|
458
|
475
|
|
459
|
476
|
changeActiveGroup((ActionGroup) groups.getSelectedValue());
|
460
|
|
- if (groups.getSelectedIndex() == -1 ||
|
461
|
|
- !((ActionGroup) groups.getSelectedValue()).isDelible()) {
|
|
477
|
+ if (groups.getSelectedIndex() == -1 || !((ActionGroup) groups.
|
|
478
|
+ getSelectedValue()).isDelible()) {
|
462
|
479
|
edit.setEnabled(false);
|
463
|
480
|
delete.setEnabled(false);
|
464
|
481
|
} else {
|
|
@@ -474,8 +491,8 @@ public final class ActionsManagerDialog extends StandardDialog implements
|
474
|
491
|
if (groups.getSelectedValue() == null) {
|
475
|
492
|
return;
|
476
|
493
|
}
|
477
|
|
- if (type.equals(CoreActionType.ACTION_CREATED) ||
|
478
|
|
- type.equals(CoreActionType.ACTION_UPDATED)) {
|
|
494
|
+ if (type.equals(CoreActionType.ACTION_CREATED) || type.equals(
|
|
495
|
+ CoreActionType.ACTION_UPDATED)) {
|
479
|
496
|
final Action action = (Action) arguments[0];
|
480
|
497
|
if (action.getGroup().equals(((ActionGroup) groups.getSelectedValue()).
|
481
|
498
|
getName())) {
|