mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
copy loaded file as-is to backup folder
This commit is contained in:
@@ -122,8 +122,9 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
|
|||||||
*
|
*
|
||||||
* @param project
|
* @param project
|
||||||
* @param freshStart
|
* @param freshStart
|
||||||
|
* @param optional file name when loading from a file
|
||||||
*/
|
*/
|
||||||
void loadProject(Project project, boolean freshStart);
|
void loadProject(Project project, boolean freshStart, String filename);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new project.
|
* Creates a new project.
|
||||||
|
|||||||
@@ -273,13 +273,13 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadProject(Project project, boolean freshStart) {
|
public void loadProject(Project project, boolean freshStart, String filename) {
|
||||||
LOG.info(String.format("loadProject(%s, %s)", project.getTitle(), freshStart));
|
LOG.info(String.format("loadProject(%s, %s)", project.getTitle(), freshStart));
|
||||||
this.currentProject = project;
|
this.currentProject = project;
|
||||||
drawingManager.clearComponentAreaMap();
|
drawingManager.clearComponentAreaMap();
|
||||||
drawingManager.clearContinuityArea();
|
drawingManager.clearContinuityArea();
|
||||||
updateSelection(EMPTY_SELECTION);
|
updateSelection(EMPTY_SELECTION);
|
||||||
messageDispatcher.dispatchMessage(EventType.PROJECT_LOADED, project, freshStart);
|
messageDispatcher.dispatchMessage(EventType.PROJECT_LOADED, project, freshStart, filename);
|
||||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
messageDispatcher.dispatchMessage(EventType.LAYER_STATE_CHANGED, currentProject.getLockedLayers());
|
messageDispatcher.dispatchMessage(EventType.LAYER_STATE_CHANGED, currentProject.getLockedLayers());
|
||||||
messageDispatcher.dispatchMessage(EventType.LAYER_VISIBILITY_CHANGED, currentProject.getHiddenLayers());
|
messageDispatcher.dispatchMessage(EventType.LAYER_VISIBILITY_CHANGED, currentProject.getHiddenLayers());
|
||||||
@@ -291,7 +291,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
try {
|
try {
|
||||||
Project project = new Project();
|
Project project = new Project();
|
||||||
instantiationManager.fillWithDefaultProperties(project, null);
|
instantiationManager.fillWithDefaultProperties(project, null);
|
||||||
loadProject(project, true);
|
loadProject(project, true, null);
|
||||||
projectFileManager.startNewFile();
|
projectFileManager.startNewFile();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Could not create new file", e);
|
LOG.error("Could not create new file", e);
|
||||||
@@ -306,7 +306,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
try {
|
try {
|
||||||
warnings = new ArrayList<String>();
|
warnings = new ArrayList<String>();
|
||||||
Project project = (Project) projectFileManager.deserializeProjectFromFile(fileName, warnings);
|
Project project = (Project) projectFileManager.deserializeProjectFromFile(fileName, warnings);
|
||||||
loadProject(project, true);
|
loadProject(project, true, fileName);
|
||||||
projectFileManager.fireFileStatusChanged();
|
projectFileManager.fireFileStatusChanged();
|
||||||
if (!warnings.isEmpty()) {
|
if (!warnings.isEmpty()) {
|
||||||
StringBuilder builder = new StringBuilder("<html>File was opened, but there were some issues with it:<br><br>");
|
StringBuilder builder = new StringBuilder("<html>File was opened, but there were some issues with it:<br><br>");
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -69,7 +69,7 @@ import org.diylc.images.IconLoader;
|
|||||||
import org.diylc.presenter.Presenter;
|
import org.diylc.presenter.Presenter;
|
||||||
import org.diylc.swing.IDynamicSubmenuHandler;
|
import org.diylc.swing.IDynamicSubmenuHandler;
|
||||||
import org.diylc.swing.ISwingUI;
|
import org.diylc.swing.ISwingUI;
|
||||||
import org.diylc.swing.gui.actionBar.ActionBarPlugin;
|
import org.diylc.swing.gui.actionbar.ActionBarPlugin;
|
||||||
import org.diylc.swing.gui.editor.PropertyEditorDialog;
|
import org.diylc.swing.gui.editor.PropertyEditorDialog;
|
||||||
import org.diylc.swing.plugins.autosave.AutoSavePlugin;
|
import org.diylc.swing.plugins.autosave.AutoSavePlugin;
|
||||||
import org.diylc.swing.plugins.canvas.CanvasPlugin;
|
import org.diylc.swing.plugins.canvas.CanvasPlugin;
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ public class TemplateDialog extends JDialog {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
plugInPort.loadProject(presenter.getCurrentProject(), true);
|
plugInPort.loadProject(presenter.getCurrentProject(), true, null);
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License along with DIYLC. If not, see
|
* You should have received a copy of the GNU General Public License along with DIYLC. If not, see
|
||||||
* <http://www.gnu.org/licenses/>.
|
* <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.diylc.swing.gui.actionBar;
|
package org.diylc.swing.gui.actionbar;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
+1
-1
@@ -19,7 +19,7 @@
|
|||||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package org.diylc.swing.gui.actionBar;
|
package org.diylc.swing.gui.actionbar;
|
||||||
|
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Cursor;
|
import java.awt.Cursor;
|
||||||
@@ -1,27 +1,28 @@
|
|||||||
/*
|
/*
|
||||||
|
*
|
||||||
DIY Layout Creator (DIYLC).
|
* DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
*
|
||||||
|
* This file is part of DIYLC.
|
||||||
This file is part of DIYLC.
|
*
|
||||||
|
* DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||||
DIYLC is free software: you can redistribute it and/or modify
|
* General Public License as published by the Free Software Foundation, either version 3 of the
|
||||||
it under the terms of the GNU General Public License as published by
|
* License, or (at your option) any later version.
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
*
|
||||||
(at your option) any later version.
|
* DIYLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
DIYLC is distributed in the hope that it will be useful,
|
* Public License for more details.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
*
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* You should have received a copy of the GNU General Public License along with DIYLC. If not, see
|
||||||
GNU General Public License for more details.
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
*/
|
|
||||||
package org.diylc.swing.plugins.autosave;
|
package org.diylc.swing.plugins.autosave;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -67,7 +68,7 @@ public class AutoSavePlugin implements IPlugIn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumSet<EventType> getSubscribedEventTypes() {
|
public EnumSet<EventType> getSubscribedEventTypes() {
|
||||||
return EnumSet.of(EventType.PROJECT_MODIFIED);
|
return EnumSet.of(EventType.PROJECT_MODIFIED, EventType.PROJECT_LOADED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -87,6 +88,34 @@ public class AutoSavePlugin implements IPlugIn {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} else if (eventType == EventType.PROJECT_LOADED) {
|
||||||
|
String fileName = (String) params[2];
|
||||||
|
if (fileName != null) {
|
||||||
|
String backupName = generateBackupFileName(fileName);
|
||||||
|
try {
|
||||||
|
copyFileUsingStream(new File(fileName), new File(backupName));
|
||||||
|
LOG.info("Copied loaded file to " + backupName);
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOG.error("Could not copy the loaded file to backup", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void copyFileUsingStream(File source, File dest) throws IOException {
|
||||||
|
InputStream is = null;
|
||||||
|
OutputStream os = null;
|
||||||
|
try {
|
||||||
|
is = new FileInputStream(source);
|
||||||
|
os = new FileOutputStream(dest);
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int length;
|
||||||
|
while ((length = is.read(buffer)) > 0) {
|
||||||
|
os.write(buffer, 0, length);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
is.close();
|
||||||
|
os.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +127,7 @@ public class AutoSavePlugin implements IPlugIn {
|
|||||||
|
|
||||||
// remove extension
|
// remove extension
|
||||||
if (name.toLowerCase().endsWith(".diy"))
|
if (name.toLowerCase().endsWith(".diy"))
|
||||||
name = name.substring(name.length() - 4);
|
name = name.substring(0, name.length() - 4);
|
||||||
|
|
||||||
// append date and time
|
// append date and time
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(Project currentState) {
|
public void actionPerformed(Project currentState) {
|
||||||
plugInPort.loadProject(currentState, false);
|
plugInPort.loadProject(currentState, false, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
clipboard.addFlavorListener(new FlavorListener() {
|
clipboard.addFlavorListener(new FlavorListener() {
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ public class ProjectPreview extends JPanel implements PropertyChangeListener, IF
|
|||||||
}
|
}
|
||||||
|
|
||||||
nameLabel.setText(selectedProject.getTitle());
|
nameLabel.setText(selectedProject.getTitle());
|
||||||
presenter.loadProject(selectedProject, true);
|
presenter.loadProject(selectedProject, true, null);
|
||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
if (renderComponent.isShowing()) {
|
if (renderComponent.isShowing()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user