Quellcode durchsuchen

Add /reloadformat command. Issue #742

pull/775/head
Shane Mc Cormack vor 7 Jahren
Ursprung
Commit
b90696a3b7

+ 6
- 0
src/main/java/com/dmdirc/commandparser/commands/CommandModule.java Datei anzeigen

38
 import com.dmdirc.commandparser.commands.global.LoadPlugin;
38
 import com.dmdirc.commandparser.commands.global.LoadPlugin;
39
 import com.dmdirc.commandparser.commands.global.NewServer;
39
 import com.dmdirc.commandparser.commands.global.NewServer;
40
 import com.dmdirc.commandparser.commands.global.OpenWindow;
40
 import com.dmdirc.commandparser.commands.global.OpenWindow;
41
+import com.dmdirc.commandparser.commands.global.ReloadFormat;
41
 import com.dmdirc.commandparser.commands.global.ReloadIdentities;
42
 import com.dmdirc.commandparser.commands.global.ReloadIdentities;
42
 import com.dmdirc.commandparser.commands.global.ReloadPlugin;
43
 import com.dmdirc.commandparser.commands.global.ReloadPlugin;
43
 import com.dmdirc.commandparser.commands.global.SaveConfig;
44
 import com.dmdirc.commandparser.commands.global.SaveConfig;
285
         return new SimpleCommandDetails(command, SaveConfig.INFO);
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
     @Provides(type = Provides.Type.SET)
294
     @Provides(type = Provides.Type.SET)
289
     public CommandDetails getSetCommand(final SetCommand command) {
295
     public CommandDetails getSetCommand(final SetCommand command) {
290
         return new SimpleCommandDetails(command, SetCommand.INFO);
296
         return new SimpleCommandDetails(command, SetCommand.INFO);

+ 77
- 0
src/main/java/com/dmdirc/commandparser/commands/global/ReloadFormat.java Datei anzeigen

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.interfaces.config.IdentityController;
30
+import com.dmdirc.ui.input.AdditionalTabTargets;
31
+import com.dmdirc.ui.messages.EventFormatProvider;
32
+import com.dmdirc.ui.messages.MultiEventFormatProvider;
33
+import com.dmdirc.ui.messages.YamlEventFormatProvider;
34
+
35
+import javax.annotation.Nonnull;
36
+import javax.inject.Inject;
37
+
38
+/**
39
+ * Allows the user to save the config file.
40
+ */
41
+public final class ReloadFormat extends BaseCommand implements IntelligentCommand {
42
+
43
+    /** A command info object for this command. */
44
+    public static final CommandInfo INFO = new BaseCommandInfo("reloadformat",
45
+            "reloadformat - force the client to reload the format.yml file",
46
+            CommandType.TYPE_GLOBAL);
47
+    /** Format provider for events. */
48
+    private final EventFormatProvider formatProvider;
49
+
50
+    /**
51
+     * Creates a new instance of the {@link ReloadFormat} command.
52
+     *
53
+     * @param controller         The controller to use for command information.
54
+     * @param identityController The controller to save identities on.
55
+     */
56
+    @Inject
57
+    public ReloadFormat(final CommandController controller,
58
+                        final IdentityController identityController,
59
+                        final EventFormatProvider formatProvider) {
60
+        super(controller);
61
+        this.formatProvider = formatProvider;
62
+    }
63
+
64
+    @Override
65
+    public void execute(@Nonnull final WindowModel origin,
66
+                        final CommandArguments args, final CommandContext context) {
67
+        formatProvider.reload();
68
+        showOutput(origin, args.isSilent(), "Format file reloaded.");
69
+    }
70
+
71
+    @Override
72
+    public AdditionalTabTargets getSuggestions(final int arg,
73
+                                               final IntelligentCommandContext context) {
74
+        return new AdditionalTabTargets().excludeAll();
75
+    }
76
+
77
+}

+ 4
- 0
src/main/java/com/dmdirc/ui/messages/EventFormatProvider.java Datei anzeigen

34
      */
34
      */
35
     Optional<EventFormat> getFormat(final Class<? extends DisplayableEvent> eventType);
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 Datei anzeigen

53
                 .map(Optional::get);
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 Datei anzeigen

128
         return Optional.ofNullable(formats.get(eventType.getSimpleName()));
128
         return Optional.ofNullable(formats.get(eventType.getSimpleName()));
129
     }
129
     }
130
 
130
 
131
+    @Override
132
+    public void reload() {
133
+        load();
134
+    }
131
 }
135
 }

Laden…
Abbrechen
Speichern