Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 44295 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/actions/NewEditorAction.java (-2 / +15 lines)
Lines 12-22 Link Here
12
package org.eclipse.ui.internal.actions;
12
package org.eclipse.ui.internal.actions;
13
13
14
import org.eclipse.ui.IEditorPart;
14
import org.eclipse.ui.IEditorPart;
15
import org.eclipse.ui.IEditorPersistable;
15
import org.eclipse.ui.IWorkbenchPage;
16
import org.eclipse.ui.IWorkbenchPage;
16
import org.eclipse.ui.IWorkbenchWindow;
17
import org.eclipse.ui.IWorkbenchWindow;
17
import org.eclipse.ui.PartInitException;
18
import org.eclipse.ui.PartInitException;
19
import org.eclipse.ui.XMLMemento;
18
import org.eclipse.ui.internal.ActiveEditorAction;
20
import org.eclipse.ui.internal.ActiveEditorAction;
21
import org.eclipse.ui.internal.IWorkbenchConstants;
19
import org.eclipse.ui.internal.WorkbenchMessages;
22
import org.eclipse.ui.internal.WorkbenchMessages;
23
import org.eclipse.ui.internal.WorkbenchPage;
20
import org.eclipse.ui.internal.dialogs.DialogUtil;
24
import org.eclipse.ui.internal.dialogs.DialogUtil;
21
25
22
/**
26
/**
Lines 52-59 Link Here
52
			return;
56
			return;
53
		}
57
		}
54
		try {
58
		try {
55
			page.openEditor(editor.getEditorInput(), editorId, true, IWorkbenchPage.MATCH_NONE);
59
			if (editor instanceof IEditorPersistable) {
56
        } catch (PartInitException e) {
60
				XMLMemento editorState = XMLMemento
61
						.createWriteRoot(IWorkbenchConstants.TAG_EDITOR_STATE);
62
				((IEditorPersistable) editor).saveState(editorState);
63
				((WorkbenchPage) page).openEditor(editor.getEditorInput(),
64
						editorId, true, IWorkbenchPage.MATCH_NONE, editorState);
65
			} else {
66
				page.openEditor(editor.getEditorInput(), editorId, true,
67
						IWorkbenchPage.MATCH_NONE);
68
			}
69
		} catch (PartInitException e) {
57
            DialogUtil.openError(page.getWorkbenchWindow().getShell(),
70
            DialogUtil.openError(page.getWorkbenchWindow().getShell(),
58
                    WorkbenchMessages.Error,
71
                    WorkbenchMessages.Error,
59
                    e.getMessage(), e);
72
                    e.getMessage(), e);
(-)Eclipse UI/org/eclipse/ui/internal/EditorReference.java (-9 / +36 lines)
Lines 56-62 Link Here
56
56
57
    private IMemento editorMemento;
57
    private IMemento editorMemento;
58
58
59
	private IMemento editorState;
59
	private IMemento editorState = null;
60
60
61
    /**
61
    /**
62
     * Flag that lets us detect malfunctioning editors that don't fire PROP_INPUT events.
62
     * Flag that lets us detect malfunctioning editors that don't fire PROP_INPUT events.
Lines 89-104 Link Here
89
	private IEditorReference[] multiEditorChildren = null;
89
	private IEditorReference[] multiEditorChildren = null;
90
90
91
    
91
    
92
    public EditorReference(EditorManager manager, IEditorInput input, EditorDescriptor desc) {
92
    /**
93
        this.manager = manager;
93
	 * @param manager
94
        initListenersAndHandlers();
94
	 *            The editor manager for this reference
95
        restoredInput = input;
95
	 * @param input
96
        init(desc.getId(), desc.getLabel(), "", desc.getImageDescriptor(), desc.getLabel(), "");  //$NON-NLS-1$//$NON-NLS-2$
96
	 *            our input
97
    }
97
	 * @param desc
98
	 *            the descriptor from the declaration
99
	 */
100
	public EditorReference(EditorManager manager, IEditorInput input,
101
			EditorDescriptor desc) {
102
		this(manager, input, desc, null);
103
	}
98
    
104
    
99
    /**
105
    /**
100
     * Constructs a new editor reference for use by editors being restored from a memento.
106
	 * @param manager
101
     */
107
	 *            The editor manager for this reference
108
	 * @param input
109
	 *            our input
110
	 * @param desc
111
	 *            the descriptor from the declaration
112
	 * @param editorState
113
	 *            propogate state from another editor. Can be <code>null</code>.
114
	 */
115
	public EditorReference(EditorManager manager, IEditorInput input,
116
			EditorDescriptor desc, IMemento editorState) {
117
		this.manager = manager;
118
		initListenersAndHandlers();
119
		restoredInput = input;
120
		this.editorState = editorState;
121
		init(desc.getId(), desc.getLabel(),
122
				"", desc.getImageDescriptor(), desc.getLabel(), ""); //$NON-NLS-1$//$NON-NLS-2$
123
	}
124
    
125
    /**
126
	 * Constructs a new editor reference for use by editors being restored from
127
	 * a memento.
128
	 */
102
    EditorReference(EditorManager manager, IMemento memento) {
129
    EditorReference(EditorManager manager, IMemento memento) {
103
        this.manager = manager;
130
        this.manager = manager;
104
        initListenersAndHandlers();
131
        initListenersAndHandlers();
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java (-5 / +15 lines)
Lines 2467-2472 Link Here
2467
    public IEditorPart openEditor(final IEditorInput input,
2467
    public IEditorPart openEditor(final IEditorInput input,
2468
            final String editorID, final boolean activate, final int matchFlags)
2468
            final String editorID, final boolean activate, final int matchFlags)
2469
            throws PartInitException {
2469
            throws PartInitException {
2470
    	return openEditor(input, editorID, activate, matchFlags, null);
2471
    }
2472
	
2473
    /**
2474
     * This is not public API but for use internally.  editorState can be <code>null</code>.
2475
     */
2476
    public IEditorPart openEditor(final IEditorInput input,
2477
            final String editorID, final boolean activate, final int matchFlags,
2478
            final IMemento editorState)
2479
            throws PartInitException {
2470
        if (input == null || editorID == null) {
2480
        if (input == null || editorID == null) {
2471
            throw new IllegalArgumentException();
2481
            throw new IllegalArgumentException();
2472
        }
2482
        }
Lines 2478-2484 Link Here
2478
                    public void run() {
2488
                    public void run() {
2479
                        try {
2489
                        try {
2480
                            result[0] = busyOpenEditor(input, editorID,
2490
                            result[0] = busyOpenEditor(input, editorID,
2481
                                    activate, matchFlags);
2491
                                    activate, matchFlags, editorState);
2482
                        } catch (PartInitException e) {
2492
                        } catch (PartInitException e) {
2483
                            ex[0] = e;
2493
                            ex[0] = e;
2484
                        }
2494
                        }
Lines 2494-2507 Link Here
2494
     * @see #openEditor(IEditorInput, String, boolean, int)
2504
     * @see #openEditor(IEditorInput, String, boolean, int)
2495
	 */
2505
	 */
2496
    private IEditorPart busyOpenEditor(IEditorInput input, String editorID,
2506
    private IEditorPart busyOpenEditor(IEditorInput input, String editorID,
2497
            boolean activate, int matchFlags) throws PartInitException {
2507
            boolean activate, int matchFlags, IMemento editorState) throws PartInitException {
2498
2508
2499
        final Workbench workbench = (Workbench) getWorkbenchWindow()
2509
        final Workbench workbench = (Workbench) getWorkbenchWindow()
2500
                .getWorkbench();
2510
                .getWorkbench();
2501
        workbench.largeUpdateStart();
2511
        workbench.largeUpdateStart();
2502
2512
2503
        try {
2513
        try {
2504
            return busyOpenEditorBatched(input, editorID, activate, matchFlags);
2514
            return busyOpenEditorBatched(input, editorID, activate, matchFlags, editorState);
2505
2515
2506
        } finally {
2516
        } finally {
2507
            workbench.largeUpdateEnd();
2517
            workbench.largeUpdateEnd();
Lines 2514-2520 Link Here
2514
     * @see IWorkbenchPage#openEditor(IEditorInput, String, boolean)
2524
     * @see IWorkbenchPage#openEditor(IEditorInput, String, boolean)
2515
     */
2525
     */
2516
    private IEditorPart busyOpenEditorBatched(IEditorInput input,
2526
    private IEditorPart busyOpenEditorBatched(IEditorInput input,
2517
            String editorID, boolean activate,  int matchFlags) throws PartInitException {
2527
            String editorID, boolean activate,  int matchFlags, IMemento editorState) throws PartInitException {
2518
2528
2519
        // If an editor already exists for the input, use it.
2529
        // If an editor already exists for the input, use it.
2520
		IEditorPart editor = getEditorManager().findEditor(editorID, input, matchFlags);
2530
		IEditorPart editor = getEditorManager().findEditor(editorID, input, matchFlags);
Lines 2566-2572 Link Here
2566
        // Otherwise, create a new one. This may cause the new editor to
2576
        // Otherwise, create a new one. This may cause the new editor to
2567
        // become the visible (i.e top) editor.
2577
        // become the visible (i.e top) editor.
2568
        IEditorReference ref = null;
2578
        IEditorReference ref = null;
2569
        ref = getEditorManager().openEditor(editorID, input, true);
2579
        ref = getEditorManager().openEditor(editorID, input, true, editorState);
2570
        if (ref != null) {
2580
        if (ref != null) {
2571
            editor = ref.getEditor(true);
2581
            editor = ref.getEditor(true);
2572
        }
2582
        }
(-)Eclipse UI/org/eclipse/ui/internal/EditorManager.java (-3 / +21 lines)
Lines 666-671 Link Here
666
	 */
666
	 */
667
	public IEditorReference openEditor(String editorId, IEditorInput input,
667
	public IEditorReference openEditor(String editorId, IEditorInput input,
668
			boolean setVisible) throws PartInitException {
668
			boolean setVisible) throws PartInitException {
669
		return openEditor(editorId, input, setVisible, null);
670
	}
671
672
	/**
673
	 * @param editorId
674
	 *            the editor part id
675
	 * @param input
676
	 *            the input
677
	 * @param setVisible
678
	 *            if this is to be created visible ... not used
679
	 * @param editorState
680
	 *            an {@link IMemento} &lt;editorState&gt; for persistable
681
	 *            editors. Can be <code>null</code>.
682
	 * @return a created editor reference
683
	 * @throws PartInitException
684
	 */
685
	public IEditorReference openEditor(String editorId, IEditorInput input,
686
			boolean setVisible, IMemento editorState) throws PartInitException {
669
		if (editorId == null || input == null) {
687
		if (editorId == null || input == null) {
670
			throw new IllegalArgumentException();
688
			throw new IllegalArgumentException();
671
		}
689
		}
Lines 678-684 Link Here
678
					editorId));
696
					editorId));
679
		}
697
		}
680
698
681
		IEditorReference result = openEditorFromDescriptor(desc, input);
699
		IEditorReference result = openEditorFromDescriptor(desc, input, editorState);
682
		return result;
700
		return result;
683
	}
701
	}
684
702
Lines 686-697 Link Here
686
	 * Open a new editor
704
	 * Open a new editor
687
	 */
705
	 */
688
	private IEditorReference openEditorFromDescriptor(EditorDescriptor desc,
706
	private IEditorReference openEditorFromDescriptor(EditorDescriptor desc,
689
			IEditorInput input) throws PartInitException {
707
			IEditorInput input, IMemento editorState) throws PartInitException {
690
		IEditorReference result = null;
708
		IEditorReference result = null;
691
		if (desc.isInternal()) {
709
		if (desc.isInternal()) {
692
			result = reuseInternalEditor(desc, input);
710
			result = reuseInternalEditor(desc, input);
693
			if (result == null) {
711
			if (result == null) {
694
				result = new EditorReference(this, input, desc);
712
				result = new EditorReference(this, input, desc, editorState);
695
			}
713
			}
696
		} else if (desc.getId()
714
		} else if (desc.getId()
697
				.equals(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID)) {
715
				.equals(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID)) {

Return to bug 44295