mirror of
https://github.com/processing/processing4.git
synced 2026-02-11 09:39:19 +01:00
handle storing caret and scroll bar positions for tabs
This commit is contained in:
@@ -148,11 +148,6 @@ public class Sketch {
|
||||
codeFolder = new File(folder, "code");
|
||||
dataFolder = new File(folder, "data");
|
||||
|
||||
//File libraryFolder = new File(folder, "library");
|
||||
//if (libraryFolder.exists()) {
|
||||
//library = true;
|
||||
//}
|
||||
|
||||
// get list of files in the sketch folder
|
||||
String list[] = folder.list();
|
||||
|
||||
@@ -195,16 +190,12 @@ public class Sketch {
|
||||
JAVA);
|
||||
}
|
||||
}
|
||||
//System.out.println("code count 2 is " + codeCount);
|
||||
|
||||
// remove any entries that didn't load properly
|
||||
int index = 0;
|
||||
while (index < codeCount) {
|
||||
//System.out.println("code is " + code);
|
||||
//System.out.println(index + " " + code[index]);
|
||||
if ((code[index] == null) ||
|
||||
(code[index].program == null)) {
|
||||
//hide(index); // although will this file be hidable?
|
||||
for (int i = index+1; i < codeCount; i++) {
|
||||
code[i-1] = code[i];
|
||||
}
|
||||
@@ -214,14 +205,11 @@ public class Sketch {
|
||||
index++;
|
||||
}
|
||||
}
|
||||
//System.out.println("code count 3 is " + codeCount);
|
||||
|
||||
// move the main class to the first tab
|
||||
// start at 1, if it's at zero, don't bother
|
||||
//System.out.println("looking for " + mainFilename);
|
||||
for (int i = 1; i < codeCount; i++) {
|
||||
if (code[i].file.getName().equals(mainFilename)) {
|
||||
//System.out.println("found main code at slot " + i);
|
||||
SketchCode temp = code[0];
|
||||
code[0] = code[i];
|
||||
code[i] = temp;
|
||||
@@ -233,7 +221,6 @@ public class Sketch {
|
||||
sortCode();
|
||||
|
||||
// set the main file to be the current tab
|
||||
//current = code[0];
|
||||
setCurrent(0);
|
||||
}
|
||||
|
||||
@@ -277,9 +264,6 @@ public class Sketch {
|
||||
// make sure the user didn't hide the sketch folder
|
||||
ensureExistence();
|
||||
|
||||
//System.out.println("new code");
|
||||
// ask for name of new file
|
||||
// maybe just popup a text area?
|
||||
renamingCode = false;
|
||||
editor.status.edit("Name for new file:", "");
|
||||
}
|
||||
@@ -289,10 +273,6 @@ public class Sketch {
|
||||
// make sure the user didn't hide the sketch folder
|
||||
ensureExistence();
|
||||
|
||||
// don't allow rename of the main code
|
||||
//if (current == code[0]) return;
|
||||
// TODO maybe gray out the menu on setCurrent(0)
|
||||
|
||||
// ask for new name of file (internal to window)
|
||||
// TODO maybe just popup a text area?
|
||||
renamingCode = true;
|
||||
@@ -926,6 +906,9 @@ public class Sketch {
|
||||
// get the text currently being edited
|
||||
if (current != null) {
|
||||
current.program = editor.getText();
|
||||
current.selectionStart = editor.textarea.getSelectionStart();
|
||||
current.selectionStop = editor.textarea.getSelectionEnd();
|
||||
current.scrollPosition = editor.textarea.getScrollPosition();
|
||||
}
|
||||
|
||||
current = code[which];
|
||||
@@ -935,8 +918,11 @@ public class Sketch {
|
||||
// (so they don't undo back to the other file.. whups!)
|
||||
editor.setText(current.program, true);
|
||||
|
||||
// and i'll personally make a note of the change
|
||||
//current = which;
|
||||
// set stored caret and scroll positions
|
||||
editor.textarea.setScrollPosition(current.scrollPosition);
|
||||
editor.textarea.select(current.selectionStart, current.selectionStop);
|
||||
//editor.textarea.setSelectionStart(current.selectionStart);
|
||||
//editor.textarea.setSelectionEnd(current.selectionStop);
|
||||
|
||||
editor.header.rebuild();
|
||||
}
|
||||
|
||||
@@ -28,11 +28,17 @@ import java.io.*;
|
||||
|
||||
|
||||
public class SketchCode {
|
||||
String name; // pretty name (no extension), not the full file name
|
||||
File file;
|
||||
int flavor;
|
||||
public String name; // pretty name (no extension), not the full file name
|
||||
public File file;
|
||||
public int flavor;
|
||||
|
||||
public String program;
|
||||
|
||||
// saved positions from last time this tab was used
|
||||
public int selectionStart;
|
||||
public int selectionStop;
|
||||
public int scrollPosition;
|
||||
|
||||
String program;
|
||||
public boolean modified;
|
||||
//SketchHistory history; // TODO add history information
|
||||
|
||||
|
||||
@@ -140,6 +140,23 @@ public class JEditTextArea extends JComponent
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get current position of the vertical scroll bar. [fry]
|
||||
*/
|
||||
public int getScrollPosition() {
|
||||
return vertical.getValue();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set position of the vertical scroll bar. [fry]
|
||||
*/
|
||||
public void setScrollPosition(int what) {
|
||||
vertical.setValue(what);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns if this component can be traversed by pressing
|
||||
* the Tab key. This returns false.
|
||||
@@ -886,12 +903,12 @@ public class JEditTextArea extends JComponent
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the specified substring of the document into a segment.
|
||||
* If the offsets are invalid, the segment will contain a null string.
|
||||
* @param start The start offset
|
||||
* @param len The length of the substring
|
||||
* @param segment The segment
|
||||
*/
|
||||
* Copies the specified substring of the document into a segment.
|
||||
* If the offsets are invalid, the segment will contain a null string.
|
||||
* @param start The start offset
|
||||
* @param len The length of the substring
|
||||
* @param segment The segment
|
||||
*/
|
||||
public final void getText(int start, int len, Segment segment)
|
||||
{
|
||||
try
|
||||
@@ -906,10 +923,10 @@ public class JEditTextArea extends JComponent
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the text on the specified line.
|
||||
* @param lineIndex The line
|
||||
* @return The text, or null if the line is invalid
|
||||
*/
|
||||
* Returns the text on the specified line.
|
||||
* @param lineIndex The line
|
||||
* @return The text, or null if the line is invalid
|
||||
*/
|
||||
public final String getLineText(int lineIndex)
|
||||
{
|
||||
int start = getLineStartOffset(lineIndex);
|
||||
@@ -917,10 +934,10 @@ public class JEditTextArea extends JComponent
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the text on the specified line into a segment. If the line
|
||||
* is invalid, the segment will contain a null string.
|
||||
* @param lineIndex The line
|
||||
*/
|
||||
* Copies the text on the specified line into a segment. If the line
|
||||
* is invalid, the segment will contain a null string.
|
||||
* @param lineIndex The line
|
||||
*/
|
||||
public final void getLineText(int lineIndex, Segment segment)
|
||||
{
|
||||
int start = getLineStartOffset(lineIndex);
|
||||
@@ -928,17 +945,17 @@ public class JEditTextArea extends JComponent
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the selection start offset.
|
||||
*/
|
||||
* Returns the selection start offset.
|
||||
*/
|
||||
public final int getSelectionStart()
|
||||
{
|
||||
return selectionStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset where the selection starts on the specified
|
||||
* line.
|
||||
*/
|
||||
* Returns the offset where the selection starts on the specified
|
||||
* line.
|
||||
*/
|
||||
public int getSelectionStart(int line)
|
||||
{
|
||||
if(line == selectionStartLine)
|
||||
@@ -959,36 +976,36 @@ public class JEditTextArea extends JComponent
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the selection start line.
|
||||
*/
|
||||
* Returns the selection start line.
|
||||
*/
|
||||
public final int getSelectionStartLine()
|
||||
{
|
||||
return selectionStartLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the selection start. The new selection will be the new
|
||||
* selection start and the old selection end.
|
||||
* @param selectionStart The selection start
|
||||
* @see #select(int,int)
|
||||
*/
|
||||
* Sets the selection start. The new selection will be the new
|
||||
* selection start and the old selection end.
|
||||
* @param selectionStart The selection start
|
||||
* @see #select(int,int)
|
||||
*/
|
||||
public final void setSelectionStart(int selectionStart)
|
||||
{
|
||||
select(selectionStart,selectionEnd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the selection end offset.
|
||||
*/
|
||||
* Returns the selection end offset.
|
||||
*/
|
||||
public final int getSelectionEnd()
|
||||
{
|
||||
return selectionEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset where the selection ends on the specified
|
||||
* line.
|
||||
*/
|
||||
* Returns the offset where the selection ends on the specified
|
||||
* line.
|
||||
*/
|
||||
public int getSelectionEnd(int line)
|
||||
{
|
||||
if(line == selectionEndLine)
|
||||
@@ -1009,19 +1026,19 @@ public class JEditTextArea extends JComponent
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the selection end line.
|
||||
*/
|
||||
* Returns the selection end line.
|
||||
*/
|
||||
public final int getSelectionEndLine()
|
||||
{
|
||||
return selectionEndLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the selection end. The new selection will be the old
|
||||
* selection start and the bew selection end.
|
||||
* @param selectionEnd The selection end
|
||||
* @see #select(int,int)
|
||||
*/
|
||||
* Sets the selection end. The new selection will be the old
|
||||
* selection start and the bew selection end.
|
||||
* @param selectionEnd The selection end
|
||||
* @see #select(int,int)
|
||||
*/
|
||||
public final void setSelectionEnd(int selectionEnd)
|
||||
{
|
||||
select(selectionStart,selectionEnd);
|
||||
@@ -1033,76 +1050,76 @@ public class JEditTextArea extends JComponent
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the caret position. This will either be the selection
|
||||
* start or the selection end, depending on which direction the
|
||||
* selection was made in.
|
||||
*/
|
||||
* Returns the caret position. This will either be the selection
|
||||
* start or the selection end, depending on which direction the
|
||||
* selection was made in.
|
||||
*/
|
||||
public final int getCaretPosition()
|
||||
{
|
||||
return (biasLeft ? selectionStart : selectionEnd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the caret line.
|
||||
*/
|
||||
* Returns the caret line.
|
||||
*/
|
||||
public final int getCaretLine()
|
||||
{
|
||||
return (biasLeft ? selectionStartLine : selectionEndLine);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mark position. This will be the opposite selection
|
||||
* bound to the caret position.
|
||||
* @see #getCaretPosition()
|
||||
*/
|
||||
* Returns the mark position. This will be the opposite selection
|
||||
* bound to the caret position.
|
||||
* @see #getCaretPosition()
|
||||
*/
|
||||
public final int getMarkPosition()
|
||||
{
|
||||
return (biasLeft ? selectionEnd : selectionStart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mark line.
|
||||
*/
|
||||
* Returns the mark line.
|
||||
*/
|
||||
public final int getMarkLine()
|
||||
{
|
||||
return (biasLeft ? selectionEndLine : selectionStartLine);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the caret position. The new selection will consist of the
|
||||
* caret position only (hence no text will be selected)
|
||||
* @param caret The caret position
|
||||
* @see #select(int,int)
|
||||
*/
|
||||
* Sets the caret position. The new selection will consist of the
|
||||
* caret position only (hence no text will be selected)
|
||||
* @param caret The caret position
|
||||
* @see #select(int,int)
|
||||
*/
|
||||
public final void setCaretPosition(int caret)
|
||||
{
|
||||
select(caret,caret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects all text in the document.
|
||||
*/
|
||||
* Selects all text in the document.
|
||||
*/
|
||||
public final void selectAll()
|
||||
{
|
||||
select(0,getDocumentLength());
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the mark to the caret position.
|
||||
*/
|
||||
* Moves the mark to the caret position.
|
||||
*/
|
||||
public final void selectNone()
|
||||
{
|
||||
select(getCaretPosition(),getCaretPosition());
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects from the start offset to the end offset. This is the
|
||||
* general selection method used by all other selecting methods.
|
||||
* The caret position will be start if start < end, and end
|
||||
* if end > start.
|
||||
* @param start The start offset
|
||||
* @param end The end offset
|
||||
*/
|
||||
* Selects from the start offset to the end offset. This is the
|
||||
* general selection method used by all other selecting methods.
|
||||
* The caret position will be start if start < end, and end
|
||||
* if end > start.
|
||||
* @param start The start offset
|
||||
* @param end The end offset
|
||||
*/
|
||||
public void select(int start, int end)
|
||||
{
|
||||
int newStart, newEnd;
|
||||
|
||||
2
todo.txt
2
todo.txt
@@ -587,6 +587,8 @@ PDE / Sketch & Sketchbook
|
||||
1 _ unless that's the current mode that's being used
|
||||
1 _ scanning sketchbook folder may be extremely slow
|
||||
1 _ not sure why this would be the case
|
||||
1 _ handle renaming with case changes (currently ignores case change)
|
||||
1 _ see notes/bitching in Sketch.nameCode()
|
||||
|
||||
|
||||
PDE / Compiler
|
||||
|
||||
Reference in New Issue
Block a user