|
@@ -0,0 +1,100 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
|
|
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
|
+package com.dmdirc.addons.activewindow;
|
|
23
|
+
|
|
24
|
+import com.dmdirc.FrameContainer;
|
|
25
|
+import com.dmdirc.WritableFrameContainer;
|
|
26
|
+import com.dmdirc.addons.ui_swing.MainFrame;
|
|
27
|
+import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
|
|
28
|
+import com.dmdirc.commandparser.CommandArguments;
|
|
29
|
+import com.dmdirc.commandparser.CommandInfo;
|
|
30
|
+import com.dmdirc.commandparser.CommandType;
|
|
31
|
+import com.dmdirc.commandparser.commands.Command;
|
|
32
|
+import com.dmdirc.commandparser.commands.IntelligentCommand;
|
|
33
|
+import com.dmdirc.commandparser.commands.IntelligentCommand.IntelligentCommandContext;
|
|
34
|
+import com.dmdirc.commandparser.commands.context.CommandContext;
|
|
35
|
+import com.dmdirc.ui.input.AdditionalTabTargets;
|
|
36
|
+import com.dmdirc.ui.input.TabCompleter;
|
|
37
|
+
|
|
38
|
+/**
|
|
39
|
+ * Executes another command as if it were executed in the active window.
|
|
40
|
+ */
|
|
41
|
+public final class ActiveCommand extends Command implements CommandInfo,
|
|
42
|
+ IntelligentCommand {
|
|
43
|
+
|
|
44
|
+ /** Parent MainFrame. */
|
|
45
|
+ private final MainFrame mainFrame;
|
|
46
|
+
|
|
47
|
+ /**
|
|
48
|
+ * Creates a new active command.
|
|
49
|
+ *
|
|
50
|
+ * @param mainFrame Parent MainFrame
|
|
51
|
+ */
|
|
52
|
+ public ActiveCommand(final MainFrame mainFrame) {
|
|
53
|
+ super();
|
|
54
|
+ this.mainFrame = mainFrame;
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ /** {@inheritDoc} */
|
|
58
|
+ @Override
|
|
59
|
+ public void execute(final FrameContainer origin,
|
|
60
|
+ final CommandArguments args, final CommandContext context) {
|
|
61
|
+ final TextFrame frame = mainFrame.getActiveFrame();
|
|
62
|
+ if (frame.getContainer() instanceof WritableFrameContainer) {
|
|
63
|
+ ((WritableFrameContainer) frame.getContainer()).getCommandParser()
|
|
64
|
+ .parseCommand(frame.getContainer(), context.getSource(),
|
|
65
|
+ args.getArgumentsAsString());
|
|
66
|
+ }
|
|
67
|
+ }
|
|
68
|
+
|
|
69
|
+ /** {@inheritDoc} */
|
|
70
|
+ @Override
|
|
71
|
+ public String getName() {
|
|
72
|
+ return "active";
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ /** {@inheritDoc} */
|
|
76
|
+ @Override
|
|
77
|
+ public boolean showInHelp() {
|
|
78
|
+ return true;
|
|
79
|
+ }
|
|
80
|
+
|
|
81
|
+ /** {@inheritDoc} */
|
|
82
|
+ @Override
|
|
83
|
+ public CommandType getType() {
|
|
84
|
+ return CommandType.TYPE_GLOBAL;
|
|
85
|
+ }
|
|
86
|
+
|
|
87
|
+ /** {@inheritDoc} */
|
|
88
|
+ @Override
|
|
89
|
+ public String getHelp() {
|
|
90
|
+ return "active <command> - Executes the command as though it had been "
|
|
91
|
+ + "executed in the active window";
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ /** {@inheritDoc} */
|
|
95
|
+ @Override
|
|
96
|
+ public AdditionalTabTargets getSuggestions(final int arg,
|
|
97
|
+ final IntelligentCommandContext context) {
|
|
98
|
+ return TabCompleter.getIntelligentResults(arg, context, 0);
|
|
99
|
+ }
|
|
100
|
+}
|