mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-22 11:52:14 +01:00
982d4f3fbf
RSyntaxTextArea appears to support using a single instance and replacing the underlying text and document when switching between tabs, but in practice this support is not complete and even though the RSyntaxTextArea developers did some work to improve the situation, they recommend to just use a seperate instance for each tab. This commit implements exactly that. A new class EditorTab is introduce to wrap the RSyntaxTextArea and containing scroll pane, and to encapsulate the code related to handling the text area itself. Doing so removes some quirks and prepares for some later additions. In particular, error highlights are now no longer shared between all tabs, which was previously the case. This commit mostly moves code from Editor into EditorTab, and updates the callers to use getCurrentTab() and call methods on the result instead of calling them on Editor. Some code is added to take care of creating multiple EditorTab objects and switching between them. Some small changes have been made to make the flow of opening files work, though these are mostly a bit hacky. While moving code, changes to the rest of the code were kept minimal, retaining existing interfaces as much as possible. This sometimes result in less than ideal code, which should be cleaned up in subsequent commits. The SketchCodeDocument class has been pretty much emptied out, since it was mostly used to store things for tabs in the background, which are now just stored in each RSyntaxTextArea separately. The last remaining bits of this class can probably be moved or implemented differently later, so it can be removed. The entire flow of working with sketches and files needs to be cleaned up next, so no thorough attempt at testing this commit was done. It is likely that there are plenty of corner cases and race conditions, which will be fixed once the reset of the code is cleaned up. Fixes #3441
149 lines
5.9 KiB
Java
149 lines
5.9 KiB
Java
/*
|
|
* This file is part of Arduino.
|
|
*
|
|
* Arduino is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*
|
|
* As a special exception, you may use this file as part of a free software
|
|
* library without restriction. Specifically, if other files instantiate
|
|
* templates or use macros or inline functions from this file, or you compile
|
|
* this file and link it with other files to produce an executable, this
|
|
* file does not by itself cause the resulting executable to be covered by
|
|
* the GNU General Public License. This exception does not however
|
|
* invalidate any other reasons why the executable file might be covered by
|
|
* the GNU General Public License.
|
|
*
|
|
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
|
*/
|
|
|
|
package cc.arduino.view;
|
|
|
|
import processing.app.Base;
|
|
import processing.app.Editor;
|
|
|
|
import java.awt.event.WindowEvent;
|
|
|
|
import static processing.app.I18n.tr;
|
|
|
|
public class GoToLineNumber extends javax.swing.JDialog {
|
|
|
|
private final Editor editor;
|
|
|
|
public GoToLineNumber(Editor editor) {
|
|
super(editor);
|
|
this.editor = editor;
|
|
initComponents();
|
|
|
|
Base.registerWindowCloseKeys(getRootPane(), this::cancelActionPerformed);
|
|
}
|
|
|
|
/**
|
|
* This method is called from within the constructor to initialize the form.
|
|
* WARNING: Do NOT modify this code. The content of this method is always
|
|
* regenerated by the Form Editor.
|
|
*/
|
|
@SuppressWarnings("unchecked")
|
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
|
private void initComponents() {
|
|
|
|
javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
|
|
lineNumber = new javax.swing.JTextField();
|
|
javax.swing.JButton cancel = new javax.swing.JButton();
|
|
javax.swing.JButton ok = new javax.swing.JButton();
|
|
|
|
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
|
setTitle(tr("Go to line"));
|
|
setModal(true);
|
|
setResizable(false);
|
|
|
|
jLabel1.setText(tr("Line number:"));
|
|
|
|
lineNumber.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
lineNumberActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
cancel.setText(tr("Cancel"));
|
|
cancel.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
cancelActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
ok.setText(tr("OK"));
|
|
ok.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
okActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
|
getContentPane().setLayout(layout);
|
|
layout.setHorizontalGroup(
|
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addComponent(jLabel1)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addComponent(lineNumber, javax.swing.GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE))
|
|
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
|
.addGap(0, 0, Short.MAX_VALUE)
|
|
.addComponent(ok)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addComponent(cancel)))
|
|
.addContainerGap())
|
|
);
|
|
layout.setVerticalGroup(
|
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
|
.addComponent(jLabel1)
|
|
.addComponent(lineNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
|
.addComponent(cancel)
|
|
.addComponent(ok))
|
|
.addContainerGap())
|
|
);
|
|
|
|
pack();
|
|
}// </editor-fold>//GEN-END:initComponents
|
|
|
|
private void okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okActionPerformed
|
|
try {
|
|
int line = Integer.parseInt(lineNumber.getText());
|
|
editor.getCurrentTab().goToLine(line);
|
|
cancelActionPerformed(evt);
|
|
} catch (Exception e) {
|
|
// ignore
|
|
}
|
|
}//GEN-LAST:event_okActionPerformed
|
|
|
|
private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed
|
|
dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
|
|
}//GEN-LAST:event_cancelActionPerformed
|
|
|
|
private void lineNumberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lineNumberActionPerformed
|
|
okActionPerformed(evt);
|
|
}//GEN-LAST:event_lineNumberActionPerformed
|
|
|
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
|
private javax.swing.JTextField lineNumber;
|
|
// End of variables declaration//GEN-END:variables
|
|
}
|