Пример #1
0
 @Override
 public void setMode(CommandLineMode mode) {
   if (mode == CommandLineMode.DEFAULT) {
     commandLineText.setEditable(true);
     if (registerModeSelection != null) {
       commandLineText.replaceTextRange(registerModeSelection.x, 1, "");
       commandLineText.setSelection(registerModeSelection);
       registerModeSelection = null;
     } else {
       // Reset any selection made in a readonly mode, otherwise we need to check if
       // cut/copy needs to be enabled.
       commandLineText.setSelection(commandLineText.getCaretOffset());
     }
     readOnly = false;
   } else if (mode == CommandLineMode.REGISTER) {
     if (registerModeSelection == null) {
       Point sel = commandLineText.getSelection();
       int leftOffset = Math.min(sel.x, sel.y);
       commandLineText.replaceTextRange(leftOffset, 0, "\"");
       registerModeSelection = sel;
       readOnly = true;
     }
   } else if (mode == CommandLineMode.MESSAGE || mode == CommandLineMode.MESSAGE_CLIPPED) {
     commandLineText.setEditable(false);
     setPosition(0);
     commandLineText.setTopIndex(0);
     readOnly = true;
     pasteItem.setEnabled(false);
     commandLineText.setWordWrap(mode == CommandLineMode.MESSAGE);
   }
 }
Пример #2
0
 @Override
 public void replace(int start, int end, String text) {
   int startOffset = start + contentsOffset;
   int endOffset = end + contentsOffset;
   commandLineText.replaceTextRange(startOffset, endOffset - startOffset, text);
   updateUISize();
 }
Пример #3
0
 @Override
 public void resetContents(String newContents) {
   commandLineText.replaceTextRange(
       contentsOffset, commandLineText.getCharCount() - contentsOffset, newContents);
   // Clear selection, set caret position to end of widget.
   commandLineText.setCaret(endCharCaret);
   commandLineText.setSelection(commandLineText.getCharCount());
 }
Пример #4
0
 @Override
 public void setPrompt(String newPrompt) {
   prompt = newPrompt;
   commandLineText.replaceTextRange(0, contentsOffset, newPrompt);
   contentsOffset = newPrompt.length();
   commandLineText.setCaretOffset(commandLineText.getCharCount());
   updateUISize();
 }
Пример #5
0
 /**
  * Undoes the last undo.
  *
  * @see #undo()
  * @see #getModified()
  */
 public void redo() {
   if (changeIndex == changes.size()) return;
   redoing = true;
   ExtendedModifyEvent change = changes.remove(changeIndex);
   currentText.replaceTextRange(change.start, change.length, change.replacedText);
   currentText.setCaretOffset(change.start + change.replacedText.length());
   scrollToCaret();
 }
Пример #6
0
 @Override
 public void delete() {
   clipSelection();
   if (commandLineText.getSelectionCount() > 0) {
     commandLineText.insert("");
   } else {
     int startOffset = commandLineText.getCaretOffset();
     if (startOffset < commandLineText.getCharCount()) {
       commandLineText.replaceTextRange(startOffset, 1, "");
     }
   }
   // caret doesn't move if character after caret is deleted and won't trigger caretMoved
   // update manually
   updateCaret();
 }
Пример #7
0
 @Override
 public void erase() {
   clipSelection();
   if (commandLineText.getSelectionCount() > 0) {
     commandLineText.insert("");
   } else {
     int startOffset = commandLineText.getCaretOffset();
     if (startOffset > contentsOffset) {
       commandLineText.replaceTextRange(startOffset - 1, 1, "");
       // Caret listener is called before content is updated, update manually
       updateCaret();
     }
   }
   updateUISize();
 }
Пример #8
0
    @Override
    public void verifyKey(VerifyEvent event) {
      StyledText styledText = (StyledText) event.widget;

      if (event.keyCode == '\r' || event.keyCode == '\n')
        if ((event.stateMask & SWT.SHIFT) != 0) {
          //   toggle paragraph end character
          event.doit = false;
          int index = styledText.getLineAtOffset(styledText.getCaretOffset());
          String line = styledText.getLine(index);
          if (line.length() > 0)
            if (line.charAt(line.length() - 1) != PARAGRAPH_END)
              styledText.replaceTextRange(
                  styledText.getOffsetAtLine(index),
                  line.length(),
                  line + Character.toString(PARAGRAPH_END));
            else
              styledText.replaceTextRange(
                  styledText.getOffsetAtLine(index),
                  line.length(),
                  line.substring(0, line.length() - 1));
          return;
        } else {
          //   play page bell
          int index = styledText.getLineAtOffset(styledText.getCaretOffset());
          if (index == prevLine + 1 && index % linesPerPage == pageMarginBell - 2)
            if (!pageMarginClip.isActive()) {
              pageMarginClip.setFramePosition(0);
              pageMarginClip.start();
            }
          prevLine = index;
        }

      //   check if using braille entry
      if (brailleEntry) if (event.character > ' ' && event.character < 0x7f) event.doit = false;
    }
  /**
   * Reverts the given modify event, in the way as the Eclipse text editor does it.
   *
   * @param event
   */
  private void revertEvent(ExtendedModifyEvent event) {
    editor.replaceTextRange(event.start, event.length, event.replacedText);
    // (causes the modifyText() listener method to be called)

    editor.setSelectionRange(event.start, event.replacedText.length());
  }