Ejemplo n.º 1
0
  /**
   * Refreshes the elements in the Macros menu to be in sync with the macros the user has defined.
   */
  private void refreshMacrosMenu() {

    while (macrosMenu.getMenuComponentCount() > 3) {
      macrosMenu.remove(3);
    }

    if (MacroManager.get().getMacroCount() > 0) {
      Iterator<Macro> i = MacroManager.get().getMacroIterator();
      while (i.hasNext()) {
        Macro macro = i.next();
        RunMacroAction a = new RunMacroAction(app, this, macro);
        macrosMenu.add(createMenuItem(a));
      }
    } else {
      String text = MacroPlugin.msg.getString("NoMacrosDefined");
      JMenuItem item = new JMenuItem(text);
      item.setEnabled(false);
      macrosMenu.add(item);
    }
  }
Ejemplo n.º 2
0
 /**
  * Saves our current set of macros.
  *
  * @see #loadMacros()
  */
 private void saveMacros() {
   try {
     MacroManager.get().saveMacros(getMacroDir());
   } catch (IOException ioe) {
     String text = ioe.getMessage();
     if (text == null) {
       text = ioe.toString();
     }
     String desc = getString("Error.SavingMacros");
     desc = MessageFormat.format(desc, new Object[] {text});
     app.displayException(ioe, desc);
   }
 }
Ejemplo n.º 3
0
  /** {@inheritDoc} */
  public void install(AbstractPluggableGUIApplication app) {

    MacroManager.get().addPropertyChangeListener(MacroManager.PROPERTY_MACROS, this);

    // Add a new menu for selecting macros
    RText rtext = (RText) app;
    MenuBar mb = (org.fife.ui.app.MenuBar) rtext.getJMenuBar();
    macrosMenu = new JMenu(getString("Plugin.Name"));
    Action a = rtext.getAction(MacroPlugin.NEW_MACRO_ACTION);
    macrosMenu.add(createMenuItem(a)); // createMenuItem(a));
    a = rtext.getAction(MacroPlugin.EDIT_MACROS_ACTION);
    macrosMenu.add(createMenuItem(a)); // createMenuItem(a));
    macrosMenu.addSeparator();
    mb.addExtraMenu(macrosMenu);
    mb.revalidate();

    loadMacros(); // Do after menu has been added
  }
Ejemplo n.º 4
0
  /**
   * Loads the previously saved macros.
   *
   * @see #saveMacros()
   */
  private void loadMacros() {

    // First time through, this directory won't exist.
    File macroDir = getMacroDir();
    if (!macroDir.isDirectory()) {
      macroDir.mkdirs();
    }

    try {
      MacroManager.get().loadMacros(macroDir);
    } catch (IOException ioe) {
      String text = ioe.getMessage();
      if (text == null) {
        text = ioe.toString();
      }
      String desc = getString("Error.LoadingMacros");
      desc = MessageFormat.format(desc, new Object[] {text});
      app.displayException(ioe, desc);
    }
  }