Ticket #12391: KeepLayerNameOnSave.patch

File KeepLayerNameOnSave.patch, 4.1 KB (added by kolesar, 5 years ago)
  • src/org/openstreetmap/josm/actions/RenameLayerAction.java

    diff --git a/src/org/openstreetmap/josm/actions/RenameLayerAction.java b/src/org/openstreetmap/josm/actions/RenameLayerAction.java
    index b5bd308..c459b50 100644
    a b public class RenameLayerAction extends AbstractAction { 
    8585                File newFile = new File(newname);
    8686                if (Main.platform.rename(file, newFile)) {
    8787                    layer.setAssociatedFile(newFile);
    88                     nameText = newFile.getName();
     88                    if (!layer.isRenamed()) nameText = newFile.getName();
    8989                } else {
    9090                    JOptionPane.showMessageDialog(
    9191                            Main.parent,
    public class RenameLayerAction extends AbstractAction { 
    9797                }
    9898            }
    9999        }
    100         layer.setName(nameText);
     100        layer.rename(nameText);
    101101        Main.parent.repaint();
    102102    }
    103103}
  • src/org/openstreetmap/josm/actions/SaveActionBase.java

    diff --git a/src/org/openstreetmap/josm/actions/SaveActionBase.java b/src/org/openstreetmap/josm/actions/SaveActionBase.java
    index 0eebdae..70bba1f 100644
    a b public abstract class SaveActionBase extends DiskAccessAction { 
    9292            } else if (canceled) {
    9393                return false;
    9494            }
    95             layer.setName(file.getName());
     95            if (!layer.isRenamed()) layer.setName(file.getName());
    9696            layer.setAssociatedFile(file);
    9797            if (layer instanceof OsmDataLayer) {
    9898                ((OsmDataLayer) layer).onPostSaveToFile();
  • src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java b/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
    index 0ea557b..4223c02 100644
    a b public class LayerListDialog extends ToggleDialog { 
    16001600                    l.setVisible((Boolean) value);
    16011601                    break;
    16021602                case 2:
    1603                     l.setName((String) value);
     1603                    l.rename((String) value);
    16041604                    break;
    16051605                default: throw new RuntimeException();
    16061606                }
  • src/org/openstreetmap/josm/gui/layer/Layer.java

    diff --git a/src/org/openstreetmap/josm/gui/layer/Layer.java b/src/org/openstreetmap/josm/gui/layer/Layer.java
    index 2357a2f..00ef037 100644
    a b public abstract class Layer implements Destroyable, MapViewPaintable, Projection 
    114114     * The name of this layer.
    115115     *
    116116     */
    117     private  String name;
     117    private String name;
     118
     119    /**
     120     * This is set if user renamed this layer.
     121     */
     122    private boolean renamed = false;
    118123
    119124    /**
    120125     * If a file is associated with this layer, this variable should be set to it.
    public abstract class Layer implements Destroyable, MapViewPaintable, Projection 
    263268    /**
    264269     * Sets the name of the layer
    265270     *
    266      *@param name the name. If null, the name is set to the empty string.
     271     * @param name the name. If null, the name is set to the empty string.
    267272     *
    268273     */
    269274    public final void setName(String name) {
    public abstract class Layer implements Destroyable, MapViewPaintable, Projection 
    278283    }
    279284
    280285    /**
     286     * Rename layer and set renamed flag to mark it as renamed (has user given name).
     287     *
     288     * @param name the name. If null, the name is set to the empty string.
     289     *
     290     */
     291    public final void rename(String name) {
     292        renamed = true;
     293        setName(name);
     294    }
     295
     296    /**
     297     * Replies true if this layer was renamed by user
     298     *
     299     * @return true if this layer was renamed by user
     300     */
     301    public boolean isRenamed() {
     302        return renamed;
     303    }
     304
     305    /**
    281306     * Replies true if this layer is a background layer
    282307     *
    283308     * @return true if this layer is a background layer