Exemple #1
0
  public void saveCaretInfo() {
    if (!buffer.isLoaded()) return;

    buffer.setIntegerProperty(Buffer.CARET, textArea.getCaretPosition());

    CaretInfo caretInfo = caretsForPath.get(buffer.getPath());
    if (caretInfo == null) {
      caretInfo = new CaretInfo();
      caretsForPath.put(buffer.getPath(), caretInfo);
    }
    caretInfo.caret = textArea.getCaretPosition();

    Selection[] selection = textArea.getSelection();
    for (int i = 0; i < selection.length; i++) selection[i] = (Selection) selection[i].clone();
    buffer.setProperty(Buffer.SELECTION, selection);
    caretInfo.selection = selection;

    caretInfo.rectangularSelection = textArea.isRectangularSelectionEnabled();
    caretInfo.multipleSelection = textArea.isMultipleSelectionEnabled();

    buffer.setIntegerProperty(Buffer.SCROLL_VERT, textArea.getFirstPhysicalLine());
    caretInfo.scrollVert = textArea.getFirstPhysicalLine();
    buffer.setIntegerProperty(Buffer.SCROLL_HORIZ, textArea.getHorizontalOffset());
    caretInfo.scrollHoriz = textArea.getHorizontalOffset();
    if (!buffer.isUntitled()) {
      BufferHistory.setEntry(
          buffer.getPath(),
          textArea.getCaretPosition(),
          (Selection[]) buffer.getProperty(Buffer.SELECTION),
          buffer.getStringProperty(JEditBuffer.ENCODING),
          buffer.getMode().getName());
    }
  }
  private void construct() {
    Vector recent = BufferHistory.getBufferHistory();
    JMenuItem item;
    File file;
    int max = recent.size();
    int min = max - 20;

    if (max == 0) {
      item = new JMenuItem(jEdit.getProperty("MacOSPlugin.menu.recent.none"));
      item.setEnabled(false);
      add(item);
      return;
    }

    if (min < 0) min = 0;

    for (int i = max - 1; i >= min; i--) {
      file = new File(((BufferHistory.Entry) recent.get(i)).path);
      item = new ShowRecentMenuItem(file.getName(), file.getPath());
      item.setIcon(FileCellRenderer.fileIcon);
      add(item);
    }
  }