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:   Sprache: Unknown

Columbo aufrufen.bsh zum Wurzelverzeichnis wechselnC {C[102] Abap[173] [0]}Datei anzeigen

/*
Move_Lines_Up.bsh - Beanshell macro to move a selection of lines up 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 remove the line immediately preceding the selection
// and insert it immediately following the selection
Selection selection;
int startLine;
int endLine;
int prevLine;
int insertionPoint;
int insertionLine;

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 = selection.getStartLine();
 endLine = selection.getEndLine();
 // limit to lines that are actually selected
 if (textArea.getLineStartOffset(endLine) == selections[0].getEnd()) {
  -- endLine; 
 }
}
if (startLine == 0) {
 // already at top, can't move further up
 return
}
// get the text of the line immediately preceding the selection, this is the 
// text to be moved
prevLine = startLine - 1;
String prevLineText = buffer.getLineText(prevLine);

// remove the previous line from the buffer
int removalStart = buffer.getLineStartOffset(prevLine);
int removalLength = buffer.getLineStartOffset(startLine) - buffer.getLineStartOffset(prevLine);
buffer.remove(removalStart, removalLength);

// then insert the previous line immediately after the selection
insertionLine = endLine;
boolean endLineIsLast = endLine == buffer.getLineCount();
if (endLineIsLast) {
 insertionPoint = buffer.getLength();
 buffer.insert(insertionPoint, '\n' + prevLineText);
}
else {
 insertionPoint = textArea.getLineStartOffset(insertionLine);
 buffer.insert(insertionPoint, prevLineText + '\n');
}

// 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), textArea.getLineStartOffset(endLine));
textArea.addToSelection(selection);

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


[ Original von:0.127Diese Quellcodebibliothek enthält Beispiele in vielen Programmiersprachen. Man kann per Verzeichnistruktur darin navigieren. Der Code wird farblich markiert angezeigt.  ]