Ignore:
Timestamp:
2010-01-14T20:28:40+01:00 (14 years ago)
Author:
Gubaer
Message:

minor clean up

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r2858 r2859  
    706706    }
    707707
    708     private static boolean confirmDisablingPluginAfterException(PluginProxy plugin) {
     708    private static boolean confirmDeactivatingPluginAfterException(PluginProxy plugin) {
    709709        ButtonSpec [] options = new ButtonSpec[] {
    710710                new ButtonSpec(
     
    748748    }
    749749
     750    /**
     751     * Replies the plugin which most likely threw the exception <code>ex</code>.
     752     *
     753     * @param ex the exception
     754     * @return the plugin; null, if the exception proably wasn't thrown from a plugin
     755     */
    750756    private static PluginProxy getPluginCausingException(Throwable ex) {
    751757        for (PluginProxy p : pluginList) {
     
    762768    }
    763769
    764     public static boolean checkException(Throwable e) {
     770    /**
     771     * Checks whether the exception <code>e</code> was thrown by a plugin. If so,
     772     * conditionally deactivates the plugin, but asks the user first.
     773     *
     774     * @param e the exception
     775     */
     776    public static void disablePluginAfterException(Throwable e) {
    765777        PluginProxy plugin = null;
    766 
    767778        // Check for an explicit problem when calling a plugin function
    768779        if (e instanceof PluginException) {
    769780            plugin = ((PluginException) e).plugin;
    770781        }
    771 
    772782        if (plugin == null) {
    773783            plugin = getPluginCausingException(e);
    774784        }
    775 
    776         if (plugin != null && confirmDisablingPluginAfterException(plugin)) {
    777             List<String> plugins = new ArrayList<String>(Main.pref.getCollection("plugins", Collections
    778                     .<String> emptyList()));
    779             if (plugins.contains(plugin.getPluginInformation().name)) {
    780                 while (plugins.remove(plugin.getPluginInformation().name)) {
    781                 }
    782                 Main.pref.putCollection("plugins", plugins);
    783                 JOptionPane
    784                 .showMessageDialog(
    785                         Main.parent,
    786                         tr("The plugin has been removed from the configuration. Please restart JOSM to unload the plugin."),
    787                         tr("Information"), JOptionPane.INFORMATION_MESSAGE);
    788             } else {
    789                 JOptionPane.showMessageDialog(Main.parent,
    790                         tr("The plugin could not be removed. Probably it was already disabled"), tr("Error"),
    791                         JOptionPane.ERROR_MESSAGE);
    792             }
    793             return true;
    794         }
    795         return false;
     785        if (plugin == null)
     786            // don't know what plugin threw the exception
     787            return;
     788
     789        Set<String> plugins = new HashSet<String>(
     790                Main.pref.getCollection("plugins",Collections.<String> emptySet())
     791        );
     792        if (! plugins.contains(plugin.getPluginInformation().name))
     793            // plugin not activated ? strange in this context but anyway, don't bother
     794            // the user with dialogs, skip condiational deactivation
     795            return;
     796
     797        if (!confirmDeactivatingPluginAfterException(plugin))
     798            // user doesn't want to deactivate the plugin
     799            return;
     800
     801        // deactivate the plugin
     802        plugins.remove(plugin.getPluginInformation().name);
     803        Main.pref.putCollection("plugins", plugins);
     804        JOptionPane.showMessageDialog(
     805                Main.parent,
     806                tr("The plugin has been removed from the configuration. Please restart JOSM to unload the plugin."),
     807                tr("Information"),
     808                JOptionPane.INFORMATION_MESSAGE
     809        );
     810        return;
    796811    }
    797812
Note: See TracChangeset for help on using the changeset viewer.