use of org.freeplane.features.map.mindmapmode.MMapModel in project freeplane by freeplane.
the class DoAutomaticSave method run.
@Override
public void run() {
/* Map is dirty enough? */
if (model.getNumberOfChangesSinceLastSave() == changeState) {
return;
}
changeState = model.getNumberOfChangesSinceLastSave();
if (changeState == 0) {
/* map was recently saved. */
return;
}
try {
cancel();
Controller.getCurrentController().getViewController().invokeAndWait(new Runnable() {
public void run() {
/* Now, it is dirty, we save it. */
try {
final ModeController currentModeController = Controller.getCurrentModeController();
if (!(currentModeController instanceof MModeController))
return;
MModeController modeController = ((MModeController) currentModeController);
final File pathToStore;
final URL url = model.getURL();
final File file = new File(//
url != null ? //
url.getFile() : model.getTitle() + UrlManager.FREEPLANE_FILE_EXTENSION);
if (url == null) {
pathToStore = new File(ResourceController.getResourceController().getFreeplaneUserDirectory(), BACKUP_DIR);
} else if (singleBackupDirectory != null) {
pathToStore = singleBackupDirectory;
} else {
pathToStore = new File(file.getParent(), BACKUP_DIR);
}
pathToStore.mkdirs();
final File tempFile = MFileManager.renameBackupFiles(pathToStore, file, numberOfFiles, AUTOSAVE_EXTENSION);
if (tempFile == null) {
return;
}
if (filesShouldBeDeletedAfterShutdown) {
tempFile.deleteOnExit();
}
((MFileManager) UrlManager.getController()).saveInternal((MMapModel) model, tempFile, true);
modeController.getController().getViewController().out(TextUtils.format("automatically_save_message", tempFile));
} catch (final Exception e) {
LogUtils.severe("Error in automatic MapModel.save(): ", e);
}
}
});
} catch (final Exception e) {
LogUtils.severe(e);
}
}
use of org.freeplane.features.map.mindmapmode.MMapModel in project freeplane by freeplane.
the class UndoAction method afterMapChange.
public void afterMapChange(final MapModel oldMap, final MapModel newMap) {
if (oldMap instanceof MMapModel) {
final IUndoHandler undoHandler = oldMap.getExtension(IUndoHandler.class);
undoHandler.removeChangeListener(changeListener);
}
if (newMap == null) {
setEnabled(false);
redo.setEnabled(false);
return;
}
final IUndoHandler undoHandler = (newMap.getExtension(IUndoHandler.class));
if (undoHandler != null) {
setEnabled(undoHandler.canUndo());
redo.setEnabled(undoHandler.canRedo());
undoHandler.addChangeListener(changeListener);
}
}
Aggregations