瀏覽代碼

Make preferences manager use current UI

Fixes issue 4415

Change-Id: I52c7f76361f8b2fe4ebd38b00795e28ca4eee9e5
Reviewed-on: http://gerrit.dmdirc.com/1460
Automatic-Compile: Gregory Holmes <greg@dmdirc.com>
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
tags/0.6.5b1
Chris Smith 14 年之前
父節點
當前提交
eafec02238

+ 25
- 10
src/com/dmdirc/config/prefs/PreferencesManager.java 查看文件

@@ -22,16 +22,17 @@
22 22
 
23 23
 package com.dmdirc.config.prefs;
24 24
 
25
-import com.dmdirc.Main;
26 25
 import com.dmdirc.actions.ActionManager;
27 26
 import com.dmdirc.actions.CoreActionType;
28 27
 import com.dmdirc.util.validators.NumericalValidator;
29 28
 import com.dmdirc.util.validators.OptionalValidator;
30 29
 import com.dmdirc.plugins.PluginManager;
31 30
 import com.dmdirc.plugins.Service;
31
+import com.dmdirc.ui.interfaces.UIController;
32 32
 import com.dmdirc.util.ListenerList;
33 33
 
34 34
 import java.util.ArrayList;
35
+import java.util.Collections;
35 36
 import java.util.HashMap;
36 37
 import java.util.List;
37 38
 import java.util.Map;
@@ -43,6 +44,9 @@ import java.util.Map;
43 44
  */
44 45
 public class PreferencesManager {
45 46
 
47
+    /** The UI controller to use for custom categories. */
48
+    private final UIController controller;
49
+
46 50
     /** A list of categories. */
47 51
     private final List<PreferencesCategory> categories
48 52
             = new ArrayList<PreferencesCategory>();
@@ -52,8 +56,13 @@ public class PreferencesManager {
52 56
 
53 57
     /**
54 58
      * Creates a new instance of PreferencesManager.
59
+     *
60
+     * @param controller The UI controller to use to retrieve custom UIs for
61
+     * preferences panels.
55 62
      */
56
-    public PreferencesManager() {
63
+    public PreferencesManager(final UIController controller) {
64
+        this.controller = controller;
65
+
57 66
         addDefaultCategories();
58 67
 
59 68
         ActionManager.processEvent(CoreActionType.CLIENT_PREFS_OPENED, null, this);
@@ -74,7 +83,7 @@ public class PreferencesManager {
74 83
      * @return An ordered list of categories
75 84
      */
76 85
     public List<PreferencesCategory> getCategories() {
77
-        return categories;
86
+        return Collections.unmodifiableList(categories);
78 87
     }
79 88
 
80 89
     /**
@@ -104,7 +113,7 @@ public class PreferencesManager {
104 113
         boolean restart = false;
105 114
         for (PreferencesCategory category : categories) {
106 115
             if (category.save()) {
107
-                restart = true;
116
+                restart |= true;
108 117
             }
109 118
         }
110 119
 
@@ -174,9 +183,11 @@ public class PreferencesManager {
174 183
 
175 184
     /**
176 185
      * Creates and adds the "Tab Completion" category.
186
+     *
187
+     * @param parent Parent category to add this category to
177 188
      * @since 0.6.4
178 189
      */
179
-    private void addTabCompletionCategory(PreferencesCategory parent) {
190
+    private void addTabCompletionCategory(final PreferencesCategory parent) {
180 191
         final PreferencesCategory category = new PreferencesCategory("Tab Completion", "");
181 192
         final Map<String, String> taboptions = new HashMap<String, String>();
182 193
 
@@ -251,6 +262,8 @@ public class PreferencesManager {
251 262
 
252 263
     /**
253 264
      * Creates and adds the "SSL" category.
265
+     *
266
+     * @param parent Parent category to add this category to
254 267
      */
255 268
     private void addSSLCategory(final PreferencesCategory parent) {
256 269
         final PreferencesCategory category = new PreferencesCategory("SSL",
@@ -454,9 +467,11 @@ public class PreferencesManager {
454 467
 
455 468
     /**
456 469
      * Creates the Style subcategory in "GUI".
470
+     *
457 471
      * @since 0.6.4
472
+     * @param parent Parent category to add this category to
458 473
      */
459
-    private void addStyleSubCategory(PreferencesCategory parent) {
474
+    private void addStyleSubCategory(final PreferencesCategory parent) {
460 475
         final PreferencesCategory category = new PreferencesCategory("Link styles"
461 476
                 + " and colours", "");
462 477
         category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
@@ -481,7 +496,7 @@ public class PreferencesManager {
481 496
      */
482 497
     private void addThemesCategory(final PreferencesCategory parent) {
483 498
         parent.addSubCategory(new PreferencesCategory("Themes", "",
484
-                "category-addons", Main.getUI().getThemesPrefsPanel()));
499
+                "category-addons", controller.getThemesPrefsPanel()));
485 500
     }
486 501
 
487 502
     /**
@@ -489,7 +504,7 @@ public class PreferencesManager {
489 504
      */
490 505
     private void addPluginsCategory() {
491 506
         addCategory(new PreferencesCategory("Plugins", "", "category-addons",
492
-                Main.getUI().getPluginPrefsPanel()));
507
+                controller.getPluginPrefsPanel()));
493 508
     }
494 509
 
495 510
     /**
@@ -497,7 +512,7 @@ public class PreferencesManager {
497 512
      */
498 513
     private void addUpdatesCategory() {
499 514
         addCategory(new PreferencesCategory("Updates", "", "category-updates",
500
-                Main.getUI().getUpdatesPrefsPanel()));
515
+                controller.getUpdatesPrefsPanel()));
501 516
     }
502 517
 
503 518
     /**
@@ -506,7 +521,7 @@ public class PreferencesManager {
506 521
     private void addUrlHandlerCategory() {
507 522
         addCategory(new PreferencesCategory("URL Handlers",
508 523
                 "Configure how DMDirc handles different types of URLs",
509
-                "category-urlhandlers", Main.getUI().getUrlHandlersPrefsPanel()));
524
+                "category-urlhandlers", controller.getUrlHandlersPrefsPanel()));
510 525
     }
511 526
 
512 527
     /**

+ 13
- 9
test/com/dmdirc/config/prefs/PreferencesManagerTest.java 查看文件

@@ -29,6 +29,7 @@ import com.dmdirc.config.IdentityManager;
29 29
 import com.dmdirc.interfaces.ActionListener;
30 30
 
31 31
 import com.dmdirc.plugins.PluginManager;
32
+import com.dmdirc.ui.interfaces.UIController;
32 33
 import org.junit.BeforeClass;
33 34
 import org.junit.Test;
34 35
 import static org.junit.Assert.*;
@@ -36,17 +37,20 @@ import static org.mockito.Mockito.*;
36 37
 
37 38
 public class PreferencesManagerTest {
38 39
 
40
+    private static UIController controller;
41
+
39 42
     @BeforeClass
40 43
     public static void setUp() throws Exception {
41 44
         IdentityManager.load();
42 45
         Main.extractCorePlugins("ui_");
43 46
         Main.setUI(new SwingController());
44 47
         PluginManager.getPluginManager();
48
+        controller = mock(UIController.class);
45 49
     }
46 50
 
47 51
     @Test
48 52
     public void testDefaults() {
49
-        final PreferencesManager pm = new PreferencesManager();
53
+        final PreferencesManager pm = new PreferencesManager(controller);
50 54
         assertNotNull(pm.getCategory("General"));
51 55
         assertNotNull(pm.getCategory("Connection"));
52 56
         assertNotNull(pm.getCategory("Messages"));
@@ -60,7 +64,7 @@ public class PreferencesManagerTest {
60 64
     @Test
61 65
     public void testDismiss() {
62 66
         final PreferencesCategory category = mock(PreferencesCategory.class);
63
-        final PreferencesManager pm = new PreferencesManager();
67
+        final PreferencesManager pm = new PreferencesManager(controller);
64 68
         pm.addCategory(category);
65 69
         pm.dismiss();
66 70
 
@@ -72,7 +76,7 @@ public class PreferencesManagerTest {
72 76
         final PreferencesCategory category = mock(PreferencesCategory.class);
73 77
         when(category.save()).thenReturn(false);
74 78
 
75
-        final PreferencesManager pm = new PreferencesManager();
79
+        final PreferencesManager pm = new PreferencesManager(controller);
76 80
         pm.addCategory(category);
77 81
         assertFalse(pm.save());
78 82
 
@@ -84,7 +88,7 @@ public class PreferencesManagerTest {
84 88
         final PreferencesCategory category = mock(PreferencesCategory.class);
85 89
         when(category.save()).thenReturn(true);
86 90
 
87
-        final PreferencesManager pm = new PreferencesManager();
91
+        final PreferencesManager pm = new PreferencesManager(controller);
88 92
         pm.addCategory(category);
89 93
         assertTrue(pm.save());
90 94
 
@@ -93,13 +97,13 @@ public class PreferencesManagerTest {
93 97
 
94 98
     @Test
95 99
     public void testGetCategory() {
96
-        final PreferencesManager pm = new PreferencesManager();
100
+        final PreferencesManager pm = new PreferencesManager(controller);
97 101
         assertNull(pm.getCategory("unittest123"));
98 102
     }
99 103
 
100 104
     @Test
101 105
     public void testGetCategories() {
102
-        final PreferencesManager pm = new PreferencesManager();
106
+        final PreferencesManager pm = new PreferencesManager(controller);
103 107
         assertNotNull(pm.getCategories());
104 108
         assertFalse(pm.getCategories().isEmpty());
105 109
 
@@ -110,7 +114,7 @@ public class PreferencesManagerTest {
110 114
 
111 115
     @Test
112 116
     public void testSaveListener() {
113
-        final PreferencesManager pm = new PreferencesManager();
117
+        final PreferencesManager pm = new PreferencesManager(controller);
114 118
         final PreferencesInterface tpi = mock(PreferencesInterface.class);
115 119
 
116 120
         pm.registerSaveListener(tpi);
@@ -125,7 +129,7 @@ public class PreferencesManagerTest {
125 129
         ActionManager.init();
126 130
         ActionManager.addListener(tal, CoreActionType.CLIENT_PREFS_OPENED);
127 131
 
128
-        final PreferencesManager pm = new PreferencesManager();
132
+        final PreferencesManager pm = new PreferencesManager(controller);
129 133
 
130 134
         verify(tal).processEvent(eq(CoreActionType.CLIENT_PREFS_OPENED),
131 135
                 (StringBuffer) same(null), same(pm));
@@ -138,7 +142,7 @@ public class PreferencesManagerTest {
138 142
         ActionManager.init();
139 143
         ActionManager.addListener(tal, CoreActionType.CLIENT_PREFS_CLOSED);
140 144
 
141
-        final PreferencesManager pm = new PreferencesManager();
145
+        final PreferencesManager pm = new PreferencesManager(controller);
142 146
         pm.close();
143 147
 
144 148
         verify(tal).processEvent(eq(CoreActionType.CLIENT_PREFS_CLOSED),

Loading…
取消
儲存