浏览代码

Merge pull request #732 from csmith/master

Add an interface for tab completers, move to API.
pull/733/head
Greg Holmes 7 年前
父节点
当前提交
179a10b77d

src/main/java/com/dmdirc/ui/input/AdditionalTabTargets.java → api/src/main/java/com/dmdirc/ui/input/AdditionalTabTargets.java 查看文件


+ 79
- 0
api/src/main/java/com/dmdirc/ui/input/TabCompleter.java 查看文件

@@ -0,0 +1,79 @@
1
+/*
2
+ * Copyright (c) 2006-2015 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.ui.input;
24
+
25
+import javax.annotation.Nullable;
26
+import java.util.List;
27
+
28
+/**
29
+ * The tab completer handles a user's request to tab complete some word.
30
+ */
31
+public interface TabCompleter {
32
+
33
+    /**
34
+     * Attempts to complete the partial string.
35
+     *
36
+     * @param partial     The string to tab complete
37
+     * @param additionals A list of additional strings to use
38
+     *
39
+     * @return A TabCompleterResult containing any matches found
40
+     */
41
+    List<String> complete(String partial, @Nullable AdditionalTabTargets additionals);
42
+
43
+    /**
44
+     * Adds a new entry to this tab completer's list.
45
+     *
46
+     * @param type  The type of the entry that's being added
47
+     * @param entry The new entry to be added
48
+     */
49
+    void addEntry(TabCompletionType type, String entry);
50
+
51
+    /**
52
+     * Adds multiple new entries to this tab completer's list.
53
+     *
54
+     * @param type       The type of the entries that're being added
55
+     * @param newEntries Entries to be added
56
+     */
57
+    void addEntries(TabCompletionType type, Iterable<String> newEntries);
58
+
59
+    /**
60
+     * Removes a specified entry from this tab completer's list.
61
+     *
62
+     * @param type  The type of the entry that should be removed
63
+     * @param entry The entry to be removed
64
+     */
65
+    void removeEntry(TabCompletionType type, String entry);
66
+
67
+    /**
68
+     * Clears all entries in this tab completer.
69
+     */
70
+    void clear();
71
+
72
+    /**
73
+     * Clears all entries of the specified type in this tab completer.
74
+     *
75
+     * @param type The type of entry to clear
76
+     */
77
+    void clear(TabCompletionType type);
78
+
79
+}

src/main/java/com/dmdirc/ui/input/TabCompletionType.java → api/src/main/java/com/dmdirc/ui/input/TabCompletionType.java 查看文件


+ 2
- 2
src/main/java/com/dmdirc/ui/input/TabCompleterFactory.java 查看文件

@@ -62,7 +62,7 @@ public class TabCompleterFactory {
62 62
     public TabCompleter getTabCompleter(
63 63
             final AggregateConfigProvider configProvider,
64 64
             final CommandType... commandTypes) {
65
-        final TabCompleter tabCompleter = new TabCompleter(configProvider);
65
+        final TabCompleter tabCompleter = new TabCompleterImpl(configProvider);
66 66
         addCommands(tabCompleter, commandTypes);
67 67
         return tabCompleter;
68 68
     }
@@ -81,7 +81,7 @@ public class TabCompleterFactory {
81 81
             final TabCompleter parent,
82 82
             final AggregateConfigProvider configProvider,
83 83
             final CommandType... commandTypes) {
84
-        final TabCompleter tabCompleter = new TabCompleter(configProvider, parent);
84
+        final TabCompleter tabCompleter = new TabCompleterImpl(configProvider, parent);
85 85
         addCommands(tabCompleter, commandTypes);
86 86
         return tabCompleter;
87 87
     }

src/main/java/com/dmdirc/ui/input/TabCompleter.java → src/main/java/com/dmdirc/ui/input/TabCompleterImpl.java 查看文件

@@ -33,7 +33,7 @@ import java.util.List;
33 33
 /**
34 34
  * The tab completer handles a user's request to tab complete some word.
35 35
  */
36
-public class TabCompleter {
36
+public class TabCompleterImpl implements TabCompleter {
37 37
 
38 38
     /**
39 39
      * The parent TabCompleter. Results from parents are merged with results from this completer.
@@ -46,36 +46,29 @@ public class TabCompleter {
46 46
     private final Multimap<TabCompletionType, String> entries = ArrayListMultimap.create();
47 47
 
48 48
     /**
49
-     * Creates a new instance of {@link TabCompleter}.
49
+     * Creates a new instance of {@link TabCompleterImpl}.
50 50
      *
51 51
      * @param configManager     The manager to read config settings from.
52 52
      */
53
-    public TabCompleter(final AggregateConfigProvider configManager) {
53
+    public TabCompleterImpl(final AggregateConfigProvider configManager) {
54 54
         this.parent = null;
55 55
         this.configManager = configManager;
56 56
     }
57 57
 
58 58
     /**
59
-     * Creates a new instance of {@link TabCompleter}.
59
+     * Creates a new instance of {@link TabCompleterImpl}.
60 60
      *
61 61
      * @param configManager     The manager to read config settings from.
62 62
      * @param parent            The parent tab completer to inherit completions from.
63 63
      */
64
-    public TabCompleter(
64
+    public TabCompleterImpl(
65 65
             final AggregateConfigProvider configManager,
66 66
             @Nullable final TabCompleter parent) {
67 67
         this.parent = parent;
68 68
         this.configManager = configManager;
69 69
     }
70 70
 
71
-    /**
72
-     * Attempts to complete the partial string.
73
-     *
74
-     * @param partial     The string to tab complete
75
-     * @param additionals A list of additional strings to use
76
-     *
77
-     * @return A TabCompleterResult containing any matches found
78
-     */
71
+    @Override
79 72
     public List<String> complete(final String partial, @Nullable final AdditionalTabTargets additionals) {
80 73
         final List<String> result = new ArrayList<>();
81 74
 
@@ -118,22 +111,12 @@ public class TabCompleter {
118 111
         return result;
119 112
     }
120 113
 
121
-    /**
122
-     * Adds a new entry to this tab completer's list.
123
-     *
124
-     * @param type  The type of the entry that's being added
125
-     * @param entry The new entry to be added
126
-     */
114
+    @Override
127 115
     public void addEntry(final TabCompletionType type, final String entry) {
128 116
         entries.put(type, entry);
129 117
     }
130 118
 
131
-    /**
132
-     * Adds multiple new entries to this tab completer's list.
133
-     *
134
-     * @param type       The type of the entries that're being added
135
-     * @param newEntries Entries to be added
136
-     */
119
+    @Override
137 120
     public void addEntries(final TabCompletionType type, final Iterable<String> newEntries) {
138 121
         if (newEntries == null) {
139 122
             return;
@@ -144,28 +127,17 @@ public class TabCompleter {
144 127
         }
145 128
     }
146 129
 
147
-    /**
148
-     * Removes a specified entry from this tab completer's list.
149
-     *
150
-     * @param type  The type of the entry that should be removed
151
-     * @param entry The entry to be removed
152
-     */
130
+    @Override
153 131
     public void removeEntry(final TabCompletionType type, final String entry) {
154 132
         entries.remove(type, entry);
155 133
     }
156 134
 
157
-    /**
158
-     * Clears all entries in this tab completer.
159
-     */
135
+    @Override
160 136
     public void clear() {
161 137
         entries.clear();
162 138
     }
163 139
 
164
-    /**
165
-     * Clears all entries of the specified type in this tab completer.
166
-     *
167
-     * @param type The type of entry to clear
168
-     */
140
+    @Override
169 141
     public void clear(final TabCompletionType type) {
170 142
         entries.removeAll(type);
171 143
     }

+ 2
- 2
src/test/java/com/dmdirc/harness/TestWritableFrameContainer.java 查看文件

@@ -29,7 +29,7 @@ import com.dmdirc.commandparser.parsers.GlobalCommandParser;
29 29
 import com.dmdirc.interfaces.Connection;
30 30
 import com.dmdirc.interfaces.EventBus;
31 31
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
32
-import com.dmdirc.ui.input.TabCompleter;
32
+import com.dmdirc.ui.input.TabCompleterImpl;
33 33
 import com.dmdirc.ui.messages.BackBufferFactory;
34 34
 
35 35
 import java.util.Collections;
@@ -49,7 +49,7 @@ public class TestWritableFrameContainer extends FrameContainer {
49 49
                 new DefaultInputModel(
50 50
                         line -> {},
51 51
                         new GlobalCommandParser(cm, commandManager, eventBus),
52
-                        new TabCompleter(cm),
52
+                        new TabCompleterImpl(cm),
53 53
                         () -> lineLength));
54 54
     }
55 55
 

正在加载...
取消
保存