Browse Source

Move tab completion styles to addons

Fixes issue 2171, fixes issue 2310 (dev error), fixes issue 2311 (dev error)
tags/0.6.3m1rc1
Chris Smith 15 years ago
parent
commit
245a8c1ea9

src/com/dmdirc/ui/input/tabstyles/BashStyle.java → src/com/dmdirc/addons/tabcompletion_bash/BashStyle.java View File

@@ -20,17 +20,19 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.ui.input.tabstyles;
23
+package com.dmdirc.addons.tabcompletion_bash;
24 24
 
25
+import com.dmdirc.plugins.Plugin;
25 26
 import com.dmdirc.ui.input.AdditionalTabTargets;
27
+import com.dmdirc.ui.input.TabCompleter;
26 28
 import com.dmdirc.ui.input.TabCompleterResult;
29
+import com.dmdirc.ui.input.tabstyles.TabCompletionResult;
30
+import com.dmdirc.ui.input.tabstyles.TabCompletionStyle;
31
+import com.dmdirc.ui.interfaces.InputWindow;
27 32
 
28 33
 import java.awt.Toolkit;
29 34
 
30
-public class BashStyle extends TabCompletionStyle {
31
-    
32
-    /** The name of this style. */
33
-    private static final String NAME = "bash";
35
+public class BashStyle extends Plugin implements TabCompletionStyle {
34 36
     
35 37
     /** The last position the user tab-completed at. */
36 38
     private int lastPosition = -1;
@@ -40,13 +42,22 @@ public class BashStyle extends TabCompletionStyle {
40 42
     
41 43
     /** The last word that was tab completed. */
42 44
     private String lastWord = "";
43
-    
45
+
46
+    /** The tab completer that we use. */
47
+    protected TabCompleter tabCompleter;
48
+
49
+    /** The input window that we use. */
50
+    protected InputWindow window;
51
+
44 52
     /** {@inheritDoc} */
45
-    public String getName() {
46
-        return NAME;
53
+    @Override
54
+    public void setContext(final TabCompleter completer, final InputWindow window) {
55
+        this.tabCompleter = completer;
56
+        this.window = window;
47 57
     }
48 58
     
49 59
     /** {@inheritDoc} */
60
+    @Override
50 61
     public TabCompletionResult getResult(final String original, final int start,
51 62
             final int end, final AdditionalTabTargets additional) {
52 63
         final String word = original.substring(start, end);
@@ -87,5 +98,17 @@ public class BashStyle extends TabCompletionStyle {
87 98
             }
88 99
         }
89 100
     }
101
+
102
+    /** {@inheritDoc} */
103
+    @Override
104
+    public void onLoad() {
105
+        // Do nothing
106
+    }
107
+
108
+    /** {@inheritDoc} */
109
+    @Override
110
+    public void onUnload() {
111
+        // Do nothing
112
+    }
90 113
     
91 114
 }

+ 25
- 0
src/com/dmdirc/addons/tabcompletion_bash/plugin.config View File

@@ -0,0 +1,25 @@
1
+# This is a DMDirc configuration file.
2
+
3
+# This section indicates which sections below take key/value
4
+# pairs, rather than a simple list. It should be placed above
5
+# any sections that take key/values.
6
+keysections:
7
+  metadata
8
+  updates
9
+#  version
10
+
11
+metadata:
12
+  author=Chris <chris@dmdirc.com>
13
+  mainclass=com.dmdirc.addons.tabcompletion_bash.BashStyle
14
+  description=Tab completion that lists all possible matches
15
+  name=tabcompletion_bash
16
+  nicename=Bash-style completion
17
+
18
+updates:
19
+  id=43
20
+
21
+#version:
22
+#  friendly=0
23
+
24
+provides:
25
+  bash tabcompletion

src/com/dmdirc/ui/input/tabstyles/MircStyle.java → src/com/dmdirc/addons/tabcompletion_mirc/MircStyle.java View File

@@ -20,19 +20,21 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.ui.input.tabstyles;
23
+package com.dmdirc.addons.tabcompletion_mirc;
24 24
 
25 25
 import com.dmdirc.Channel;
26
+import com.dmdirc.plugins.Plugin;
26 27
 import com.dmdirc.ui.input.AdditionalTabTargets;
28
+import com.dmdirc.ui.input.TabCompleter;
27 29
 import com.dmdirc.ui.input.TabCompleterResult;
30
+import com.dmdirc.ui.input.tabstyles.TabCompletionResult;
31
+import com.dmdirc.ui.input.tabstyles.TabCompletionStyle;
32
+import com.dmdirc.ui.interfaces.InputWindow;
28 33
 
29 34
 import java.awt.Toolkit;
30 35
 import java.util.List;
31 36
 
32
-public class MircStyle extends TabCompletionStyle {
33
-    
34
-    /** The name of this style. */
35
-    private static final String NAME = "mirc";
37
+public class MircStyle extends Plugin implements TabCompletionStyle {
36 38
     
37 39
     /** The last set of results we retrieved. */
38 40
     private List<String> lastResult;
@@ -40,12 +42,21 @@ public class MircStyle extends TabCompletionStyle {
40 42
     /** The last word that was tab completed. */
41 43
     private String lastWord;
42 44
     
45
+    /** The tab completer that we use. */
46
+    protected TabCompleter tabCompleter;
47
+
48
+    /** The input window that we use. */
49
+    protected InputWindow window;
50
+
43 51
     /** {@inheritDoc} */
44
-    public String getName() {
45
-        return NAME;
52
+    @Override
53
+    public void setContext(final TabCompleter completer, final InputWindow window) {
54
+        this.tabCompleter = completer;
55
+        this.window = window;
46 56
     }
47 57
     
48 58
     /** {@inheritDoc} */
59
+    @Override
49 60
     public TabCompletionResult getResult(final String original, final int start,
50 61
             final int end, final AdditionalTabTargets additional) {
51 62
         
@@ -64,7 +75,8 @@ public class MircStyle extends TabCompletionStyle {
64 75
                 return null;
65 76
             } else {
66 77
                 if (word.length() > 0 && window.getContainer() instanceof Channel
67
-                        && ((Channel) window.getContainer()).getChannelInfo().getName().startsWith(word)) {
78
+                        && ((Channel) window.getContainer())
79
+                        .getChannelInfo().getName().startsWith(word)) {
68 80
                     target = ((Channel) window.getContainer()).getChannelInfo().getName();
69 81
                 } else {
70 82
                     target = res.getResults().get(0);
@@ -75,9 +87,20 @@ public class MircStyle extends TabCompletionStyle {
75 87
         
76 88
         lastWord = target;
77 89
         
78
-        return new TabCompletionResult(
79
-                original.substring(0, start) + target + original.substring(end),
80
-                start + target.length());
90
+        return new TabCompletionResult(original.substring(0, start) + target
91
+                + original.substring(end), start + target.length());
92
+    }
93
+
94
+    /** {@inheritDoc} */
95
+    @Override
96
+    public void onLoad() {
97
+        // Do nothing
98
+    }
99
+
100
+    /** {@inheritDoc} */
101
+    @Override
102
+    public void onUnload() {
103
+        // Do nothing
81 104
     }
82 105
     
83 106
 }

+ 25
- 0
src/com/dmdirc/addons/tabcompletion_mirc/plugin.config View File

@@ -0,0 +1,25 @@
1
+# This is a DMDirc configuration file.
2
+
3
+# This section indicates which sections below take key/value
4
+# pairs, rather than a simple list. It should be placed above
5
+# any sections that take key/values.
6
+keysections:
7
+  metadata
8
+  updates
9
+#  version
10
+
11
+metadata:
12
+  author=Chris <chris@dmdirc.com>
13
+  mainclass=com.dmdirc.addons.tabcompletion_mirc.MircStyle
14
+  description=Tab completion that cycles through matches
15
+  name=tabcompletion_mirc
16
+  nicename=mIRC-style completion
17
+
18
+updates:
19
+  id=44
20
+
21
+#version:
22
+#  friendly=0
23
+
24
+provides:
25
+  mirc tabcompletion

+ 5
- 2
src/com/dmdirc/config/prefs/PreferencesManager.java View File

@@ -25,6 +25,8 @@ import com.dmdirc.Main;
25 25
 import com.dmdirc.actions.ActionManager;
26 26
 import com.dmdirc.actions.CoreActionType;
27 27
 import com.dmdirc.config.prefs.validator.NumericalValidator;
28
+import com.dmdirc.plugins.PluginManager;
29
+import com.dmdirc.plugins.Service;
28 30
 import com.dmdirc.util.ListenerList;
29 31
 
30 32
 import java.util.ArrayList;
@@ -171,8 +173,9 @@ public class PreferencesManager {
171 173
                 "contains more than this many lines."));
172 174
         
173 175
         final Map<String, String> taboptions = new HashMap<String, String>();
174
-        taboptions.put("bash", "Bash style");
175
-        taboptions.put("mirc", "mIRC style (cyclic)");
176
+        for (Service service : PluginManager.getPluginManager().getServicesByType("tabcompletion")) {
177
+            taboptions.put(service.getName(), service.getName());
178
+        }
176 179
         
177 180
         category.addSetting(new PreferencesSetting("tabcompletion", "style",
178 181
                 "Tab completion style", "Determines the behaviour of " +

+ 5
- 8
src/com/dmdirc/ui/input/InputHandler.java View File

@@ -33,8 +33,8 @@ import com.dmdirc.commandparser.commands.WrappableCommand;
33 33
 import com.dmdirc.commandparser.parsers.CommandParser;
34 34
 import com.dmdirc.config.prefs.validator.ValidationResponse;
35 35
 import com.dmdirc.interfaces.ConfigChangeListener;
36
-import com.dmdirc.ui.input.tabstyles.BashStyle;
37
-import com.dmdirc.ui.input.tabstyles.MircStyle;
36
+import com.dmdirc.plugins.PluginInfo;
37
+import com.dmdirc.plugins.PluginManager;
38 38
 import com.dmdirc.ui.input.tabstyles.TabCompletionResult;
39 39
 import com.dmdirc.ui.input.tabstyles.TabCompletionStyle;
40 40
 import com.dmdirc.ui.interfaces.InputField;
@@ -173,12 +173,9 @@ public abstract class InputHandler implements ConfigChangeListener {
173 173
      * Sets this inputhandler's tab completion style.
174 174
      */
175 175
     private void setStyle() {
176
-        if ("bash".equals(parentWindow.getConfigManager().getOption("tabcompletion",
177
-                "style"))) {
178
-            style = new BashStyle();
179
-        } else {
180
-            style = new MircStyle();
181
-        }
176
+        style = (TabCompletionStyle) ((PluginInfo) PluginManager.getPluginManager()
177
+                .getServiceProvider("tabcompletion", parentWindow.getConfigManager()
178
+                .getOption("tabcompletion", "style"))).getPlugin();
182 179
         
183 180
         style.setContext(tabCompleter, parentWindow);
184 181
     }

+ 4
- 20
src/com/dmdirc/ui/input/tabstyles/TabCompletionStyle.java View File

@@ -32,13 +32,7 @@ import com.dmdirc.ui.interfaces.InputWindow;
32 32
  * 
33 33
  * @author Chris
34 34
  */
35
-public abstract class TabCompletionStyle {
36
-        
37
-    /** The tab completer that we use. */
38
-    protected TabCompleter tabCompleter;
39
-    
40
-    /** The input window that we use. */
41
-    protected InputWindow window;
35
+public interface TabCompletionStyle {
42 36
     
43 37
     /**
44 38
      * Sets this style's tab completer and window to the ones specified.
@@ -46,17 +40,7 @@ public abstract class TabCompletionStyle {
46 40
      * @param completer The new tab completer to use
47 41
      * @param window The window in which the tab completer is used
48 42
      */
49
-    public void setContext(final TabCompleter completer, final InputWindow window) {
50
-        this.tabCompleter = completer;
51
-        this.window = window;
52
-    }
53
-    
54
-    /**
55
-     * Retrieves a name for this completion style.
56
-     * 
57
-     * @return The name for this completion style
58
-     */
59
-    public abstract String getName();
43
+    void setContext(final TabCompleter completer, final InputWindow window);
60 44
     
61 45
     /**
62 46
      * Retrieves this style's result for the specified parameters.
@@ -67,7 +51,7 @@ public abstract class TabCompletionStyle {
67 51
      * @param additional A list of additional targets which may match
68 52
      * @return This style's proposed result
69 53
      */
70
-    public abstract TabCompletionResult getResult(final String original,
71
-            final int start, final int end, final AdditionalTabTargets additional);
54
+    TabCompletionResult getResult(final String original, final int start,
55
+            final int end, final AdditionalTabTargets additional);
72 56
     
73 57
 }

Loading…
Cancel
Save