aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Rolka2013-04-16 10:11:23 (EDT)
committerGerrit Code Review @ Eclipse.org2013-04-17 07:59:46 (EDT)
commitc46a23e9fbcdb7cc180e23e6f668d943d752514c (patch)
tree86e9b57b19da2dcbc155dfa86206ece85815c493
parentd5035eacf0c9a55dce6f329c9ab77f2cd80759ae (diff)
downloadeclipse.platform.ui-c46a23e9fbcdb7cc180e23e6f668d943d752514c.zip
eclipse.platform.ui-c46a23e9fbcdb7cc180e23e6f668d943d752514c.tar.gz
eclipse.platform.ui-c46a23e9fbcdb7cc180e23e6f668d943d752514c.tar.bz2
Bug 338450 - [Compatibility] List of recently opened editors notrefs/changes/38/11938/2
persisted across workbench restarts
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ReopenEditorMenu.java2
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java102
2 files changed, 103 insertions, 1 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ReopenEditorMenu.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ReopenEditorMenu.java
index 47f64f6..d6644ec 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ReopenEditorMenu.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ReopenEditorMenu.java
@@ -263,7 +263,7 @@ public class ReopenEditorMenu extends ContributionItem {
}
IEditorInput input = item.getInput();
IEditorDescriptor desc = item.getDescriptor();
- if (input == null || desc == null) {
+ if (input == null || !input.exists() || desc == null) {
String title = WorkbenchMessages.OpenRecent_errorTitle;
String msg = NLS.bind(WorkbenchMessages.OpenRecent_unableToOpen, itemName );
MessageDialog.openWarning(window.getShell(), title, msg);
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java
index dd2bb22..5d604ac 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java
@@ -22,6 +22,8 @@ import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.StringReader;
+import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Dictionary;
@@ -59,6 +61,7 @@ import org.eclipse.core.runtime.IRegistryChangeEvent;
import org.eclipse.core.runtime.IRegistryChangeListener;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.ListenerList;
+import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.Status;
@@ -140,6 +143,7 @@ import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorRegistry;
import org.eclipse.ui.IElementFactory;
import org.eclipse.ui.ILocalWorkingSetManager;
+import org.eclipse.ui.IMemento;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IPerspectiveRegistry;
import org.eclipse.ui.ISaveableFilter;
@@ -160,6 +164,7 @@ import org.eclipse.ui.IWorkingSetManager;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.Saveable;
import org.eclipse.ui.WorkbenchException;
+import org.eclipse.ui.XMLMemento;
import org.eclipse.ui.activities.IWorkbenchActivitySupport;
import org.eclipse.ui.application.WorkbenchAdvisor;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
@@ -264,6 +269,8 @@ public final class Workbench extends EventManager implements IWorkbench {
public static String WORKBENCH_AUTO_SAVE_JOB = "Workbench Auto-Save Job"; //$NON-NLS-1$
+ private static String MEMENTO_KEY = "memento"; //$NON-NLS-1$
+
private final class StartupProgressBundleListener implements SynchronousBundleListener {
private final IProgressMonitor progressMonitor;
@@ -1144,6 +1151,28 @@ public final class Workbench extends EventManager implements IWorkbench {
}
});
+ // persist workbench state
+ if (getWorkbenchConfigurer().getSaveAndRestore()) {
+ SafeRunner.run(new SafeRunnable() {
+ public void run() {
+ persistWorkbenchState();
+ }
+
+ public void handleException(Throwable e) {
+ String message;
+ if (e.getMessage() == null) {
+ message = WorkbenchMessages.ErrorClosingNoArg;
+ } else {
+ message = NLS.bind(WorkbenchMessages.ErrorClosingOneArg, e.getMessage());
+ }
+
+ if (!MessageDialog.openQuestion(null, WorkbenchMessages.Error, message)) {
+ isClosing = false;
+ }
+ }
+ });
+ }
+
// persist view states
SafeRunner.run(new SafeRunnable() {
public void run() {
@@ -1560,6 +1589,8 @@ public final class Workbench extends EventManager implements IWorkbench {
if (isClosing()) {
bail[0] = true;
}
+
+ restoreWorkbenchState();
}
});
@@ -3526,4 +3557,75 @@ UIEvents.Context.TOPIC_CONTEXT,
public MApplication getApplication() {
return application;
}
+
+ /*
+ * Record the workbench UI in a document
+ */
+ private void persistWorkbenchState() {
+ try {
+ XMLMemento memento = XMLMemento.createWriteRoot(IWorkbenchConstants.TAG_WORKBENCH);
+ IStatus status = saveWorkbenchState(memento);
+
+ if (status.getSeverity() == IStatus.OK) {
+ StringWriter writer = new StringWriter();
+ memento.save(writer);
+ application.getPersistedState().put(MEMENTO_KEY, writer.toString());
+ } else {
+ WorkbenchPlugin.log(new Status(status.getSeverity(), PlatformUI.PLUGIN_ID,
+ WorkbenchMessages.Workbench_problemsSavingMsg));
+ }
+ } catch (IOException e) {
+ WorkbenchPlugin.log(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0,
+ WorkbenchMessages.Workbench_problemsSavingMsg, e));
+ }
+ }
+
+ /*
+ * Saves the current state of the workbench so it can be restored later on
+ */
+ private IStatus saveWorkbenchState(IMemento memento) {
+ MultiStatus result = new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK,
+ WorkbenchMessages.Workbench_problemsSaving, null);
+
+ // TODO: Currently we store the editors history only. Add more if needed
+
+ result.add(getEditorHistory().saveState(
+ memento.createChild(IWorkbenchConstants.TAG_MRU_LIST)));
+ return result;
+ }
+
+ private void restoreWorkbenchState() {
+ try {
+ String persistedState = application.getPersistedState().get(MEMENTO_KEY);
+ if (persistedState != null) {
+ XMLMemento memento = XMLMemento.createReadRoot(new StringReader(persistedState));
+ IStatus status = readWorkbenchState(memento);
+
+ if (status.getSeverity() != IStatus.OK) {
+ WorkbenchPlugin.log(new Status(status.getSeverity(), PlatformUI.PLUGIN_ID,
+ WorkbenchMessages.Workbench_problemsRestoring));
+ }
+ }
+ } catch (Exception e) {
+ WorkbenchPlugin.log(new Status(
+ IStatus.ERROR, PlatformUI.PLUGIN_ID, 0,
+ WorkbenchMessages.Workbench_problemsRestoring, e));
+ }
+ }
+
+ private IStatus readWorkbenchState(IMemento memento) {
+ MultiStatus result = new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK,
+ WorkbenchMessages.Workbench_problemsRestoring, null);
+
+ try {
+ UIStats.start(UIStats.RESTORE_WORKBENCH, "MRUList"); //$NON-NLS-1$
+ IMemento mruMemento = memento.getChild(IWorkbenchConstants.TAG_MRU_LIST);
+ if (mruMemento != null) {
+ result.add(getEditorHistory().restoreState(mruMemento));
+ }
+ } finally {
+ UIStats.end(UIStats.RESTORE_WORKBENCH, this, "MRUList"); //$NON-NLS-1$
+ }
+ return result;
+ }
}