Browse Source

Merge pull request #775 from ShaneMcC/master

Add /reloadformat command.
pull/783/head
Shane Mc Cormack 7 years ago
parent
commit
422e3f2c43

+ 6
- 0
src/main/java/com/dmdirc/commandparser/commands/CommandModule.java View File

@@ -38,6 +38,7 @@ import com.dmdirc.commandparser.commands.global.Ifplugin;
38 38
 import com.dmdirc.commandparser.commands.global.LoadPlugin;
39 39
 import com.dmdirc.commandparser.commands.global.NewServer;
40 40
 import com.dmdirc.commandparser.commands.global.OpenWindow;
41
+import com.dmdirc.commandparser.commands.global.ReloadFormat;
41 42
 import com.dmdirc.commandparser.commands.global.ReloadIdentities;
42 43
 import com.dmdirc.commandparser.commands.global.ReloadPlugin;
43 44
 import com.dmdirc.commandparser.commands.global.SaveConfig;
@@ -285,6 +286,11 @@ public class CommandModule {
285 286
         return new SimpleCommandDetails(command, SaveConfig.INFO);
286 287
     }
287 288
 
289
+    @Provides(type = Provides.Type.SET)
290
+    public CommandDetails getReloadFormatCommand(final ReloadFormat command) {
291
+        return new SimpleCommandDetails(command, ReloadFormat.INFO);
292
+    }
293
+
288 294
     @Provides(type = Provides.Type.SET)
289 295
     public CommandDetails getSetCommand(final SetCommand command) {
290 296
         return new SimpleCommandDetails(command, SetCommand.INFO);

+ 76
- 0
src/main/java/com/dmdirc/commandparser/commands/global/ReloadFormat.java View File

@@ -0,0 +1,76 @@
1
+/*
2
+ * Copyright (c) 2006-2017 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7
+ * permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ *
9
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ * Software.
11
+ *
12
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
14
+ * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ */
17
+
18
+package com.dmdirc.commandparser.commands.global;
19
+
20
+import com.dmdirc.commandparser.BaseCommandInfo;
21
+import com.dmdirc.commandparser.CommandArguments;
22
+import com.dmdirc.commandparser.CommandInfo;
23
+import com.dmdirc.commandparser.CommandType;
24
+import com.dmdirc.commandparser.commands.BaseCommand;
25
+import com.dmdirc.commandparser.commands.IntelligentCommand;
26
+import com.dmdirc.commandparser.commands.context.CommandContext;
27
+import com.dmdirc.interfaces.CommandController;
28
+import com.dmdirc.interfaces.WindowModel;
29
+import com.dmdirc.ui.input.AdditionalTabTargets;
30
+import com.dmdirc.ui.messages.EventFormatProvider;
31
+
32
+import javax.annotation.Nonnull;
33
+import javax.inject.Inject;
34
+
35
+/**
36
+ * Allows the user to save the config file.
37
+ */
38
+public final class ReloadFormat extends BaseCommand implements IntelligentCommand {
39
+
40
+    /**
41
+     * A command info object for this command.
42
+     */
43
+    public static final CommandInfo INFO = new BaseCommandInfo("reloadformat",
44
+            "reloadformat - force the client to reload the format.yml file",
45
+            CommandType.TYPE_GLOBAL);
46
+    /**
47
+     * Format provider for events.
48
+     */
49
+    private final EventFormatProvider formatProvider;
50
+
51
+    /**
52
+     * Creates a new instance of the {@link ReloadFormat} command.
53
+     *
54
+     * @param controller         The controller to use for command information.
55
+     */
56
+    @Inject
57
+    public ReloadFormat(final CommandController controller,
58
+                        final EventFormatProvider formatProvider) {
59
+        super(controller);
60
+        this.formatProvider = formatProvider;
61
+    }
62
+
63
+    @Override
64
+    public void execute(@Nonnull final WindowModel origin,
65
+                        final CommandArguments args, final CommandContext context) {
66
+        formatProvider.reload();
67
+        showOutput(origin, args.isSilent(), "Format file reloaded.");
68
+    }
69
+
70
+    @Override
71
+    public AdditionalTabTargets getSuggestions(final int arg,
72
+                                               final IntelligentCommandContext context) {
73
+        return new AdditionalTabTargets().excludeAll();
74
+    }
75
+
76
+}

+ 4
- 0
src/main/java/com/dmdirc/ui/messages/EventFormatProvider.java View File

@@ -34,4 +34,8 @@ public interface EventFormatProvider {
34 34
      */
35 35
     Optional<EventFormat> getFormat(final Class<? extends DisplayableEvent> eventType);
36 36
 
37
+    /**
38
+     * Reload the formats for this provider.
39
+     */
40
+    void reload();
37 41
 }

+ 4
- 0
src/main/java/com/dmdirc/ui/messages/MultiEventFormatProvider.java View File

@@ -53,4 +53,8 @@ public class MultiEventFormatProvider implements EventFormatProvider {
53 53
                 .map(Optional::get);
54 54
     }
55 55
 
56
+    @Override
57
+    public void reload() {
58
+        for (final EventFormatProvider evp : providers) { evp.reload(); }
59
+    }
56 60
 }

+ 4
- 0
src/main/java/com/dmdirc/ui/messages/YamlEventFormatProvider.java View File

@@ -128,4 +128,8 @@ public class YamlEventFormatProvider implements EventFormatProvider {
128 128
         return Optional.ofNullable(formats.get(eventType.getSimpleName()));
129 129
     }
130 130
 
131
+    @Override
132
+    public void reload() {
133
+        load();
134
+    }
131 135
 }

Loading…
Cancel
Save