Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor cleanup #4363

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
af430b8
Let EditorToolbar use the global KeyboardFocusManager
matthijskooijman Dec 3, 2015
c5e44c0
Use a separate RSyntaxTextArea for each editor tab
matthijskooijman Dec 3, 2015
448b8d5
Remove SketchCode::getLineCount()
matthijskooijman Dec 7, 2015
b1bb853
Let EditorTab listen for changes to the text area
matthijskooijman Dec 7, 2015
97bed6d
Do not store file contents in SketchCode
matthijskooijman Dec 8, 2015
d8e449a
Add getTabs() and getCurrentTabIndex() to Editor and use them
matthijskooijman Dec 8, 2015
3c48410
Remove current and currentIndex variables from Sketch
matthijskooijman Dec 8, 2015
e5f05a4
Remove tab switching logic from Sketch
matthijskooijman Dec 8, 2015
851a2e8
Remove SketchCodeDocument
matthijskooijman Dec 8, 2015
f3ab2ed
Remove `SketchData.setName()`
matthijskooijman Dec 8, 2015
2d1ffda
Remove unused import
matthijskooijman Dec 8, 2015
2edd4a2
Let SketchCode track if it is the primary file
matthijskooijman Dec 8, 2015
71982ab
Simplify `SketchData.removeCode()` and `indexOfCode()`
matthijskooijman Dec 8, 2015
a02cd41
Simplify sorting in SketchData
matthijskooijman Dec 8, 2015
4fb3503
Print errors while reloading externally edited files
matthijskooijman Dec 8, 2015
7e3c251
Clean up sketch loading
matthijskooijman Dec 9, 2015
4976817
Do not show invalid sketch filename warnings on reload
matthijskooijman Dec 9, 2015
f7d40a0
Merge `SketchData.sortCodes()` into `addCode()`
matthijskooijman Dec 11, 2015
e852b60
Remove UndoManager stuff from AStyle
matthijskooijman Dec 9, 2015
14f214b
Remove all highlights in `EditorTab.setText()`
matthijskooijman Dec 9, 2015
8c8207c
Remove code that preserves caret position during auto format
matthijskooijman Dec 9, 2015
1db8bf6
Replace `requestFocus()` by `requestFocusInWindow()` where applicable
matthijskooijman Dec 11, 2015
5e35929
Remove applet.html handling
matthijskooijman Dec 11, 2015
4ef5699
Remove support for a "code" folder in sketches
matthijskooijman Dec 11, 2015
d056f89
Delete `Sketch.prepare()`
matthijskooijman Dec 16, 2015
1eafdde
Rename Sketch and SketchData classes
matthijskooijman Dec 17, 2015
44d6d76
Move `isModified()` from SketchController to Sketch
matthijskooijman Dec 17, 2015
f921163
Use `SketchCode.isPrimary()` in more places
matthijskooijman Dec 17, 2015
1491798
Do not find a tab based on filename, when we have a SketchCode
matthijskooijman Dec 17, 2015
f484774
In SketchController.nameCode, only switch tabs when adding file
matthijskooijman Dec 17, 2015
2e9af61
Remove `Editor.findTabIndex(String)`, which is now unused
matthijskooijman Dec 17, 2015
8c4a125
Let `Sketch.getPrettyName()` hide extension for .ino and .pde only
matthijskooijman Dec 17, 2015
331b83e
Simplify SketchController.addFile using FileUtils.hasExtension
matthijskooijman Dec 17, 2015
98c0818
Clean up SketchController.nameCode a bit
matthijskooijman Dec 17, 2015
a20d620
Let importLibrary use `Sketch.SKETCH_EXTENSIONS`
matthijskooijman Dec 17, 2015
a84b989
Move `SketchController.prepareDataFolder()` to Sketch
matthijskooijman Dec 17, 2015
f6d9cc6
Store a SketchCode instance in RunnerException
matthijskooijman Dec 17, 2015
05323fc
Rename SketchCode to SketchFile
matthijskooijman Dec 17, 2015
56fa4cc
Remove Editor.stopHandler
matthijskooijman Dec 17, 2015
022aa4d
Remove `Base.handle*Replace()`
matthijskooijman Dec 17, 2015
7e83b77
Allow .cpp files named after the primary .ino file
matthijskooijman Dec 17, 2015
c651d65
Do not store the "data" folder in Sketch
matthijskooijman Dec 18, 2015
4735dc5
Let Sketch.getPrimaryFile return a SketchFile
matthijskooijman Dec 18, 2015
934d7ac
Change `Compiler.pathToSketch` from String to File
matthijskooijman Dec 18, 2015
79da6d0
Do not store the sketch name in Sketch
matthijskooijman Dec 18, 2015
5c00e39
Remove `Base.copyDir()`
matthijskooijman Dec 18, 2015
abe35e6
Clean up pde to ino renaming
matthijskooijman Dec 21, 2015
1c3f317
Use `File.getParentFile()` in Sketch constructor
matthijskooijman Dec 21, 2015
915df8b
Refactor file adding and renaming, and save as handling
matthijskooijman Dec 21, 2015
ce06179
Remove `Base.removeDir()` and `Base.removeDescendants()`
matthijskooijman Dec 29, 2015
15e6e04
Remove unused `Base.listFiles()` methods
matthijskooijman Dec 29, 2015
8689273
Let SketchFile store a reference to the Sketch it belongs to
matthijskooijman Dec 29, 2015
087620f
Merge `Sketch.renameFileTo()` into `SketchFile.renameTo()`
matthijskooijman Dec 29, 2015
0b79fe1
Move sketch deletion from SketchController into Sketch
matthijskooijman Dec 29, 2015
6a420d1
Rename `SketchFile.deleteFile()` to `delete()`
matthijskooijman Dec 29, 2015
300e0d7
Let `SketchFile.delete()` call `Sketch.removeFile()`
matthijskooijman Dec 29, 2015
39dea53
Let SketchFile figure out if it is primary by itself
matthijskooijman Dec 29, 2015
dfe842d
Store the build path used in Sketch
matthijskooijman Dec 29, 2015
8e954d2
Randomize the the build path name
matthijskooijman Dec 29, 2015
7b1d0c6
In `Base.handleOpen()`, compare Files rather than Strings
matthijskooijman Dec 29, 2015
c74065a
Update comment
matthijskooijman Dec 30, 2015
bf17841
TOMERGE: Fix EditorTab.setText
matthijskooijman Dec 30, 2015
3c8a3b9
TOMERGE: Fix undo menu items
matthijskooijman Dec 30, 2015
8300081
TOBEMERGED: fix error in commit 39ffb7f7
cmaglie Jan 11, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 2 additions & 49 deletions app/src/cc/arduino/packages/formatter/AStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@
import processing.app.BaseNoGui;
import processing.app.Editor;
import processing.app.helpers.FileUtils;
import processing.app.syntax.SketchTextArea;
import processing.app.tools.Tool;

import javax.swing.text.BadLocationException;
import java.io.File;
import java.io.IOException;

Expand Down Expand Up @@ -78,65 +76,20 @@ public void init(Editor editor) {

@Override
public void run() {
String originalText = editor.getText();
String originalText = editor.getCurrentTab().getText();
String formattedText = aStyleInterface.AStyleMain(originalText, formatterConfiguration);

if (formattedText.equals(originalText)) {
editor.statusNotice(tr("No changes necessary for Auto Format."));
return;
}

SketchTextArea textArea = editor.getTextArea();

int line = getLineOfOffset(textArea);
int lineOffset = getLineOffset(textArea, line);

textArea.getUndoManager().beginInternalAtomicEdit();
editor.removeAllLineHighlights();
editor.setText(formattedText);
editor.getSketch().setModified(true);
textArea.getUndoManager().endInternalAtomicEdit();

if (line != -1 && lineOffset != -1) {
try {
setCaretPosition(textArea, line, lineOffset);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
editor.getCurrentTab().setText(formattedText);

// mark as finished
editor.statusNotice(tr("Auto Format finished."));
}

private void setCaretPosition(SketchTextArea textArea, int line, int lineOffset) throws BadLocationException {
int caretPosition;
if (line < textArea.getLineCount()) {
caretPosition = Math.min(textArea.getLineStartOffset(line) + lineOffset, textArea.getLineEndOffset(line) - 1);
} else {
caretPosition = textArea.getText().length() - 1;
}
textArea.setCaretPosition(caretPosition);
}

private int getLineOffset(SketchTextArea textArea, int line) {
try {
return textArea.getCaretPosition() - textArea.getLineStartOffset(line);
} catch (BadLocationException e) {
e.printStackTrace();
}
return -1;
}

private int getLineOfOffset(SketchTextArea textArea) {
try {
return textArea.getLineOfOffset(textArea.getCaretPosition());
} catch (BadLocationException e) {
e.printStackTrace();
}
return -1;
}

@Override
public String getMenuTitle() {
return tr("Auto Format");
Expand Down
2 changes: 1 addition & 1 deletion app/src/cc/arduino/view/GoToLineNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
private void okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okActionPerformed
try {
int line = Integer.parseInt(lineNumber.getText());
editor.goToLine(line);
editor.getCurrentTab().goToLine(line);
cancelActionPerformed(evt);
} catch (Exception e) {
// ignore
Expand Down
43 changes: 20 additions & 23 deletions app/src/cc/arduino/view/findreplace/FindReplace.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import processing.app.Base;
import processing.app.Editor;
import processing.app.Sketch;
import processing.app.helpers.OSUtils;

import java.awt.*;
Expand Down Expand Up @@ -292,7 +291,7 @@ private boolean find(boolean wrap, boolean backwards, boolean searchTabs, int or
return false;
}

String text = editor.getText();
String text = editor.getCurrentTab().getText();

if (ignoreCaseBox.isSelected()) {
search = search.toLowerCase();
Expand All @@ -302,7 +301,7 @@ private boolean find(boolean wrap, boolean backwards, boolean searchTabs, int or
int nextIndex;
if (!backwards) {
// int selectionStart = editor.textarea.getSelectionStart();
int selectionEnd = editor.getSelectionStop();
int selectionEnd = editor.getCurrentTab().getSelectionStop();

nextIndex = text.indexOf(search, selectionEnd);
if (wrap && nextIndex == -1) {
Expand All @@ -311,7 +310,7 @@ private boolean find(boolean wrap, boolean backwards, boolean searchTabs, int or
}
} else {
// int selectionStart = editor.textarea.getSelectionStart();
int selectionStart = editor.getSelectionStart() - 1;
int selectionStart = editor.getCurrentTab().getSelectionStart() - 1;

if (selectionStart >= 0) {
nextIndex = text.lastIndexOf(search, selectionStart);
Expand All @@ -327,31 +326,31 @@ private boolean find(boolean wrap, boolean backwards, boolean searchTabs, int or
if (nextIndex == -1) {
// Nothing found on this tab: Search other tabs if required
if (searchTabs) {
// editor.
Sketch sketch = editor.getSketch();
if (sketch.getCodeCount() > 1) {
int realCurrentTab = sketch.getCodeIndex(sketch.getCurrentCode());
int numTabs = editor.getTabs().size();
if (numTabs > 1) {
int realCurrentTab = editor.getCurrentTabIndex();

if (originTab != realCurrentTab) {
if (originTab < 0) {
originTab = realCurrentTab;
}

if (!wrap) {
if ((!backwards && realCurrentTab + 1 >= sketch.getCodeCount()) || (backwards && realCurrentTab - 1 < 0)) {
if ((!backwards && realCurrentTab + 1 >= numTabs)
|| (backwards && realCurrentTab - 1 < 0)) {
return false; // Can't continue without wrap
}
}

if (backwards) {
sketch.handlePrevCode();
editor.selectNextTab();
this.setVisible(true);
int l = editor.getText().length() - 1;
editor.setSelection(l, l);
int l = editor.getCurrentTab().getText().length() - 1;
editor.getCurrentTab().setSelection(l, l);
} else {
sketch.handleNextCode();
editor.selectPrevTab();
this.setVisible(true);
editor.setSelection(0, 0);
editor.getCurrentTab().setSelection(0, 0);
}

return find(wrap, backwards, true, originTab);
Expand All @@ -365,7 +364,7 @@ private boolean find(boolean wrap, boolean backwards, boolean searchTabs, int or
}

if (nextIndex != -1) {
editor.setSelection(nextIndex, nextIndex + search.length());
editor.getCurrentTab().setSelection(nextIndex, nextIndex + search.length());
return true;
}

Expand All @@ -381,18 +380,17 @@ private void replace() {
return;
}

int newpos = editor.getSelectionStart() - findField.getText().length();
int newpos = editor.getCurrentTab().getSelectionStart() - findField.getText().length();
if (newpos < 0) {
newpos = 0;
}
editor.setSelection(newpos, newpos);
editor.getCurrentTab().setSelection(newpos, newpos);

boolean foundAtLeastOne = false;

if (find(false, false, searchAllFilesBox.isSelected(), -1)) {
foundAtLeastOne = true;
editor.setSelectedText(replaceField.getText());
editor.getSketch().setModified(true); // TODO is this necessary?
editor.getCurrentTab().setSelectedText(replaceField.getText());
}

if (!foundAtLeastOne) {
Expand Down Expand Up @@ -420,17 +418,16 @@ private void replaceAll() {
}

if (searchAllFilesBox.isSelected()) {
editor.getSketch().setCurrentCode(0); // select the first tab
editor.selectTab(0); // select the first tab
}

editor.setSelection(0, 0); // move to the beginning
editor.getCurrentTab().setSelection(0, 0); // move to the beginning

boolean foundAtLeastOne = false;
while (true) {
if (find(false, false, searchAllFilesBox.isSelected(), -1)) {
foundAtLeastOne = true;
editor.setSelectedText(replaceField.getText());
editor.getSketch().setModified(true); // TODO is this necessary?
editor.getCurrentTab().setSelectedText(replaceField.getText());
} else {
break;
}
Expand Down
Loading