Skip to content

Commit fd79bfe

Browse files
author
Federico Fissore
committed
Implemented Go to Line menu and shortcut CTRL+L. Fixes #976
1 parent 5304904 commit fd79bfe

File tree

4 files changed

+283
-0
lines changed

4 files changed

+283
-0
lines changed

Diff for: app/src/cc/arduino/view/GoToLineNumber.form

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
4+
<Properties>
5+
<Property name="defaultCloseOperation" type="int" value="2"/>
6+
<Property name="title" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
7+
<Connection code="tr(&quot;Go to line&quot;)" type="code"/>
8+
</Property>
9+
<Property name="modal" type="boolean" value="true"/>
10+
<Property name="resizable" type="boolean" value="false"/>
11+
</Properties>
12+
<SyntheticProperties>
13+
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
14+
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
15+
</SyntheticProperties>
16+
<AuxValues>
17+
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
18+
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
19+
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
20+
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
21+
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
22+
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
23+
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
24+
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
25+
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
26+
</AuxValues>
27+
28+
<Layout>
29+
<DimensionLayout dim="0">
30+
<Group type="103" groupAlignment="0" attributes="0">
31+
<Group type="102" attributes="0">
32+
<EmptySpace max="-2" attributes="0"/>
33+
<Group type="103" groupAlignment="0" attributes="0">
34+
<Group type="102" alignment="0" attributes="0">
35+
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
36+
<EmptySpace max="-2" attributes="0"/>
37+
<Component id="lineNumber" pref="203" max="32767" attributes="0"/>
38+
</Group>
39+
<Group type="102" alignment="1" attributes="0">
40+
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
41+
<Component id="ok" min="-2" max="-2" attributes="0"/>
42+
<EmptySpace max="-2" attributes="0"/>
43+
<Component id="cancel" min="-2" max="-2" attributes="0"/>
44+
</Group>
45+
</Group>
46+
<EmptySpace max="-2" attributes="0"/>
47+
</Group>
48+
</Group>
49+
</DimensionLayout>
50+
<DimensionLayout dim="1">
51+
<Group type="103" groupAlignment="0" attributes="0">
52+
<Group type="102" alignment="0" attributes="0">
53+
<EmptySpace max="-2" attributes="0"/>
54+
<Group type="103" groupAlignment="3" attributes="0">
55+
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
56+
<Component id="lineNumber" alignment="3" min="-2" max="-2" attributes="0"/>
57+
</Group>
58+
<EmptySpace max="32767" attributes="0"/>
59+
<Group type="103" groupAlignment="3" attributes="0">
60+
<Component id="cancel" alignment="3" min="-2" max="-2" attributes="0"/>
61+
<Component id="ok" alignment="3" min="-2" max="-2" attributes="0"/>
62+
</Group>
63+
<EmptySpace max="-2" attributes="0"/>
64+
</Group>
65+
</Group>
66+
</DimensionLayout>
67+
</Layout>
68+
<SubComponents>
69+
<Component class="javax.swing.JLabel" name="jLabel1">
70+
<Properties>
71+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
72+
<Connection code="tr(&quot;Line number:&quot;)" type="code"/>
73+
</Property>
74+
</Properties>
75+
<AuxValues>
76+
<AuxValue name="JavaCodeGenerator_VariableLocal" type="java.lang.Boolean" value="true"/>
77+
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
78+
</AuxValues>
79+
</Component>
80+
<Component class="javax.swing.JTextField" name="lineNumber">
81+
<Events>
82+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="lineNumberActionPerformed"/>
83+
</Events>
84+
</Component>
85+
<Component class="javax.swing.JButton" name="cancel">
86+
<Properties>
87+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
88+
<Connection code="tr(&quot;Cancel&quot;)" type="code"/>
89+
</Property>
90+
</Properties>
91+
<Events>
92+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cancelActionPerformed"/>
93+
</Events>
94+
<AuxValues>
95+
<AuxValue name="JavaCodeGenerator_VariableLocal" type="java.lang.Boolean" value="true"/>
96+
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
97+
</AuxValues>
98+
</Component>
99+
<Component class="javax.swing.JButton" name="ok">
100+
<Properties>
101+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
102+
<Connection code="tr(&quot;OK&quot;)" type="code"/>
103+
</Property>
104+
</Properties>
105+
<Events>
106+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="okActionPerformed"/>
107+
</Events>
108+
<AuxValues>
109+
<AuxValue name="JavaCodeGenerator_VariableLocal" type="java.lang.Boolean" value="true"/>
110+
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
111+
</AuxValues>
112+
</Component>
113+
</SubComponents>
114+
</Form>

Diff for: app/src/cc/arduino/view/GoToLineNumber.java

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
* This file is part of Arduino.
3+
*
4+
* Arduino is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
* As a special exception, you may use this file as part of a free software
19+
* library without restriction. Specifically, if other files instantiate
20+
* templates or use macros or inline functions from this file, or you compile
21+
* this file and link it with other files to produce an executable, this
22+
* file does not by itself cause the resulting executable to be covered by
23+
* the GNU General Public License. This exception does not however
24+
* invalidate any other reasons why the executable file might be covered by
25+
* the GNU General Public License.
26+
*
27+
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
28+
*/
29+
30+
package cc.arduino.view;
31+
32+
import processing.app.Base;
33+
import processing.app.Editor;
34+
35+
import java.awt.event.WindowEvent;
36+
37+
import static processing.app.I18n.tr;
38+
39+
public class GoToLineNumber extends javax.swing.JDialog {
40+
41+
private final Editor editor;
42+
43+
public GoToLineNumber(Editor editor) {
44+
super(editor);
45+
this.editor = editor;
46+
initComponents();
47+
48+
Base.registerWindowCloseKeys(getRootPane(), this::cancelActionPerformed);
49+
}
50+
51+
/**
52+
* This method is called from within the constructor to initialize the form.
53+
* WARNING: Do NOT modify this code. The content of this method is always
54+
* regenerated by the Form Editor.
55+
*/
56+
@SuppressWarnings("unchecked")
57+
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
58+
private void initComponents() {
59+
60+
javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
61+
lineNumber = new javax.swing.JTextField();
62+
javax.swing.JButton cancel = new javax.swing.JButton();
63+
javax.swing.JButton ok = new javax.swing.JButton();
64+
65+
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
66+
setTitle(tr("Go to line"));
67+
setModal(true);
68+
setResizable(false);
69+
70+
jLabel1.setText(tr("Line number:"));
71+
72+
lineNumber.addActionListener(new java.awt.event.ActionListener() {
73+
public void actionPerformed(java.awt.event.ActionEvent evt) {
74+
lineNumberActionPerformed(evt);
75+
}
76+
});
77+
78+
cancel.setText(tr("Cancel"));
79+
cancel.addActionListener(new java.awt.event.ActionListener() {
80+
public void actionPerformed(java.awt.event.ActionEvent evt) {
81+
cancelActionPerformed(evt);
82+
}
83+
});
84+
85+
ok.setText(tr("OK"));
86+
ok.addActionListener(new java.awt.event.ActionListener() {
87+
public void actionPerformed(java.awt.event.ActionEvent evt) {
88+
okActionPerformed(evt);
89+
}
90+
});
91+
92+
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
93+
getContentPane().setLayout(layout);
94+
layout.setHorizontalGroup(
95+
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
96+
.addGroup(layout.createSequentialGroup()
97+
.addContainerGap()
98+
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
99+
.addGroup(layout.createSequentialGroup()
100+
.addComponent(jLabel1)
101+
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
102+
.addComponent(lineNumber, javax.swing.GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE))
103+
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
104+
.addGap(0, 0, Short.MAX_VALUE)
105+
.addComponent(ok)
106+
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
107+
.addComponent(cancel)))
108+
.addContainerGap())
109+
);
110+
layout.setVerticalGroup(
111+
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
112+
.addGroup(layout.createSequentialGroup()
113+
.addContainerGap()
114+
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
115+
.addComponent(jLabel1)
116+
.addComponent(lineNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
117+
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
118+
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
119+
.addComponent(cancel)
120+
.addComponent(ok))
121+
.addContainerGap())
122+
);
123+
124+
pack();
125+
}// </editor-fold>//GEN-END:initComponents
126+
127+
private void okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okActionPerformed
128+
try {
129+
int line = Integer.parseInt(lineNumber.getText());
130+
editor.goToLine(line);
131+
cancelActionPerformed(evt);
132+
} catch (Exception e) {
133+
// ignore
134+
}
135+
}//GEN-LAST:event_okActionPerformed
136+
137+
private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed
138+
dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
139+
}//GEN-LAST:event_cancelActionPerformed
140+
141+
private void lineNumberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lineNumberActionPerformed
142+
okActionPerformed(evt);
143+
}//GEN-LAST:event_lineNumberActionPerformed
144+
145+
// Variables declaration - do not modify//GEN-BEGIN:variables
146+
private javax.swing.JTextField lineNumber;
147+
// End of variables declaration//GEN-END:variables
148+
}

Diff for: app/src/processing/app/Editor.java

+20
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import cc.arduino.packages.MonitorFactory;
2727
import cc.arduino.packages.Uploader;
2828
import cc.arduino.packages.uploaders.SerialUploader;
29+
import cc.arduino.view.GoToLineNumber;
2930
import cc.arduino.view.StubMenuListener;
3031
import cc.arduino.view.findreplace.FindReplace;
3132
import com.jcraft.jsch.JSchException;
@@ -1446,6 +1447,14 @@ public void actionPerformed(ActionEvent e) {
14461447
});
14471448
menu.add(selectAllItem);
14481449

1450+
JMenuItem gotoLine = newJMenuItem(tr("Go to line..."), 'L');
1451+
gotoLine.addActionListener(e -> {
1452+
GoToLineNumber goToLineNumber = new GoToLineNumber(Editor.this);
1453+
goToLineNumber.setLocationRelativeTo(Editor.this);
1454+
goToLineNumber.setVisible(true);
1455+
});
1456+
menu.add(gotoLine);
1457+
14491458
menu.addSeparator();
14501459

14511460
JMenuItem commentItem = newJMenuItem(tr("Comment/Uncomment"), '/');
@@ -3008,4 +3017,15 @@ public void popupMenuCanceled(PopupMenuEvent e) {
30083017

30093018
}
30103019

3020+
public void goToLine(int line) {
3021+
if (line <= 0) {
3022+
return;
3023+
}
3024+
try {
3025+
textarea.setCaretPosition(textarea.getLineStartOffset(line - 1));
3026+
} catch (BadLocationException e) {
3027+
//ignore
3028+
}
3029+
}
3030+
30113031
}

Diff for: build/shared/revisions.txt

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ARDUINO 1.6.6
2020
* Update notifications: when updates are available from either Library or Boards Managers, a popup will be shown
2121
* Introducing arduino-builder, a command line tool that properly calls gcc. Fixes lots of issues about buggy preprocessing.
2222
* Each open sketch gets built in its own folder, allowing the IDE to recycle previous compilations and being much faster
23+
* "Go to line": CTRL+L or Edit > Go to line... will open a dialog where you can type the line number where you want the editor to jump to
2324

2425
[libraries]
2526
* Bridge: YunClient.connected() returns true if there are bytes available for read. Thanks @RobAtticus

0 commit comments

Comments
 (0)