Browse Source

Fixes issue 1568. ActionGroupValidator no longer cares about file names, FileNameValidator now allows - and _, AMD now uses a chain of both

git-svn-id: http://svn.dmdirc.com/trunk@4467 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith 16 years ago
parent
commit
de32464ab4

+ 2
- 8
src/com/dmdirc/config/prefs/validator/ActionGroupValidator.java View File

@@ -29,10 +29,6 @@ import com.dmdirc.actions.ActionManager;
29 29
  */
30 30
 public class ActionGroupValidator implements Validator<String> {
31 31
 
32
-    /** Filename regex. */
33
-    private static final String FILENAME_REGEX = "[A-Za-z0-9 \\-_]+";
34
-    /** Failure reason for regex failures. */
35
-    private static final String FAILURE_REGEX = "Must be a valid filename.";
36 32
     /** Failure reason for duplicates. */
37 33
     private static final String FAILURE_EXISTS = "Must not already exist.";
38 34
 
@@ -40,15 +36,13 @@ public class ActionGroupValidator implements Validator<String> {
40 36
      * Instantiates a new filename validator.
41 37
      */
42 38
     public ActionGroupValidator() {
43
-    //Do nothing
39
+        //Do nothing
44 40
     }
45 41
 
46 42
     /** {@inheritDoc} */
47 43
     @Override
48 44
     public ValidationResponse validate(final String object) {
49
-        if (!object.matches(FILENAME_REGEX)) {
50
-            return new ValidationResponse(FAILURE_REGEX);
51
-        } else if (ActionManager.getGroups().containsKey(object)) {
45
+        if (ActionManager.getGroups().containsKey(object)) {
52 46
             return new ValidationResponse(FAILURE_EXISTS);
53 47
         } else {
54 48
             return new ValidationResponse();

+ 1
- 1
src/com/dmdirc/config/prefs/validator/FileNameValidator.java View File

@@ -28,7 +28,7 @@ package com.dmdirc.config.prefs.validator;
28 28
 public class FileNameValidator implements Validator<String> {
29 29
 
30 30
     /** Filename regex. */
31
-    private static final String FILENAME_REGEX = "[A-Za-z0-9 ]+";
31
+    private static final String FILENAME_REGEX = "[A-Za-z0-9 \\-_]+";
32 32
     /** Failure reason. */
33 33
     private static final String FAILURE_REASON = "Must be a valid filename";
34 34
 

+ 8
- 4
src/com/dmdirc/ui/swing/dialogs/actionsmanager/ActionsManagerDialog.java View File

@@ -31,6 +31,7 @@ import com.dmdirc.actions.interfaces.ActionType;
31 31
 import com.dmdirc.config.IdentityManager;
32 32
 import com.dmdirc.config.prefs.validator.ActionGroupValidator;
33 33
 import com.dmdirc.config.prefs.validator.FileNameValidator;
34
+import com.dmdirc.config.prefs.validator.ValidatorChain;
34 35
 import com.dmdirc.ui.swing.components.TextLabel;
35 36
 import com.dmdirc.ui.swing.MainFrame;
36 37
 import com.dmdirc.ui.swing.SwingController;
@@ -157,6 +158,7 @@ public final class ActionsManagerDialog extends StandardDialog implements Action
157 158
         edit = new JButton("Edit");
158 159
         delete = new JButton("Delete");
159 160
         groupPanel = new JPanel();
161
+        groupPanel.setName("Groups");
160 162
 
161 163
         groupPanel.setBorder(BorderFactory.createTitledBorder(groupPanel.getBorder(),
162 164
                 "Groups"));
@@ -299,11 +301,12 @@ public final class ActionsManagerDialog extends StandardDialog implements Action
299 301
     /**
300 302
      * Prompts then adds an action group.
301 303
      */
304
+    @SuppressWarnings("unchecked")
302 305
     private void addGroup() {
303
-        final StandardInputDialog inputDialog = new StandardInputDialog(SwingController.getMainFrame(), false,
304
-                "New action group",
306
+        final StandardInputDialog inputDialog = new StandardInputDialog(SwingController.getMainFrame(),
307
+                false, "New action group",
305 308
                 "Please enter the name of the new action group",
306
-                new ActionGroupValidator()) {
309
+                new ValidatorChain<String>(new FileNameValidator(), new ActionGroupValidator())) {
307 310
 
308 311
             /**
309 312
              * A version number for this class. It should be changed whenever the class
@@ -338,13 +341,14 @@ public final class ActionsManagerDialog extends StandardDialog implements Action
338 341
     /**
339 342
      * Prompts then edits an action group.
340 343
      */
344
+    @SuppressWarnings("unchecked")
341 345
     private void editGroup() {
342 346
         final String oldName =
343 347
                 ((ActionGroup) groups.getSelectedValue()).getName();
344 348
         final StandardInputDialog inputDialog = new StandardInputDialog(SwingController.getMainFrame(), false,
345 349
                 "Edit action group",
346 350
                 "Please enter the new name of the action group",
347
-                new FileNameValidator()) {
351
+                new ValidatorChain<String>(new FileNameValidator(), new ActionGroupValidator())) {
348 352
 
349 353
             /**
350 354
              * A version number for this class. It should be changed whenever the class

Loading…
Cancel
Save