Changeset 2859 in josm for trunk/src/org/openstreetmap/josm/plugins
- Timestamp:
- 2010-01-14T20:28:40+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r2858 r2859 706 706 } 707 707 708 private static boolean confirmD isablingPluginAfterException(PluginProxy plugin) {708 private static boolean confirmDeactivatingPluginAfterException(PluginProxy plugin) { 709 709 ButtonSpec [] options = new ButtonSpec[] { 710 710 new ButtonSpec( … … 748 748 } 749 749 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 */ 750 756 private static PluginProxy getPluginCausingException(Throwable ex) { 751 757 for (PluginProxy p : pluginList) { … … 762 768 } 763 769 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) { 765 777 PluginProxy plugin = null; 766 767 778 // Check for an explicit problem when calling a plugin function 768 779 if (e instanceof PluginException) { 769 780 plugin = ((PluginException) e).plugin; 770 781 } 771 772 782 if (plugin == null) { 773 783 plugin = getPluginCausingException(e); 774 784 } 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; 796 811 } 797 812
Note:
See TracChangeset
for help on using the changeset viewer.