Search in sources :

Example 6 with MMapModel

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);
    }
}
Also used : MMapModel(org.freeplane.features.map.mindmapmode.MMapModel) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) File(java.io.File) URL(java.net.URL) InvocationTargetException(java.lang.reflect.InvocationTargetException) MModeController(org.freeplane.features.mode.mindmapmode.MModeController)

Example 7 with MMapModel

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);
    }
}
Also used : MMapModel(org.freeplane.features.map.mindmapmode.MMapModel) IUndoHandler(org.freeplane.core.undo.IUndoHandler)

Aggregations

MMapModel (org.freeplane.features.map.mindmapmode.MMapModel)7 URL (java.net.URL)3 IUndoHandler (org.freeplane.core.undo.IUndoHandler)3 MapModel (org.freeplane.features.map.MapModel)3 ModeController (org.freeplane.features.mode.ModeController)3 MModeController (org.freeplane.features.mode.mindmapmode.MModeController)3 File (java.io.File)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 JTabbedPane (javax.swing.JTabbedPane)1 ResourceController (org.freeplane.core.resources.ResourceController)1 XsltPipeReaderFactory (org.freeplane.core.util.XsltPipeReaderFactory)1 MapController (org.freeplane.features.map.MapController)1 Controller (org.freeplane.features.mode.Controller)1 MFileManager (org.freeplane.features.url.mindmapmode.MFileManager)1