Exemplo n.º 1
0
 /**
  * Prompts the user that a file does not exist, and asks whether they want to remove the tree node
  * for it. The node is removed (and the project updated) if the user selects "yes."
  *
  * @param node The node to prompt about and possibly remove.
  */
 public void promptForRemoval(FileProjectEntryTreeNode node) {
   File file = node.getFile();
   if (file.isDirectory()) {
     // FolderProjectEntryTreeNode extends FileProjectEntryTreeNode,
     // and careless callers might not realize this.
     return;
   }
   String msg =
       Messages.getString("Prompt.FileDoesntExist.Remove", node.getFile().getAbsolutePath());
   RText rtext = plugin.getRText();
   String title = rtext.getString("ConfDialogTitle");
   int rc = JOptionPane.showConfirmDialog(rtext, msg, title, JOptionPane.YES_NO_OPTION);
   if (rc == JOptionPane.YES_OPTION) {
     model.removeNodeFromParent(node);
     node.entry.removeFromParent();
   }
 }
Exemplo n.º 2
0
  public void savePreferences() {

    saveMacros();

    MacroPrefs prefs = new MacroPrefs();

    StandardAction a = (StandardAction) app.getAction(NEW_MACRO_ACTION);
    prefs.newMacroAccelerator = a.getAccelerator();
    a = (StandardAction) app.getAction(EDIT_MACROS_ACTION);
    prefs.editMacrosAccelerator = a.getAccelerator();

    File prefsFile = getPrefsFile();
    try {
      prefs.save(prefsFile);
    } catch (IOException ioe) {
      app.displayException(ioe);
    }
  }
Exemplo 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
  }
Exemplo n.º 4
0
  protected void findInFilesFromSelectedDir() {

    File dir = getSelectedFile();
    Object sel = getLastSelectedPathComponent();

    if (dir != null && dir.isDirectory()) {
      RText rtext = plugin.getRText();
      rtext.getMainView().getFindInFilesDialog().setSearchIn(dir);
      // Note the ActionEvent isn't actually used; we're just doing
      // this for completeness.
      ActionEvent ae = new ActionEvent(this, 0, "ignored");
      rtext.getAction(RTextActionInfo.FIND_IN_FILES_ACTION).actionPerformed(ae);
    } else if (dir != null && !dir.exists() && sel instanceof FileProjectEntryTreeNode) {
      // Directory was deleted out from under us
      FileProjectEntryTreeNode fpetn = (FileProjectEntryTreeNode) sel;
      promptForRemoval(fpetn);
    } else { // Directory changed to a file out from under us?
      UIManager.getLookAndFeel().provideErrorFeedback(this);
    }
  }
Exemplo n.º 5
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);
   }
 }
Exemplo n.º 6
0
 /**
  * Loads saved preferences for this plugin. If this is the first time through, default values will
  * be returned.
  *
  * @return The preferences.
  */
 private MacroPrefs loadPrefs() {
   MacroPrefs prefs = new MacroPrefs();
   File prefsFile = getPrefsFile();
   if (prefsFile.isFile()) {
     try {
       prefs.load(prefsFile);
     } catch (IOException ioe) {
       app.displayException(ioe);
       // (Some) defaults will be used
     }
   }
   return prefs;
 }
Exemplo n.º 7
0
  /**
   * Constructor.
   *
   * @param app The parent RText application.
   */
  public MacroPlugin(AbstractPluggableGUIApplication app) {

    URL url = getClass().getResource("cog.png");
    if (url != null) { // Should always be true
      try {
        icon = new ImageIcon(ImageIO.read(url));
      } catch (IOException ioe) {
        app.displayException(ioe);
      }
    }

    MacroPrefs prefs = loadPrefs();

    RText rtext = (RText) app;
    this.app = rtext;
    StandardAction a = new NewMacroAction(this, rtext, msg);
    a.setAccelerator(prefs.newMacroAccelerator);
    rtext.addAction(NEW_MACRO_ACTION, a);

    a = new EditMacrosAction(rtext, msg);
    a.setAccelerator(prefs.editMacrosAccelerator);
    rtext.addAction(EDIT_MACROS_ACTION, a);
  }
Exemplo n.º 8
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);
    }
  }
Exemplo n.º 9
0
 public void actionPerformed(ActionEvent e) {
   RText owner = (RText) getApplication();
   RemoteFileChooser rfc = owner.getRemoteFileChooser();
   rfc.setMode(RemoteFileChooser.OPEN_MODE);
   rfc.setVisible(true);
 }