Example #1
0
  // {{{ userInput() method
  protected void userInput(char ch) {
    lastActionCount = 0;

    JEditTextArea textArea = view.getTextArea();

    /* Buffer buffer = view.getBuffer();
    if(!buffer.insideCompoundEdit())
    	buffer.beginCompoundEdit(); */

    if (repeatCount == 1) textArea.userInput(ch);
    else {
      // stop people doing dumb stuff like C+ENTER 100 C+n
      if (repeatCount > REPEAT_COUNT_THRESHOLD) {
        Object[] pp = {String.valueOf(ch), repeatCount};

        if (GUIUtilities.confirm(
                view,
                "large-repeat-count.user-input",
                pp,
                JOptionPane.WARNING_MESSAGE,
                JOptionPane.YES_NO_OPTION)
            != JOptionPane.YES_OPTION) {
          repeatCount = 1;
          view.getStatus().setMessage(null);
          return;
        }
      }

      JEditBuffer buffer = view.getBuffer();
      try {
        if (repeatCount != 1) buffer.beginCompoundEdit();
        for (int i = 0; i < repeatCount; i++) textArea.userInput(ch);
      } finally {
        if (repeatCount != 1) buffer.endCompoundEdit();
      }
    }

    Macros.Recorder recorder = view.getMacroRecorder();

    if (recorder != null) {
      recorder.recordInput(repeatCount, ch, textArea.isOverwriteEnabled());
    }

    repeatCount = 1;
  } // }}}
Example #2
0
  // {{{ invokeReadNextChar() method
  protected void invokeReadNextChar(char ch) {
    JEditBuffer buffer = view.getBuffer();

    /* if(buffer.insideCompoundEdit())
    buffer.endCompoundEdit(); */

    String charStr = StandardUtilities.charsToEscapes(String.valueOf(ch));

    // this might be a bit slow if __char__ occurs a lot
    int index;
    while ((index = readNextChar.indexOf("__char__")) != -1) {
      readNextChar =
          readNextChar.substring(0, index)
              + '\''
              + charStr
              + '\''
              + readNextChar.substring(index + 8);
    }

    Macros.Recorder recorder = view.getMacroRecorder();
    if (recorder != null) recorder.record(getRepeatCount(), readNextChar);

    view.getStatus().setMessage(null);

    if (getRepeatCount() != 1) {
      try {
        buffer.beginCompoundEdit();

        BeanShell.eval(
            view,
            BeanShell.getNameSpace(),
            "for(int i = 1; i < " + getRepeatCount() + "; i++)\n{\n" + readNextChar + "\n}");
      } finally {
        buffer.endCompoundEdit();
      }
    } else BeanShell.eval(view, BeanShell.getNameSpace(), readNextChar);

    readNextChar = null;
  } // }}}
Example #3
0
  // {{{ update() method
  public void update(JMenu menu) {
    final View view = GUIUtilities.getView(menu);

    String path;
    if (dir == null) {
      path = view.getBuffer().getDirectory();
    } else path = dir;

    JMenuItem mi = new JMenuItem(path + ':');
    mi.setActionCommand(path);
    mi.setIcon(FileCellRenderer.openDirIcon);

    // {{{ ActionListeners
    ActionListener fileListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            jEdit.openFile(view, evt.getActionCommand());
          }
        };

    ActionListener dirListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            VFSBrowser.browseDirectory(view, evt.getActionCommand());
          }
        }; // }}}

    mi.addActionListener(dirListener);

    menu.add(mi);
    menu.addSeparator();

    if (dir == null && !(view.getBuffer().getVFS() instanceof FileVFS)) {
      mi = new JMenuItem(jEdit.getProperty("directory.not-local"));
      mi.setEnabled(false);
      menu.add(mi);
      return;
    }

    File directory = new File(path);

    JMenu current = menu;

    // for filtering out backups
    String backupPrefix = jEdit.getProperty("backup.prefix");
    String backupSuffix = jEdit.getProperty("backup.suffix");

    File[] list = directory.listFiles();
    if (list == null || list.length == 0) {
      mi = new JMenuItem(jEdit.getProperty("directory.no-files"));
      mi.setEnabled(false);
      menu.add(mi);
    } else {
      int maxItems = jEdit.getIntegerProperty("menu.spillover", 20);

      Arrays.sort(list, new StandardUtilities.StringCompare<File>(true));
      for (int i = 0; i < list.length; i++) {
        File file = list[i];

        String name = file.getName();

        // skip marker files
        if (name.endsWith(".marks")) continue;

        // skip autosave files
        if (name.startsWith("#") && name.endsWith("#")) continue;

        // skip backup files
        if ((backupPrefix.length() != 0 && name.startsWith(backupPrefix))
            || (backupSuffix.length() != 0 && name.endsWith(backupSuffix))) continue;

        // skip directories
        // if(file.isDirectory())
        //	continue;

        mi = new JMenuItem(name);
        mi.setActionCommand(file.getPath());
        mi.addActionListener(file.isDirectory() ? dirListener : fileListener);
        mi.setIcon(file.isDirectory() ? FileCellRenderer.dirIcon : FileCellRenderer.fileIcon);

        if (current.getItemCount() >= maxItems && i != list.length - 1) {
          // current.addSeparator();
          JMenu newCurrent = new JMenu(jEdit.getProperty("common.more"));
          current.add(newCurrent);
          current = newCurrent;
        }
        current.add(mi);
      }
    }
  } // }}}