1 11 package org.eclipse.ui.internal.editors.text; 12 13 import org.eclipse.core.filesystem.EFS; 14 import org.eclipse.core.filesystem.IFileStore; 15 16 import org.eclipse.core.runtime.IPath; 17 18 import org.eclipse.jface.viewers.IStructuredSelection; 19 import org.eclipse.jface.wizard.Wizard; 20 21 import org.eclipse.ui.editors.text.EditorsUI; 22 23 import org.eclipse.ui.IEditorDescriptor; 24 import org.eclipse.ui.IEditorInput; 25 import org.eclipse.ui.IEditorRegistry; 26 import org.eclipse.ui.INewWizard; 27 import org.eclipse.ui.IWorkbench; 28 import org.eclipse.ui.IWorkbenchPage; 29 import org.eclipse.ui.IWorkbenchWindow; 30 import org.eclipse.ui.PartInitException; 31 32 38 public class UntitledTextFileWizard extends Wizard implements INewWizard { 39 40 private IWorkbenchWindow fWindow; 41 42 public UntitledTextFileWizard() { 43 } 44 45 48 public void dispose() { 49 fWindow= null; 50 } 51 52 private IFileStore queryFileStore() { 53 IPath stateLocation= EditorsPlugin.getDefault().getStateLocation(); 54 IPath path= stateLocation.append("/_" + new Object ().hashCode()); return EFS.getLocalFileSystem().getStore(path); 56 } 57 58 private String getEditorId(IFileStore fileStore) { 59 IWorkbench workbench= fWindow.getWorkbench(); 60 IEditorRegistry editorRegistry= workbench.getEditorRegistry(); 61 IEditorDescriptor descriptor= editorRegistry.getDefaultEditor(fileStore.getName()); 62 if (descriptor != null) 63 return descriptor.getId(); 64 return EditorsUI.DEFAULT_TEXT_EDITOR_ID; 65 } 66 67 private IEditorInput createEditorInput(IFileStore fileStore) { 68 return new NonExistingFileEditorInput(fileStore, TextEditorMessages.NewTextEditorAction_namePrefix); 69 } 70 71 74 public boolean performFinish() { 75 IFileStore fileStore= queryFileStore(); 76 IEditorInput input= createEditorInput(fileStore); 77 String editorId= getEditorId(fileStore); 78 IWorkbenchPage page= fWindow.getActivePage(); 79 try { 80 page.openEditor(input, editorId); 81 } catch (PartInitException e) { 82 EditorsPlugin.log(e); 83 return false; 84 } 85 return true; 86 } 87 88 91 public void init(IWorkbench workbench, IStructuredSelection selection) { 92 fWindow= workbench.getActiveWorkbenchWindow(); 93 } 94 } 95 | Popular Tags |