Permalink
Browse files

Some adjustments of scratchpad

Removed some wizards
  • Loading branch information...
1 parent dff9b40 commit 2b9a67c21c769410afcf3250bfe30f6352f94416 @jakobc jakobc committed Feb 25, 2013
View
@@ -77,6 +77,13 @@
id="org.erlide.ui.wizards.ErlangSourceFile"
name="Module">
</wizard>
+ <wizard
+ category="org.erlide.ui.wizards.newWizards"
+ class="org.erlide.ui.editors.scratchpad.NewErlangScratchPadWizard"
+ icon="icons/full/obj16/newproject.png"
+ id="org.erlide.ui.wizards.ErlangScratchpad"
+ name="Erlang Scratchpad">
+ </wizard>
</extension>
<extension
point="org.eclipse.ui.popupMenus">
@@ -1456,6 +1463,11 @@
</adapt>
</enablement>
</actionProvider>
+ <commonWizard
+ type="new"
+ wizardId="org.erlide.ui.wizards.ErlangScratchpad">
+ <enablement></enablement>
+ </commonWizard>
</extension>
<extension
point="org.eclipse.ui.navigator.linkHelper">
@@ -1506,39 +1518,6 @@
</wizard>
</extension>
<extension
- point="org.eclipse.ui.popupMenus">
- <objectContribution
- id="org.erlide.ui.navigatorObjectContribution"
- objectClass="org.eclipse.core.resources.IResource">
- <action
- class="org.erlide.ui.actions.NewErlangModuleAction"
- icon="icons/full/obj16/erlang_NewModule.png"
- id="org.erlide.ui.menuModuleAction"
- label="New Module"
- menubarPath="erlideMenu2">
- </action>
- <action
- class="org.erlide.ui.editors.scratchpad.NewErlangScratchPadAction"
- icon="icons/full/obj16/erlang_NewModule.png"
- id="org.erlide.ui.menuNewScratchPadAction"
- label="New Scratch Pad"
- menubarPath="erlideMenu2">
- </action>
-
- </objectContribution>
- <viewerContribution
- id="org.erlide.ui.navigatorViewerContribution"
- targetID="org.erlide.ui.views.navigator.view#PopupMenu">
- <action
- class="org.erlide.ui.actions.NewErlangProjectAction"
- icon="icons/full/obj16/newproject.png"
- id="org.erlide.ui.menuProjectAction"
- label="New Erlang Project"
- menubarPath="erlidemenu1">
- </action>
- </viewerContribution>
- </extension>
- <extension
point="org.eclipse.ui.navigator.linkHelper">
<linkHelper
class="org.erlide.ui.actions.ErlangLinkHelperAction"
@@ -1,66 +0,0 @@
-package org.erlide.ui.editors.scratchpad;
-
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.actions.ActionDelegate;
-
-public class NewErlangScratchPadAction extends ActionDelegate {
-
- private IStructuredSelection selection;
-
- public NewErlangScratchPadAction() {
- selection = StructuredSelection.EMPTY;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.actions.ActionDelegate#selectionChanged(org.eclipse.jface
- * .action.IAction, org.eclipse.jface.viewers.ISelection)
- */
- @Override
- public void selectionChanged(final IAction action, final ISelection sel) {
- if (sel instanceof IStructuredSelection) {
- selectionChanged((IStructuredSelection) sel);
- } else {
- selection = StructuredSelection.EMPTY;
- }
- }
-
- @Override
- public void run(final IAction action) {
- // Create the Wizard
- final NewErlangScratchPadWizard wizard = new NewErlangScratchPadWizard();
- wizard.init(getWorkbench(), selection);
-
- // Create the wizard dialog
- final Shell shell = getWorkbench().getActiveWorkbenchWindow()
- .getShell();
- final WizardDialog dialog = new WizardDialog(shell, wizard);
- // Open the wizard dialog
- dialog.open();
- }
-
- private IWorkbench getWorkbench() {
- return PlatformUI.getWorkbench();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse
- * .jface.viewers.IStructuredSelection)
- */
- public void selectionChanged(final IStructuredSelection aSelection) {
- selection = aSelection;
- }
-
-}
@@ -30,125 +30,124 @@
public class NewErlangScratchPadWizard extends Wizard implements INewWizard {
- private IStructuredSelection fSelection;
- private NewErlangScratchPadWizardPage fPage;
-
- NewErlangScratchPadWizard() {
- super();
- setNeedsProgressMonitor(true);
- }
-
- @Override
- public void addPages() {
- fPage = new NewErlangScratchPadWizardPage(fSelection);
- addPage(fPage);
- }
-
- // FIXME copied a lot from ErlangFileWizard, we should refactor to common
- // base class...
-
- @Override
- public boolean performFinish() {
- final IPath containerFullPath = fPage.getContainerFullPath();
- final String fileName = fPage.getFileName();
- final IRunnableWithProgress op = new IRunnableWithProgress() {
-
- public void run(final IProgressMonitor monitor)
- throws InvocationTargetException {
- try {
- doFinish(containerFullPath, fileName, monitor);
- } catch (final CoreException e) {
- throw new InvocationTargetException(e);
- } finally {
- monitor.done();
- }
- }
- };
- try {
- getContainer().run(true, false, op);
- } catch (final InterruptedException e) {
- return false;
- } catch (final InvocationTargetException e) {
- final Throwable realException = e.getTargetException();
- MessageDialog.openError(getShell(), "Error", realException
- .getMessage());
- return false;
- }
- return true;
- }
-
- /**
- * The worker method. It will find the container, create the file if missing
- * or just replace its contents, and open the editor on the newly created
- * file.
- */
- public void doFinish(final IPath containerFullPath, final String fileName,
- final IProgressMonitor monitor) throws CoreException {
-
- // ErlLogger.debug("Generating a file with skeleton: "+skeleton);
-
- // create a sample file
- monitor.beginTask("Creating " + fileName, 2);
- final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- final IResource resource = root.findMember(containerFullPath);
- if (!resource.exists() || !(resource instanceof IContainer)) {
- throwCoreException("Container \"" + containerFullPath
- + "\" does not exist.");
- }
- final IContainer container = (IContainer) resource;
- IPath path = new Path(fileName);
- final String ext = path.getFileExtension();
- if (!"erlScratchPad".equals(ext)) {
- path = path.addFileExtension("erlScratchPad");
- }
- final IFile file = container.getFile(path);
- try {
- final InputStream stream = openContentStream();
- if (file.exists()) {
- file.setContents(stream, true, true, monitor);
- } else {
- file.create(stream, true, monitor);
- }
- stream.close();
- } catch (final IOException e) {
- }
- monitor.worked(1);
-
- // ErlangCore.getModelManager().create(file, null);
-
- monitor.setTaskName("Opening file for editing...");
- getShell().getDisplay().asyncExec(new Runnable() {
-
- public void run() {
- final IWorkbenchPage page = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow().getActivePage();
- try {
- IDE.openEditor(page, file, true);
- } catch (final PartInitException e) {
- }
- }
- });
- monitor.worked(1);
- }
-
- /**
- * We will initialize file contents with a sample text.
- */
-
- private InputStream openContentStream() {
- String s = "%% This is a scratch pad for running erlang code on a node\n%% Everything is saved";
- return new ByteArrayInputStream(s.getBytes(Charset.forName("UTF8")));
- }
-
- private void throwCoreException(final String message) throws CoreException {
- final IStatus status = new Status(IStatus.ERROR, "Erlang_Wizard",
- IStatus.OK, message, null);
- throw new CoreException(status);
- }
-
- public void init(final IWorkbench workbench,
- final IStructuredSelection selection) {
- fSelection = selection;
- }
+ private IStructuredSelection fSelection;
+ private NewErlangScratchPadWizardPage fPage;
+
+ @Override
+ public void addPages() {
+ fPage = new NewErlangScratchPadWizardPage(fSelection);
+ addPage(fPage);
+ }
+
+ // FIXME copied a lot from ErlangFileWizard, we should refactor to common
+ // base class...
+
+ @Override
+ public boolean performFinish() {
+ final IPath containerFullPath = fPage.getContainerFullPath();
+ final String fileName = fPage.getFileName();
+ final IRunnableWithProgress op = new IRunnableWithProgress() {
+
+ @Override
+ public void run(final IProgressMonitor monitor)
+ throws InvocationTargetException {
+ try {
+ doFinish(containerFullPath, fileName, monitor);
+ } catch (final CoreException e) {
+ throw new InvocationTargetException(e);
+ } finally {
+ monitor.done();
+ }
+ }
+ };
+ try {
+ getContainer().run(true, false, op);
+ } catch (final InterruptedException e) {
+ return false;
+ } catch (final InvocationTargetException e) {
+ final Throwable realException = e.getTargetException();
+ MessageDialog.openError(getShell(), "Error",
+ realException.getMessage());
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * The worker method. It will find the container, create the file if missing
+ * or just replace its contents, and open the editor on the newly created
+ * file.
+ */
+ public void doFinish(final IPath containerFullPath, final String fileName,
+ final IProgressMonitor monitor) throws CoreException {
+
+ // ErlLogger.debug("Generating a file with skeleton: "+skeleton);
+
+ // create a sample file
+ monitor.beginTask("Creating " + fileName, 2);
+ final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ final IResource resource = root.findMember(containerFullPath);
+ if (!resource.exists() || !(resource instanceof IContainer)) {
+ throwCoreException("Container \"" + containerFullPath
+ + "\" does not exist.");
+ }
+ final IContainer container = (IContainer) resource;
+ IPath path = new Path(fileName);
+ final String ext = path.getFileExtension();
+ if (!"erlScratchPad".equals(ext)) {
+ path = path.addFileExtension("erlScratchPad");
+ }
+ final IFile file = container.getFile(path);
+ try {
+ final InputStream stream = openContentStream();
+ if (file.exists()) {
+ file.setContents(stream, true, true, monitor);
+ } else {
+ file.create(stream, true, monitor);
+ }
+ stream.close();
+ } catch (final IOException e) {
+ }
+ monitor.worked(1);
+
+ // ErlangCore.getModelManager().create(file, null);
+
+ monitor.setTaskName("Opening file for editing...");
+ getShell().getDisplay().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ final IWorkbenchPage page = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage();
+ try {
+ IDE.openEditor(page, file, true);
+ } catch (final PartInitException e) {
+ }
+ }
+ });
+ monitor.worked(1);
+ }
+
+ /**
+ * We will initialize file contents with a sample text.
+ */
+
+ private InputStream openContentStream() {
+ final String s = "%% This is a scratch pad for running erlang code\n%% Everything is saved";
+ return new ByteArrayInputStream(s.getBytes(Charset.forName("UTF8")));
+ }
+
+ private void throwCoreException(final String message) throws CoreException {
+ final IStatus status = new Status(IStatus.ERROR, "Erlang_Wizard",
+ IStatus.OK, message, null);
+ throw new CoreException(status);
+ }
+
+ @Override
+ public void init(final IWorkbench workbench,
+ final IStructuredSelection selection) {
+ fSelection = selection;
+ setNeedsProgressMonitor(true);
+ }
}
@@ -94,11 +94,12 @@ private void defineShortcuts(final IPageLayout layout) {
layout.addShowViewShortcut(IPageLayout.ID_OUTLINE);
layout.addShowViewShortcut(IPageLayout.ID_PROJECT_EXPLORER);
//
- layout.addNewWizardShortcut("org.erlide.ui.wizards.newproject");
- layout.addNewWizardShortcut("org.erlide.ui.wizards.ErlangSourceFile");
+ layout.addNewWizardShortcut("org.erlide.ui.wizards.newproject");//$NON-NLS-1$
+ layout.addNewWizardShortcut("org.erlide.ui.wizards.ErlangSourceFile");//$NON-NLS-1$
layout.addNewWizardShortcut("org.eclipse.ui.wizards.new.folder"); //$NON-NLS-1$
layout.addNewWizardShortcut("org.eclipse.ui.wizards.new.file"); //$NON-NLS-1$
layout.addNewWizardShortcut("org.eclipse.ui.editors.wizards.UntitledTextFileWizard");//$NON-NLS-1$
+ layout.addNewWizardShortcut("org.erlide.ui.wizards.ErlangScratchpad");//$NON-NLS-1$
}
}

0 comments on commit 2b9a67c

Please sign in to comment.