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
  */
29
  */
30
 public class ActionGroupValidator implements Validator<String> {
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
     /** Failure reason for duplicates. */
32
     /** Failure reason for duplicates. */
37
     private static final String FAILURE_EXISTS = "Must not already exist.";
33
     private static final String FAILURE_EXISTS = "Must not already exist.";
38
 
34
 
40
      * Instantiates a new filename validator.
36
      * Instantiates a new filename validator.
41
      */
37
      */
42
     public ActionGroupValidator() {
38
     public ActionGroupValidator() {
43
-    //Do nothing
39
+        //Do nothing
44
     }
40
     }
45
 
41
 
46
     /** {@inheritDoc} */
42
     /** {@inheritDoc} */
47
     @Override
43
     @Override
48
     public ValidationResponse validate(final String object) {
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
             return new ValidationResponse(FAILURE_EXISTS);
46
             return new ValidationResponse(FAILURE_EXISTS);
53
         } else {
47
         } else {
54
             return new ValidationResponse();
48
             return new ValidationResponse();

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

28
 public class FileNameValidator implements Validator<String> {
28
 public class FileNameValidator implements Validator<String> {
29
 
29
 
30
     /** Filename regex. */
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
     /** Failure reason. */
32
     /** Failure reason. */
33
     private static final String FAILURE_REASON = "Must be a valid filename";
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
 import com.dmdirc.config.IdentityManager;
31
 import com.dmdirc.config.IdentityManager;
32
 import com.dmdirc.config.prefs.validator.ActionGroupValidator;
32
 import com.dmdirc.config.prefs.validator.ActionGroupValidator;
33
 import com.dmdirc.config.prefs.validator.FileNameValidator;
33
 import com.dmdirc.config.prefs.validator.FileNameValidator;
34
+import com.dmdirc.config.prefs.validator.ValidatorChain;
34
 import com.dmdirc.ui.swing.components.TextLabel;
35
 import com.dmdirc.ui.swing.components.TextLabel;
35
 import com.dmdirc.ui.swing.MainFrame;
36
 import com.dmdirc.ui.swing.MainFrame;
36
 import com.dmdirc.ui.swing.SwingController;
37
 import com.dmdirc.ui.swing.SwingController;
157
         edit = new JButton("Edit");
158
         edit = new JButton("Edit");
158
         delete = new JButton("Delete");
159
         delete = new JButton("Delete");
159
         groupPanel = new JPanel();
160
         groupPanel = new JPanel();
161
+        groupPanel.setName("Groups");
160
 
162
 
161
         groupPanel.setBorder(BorderFactory.createTitledBorder(groupPanel.getBorder(),
163
         groupPanel.setBorder(BorderFactory.createTitledBorder(groupPanel.getBorder(),
162
                 "Groups"));
164
                 "Groups"));
299
     /**
301
     /**
300
      * Prompts then adds an action group.
302
      * Prompts then adds an action group.
301
      */
303
      */
304
+    @SuppressWarnings("unchecked")
302
     private void addGroup() {
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
                 "Please enter the name of the new action group",
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
              * A version number for this class. It should be changed whenever the class
312
              * A version number for this class. It should be changed whenever the class
338
     /**
341
     /**
339
      * Prompts then edits an action group.
342
      * Prompts then edits an action group.
340
      */
343
      */
344
+    @SuppressWarnings("unchecked")
341
     private void editGroup() {
345
     private void editGroup() {
342
         final String oldName =
346
         final String oldName =
343
                 ((ActionGroup) groups.getSelectedValue()).getName();
347
                 ((ActionGroup) groups.getSelectedValue()).getName();
344
         final StandardInputDialog inputDialog = new StandardInputDialog(SwingController.getMainFrame(), false,
348
         final StandardInputDialog inputDialog = new StandardInputDialog(SwingController.getMainFrame(), false,
345
                 "Edit action group",
349
                 "Edit action group",
346
                 "Please enter the new name of the action group",
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
              * A version number for this class. It should be changed whenever the class
354
              * A version number for this class. It should be changed whenever the class

Loading…
Cancel
Save