Exemple #1
0
  // {{{ createMacrosMenu() method
  private void createMacrosMenu(JMenu menu, Vector vector, int start) {
    Vector<JMenuItem> menuItems = new Vector<JMenuItem>();
    int maxItems = jEdit.getIntegerProperty("menu.spillover", 20);
    JMenu subMenu = null;
    for (int i = start; i < vector.size(); i++) {
      if (i != start && i % maxItems == 0) {
        subMenu = new JMenu(jEdit.getProperty("common.more"));
        createMacrosMenu(subMenu, vector, i);
        break;
      }
      Object obj = vector.elementAt(i);
      if (obj instanceof String) {
        menuItems.add(
            new EnhancedMenuItem(
                jEdit.getProperty(obj + ".label"), (String) obj, jEdit.getActionContext()));
      } else if (obj instanceof Vector) {
        Vector subvector = (Vector) obj;
        String name = (String) subvector.elementAt(0);
        JMenu submenu = new JMenu(jEdit.getProperty("macros.folder." + name + ".label", name));
        createMacrosMenu(submenu, subvector, 1);
        if (submenu.getMenuComponentCount() != 0) menuItems.add(submenu);
      }
    }

    Collections.sort(menuItems, new MenuItemTextComparator());

    if (subMenu != null) menuItems.add(subMenu);

    for (int i = 0; i < menuItems.size(); i++) {
      menu.add(menuItems.get(i));
    }
  } // }}}
Exemple #2
0
  // {{{ update() method
  public void update(JMenu menu) {
    Vector macroVector = Macros.getMacroHierarchy();

    int count = menu.getMenuComponentCount();

    createMacrosMenu(menu, macroVector, 0);

    if (count == menu.getMenuComponentCount()) {
      JMenuItem mi = new JMenuItem(jEdit.getProperty("no-macros.label"));
      mi.setEnabled(false);
      menu.add(mi);
    }
  } // }}}
  // {{{ update() method
  public void update(JMenu menu) {
    final View view = GUIUtilities.getView(menu);

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

            view.getStatus().setMessage(null);
          }
        }; // }}}

    // {{{ MouseListener...
    MouseListener mouseListener =
        new MouseAdapter() {
          public void mouseEntered(MouseEvent evt) {
            view.getStatus().setMessage(((JMenuItem) evt.getSource()).getActionCommand());
          }

          public void mouseExited(MouseEvent evt) {
            view.getStatus().setMessage(null);
          }
        }; // }}}

    HistoryModel model = HistoryModel.getModel("vfs.browser.path");
    if (model.getSize() == 0) {
      JMenuItem menuItem = new JMenuItem(jEdit.getProperty("no-recent-dirs.label"));
      menuItem.setEnabled(false);
      menu.add(menuItem);
      return;
    }

    boolean sort = jEdit.getBooleanProperty("sortRecent");

    int maxItems = jEdit.getIntegerProperty("menu.spillover", 20);

    Vector menuItems = new Vector();

    for (int i = 0; i < model.getSize(); i++) {
      String path = model.getItem(i);
      JMenuItem menuItem = new JMenuItem(MiscUtilities.getFileName(path));
      menuItem.setActionCommand(path);
      menuItem.addActionListener(actionListener);
      menuItem.addMouseListener(mouseListener);
      menuItem.setIcon(FileCellRenderer.dirIcon);

      if (sort) menuItems.addElement(menuItem);
      else {
        if (menu.getMenuComponentCount() >= maxItems && i != model.getSize() - 1) {
          JMenu newMenu = new JMenu(jEdit.getProperty("common.more"));
          menu.add(newMenu);
          menu = newMenu;
        }

        menu.add(menuItem);
      }
    }

    if (sort) {
      Collections.sort(menuItems, new MiscUtilities.MenuItemCompare());
      for (int i = 0; i < menuItems.size(); i++) {
        if (menu.getMenuComponentCount() >= maxItems && i != 0) {
          JMenu newMenu = new JMenu(jEdit.getProperty("common.more"));
          menu.add(newMenu);
          menu = newMenu;
        }

        menu.add((JMenuItem) menuItems.elementAt(i));
      }
    }
  } // }}}
Exemple #4
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);
      }
    }
  } // }}}