|
@@ -33,12 +33,9 @@ import com.dmdirc.addons.ui_swing.components.AwayLabel;
|
33
|
33
|
import com.dmdirc.addons.ui_swing.components.TypingLabel;
|
34
|
34
|
import com.dmdirc.addons.ui_swing.components.inputfields.SwingInputField;
|
35
|
35
|
import com.dmdirc.addons.ui_swing.components.inputfields.SwingInputHandler;
|
36
|
|
-import com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialogFactory;
|
37
|
36
|
import com.dmdirc.config.ConfigBinding;
|
38
|
|
-import com.dmdirc.events.UserErrorEvent;
|
39
|
37
|
import com.dmdirc.interfaces.CommandController;
|
40
|
38
|
import com.dmdirc.interfaces.ui.InputWindow;
|
41
|
|
-import com.dmdirc.logger.ErrorLevel;
|
42
|
39
|
import com.dmdirc.plugins.PluginManager;
|
43
|
40
|
import com.dmdirc.ui.input.InputHandler;
|
44
|
41
|
import com.dmdirc.ui.input.TabCompleterUtils;
|
|
@@ -46,15 +43,9 @@ import com.dmdirc.ui.input.TabCompleterUtils;
|
46
|
43
|
import java.awt.BorderLayout;
|
47
|
44
|
import java.awt.Color;
|
48
|
45
|
import java.awt.Point;
|
49
|
|
-import java.awt.Toolkit;
|
50
|
|
-import java.awt.Window;
|
51
|
|
-import java.awt.datatransfer.Clipboard;
|
52
|
|
-import java.awt.datatransfer.DataFlavor;
|
53
|
|
-import java.awt.datatransfer.UnsupportedFlavorException;
|
54
|
46
|
import java.awt.event.KeyEvent;
|
55
|
47
|
import java.awt.event.MouseEvent;
|
56
|
48
|
import java.awt.event.MouseListener;
|
57
|
|
-import java.io.IOException;
|
58
|
49
|
|
59
|
50
|
import javax.inject.Provider;
|
60
|
51
|
import javax.swing.JPanel;
|
|
@@ -70,6 +61,8 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow, M
|
70
|
61
|
|
71
|
62
|
/** Serial version UID. */
|
72
|
63
|
private static final long serialVersionUID = 3;
|
|
64
|
+ /** Factory to create an {@link InputTextFramePasteAction}. */
|
|
65
|
+ private final InputTextFramePasteActionFactory inputTextFramePasteActionFactory;
|
73
|
66
|
/** Input field panel. */
|
74
|
67
|
protected JPanel inputPanel;
|
75
|
68
|
/** The InputHandler for our input field. */
|
|
@@ -84,14 +77,8 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow, M
|
84
|
77
|
private AwayLabel awayLabel;
|
85
|
78
|
/** Typing indicator label. */
|
86
|
79
|
private TypingLabel typingLabel;
|
87
|
|
- /** Main frame. */
|
88
|
|
- private final Provider<Window> parentWindow;
|
89
|
80
|
/** Plugin Manager. */
|
90
|
81
|
private final PluginManager pluginManager;
|
91
|
|
- /** Paste dialog factory. */
|
92
|
|
- private final PasteDialogFactory pasteDialogFactory;
|
93
|
|
- /** Clipboard to use for copying and pasting. */
|
94
|
|
- private final Clipboard clipboard;
|
95
|
82
|
/** The controller to use to retrieve command information. */
|
96
|
83
|
private final CommandController commandController;
|
97
|
84
|
/** The bus to dispatch input events on. */
|
|
@@ -107,15 +94,14 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow, M
|
107
|
94
|
protected InputTextFrame(
|
108
|
95
|
final TextFrameDependencies deps,
|
109
|
96
|
final Provider<SwingInputField> inputFieldProvider,
|
|
97
|
+ final InputTextFramePasteActionFactory inputTextFramePasteActionFactory,
|
110
|
98
|
final FrameContainer owner) {
|
111
|
99
|
super(owner, owner.getCommandParser(), deps);
|
112
|
100
|
|
113
|
|
- parentWindow = deps.mainWindow;
|
114
|
101
|
pluginManager = deps.pluginManager;
|
115
|
|
- pasteDialogFactory = deps.pasteDialog;
|
116
|
|
- clipboard = deps.clipboard;
|
117
|
102
|
commandController = deps.commandController;
|
118
|
103
|
eventBus = deps.eventBus;
|
|
104
|
+ this.inputTextFramePasteActionFactory = inputTextFramePasteActionFactory;
|
119
|
105
|
|
120
|
106
|
initComponents(inputFieldProvider, deps.tabCompleterUtils);
|
121
|
107
|
|
|
@@ -165,7 +151,8 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow, M
|
165
|
151
|
|
166
|
152
|
inputFieldPopup.add(new CutAction(getInputField().getTextField()));
|
167
|
153
|
inputFieldPopup.add(new CopyAction(getInputField().getTextField()));
|
168
|
|
- inputFieldPopup.add(new InputTextFramePasteAction(clipboard, this));
|
|
154
|
+ inputFieldPopup.add(inputTextFramePasteActionFactory.getInputTextFramePasteAction(this,
|
|
155
|
+ inputField, getContainer()));
|
169
|
156
|
inputFieldPopup.setOpaque(true);
|
170
|
157
|
inputFieldPopup.setLightWeightPopupEnabled(true);
|
171
|
158
|
|
|
@@ -181,12 +168,11 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow, M
|
181
|
168
|
private void initInputField() {
|
182
|
169
|
UIUtilities.addUndoManager(eventBus, getInputField().getTextField());
|
183
|
170
|
|
184
|
|
- getInputField().getActionMap().put("paste",
|
185
|
|
- new InputTextFramePasteAction(clipboard, this));
|
|
171
|
+ getInputField().getActionMap().put("paste", inputTextFramePasteActionFactory
|
|
172
|
+ .getInputTextFramePasteAction(this, inputField, getContainer()));
|
186
|
173
|
getInputField().getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(
|
187
|
174
|
"shift INSERT"), "paste");
|
188
|
|
- getInputField().getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(
|
189
|
|
- "ctrl V"), "paste");
|
|
175
|
+ getInputField().getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ctrl V"), "paste");
|
190
|
176
|
}
|
191
|
177
|
|
192
|
178
|
/**
|
|
@@ -250,82 +236,6 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow, M
|
250
|
236
|
}
|
251
|
237
|
}
|
252
|
238
|
|
253
|
|
- /** Checks and pastes text. */
|
254
|
|
- public void doPaste() {
|
255
|
|
- try {
|
256
|
|
- if (!clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor)) {
|
257
|
|
- return;
|
258
|
|
- }
|
259
|
|
- } catch (final IllegalStateException ex) {
|
260
|
|
- eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ex,
|
261
|
|
- "Unable to past from clipboard.", ""));
|
262
|
|
- return;
|
263
|
|
- }
|
264
|
|
-
|
265
|
|
- try {
|
266
|
|
- //get the contents of the input field and combine it with the
|
267
|
|
- //clipboard
|
268
|
|
- doPaste((String) Toolkit.getDefaultToolkit()
|
269
|
|
- .getSystemClipboard().getData(DataFlavor.stringFlavor));
|
270
|
|
- } catch (final IOException ex) {
|
271
|
|
- eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ex,
|
272
|
|
- "Unable to get clipboard contents: " + ex.getMessage(), ""));
|
273
|
|
- } catch (final UnsupportedFlavorException ex) {
|
274
|
|
- eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ex,
|
275
|
|
- "Unsupported clipboard type", ""));
|
276
|
|
- }
|
277
|
|
- }
|
278
|
|
-
|
279
|
|
- /**
|
280
|
|
- * Pastes the specified content into the input area.
|
281
|
|
- *
|
282
|
|
- * @param clipboard The contents of the clipboard to be pasted
|
283
|
|
- *
|
284
|
|
- * @since 0.6.3m1
|
285
|
|
- */
|
286
|
|
- protected void doPaste(final String clipboard) {
|
287
|
|
- final String inputFieldText = getInputField().getText();
|
288
|
|
- //Get the text that would result from the paste (inputfield
|
289
|
|
- //- selection + clipboard)
|
290
|
|
- final String text = inputFieldText.substring(0, getInputField().
|
291
|
|
- getSelectionStart()) + clipboard + inputFieldText.substring(
|
292
|
|
- getInputField().getSelectionEnd());
|
293
|
|
- final String[] clipboardLines = getSplitLine(text);
|
294
|
|
- //check theres something to paste
|
295
|
|
- if (clipboardLines.length > 1) {
|
296
|
|
- //Clear the input field
|
297
|
|
- inputField.setText("");
|
298
|
|
- final Integer pasteTrigger = getContainer().getConfigManager().
|
299
|
|
- getOptionInt("ui", "pasteProtectionLimit", false);
|
300
|
|
- //check whether the number of lines is over the limit
|
301
|
|
- if (pasteTrigger != null && getContainer().getNumLines(text)
|
302
|
|
- > pasteTrigger) {
|
303
|
|
- //show the multi line paste dialog
|
304
|
|
- pasteDialogFactory.getPasteDialog(this, text, parentWindow.get()).
|
305
|
|
- displayOrRequestFocus();
|
306
|
|
- } else {
|
307
|
|
- //send the lines
|
308
|
|
- for (final String clipboardLine : clipboardLines) {
|
309
|
|
- getContainer().sendLine(clipboardLine);
|
310
|
|
- }
|
311
|
|
- }
|
312
|
|
- } else {
|
313
|
|
- //put clipboard text in input field
|
314
|
|
- inputField.replaceSelection(clipboard);
|
315
|
|
- }
|
316
|
|
- }
|
317
|
|
-
|
318
|
|
- /**
|
319
|
|
- * Splits the line on all line endings.
|
320
|
|
- *
|
321
|
|
- * @param line Line that will be split
|
322
|
|
- *
|
323
|
|
- * @return Split line array
|
324
|
|
- */
|
325
|
|
- private String[] getSplitLine(final String line) {
|
326
|
|
- return line.replace("\r\n", "\n").replace('\r', '\n').split("\n");
|
327
|
|
- }
|
328
|
|
-
|
329
|
239
|
@ConfigBinding(domain="ui", key="inputbackgroundcolour",
|
330
|
240
|
fallbacks = {"ui", "backgroundcolour"}, invocation = EDTInvocation.class)
|
331
|
241
|
public void handleInputBackgroundColour(final String value) {
|