1 11 12 package org.eclipse.ui.internal.actions; 13 14 import org.eclipse.ui.IEditorPart; 15 import org.eclipse.ui.IPersistableEditor; 16 import org.eclipse.ui.IWorkbenchPage; 17 import org.eclipse.ui.IWorkbenchWindow; 18 import org.eclipse.ui.PartInitException; 19 import org.eclipse.ui.XMLMemento; 20 import org.eclipse.ui.internal.ActiveEditorAction; 21 import org.eclipse.ui.internal.IWorkbenchConstants; 22 import org.eclipse.ui.internal.WorkbenchMessages; 23 import org.eclipse.ui.internal.WorkbenchPage; 24 import org.eclipse.ui.internal.dialogs.DialogUtil; 25 26 31 public class NewEditorAction extends ActiveEditorAction { 32 33 38 public NewEditorAction(IWorkbenchWindow window) { 39 super(WorkbenchMessages.NewEditorAction_text, window); 40 setId("newEditorAction"); setToolTipText(WorkbenchMessages.NewEditorAction_tooltip); 42 setActionDefinitionId("org.eclipse.ui.window.newEditor"); } 44 45 48 public void run() { 49 IWorkbenchPage page = getActivePage(); 50 IEditorPart editor = getActiveEditor(); 51 if (page == null || editor == null) { 52 return; 53 } 54 String editorId = editor.getSite().getId(); 55 if (editorId == null) { 56 return; 57 } 58 try { 59 if (editor instanceof IPersistableEditor) { 60 XMLMemento editorState = XMLMemento 61 .createWriteRoot(IWorkbenchConstants.TAG_EDITOR_STATE); 62 ((IPersistableEditor) 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) { 70 DialogUtil.openError(page.getWorkbenchWindow().getShell(), 71 WorkbenchMessages.Error, 72 e.getMessage(), e); 73 } 74 } 75 } 76 77 | Popular Tags |