products/sources/formale Sprachen/Isabelle/Tools/jEdit/dist/macros/Editing image not shown  

Quellcode-Bibliothek

© Kompilation durch diese Firma

[Weder Korrektheit noch Funktionsfähigkeit der Software werden zugesichert.]

Datei: TestDescription.java   Sprache: Unknown

Spracherkennung für: .bsh vermutete Sprache: C {C[102] Abap[171] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

/*
Move_Lines_Down.bsh - Beanshell macro to move a selection of lines down by one
line.  This does not handle multiple selections and will abort if there are
multiple selections. Entire lines are selected for moving, so if the selection
only includes part of a line, the entire line will be selected and moved. Note
that if the selection places the caret at the start of a line, that line will 
NOT be selected for moving. If no lines are selected, then the line containing
the caret will be moved.

Copyright (c) Dale Anson, 2004
 :tabSize=4:indentSize=4:noTabs=false:
 :folding=explicit:collapseFolds=1:

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

   1. Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.
   2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
   3. The name of the author may not be used to endorse or promote products
   derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


//Localization
final static String NoMultipleSelectionError = jEdit.getProperty("macro.rs.MoveLines.NoMultipleSelection.error""Line move does not work with multiple selection.");

// get the current selection or the current line if no selection
Selection[] selections = textArea.getSelection();

// this doesn't work right with multiple selection, so don't do anything
if (selections.length > 1)
{
 Macros.error( view, NoMultipleSelectionError );
 return;
}

// the approach is to get the line immediately following the selection
// and insert it immediately preceeding the selection
Selection selection;
int startLine;
int endLine;
int nextLine;
int insertionPoint;

if (selections.length == 0) {
 // nothing is selected, so use the line containing the caret
 startLine = textArea.getCaretLine();
 endLine = startLine;
 selection = new Selection.Range(textArea.getLineStartOffset(startLine), textArea.getLineEndOffset(endLine));
}
else {
 selection = selections[0];
 startLine = textArea.getLineOfOffset(selection.getStart());
 endLine = textArea.getLineOfOffset(selection.getEnd());
 // limit to lines that are actually selected
 if (textArea.getLineStartOffset(endLine) == selection.getEnd()) {
  -- endLine; 
 }
}

if (endLine == buffer.getLineCount() - 1) {
 // at bottom, can't move further down.
 return
}

insertionPoint = textArea.getLineStartOffset(startLine);
nextLine = endLine + 1;


// get the text of the line immediately following the selection, this is the 
// text to be moved
String nextLineText = buffer.getLineText(nextLine);

// need to check if the next line is also the last line in the buffer
boolean nextIsLast = nextLine == buffer.getLineCount() - 1;

// remove the next line from the buffer
int removalStart = buffer.getLineStartOffset(nextLine);
int removalLength = nextIsLast ? buffer.getLineLength(nextLine) : buffer.getLineStartOffset(nextLine + 1) - removalStart;
buffer.remove(removalStart, removalLength);

// then insert the next line immediately before the selection
buffer.insert(insertionPoint, nextLineText + "\n");
if (nextIsLast) {
 buffer.remove(buffer.getLength() - 1, 1); 
}

// indent the selection
Mode mode = buffer.getMode();
boolean shouldIndent = false;
String[] indentProps = new String[]{"indentOpenBrackets""indentOpenBrackets""unalignedOpenBrackets""unalignedCloseBrackets""indentNextLine""unindentThisLine""electricKeys""doubleBracketIndent""lineUpClosingBracket"} ;
for (String name : indentProps) {
    if (mode.getProperty(name) != null) {
        shouldIndent = true;
        break;
    }
}
if (shouldIndent) {
 buffer.indentLines(startLine + 1, endLine + 1); 
}

// reselect
textArea.selectNone();
selection = new Selection.Range(textArea.getLineStartOffset(startLine + 1), Math.min(textArea.getLineEndOffset(endLine + 1), buffer.length));
textArea.addToSelection(selection);

// move the caret
textArea.moveCaretPosition(selection.getEnd());



[ Dauer der Verarbeitung: 0.906 Sekunden  ]