-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathGoToAction.java
More file actions
86 lines (69 loc) · 2.29 KB
/
GoToAction.java
File metadata and controls
86 lines (69 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* 11/14/2003
*
* GoToAction.java - Action to "goto" a specific line number in RText.
* Copyright (C) 2003 Robert Futrell
* https://bobbylight.github.io/RText/
* Licensed under a modified BSD license.
* See the included license file for details.
*/
package org.fife.rtext.actions;
import java.awt.event.ActionEvent;
import java.util.ResourceBundle;
import javax.swing.Icon;
import javax.swing.JOptionPane;
import javax.swing.text.BadLocationException;
import org.fife.rsta.ui.GoToDialog;
import org.fife.rtext.AbstractMainView;
import org.fife.rtext.RText;
import org.fife.rtext.RTextEditorPane;
import org.fife.ui.app.AppAction;
import org.fife.util.MacOSUtil;
/**
* Action used by an <code>AbstractMainView</code> to "goto" a specific line
* number in the current document.
*
* @author Robert Futrell
* @version 1.0
*/
class GoToAction extends AppAction<RText> {
/**
* Constructor.
*
* @param owner The parent RText instance.
* @param msg The resource bundle to use for localization.
* @param icon The icon associated with the action.
*/
GoToAction(RText owner, ResourceBundle msg, Icon icon) {
super(owner, msg, "GoToAction");
setIcon(icon);
}
@Override
public void actionPerformed(ActionEvent e) {
RText rtext = getApplication();
AbstractMainView mainView = rtext.getMainView();
if (mainView.goToDialog==null) {
mainView.goToDialog = new GoToDialog(rtext);
MacOSUtil.applyMacOsTweaks(mainView.goToDialog);
mainView.goToDialog.setErrorDialogTitle(
rtext.getString("ErrorDialogTitle"));
}
// Prepare and show the GoTo Line dialog.
RTextEditorPane editor = mainView.getCurrentTextArea();
mainView.goToDialog.setMaxLineNumberAllowed(editor.getLineCount());
mainView.goToDialog.setVisible(true);
// If a real line number is returned, go to that line number.
int line = mainView.goToDialog.getLineNumber();
if (line>0) {
try {
editor.setCaretPosition(editor.getLineStartOffset(line-1));
} catch (BadLocationException ble) {
String temp = rtext.getString("InternalErrorILN",
Integer.toString(line));
JOptionPane.showMessageDialog(rtext, temp,
rtext.getString("ErrorDialogTitle"),
JOptionPane.ERROR_MESSAGE);
}
}
}
}