Ticket #1796: josm-1796-pluginupdate.patch

File josm-1796-pluginupdate.patch, 1.8 KB (added by stephankn, 17 years ago)

offer user to re-download a plugin when enabling

  • src/org/openstreetmap/josm/gui/preferences/PluginPreference.java

     
    1111import java.awt.event.ActionListener;
    1212import java.io.File;
    1313import java.io.FileReader;
     14import java.io.IOException;
    1415import java.util.Arrays;
    1516import java.util.Collection;
    1617import java.util.Collections;
     
    285286                        pluginMap.put(plugin, enabled);
    286287                        pluginCheck.addActionListener(new ActionListener(){
    287288                                public void actionPerformed(ActionEvent e) {
     289                                        // if user enabled a plugin, it is not loaded but found somewhere on disk: offer to delete jar
     290                                        if (pluginCheck.isSelected()) {
     291                                                PluginInformation plinfo = PluginInformation.findPlugin(plugin.name);
     292                               
     293                                                if ((PluginInformation.getLoaded(plugin.name) == null) && (plinfo != null)) {
     294                                                        try     {
     295                                                                int answer = JOptionPane.showConfirmDialog(Main.parent, tr("Plugin archive already available. Do you want to download current version by deleting existing archive?\n\n{0}",
     296                                                                                plinfo.file.getCanonicalPath()), tr("Plugin already exists"), JOptionPane.OK_CANCEL_OPTION);
     297                                                                if (answer == JOptionPane.OK_OPTION) {
     298                                                                        if (!plinfo.file.delete()) {
     299                                                                                JOptionPane.showMessageDialog(Main.parent, tr("Error deleting plugin file: {0}", plinfo.file.getCanonicalPath()));
     300                                                                        }
     301                                                                }
     302                                                        } catch (IOException e1) {
     303                                                                e1.printStackTrace();
     304                                                                JOptionPane.showMessageDialog(Main.parent, tr("Error deleting plugin file: {0}", e1.getMessage()));
     305                                                        }
     306                                                }
     307                                        }
    288308                                        pluginMap.put(plugin, pluginCheck.isSelected());
    289309                                }
    290310                        });