From: khartlage Date: Wed, 8 Jan 2003 19:16:32 +0000 (+0000) Subject: Added actions Comment, Uncommnet, AddBookmark, AddTask X-Git-Url: http://git.phpeclipse.com Added actions Comment, Uncommnet, AddBookmark, AddTask --- diff --git a/net.sourceforge.phpeclipse/plugin.properties b/net.sourceforge.phpeclipse/plugin.properties index 66559cb..b4f9b2e 100644 --- a/net.sourceforge.phpeclipse/plugin.properties +++ b/net.sourceforge.phpeclipse/plugin.properties @@ -1,7 +1,7 @@ ######################################### # ######################################### -pluginName=PHP Plugin +pluginName=PHPEclipse Tools Core providerName=EclipseProject.de naturePHP.name=PHP Project @@ -24,11 +24,18 @@ php3FileExtension=php3 php4FileExtension=php4 incFileExtension=inc phtmlFileExtension=phtml - +htmlFileExtension=html +htmFileExtension=htm +xmlFileExtension=xml # # Action sets # +AddBookmark.label=Add Boo&kmark +AddBookmark.tooltip=Add Bookmark... + +AddTask.label=Add &Task +AddTask.tooltip=Add Task... php.menu.label=&Source phpActionSet.label=PHP Source Actions phpUncommentAction.label=&Uncomment@Ctrl+\\ diff --git a/net.sourceforge.phpeclipse/plugin.xml b/net.sourceforge.phpeclipse/plugin.xml index 63b226c..e99b66f 100644 --- a/net.sourceforge.phpeclipse/plugin.xml +++ b/net.sourceforge.phpeclipse/plugin.xml @@ -93,7 +93,7 @@ - + + id="net.sourceforge.phpeclipse.ProjectNatureImagePHP"> - + - + + + + + + + + + + + + + + + @@ -491,6 +526,30 @@ + + + + + + + + + + + + + * This interface declares constants only; it is not intended to be implemented. + *

+ */ +public interface IContextMenuConstants { + + +// /** +// * Type hierarchy view part: pop-up menu target ID for type hierarchy viewer +// * (value "org.eclipse.jdt.ui.TypeHierarchy.typehierarchy"). +// * +// * @since 2.0 +// */ +// public static final String TARGET_ID_HIERARCHY_VIEW= JavaUI.ID_TYPE_HIERARCHY + ".typehierarchy"; //$NON-NLS-1$ +// +// /** +// * Type hierarchy view part: pop-up menu target ID for supertype hierarchy viewer +// * (value "org.eclipse.jdt.ui.TypeHierarchy.supertypes"). +// * +// * @since 2.0 +// */ +// public static final String TARGET_ID_SUPERTYPES_VIEW= JavaUI.ID_TYPE_HIERARCHY + ".supertypes"; //$NON-NLS-1$ +// +// /** +// * Type hierarchy view part: Pop-up menu target ID for the subtype hierarchy viewer +// * (value "org.eclipse.jdt.ui.TypeHierarchy.subtypes"). +// * +// * @since 2.0 +// */ +// public static final String TARGET_ID_SUBTYPES_VIEW= JavaUI.ID_TYPE_HIERARCHY + ".subtypes"; //$NON-NLS-1$ +// +// /** +// * Type hierarchy view part: pop-up menu target ID for the meber viewer +// * (value "org.eclipse.jdt.ui.TypeHierarchy.members"). +// * +// * @since 2.0 +// */ +// public static final String TARGET_ID_MEMBERS_VIEW= JavaUI.ID_TYPE_HIERARCHY + ".members"; //$NON-NLS-1$ +// + + /** + * Pop-up menu: name of group for goto actions (value "group.open"). + *

+ * Examples for open actions are: + *

    + *
  • Go Into
  • + *
  • Go To
  • + *
+ *

+ */ + public static final String GROUP_GOTO= "group.goto"; //$NON-NLS-1$ + /** + * Pop-up menu: name of group for open actions (value "group.open"). + *

+ * Examples for open actions are: + *

    + *
  • Open To
  • + *
  • Open With
  • + *
+ *

+ */ + public static final String GROUP_OPEN= "group.open"; //$NON-NLS-1$ + + /** + * Pop-up menu: name of group for show actions (value "group.show"). + *

+ * Examples for show actions are: + *

    + *
  • Show in Navigator
  • + *
  • Show in Type Hierarchy
  • + *
+ *

+ */ + public static final String GROUP_SHOW= "group.show"; //$NON-NLS-1$ + + /** + * Pop-up menu: name of group for new actions (value "group.new"). + *

+ * Examples for new actions are: + *

    + *
  • Create new class
  • + *
  • Create new interface
  • + *
+ *

+ */ + public static final String GROUP_NEW= "group.new"; //$NON-NLS-1$ + + /** + * Pop-up menu: name of group for build actions (value "group.build"). + */ + public static final String GROUP_BUILD= "group.build"; //$NON-NLS-1$ + + /** + * Pop-up menu: name of group for reorganize actions (value "group.reorganize"). + */ + public static final String GROUP_REORGANIZE= IWorkbenchActionConstants.GROUP_REORGANIZE; + + /** + * Pop-up menu: name of group for code generation actions ( + * value "group.generate"). + */ + public static final String GROUP_GENERATE= "group.generate"; //$NON-NLS-1$ + + /** + * Pop-up menu: name of group for source actions. This is an alias for + * GROUP_GENERATE to be more consistent with main menu + * bar structure. + * + * @since 2.0 + */ + public static final String GROUP_SOURCE= GROUP_GENERATE; + + /** + * Pop-up menu: name of group for search actions (value "group.search"). + */ + public static final String GROUP_SEARCH= "group.search"; //$NON-NLS-1$ + + /** + * Pop-up menu: name of group for additional actions (value "additions"). + */ + public static final String GROUP_ADDITIONS= "additions"; //$NON-NLS-1$ + + /** + * Pop-up menu: name of group for viewer setup actions (value "group.viewerSetup"). + */ + public static final String GROUP_VIEWER_SETUP= "group.viewerSetup"; //$NON-NLS-1$ + + /** + * Pop-up menu: name of group for properties actions (value "group.properties"). + */ + public static final String GROUP_PROPERTIES= "group.properties"; //$NON-NLS-1$ +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/actions/GenerateActionGroup.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/actions/GenerateActionGroup.java new file mode 100644 index 0000000..fa14ba5 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/actions/GenerateActionGroup.java @@ -0,0 +1,325 @@ +/******************************************************************************* + * Copyright (c) 2002 International Business Machines Corp. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ +package net.sourceforge.phpdt.ui.actions; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import net.sourceforge.phpdt.internal.ui.actions.AddTaskAction; +import net.sourceforge.phpdt.ui.IContextMenuConstants; +import net.sourceforge.phpeclipse.phpeditor.PHPEditor; +import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.util.Assert; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.IWorkbenchSite; +import org.eclipse.ui.actions.ActionGroup; +import org.eclipse.ui.actions.AddBookmarkAction; +import org.eclipse.ui.part.Page; +import org.eclipse.ui.texteditor.ConvertLineDelimitersAction; +import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; + +/** + * Action group that adds the source and generate actions to a part's context + * menu and installs handlers for the corresponding global menu actions. + * + *

+ * This class may be instantiated; it is not intended to be subclassed. + *

+ * + * @since 2.0 + */ +public class GenerateActionGroup extends ActionGroup { + + private boolean fEditorIsOwner; + private IWorkbenchSite fSite; + private String fGroupName= IContextMenuConstants.GROUP_SOURCE; + private List fRegisteredSelectionListeners; + +// private AddImportOnSelectionAction fAddImport; +// private OverrideMethodsAction fOverrideMethods; +// private AddGetterSetterAction fAddGetterSetter; +// private AddUnimplementedConstructorsAction fAddUnimplementedConstructors; +// private AddJavaDocStubAction fAddJavaDocStub; + private AddBookmarkAction fAddBookmark; + private AddTaskAction fAddTaskAction; +// private ExternalizeStringsAction fExternalizeStrings; +// private FindStringsToExternalizeAction fFindStringsToExternalize; +// private SurroundWithTryCatchAction fSurroundWithTryCatch; + + // private OrganizeImportsAction fOrganizeImports; + + private ConvertLineDelimitersAction fConvertToWindows; + private ConvertLineDelimitersAction fConvertToUNIX; + private ConvertLineDelimitersAction fConvertToMac; + + /** + * Note: This constructor is for internal use only. Clients should not call this constructor. + */ + public GenerateActionGroup(PHPEditor editor, String groupName) { + fSite= editor.getSite(); + fEditorIsOwner= true; + fGroupName= groupName; + ISelectionProvider provider= fSite.getSelectionProvider(); + ISelection selection= provider.getSelection(); + +// fAddImport= new AddImportOnSelectionAction(editor); +// fAddImport.setActionDefinitionId(IJavaEditorActionDefinitionIds.ADD_IMPORT); +// fAddImport.update(); +// editor.setAction("AddImport", fAddImport); //$NON-NLS-1$ + +// fOrganizeImports= new OrganizeImportsAction(editor); +// fOrganizeImports.setActionDefinitionId(IJavaEditorActionDefinitionIds.ORGANIZE_IMPORTS); +// fOrganizeImports.editorStateChanged(); +// editor.setAction("OrganizeImports", fOrganizeImports); //$NON-NLS-1$ + +// fOverrideMethods= new OverrideMethodsAction(editor); +// fOverrideMethods.setActionDefinitionId(IJavaEditorActionDefinitionIds.OVERRIDE_METHODS); +// fOverrideMethods.editorStateChanged(); +// editor.setAction("OverrideMethods", fOverrideMethods); //$NON-NLS-1$ + +// fAddGetterSetter= new AddGetterSetterAction(editor); +// fAddGetterSetter.setActionDefinitionId(IJavaEditorActionDefinitionIds.CREATE_GETTER_SETTER); +// fAddGetterSetter.editorStateChanged(); +// editor.setAction("AddGetterSetter", fAddGetterSetter); //$NON-NLS-1$ + +// fAddUnimplementedConstructors= new AddUnimplementedConstructorsAction(editor); +// fAddUnimplementedConstructors.setActionDefinitionId(IJavaEditorActionDefinitionIds.ADD_UNIMPLEMENTED_CONTRUCTORS); +// fAddUnimplementedConstructors.editorStateChanged(); +// editor.setAction("AddUnimplementedConstructors", fAddUnimplementedConstructors); //$NON-NLS-1$ + +// fAddJavaDocStub= new AddJavaDocStubAction(editor); +// fAddJavaDocStub.editorStateChanged(); +// +// fSurroundWithTryCatch= new SurroundWithTryCatchAction(editor); +// fSurroundWithTryCatch.setActionDefinitionId(IJavaEditorActionDefinitionIds.SURROUND_WITH_TRY_CATCH); +// fSurroundWithTryCatch.update(selection); +// provider.addSelectionChangedListener(fSurroundWithTryCatch); +// editor.setAction("SurroundWithTryCatch", fSurroundWithTryCatch); //$NON-NLS-1$ +// +// fExternalizeStrings= new ExternalizeStringsAction(editor); +// fExternalizeStrings.setActionDefinitionId(IJavaEditorActionDefinitionIds.EXTERNALIZE_STRINGS); +// fExternalizeStrings.editorStateChanged(); +// editor.setAction("ExternalizeStrings", fExternalizeStrings); //$NON-NLS-1$ + + fConvertToWindows= new ConvertLineDelimitersAction(editor, "\r\n"); //$NON-NLS-1$ + fConvertToWindows.setActionDefinitionId( ITextEditorActionDefinitionIds .CONVERT_LINE_DELIMITERS_TO_WINDOWS); + editor.setAction("ConvertLineDelimitersToWindows", fConvertToWindows); //$NON-NLS-1$ + + fConvertToUNIX= new ConvertLineDelimitersAction(editor, "\n"); //$NON-NLS-1$ + fConvertToUNIX.setActionDefinitionId( ITextEditorActionDefinitionIds .CONVERT_LINE_DELIMITERS_TO_UNIX); + editor.setAction("ConvertLineDelimitersToUNIX", fConvertToUNIX); //$NON-NLS-1$ + + fConvertToMac= new ConvertLineDelimitersAction(editor, "\r"); //$NON-NLS-1$ + fConvertToMac.setActionDefinitionId( ITextEditorActionDefinitionIds .CONVERT_LINE_DELIMITERS_TO_MAC); + editor.setAction("ConvertLineDelimitersToMac", fConvertToMac); //$NON-NLS-1$ + } + + /** + * Creates a new GenerateActionGroup. The group + * requires that the selection provided by the page's selection provider + * is of type org.eclipse.jface.viewers.IStructuredSelection. + * + * @param page the page that owns this action group + */ + public GenerateActionGroup(Page page) { + this(page.getSite()); + } + + /** + * Creates a new GenerateActionGroup. The group + * requires that the selection provided by the part's selection provider + * is of type org.eclipse.jface.viewers.IStructuredSelection. + * + * @param part the view part that owns this action group + */ + public GenerateActionGroup(IViewPart part) { + this(part.getSite()); + } + + private GenerateActionGroup(IWorkbenchSite site) { + fSite= site; + ISelectionProvider provider= fSite.getSelectionProvider(); + ISelection selection= provider.getSelection(); + +// fOverrideMethods= new OverrideMethodsAction(site); +// fAddGetterSetter= new AddGetterSetterAction(site); +// fAddUnimplementedConstructors= new AddUnimplementedConstructorsAction(site); +// fAddJavaDocStub= new AddJavaDocStubAction(site); + fAddBookmark= new AddBookmarkAction(site.getShell()); + fAddTaskAction= new AddTaskAction(site); +// fExternalizeStrings= new ExternalizeStringsAction(site); +// fFindStringsToExternalize= new FindStringsToExternalizeAction(site); +// fOrganizeImports= new OrganizeImportsAction(site); +// +// fOverrideMethods.update(selection); +// fAddGetterSetter.update(selection); +// fAddUnimplementedConstructors.update(selection); +// fAddJavaDocStub.update(selection); +// fExternalizeStrings.update(selection); +// fFindStringsToExternalize.update(selection); + fAddTaskAction.update(selection); +// fOrganizeImports.update(selection); + if (selection instanceof IStructuredSelection) { + IStructuredSelection ss= (IStructuredSelection)selection; + fAddBookmark.selectionChanged(ss); + } else { + fAddBookmark.setEnabled(false); + } + +// registerSelectionListener(provider, fOverrideMethods); +// registerSelectionListener(provider, fAddGetterSetter); +// registerSelectionListener(provider, fAddUnimplementedConstructors); +// registerSelectionListener(provider, fAddJavaDocStub); + registerSelectionListener(provider, fAddBookmark); +// registerSelectionListener(provider, fExternalizeStrings); +// registerSelectionListener(provider, fFindStringsToExternalize); +// registerSelectionListener(provider, fOrganizeImports); + registerSelectionListener(provider, fAddTaskAction); + } + + private void registerSelectionListener(ISelectionProvider provider, ISelectionChangedListener listener) { + if (fRegisteredSelectionListeners == null) + fRegisteredSelectionListeners= new ArrayList(12); + provider.addSelectionChangedListener(listener); + fRegisteredSelectionListeners.add(listener); + } + + /* + * The state of the editor owning this action group has changed. + * This method does nothing if the group's owner isn't an + * editor. + */ + /** + * Note: This method is for internal use only. Clients should not call this method. + */ + public void editorStateChanged() { + Assert.isTrue(fEditorIsOwner); +// fAddImport.update(); +// fExternalizeStrings.editorStateChanged(); +// fOrganizeImports.editorStateChanged(); +// fOverrideMethods.editorStateChanged(); +// fAddUnimplementedConstructors.editorStateChanged(); +// fAddJavaDocStub.editorStateChanged(); +// fSurroundWithTryCatch.editorStateChanged(); +// fAddGetterSetter.editorStateChanged(); + + // http://dev.eclipse.org/bugs/show_bug.cgi?id=17709 + fConvertToMac.update(); + fConvertToUNIX.update(); + fConvertToWindows.update(); + } + + /* (non-Javadoc) + * Method declared in ActionGroup + */ + public void fillActionBars(IActionBars actionBar) { + super.fillActionBars(actionBar); + setGlobalActionHandlers(actionBar); + } + + /* (non-Javadoc) + * Method declared in ActionGroup + */ + public void fillContextMenu(IMenuManager menu) { + super.fillContextMenu(menu); + if (fEditorIsOwner) { + IMenuManager subMenu= createEditorSubMenu(menu); + if (subMenu != null) + menu.appendToGroup(fGroupName, subMenu); + } else { +// appendToGroup(menu, fOrganizeImports); +// appendToGroup(menu, fOverrideMethods); +// appendToGroup(menu, fAddGetterSetter); +// appendToGroup(menu, fAddUnimplementedConstructors); +// appendToGroup(menu, fAddJavaDocStub); + appendToGroup(menu, fAddBookmark); + } + } + + private IMenuManager createEditorSubMenu(IMenuManager mainMenu) { + IMenuManager result= new MenuManager(ActionMessages.getString("SourceMenu.label")); //$NON-NLS-1$ + int added= 0; +// added+= addAction(result, fOrganizeImports); +// added+= addAction(result, fAddImport); +// result.add(new Separator()); +// added+= addAction(result, fOverrideMethods); +// added+= addAction(result, fAddGetterSetter); +// added+= addAction(result, fAddUnimplementedConstructors); +// added+= addAction(result, fAddJavaDocStub); + added+= addAction(result, fAddBookmark); +// result.add(new Separator()); +// added+= addAction(result, fSurroundWithTryCatch); +// added+= addAction(result, fExternalizeStrings); + if (added == 0) + result= null; + return result; + } + + /* (non-Javadoc) + * Method declared in ActionGroup + */ + public void dispose() { + if (fRegisteredSelectionListeners != null) { + ISelectionProvider provider= fSite.getSelectionProvider(); + for (Iterator iter= fRegisteredSelectionListeners.iterator(); iter.hasNext();) { + ISelectionChangedListener listener= (ISelectionChangedListener) iter.next(); + provider.removeSelectionChangedListener(listener); + } + } + super.dispose(); + } + + private void setGlobalActionHandlers(IActionBars actionBar) { +// actionBar.setGlobalActionHandler(JdtActionConstants.ADD_IMPORT, fAddImport); +// actionBar.setGlobalActionHandler(JdtActionConstants.SURROUND_WITH_TRY_CATCH, fSurroundWithTryCatch); +// actionBar.setGlobalActionHandler(JdtActionConstants.OVERRIDE_METHODS, fOverrideMethods); +// actionBar.setGlobalActionHandler(JdtActionConstants.GENERATE_GETTER_SETTER, fAddGetterSetter); +// actionBar.setGlobalActionHandler(JdtActionConstants.ADD_CONSTRUCTOR_FROM_SUPERCLASS, fAddUnimplementedConstructors); +// actionBar.setGlobalActionHandler(JdtActionConstants.ADD_JAVA_DOC_COMMENT, fAddJavaDocStub); +// actionBar.setGlobalActionHandler(JdtActionConstants.EXTERNALIZE_STRINGS, fExternalizeStrings); +// actionBar.setGlobalActionHandler(JdtActionConstants.FIND_STRINGS_TO_EXTERNALIZE, fFindStringsToExternalize); +// actionBar.setGlobalActionHandler(JdtActionConstants.ORGANIZE_IMPORTS, fOrganizeImports); +// actionBar.setGlobalActionHandler(JdtActionConstants.CONVERT_LINE_DELIMITERS_TO_WINDOWS, fConvertToWindows); +// actionBar.setGlobalActionHandler(JdtActionConstants.CONVERT_LINE_DELIMITERS_TO_UNIX, fConvertToUNIX); +// actionBar.setGlobalActionHandler(JdtActionConstants.CONVERT_LINE_DELIMITERS_TO_MAC, fConvertToMac); + if (!fEditorIsOwner) { + // editor provides its own implementation of these actions. + actionBar.setGlobalActionHandler(IWorkbenchActionConstants.BOOKMARK, fAddBookmark); + actionBar.setGlobalActionHandler(IWorkbenchActionConstants.ADD_TASK, fAddTaskAction); + } + } + + private int appendToGroup(IMenuManager menu, IAction action) { + if (action != null && action.isEnabled()) { + menu.appendToGroup(fGroupName, action); + return 1; + } + return 0; + } + + private int addAction(IMenuManager menu, IAction action) { + if (action != null && action.isEnabled()) { + menu.add(action); + return 1; + } + return 0; + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/actions/PHPEditorActionDefinitionIds.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/actions/PHPEditorActionDefinitionIds.java new file mode 100644 index 0000000..aab8e47 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/actions/PHPEditorActionDefinitionIds.java @@ -0,0 +1,12 @@ +package net.sourceforge.phpdt.ui.actions; + +public interface PHPEditorActionDefinitionIds { + /** + * Value: net.sourceforge.phpeclipse.phpeditor.comment */ + public static final String COMMENT= "net.sourceforge.phpdt.ui.actions.comment"; + + /** + * Value: net.sourceforge.phpeclipse.phpeditor.uncomment + */ + public static final String UNCOMMENT = "net.sourceforge.phpdt.ui.actions.uncomment"; +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/actions/PHPdtActionConstants.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/actions/PHPdtActionConstants.java new file mode 100644 index 0000000..436dc6a --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/actions/PHPdtActionConstants.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2002 International Business Machines Corp. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ +package net.sourceforge.phpdt.ui.actions; + +/** + * Action ids for standard actions, for groups in the menu bar, and + * for actions in context menus of PHPDT views. + * + *

+ * This class may be instantiated; it is not intended to be subclassed. + *

+ * + * @since 2.0 + */ +public class PHPdtActionConstants { + + // Source menu + + /** + * Source menu: name of standard Comment global action + * (value "net.sourceforge.phpdt.ui.actions.Comment"). + */ + public static final String COMMENT= "net.sourceforge.phpdt.ui.actions.Comment"; //$NON-NLS-1$ + + /** + * Source menu: name of standard Uncomment global action + * (value "net.sourceforge.phpdt.ui.actions.Uncomment"). + */ + public static final String UNCOMMENT= "net.sourceforge.phpdt.ui.actions.Uncomment"; //$NON-NLS-1$ + +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/actions/SelectionDispatchAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/actions/SelectionDispatchAction.java new file mode 100644 index 0000000..891c48e --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/actions/SelectionDispatchAction.java @@ -0,0 +1,204 @@ +/******************************************************************************* + * Copyright (c) 2002 International Business Machines Corp. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ +package net.sourceforge.phpdt.ui.actions; + +import org.eclipse.swt.widgets.Shell; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.util.Assert; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; + +import org.eclipse.core.runtime.CoreException; + +import org.eclipse.ui.IWorkbenchSite; +import org.eclipse.ui.texteditor.IUpdate; + +//import org.eclipse.jdt.internal.ui.actions.ActionMessages; +import net.sourceforge.phpdt.internal.ui.util.ExceptionHandler; + +/** + * Action that dispatches the IAction#run() and the + * ISelectionChangedListener#selectionChanged + * according to the type of the selection. + * + *
    + *
  • if selection is of type ITextSelection then + * run(ITextSelection) and selectionChanged(ITextSelection) + * is called.
  • + *
  • if selection is of type IStructuredSelection then + * run(IStructuredSelection) and + * selectionChanged(IStructuredSelection) is called.
  • + *
  • default is to call run(ISelection) and + * selectionChanged(ISelection).
  • + *
+ * + *

+ * Note: This class is not intended to be subclassed outside the JDT UI plugin. + *

+ * + * @since 2.0 + */ +public abstract class SelectionDispatchAction extends Action implements ISelectionChangedListener { + + private IWorkbenchSite fSite; + + /** + * Creates a new action with no text and no image. + *

+ * Configure the action later using the set methods. + *

+ * + * @param site the site this action is working on + */ + protected SelectionDispatchAction(IWorkbenchSite site) { + Assert.isNotNull(site); + fSite= site; + } + + /** + * Returns the site owning this action. + * + * @return the site owning this action + */ + public IWorkbenchSite getSite() { + return fSite; + } + + /** + * Returns the selection provided by the site owning this action. + * + * @return the site's selection + */ + public ISelection getSelection() { + return getSelectionProvider().getSelection(); + } + + /** + * Returns the shell provided by the site owning this action. + * + * @return the site's shell + */ + public Shell getShell() { + return fSite.getShell(); + } + + /** + * Returns the selection provider managed by the site owning this action. + * + * @return the site's selection provider + */ + public ISelectionProvider getSelectionProvider() { + return fSite.getSelectionProvider(); + } + + /** + * Updates the action's enablement state according to the given selection. This + * default implementation calls one of the selectionChanged + * methods depending on the type of the passed selection. + * + * @param selection the selection this action is working on + */ + public void update(ISelection selection) { + dispatchSelectionChanged(selection); + } + + /** + * Notifies this action that the given structured selection has changed. This default + * implementation calls selectionChanged(ISelection selection). + * + * @param selection the new selection + */ + protected void selectionChanged(IStructuredSelection selection) { + selectionChanged((ISelection)selection); + } + + /** + * Executes this actions with the given structured selection. This default implementation + * calls run(ISelection selection). + */ + protected void run(IStructuredSelection selection) { + run((ISelection)selection); + } + + /** + * Notifies this action that the given text selection has changed. This default + * implementation calls selectionChanged(ISelection selection). + * + * @param selection the new selection + */ + protected void selectionChanged(ITextSelection selection) { + selectionChanged((ISelection)selection); + } + + /** + * Executes this actions with the given text selection. This default implementation + * calls run(ISelection selection). + */ + protected void run(ITextSelection selection) { + run((ISelection)selection); + } + + /** + * Notifies this action that the given selection has changed. This default + * implementation sets the action's enablement state to false. + * + * @param selection the new selection + */ + protected void selectionChanged(ISelection selection) { + setEnabled(false); + } + + /** + * Executes this actions with the given selection. This default implementation + * does nothing. + */ + protected void run(ISelection selection) { + } + + /* (non-Javadoc) + * Method declared on IAction. + */ + public void run() { + dispatchRun(getSelection()); + } + + /* (non-Javadoc) + * Method declared on ISelectionChangedListener. + */ + public void selectionChanged(SelectionChangedEvent event) { + dispatchSelectionChanged(event.getSelection()); + } + + private void dispatchSelectionChanged(ISelection selection) { + if (selection instanceof IStructuredSelection) { + selectionChanged((IStructuredSelection)selection); + } else if (selection instanceof ITextSelection) { + selectionChanged((ITextSelection)selection); + } else { + selectionChanged(selection); + } + } + + private void dispatchRun(ISelection selection) { + if (selection instanceof IStructuredSelection) { + run((IStructuredSelection)selection); + } else if (selection instanceof ITextSelection) { + run((ITextSelection)selection); + } else { + run(selection); + } + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java index 6a4051e..c44cc36 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java @@ -35,6 +35,7 @@ import org.eclipse.ui.plugin.AbstractUIPlugin; * The main plugin class to be used in the desktop. */ public interface IPreferenceConstants { + public static final String LOCALHOST_PREF = "_localhost"; //$NON-NLS-1$ public static final String DOCUMENTROOT_PREF = "_documentroot"; //$NON-NLS-1$ public static final String USE_EXTERNAL_BROWSER_PREF = "_use_external_browser"; //$NON-NLS-1$ @@ -66,6 +67,9 @@ public interface IPreferenceConstants { /** Preference key for the foreground color of the line numbers */ public final static String LINE_NUMBER_COLOR= "_lineNumberColor"; //$NON-NLS-1$ + public final static String FORMATTER_TAB_SIZE= "_formatterTabSize"; //$NON-NLS-1$ + public final static String SPACES_FOR_TABS = "false"; + public final static String PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT = "_defaultBackgroundColor"; //$NON-NLS-1$ public final static String PREFERENCE_COLOR_BACKGROUND = "backgroundColor"; //$NON-NLS-1$ diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPPerspectiveFactory.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPPerspectiveFactory.java index 6b508d2..cc41bb1 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPPerspectiveFactory.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPPerspectiveFactory.java @@ -25,7 +25,7 @@ public class PHPPerspectiveFactory implements IPerspectiveFactory { consoleArea.addView(IPageLayout.ID_TASK_LIST); consoleArea.addView(IDebugUIConstants.ID_CONSOLE_VIEW); - consoleArea.addPlaceholder(IPageLayout.ID_BOOKMARKS); + consoleArea.addView(IPageLayout.ID_BOOKMARKS); layout.addView(IPageLayout.ID_OUTLINE, IPageLayout.RIGHT, (float)0.75, editorArea); @@ -38,6 +38,7 @@ public class PHPPerspectiveFactory implements IPerspectiveFactory { // views - standard workbench layout.addShowViewShortcut(IPageLayout.ID_OUTLINE); layout.addShowViewShortcut(IPageLayout.ID_TASK_LIST); + layout.addShowViewShortcut(IPageLayout.ID_BOOKMARKS); // new actions - PHP project creation wizards layout.addNewWizardShortcut("org.eclipse.ui.wizards.new.folder");//$NON-NLS-1$ diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java index feb1c44..15c4c7a 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java @@ -64,7 +64,7 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon //The shared instance. private static PHPeclipsePlugin plugin; //Resource bundle. - private ResourceBundle resourceBundle; + //private ResourceBundle resourceBundle; private ImageDescriptorRegistry fImageDescriptorRegistry; private PHPDocumentProvider fCompilationUnitDocumentProvider; @@ -100,11 +100,11 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon super(descriptor); plugin = this; setJVM(); - try { - resourceBundle = ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources"); - } catch (MissingResourceException x) { - resourceBundle = null; - } +// try { +// resourceBundle = ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources"); +// } catch (MissingResourceException x) { +// resourceBundle = null; +// } } public static ImageDescriptorRegistry getImageDescriptorRegistry() { @@ -229,21 +229,21 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon * Returns the string from the plugin's resource bundle, * or 'key' if not found. */ - public static String getResourceString(String key) { - ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle(); - try { - return bundle.getString(key); - } catch (MissingResourceException e) { - return key; - } - } +// public static String getResourceString(String key) { +// ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle(); +// try { +// return bundle.getString(key); +// } catch (MissingResourceException e) { +// return key; +// } +// } /** * Returns the plugin's resource bundle, */ - public ResourceBundle getResourceBundle() { - return resourceBundle; - } +// public ResourceBundle getResourceBundle() { +// return resourceBundle; +// } protected void initializeDefaultPreferences(IPreferenceStore store) { // windows preferences: @@ -284,6 +284,7 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon // show line numbers: store.setDefault(LINE_NUMBER_RULER, "false"); + store.setDefault(FORMATTER_TAB_SIZE, "4"); // php syntax highlighting PreferenceConverter.setDefault(store, PHP_MULTILINE_COMMENT, PHPColorProvider.MULTI_LINE_COMMENT); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionContributor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionContributor.java index 84fdf1c..f90cf80 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionContributor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionContributor.java @@ -12,23 +12,21 @@ Contributors: Klaus Hartlage - www.eclipseproject.de **********************************************************************/ -import java.util.ResourceBundle; +import net.sourceforge.phpdt.ui.actions.*; import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.Separator; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.editors.text.TextEditorActionContributor; +import org.eclipse.ui.actions.ActionGroup; import org.eclipse.ui.texteditor.BasicTextEditorActionContributor; import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.RetargetTextEditorAction; -import org.eclipse.ui.texteditor.TextEditorAction; /** * Contributes interesting PHP actions to the desktop's Edit menu and the toolbar. */ -public class PHPActionContributor extends BasicTextEditorActionContributor implements PHPEditorActionDefinitionIds { +public class PHPActionContributor extends BasicTextEditorActionContributor { protected RetargetTextEditorAction fContentAssistProposal; // protected RetargetTextEditorAction fContentAssistTip; @@ -78,9 +76,15 @@ public class PHPActionContributor extends BasicTextEditorActionContributor imple // fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$ IActionBars bars = getActionBars(); - bars.setGlobalActionHandler(COMMENT, getAction(textEditor, "Comment")); - bars.setGlobalActionHandler(UNCOMMENT, getAction(textEditor, "Uncomment")); - + bars.setGlobalActionHandler(PHPdtActionConstants.COMMENT, getAction(textEditor, "Comment")); + bars.setGlobalActionHandler(PHPdtActionConstants.UNCOMMENT, getAction(textEditor, "Uncomment")); + + if (part instanceof PHPEditor) { + PHPEditor cuEditor= (PHPEditor)part; + ActionGroup group= cuEditor.getActionGroup(); + if (group != null) + group.fillActionBars(bars); + } // fTogglePresentation.setEditor(editor); // fTogglePresentation.update(); @@ -92,9 +96,7 @@ public class PHPActionContributor extends BasicTextEditorActionContributor imple * @see IEditorActionBarContributor#setActiveEditor(IEditorPart) */ public void setActiveEditor(IEditorPart part) { - super.setActiveEditor(part); - doSetActiveEditor(part); - + doSetActiveEditor(part); } /* diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionGroup.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionGroup.java deleted file mode 100644 index cc4f0c3..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionGroup.java +++ /dev/null @@ -1,21 +0,0 @@ -package net.sourceforge.phpeclipse.phpeditor; - -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.ui.actions.ActionGroup; - -public class PHPActionGroup extends ActionGroup { - protected PHPEditor editor; - protected String menuGroupId; - - public PHPActionGroup(PHPEditor editor, String menuGroupId) { - this.editor = editor; - this.menuGroupId = menuGroupId; - } - - public void fillContextMenu(IMenuManager menu) { - super.fillContextMenu(menu); - - menu.add(editor.getAction("Comment")); - menu.add(editor.getAction("Uncomment")); - } -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java index 2d0b71d..b3e4656 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java @@ -11,6 +11,9 @@ Contributors: IBM Corporation - Initial implementation Klaus Hartlage - www.eclipseproject.de **********************************************************************/ +import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup; +import net.sourceforge.phpdt.ui.actions.*; +import net.sourceforge.phpdt.ui.actions.GenerateActionGroup; import net.sourceforge.phpeclipse.IPreferenceConstants; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner; @@ -37,6 +40,8 @@ import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.RGB; import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.actions.ActionContext; +import org.eclipse.ui.actions.ActionGroup; import org.eclipse.ui.editors.text.TextEditor; import org.eclipse.ui.texteditor.DefaultRangeIndicator; import org.eclipse.ui.texteditor.ITextEditorActionConstants; @@ -45,9 +50,9 @@ import org.eclipse.ui.views.contentoutline.IContentOutlinePage; /** * PHP specific text editor. */ -public class PHPEditor extends TextEditor { +public class PHPEditor extends TextEditor { - protected PHPActionGroup actionGroup; + // protected PHPActionGroup fActionGroups; /** The outline page */ private PHPContentOutlinePage fOutlinePage; private IPreferenceStore phpPrefStore; @@ -55,13 +60,25 @@ public class PHPEditor extends TextEditor { /** The line number ruler column */ private LineNumberRulerColumn fLineNumberRulerColumn; + protected CompositeActionGroup fActionGroups; + /** The standard action groups added to the menu */ + private GenerateActionGroup fGenerateActionGroup; + private CompositeActionGroup fContextMenuGroup; /** * Default constructor. */ public PHPEditor() { super(); + setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$ } + /** + * Returns the standard action group of this editor. + */ + protected ActionGroup getActionGroup() { + return fActionGroups; + } + public PHPContentOutlinePage getfOutlinePage() { return fOutlinePage; } @@ -95,11 +112,23 @@ public class PHPEditor extends TextEditor { action.setActionDefinitionId(PHPEditorActionDefinitionIds.UNCOMMENT); setAction("Uncomment", action); - actionGroup = new PHPActionGroup(this, ITextEditorActionConstants.GROUP_EDIT); + // fActionGroups = new PHPActionGroup(this, ITextEditorActionConstants.GROUP_EDIT); markAsStateDependentAction("Comment", true); //$NON-NLS-1$ markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$ + + fGenerateActionGroup= new GenerateActionGroup(this, ITextEditorActionConstants.GROUP_EDIT); + + fActionGroups= new CompositeActionGroup( + new ActionGroup[] { fGenerateActionGroup } + ); + + // We have to keep the context menu group separate to have better control over positioning + fContextMenuGroup= new CompositeActionGroup(new ActionGroup[] { + fGenerateActionGroup }); +// rg, +// new LocalHistoryActionGroup(this, ITextEditorActionConstants.GROUP_EDIT)}); } /** The PHPEditor implementation of this @@ -110,6 +139,10 @@ public class PHPEditor extends TextEditor { PHPEditorEnvironment.disconnect(this); if (fOutlinePage != null) fOutlinePage.setInput(null); + + if (fActionGroups != null) + fActionGroups.dispose(); + super.dispose(); } @@ -168,9 +201,20 @@ public class PHPEditor extends TextEditor { super.editorContextMenuAboutToShow(menu); // addAction(menu, "ContentAssistProposal"); //$NON-NLS-1$ // addAction(menu, "ContentAssistTip"); //$NON-NLS-1$ - actionGroup.fillContextMenu(menu); + + // fActionGroups.fillContextMenu(menu); + + ActionContext context= new ActionContext(getSelectionProvider().getSelection()); + fContextMenuGroup.setContext(context); + fContextMenuGroup.fillContextMenu(menu); + fContextMenuGroup.setContext(null); } + protected void updateStateDependentActions() { + super.updateStateDependentActions(); + fGenerateActionGroup.editorStateChanged(); + } + /** The PHPEditor implementation of this * AbstractTextEditor method performs gets * the java content outline page if request is for a an @@ -188,27 +232,27 @@ public class PHPEditor extends TextEditor { return super.getAdapter(required); } -// public void openContextHelp() { -// IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput()); -// ITextSelection selection = (ITextSelection) this.getSelectionProvider().getSelection(); -// int pos = selection.getOffset(); -// String word = getFunctionName(doc, pos); -// openContextHelp(word); -// } -// -// private void openContextHelp(String word) { -// open(word); -// } -// -// public static void open(String word) { -// IHelp help = WorkbenchHelp.getHelpSupport(); -// if (help != null) { -// IHelpResource helpResource = new PHPFunctionHelpResource(word); -// WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource); -// } else { -// // showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$ -// } -// } + // public void openContextHelp() { + // IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput()); + // ITextSelection selection = (ITextSelection) this.getSelectionProvider().getSelection(); + // int pos = selection.getOffset(); + // String word = getFunctionName(doc, pos); + // openContextHelp(word); + // } + // + // private void openContextHelp(String word) { + // open(word); + // } + // + // public static void open(String word) { + // IHelp help = WorkbenchHelp.getHelpSupport(); + // if (help != null) { + // IHelpResource helpResource = new PHPFunctionHelpResource(word); + // WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource); + // } else { + // // showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$ + // } + // } private String getFunctionName(IDocument doc, int pos) { Point word = PHPWordExtractor.findWord(doc, pos); @@ -291,7 +335,10 @@ public class PHPEditor extends TextEditor { IVerticalRuler v = getVerticalRuler(); if (v instanceof CompositeRuler) { CompositeRuler c = (CompositeRuler) v; - c.removeDecorator(1); + try { + c.removeDecorator(1); + } catch (Throwable e) { + } } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java index fe08e43..5c0e7b1 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java @@ -11,12 +11,16 @@ Contributors: **********************************************************************/ package net.sourceforge.phpeclipse.phpeditor; +import java.util.Vector; + +import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.phpeditor.php.HTMLCompletionProcessor; import net.sourceforge.phpeclipse.phpeditor.php.PHPAutoIndentStrategy; import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor; import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector; import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner; import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.DefaultAutoIndentStrategy; import org.eclipse.jface.text.IAutoIndentStrategy; import org.eclipse.jface.text.IDocument; @@ -100,11 +104,19 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { /* (non-Javadoc) * Method declared on SourceViewerConfiguration */ - public String getDefaultPrefix(ISourceViewer sourceViewer, String contentType) { - return (PHPPartitionScanner.PHP.equals(contentType) ? "//" : null); //$NON-NLS-1$ - // return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" : null); //$NON-NLS-1$ +// public String getDefaultPrefix(ISourceViewer sourceViewer, String contentType) { +// return (PHPPartitionScanner.PHP.equals(contentType) ? "//" : null); //$NON-NLS-1$ +// // return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" : null); //$NON-NLS-1$ +// } + + /* + * @see SourceViewerConfiguration#getDefaultPrefix(ISourceViewer, String) + * @since 2.0 + */ + public String[] getDefaultPrefixes(ISourceViewer sourceViewer, String contentType) { + return new String[] { "//", "" }; //$NON-NLS-1$ //$NON-NLS-2$ } - + /* (non-Javadoc) * Method declared on SourceViewerConfiguration */ @@ -115,10 +127,48 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { /* (non-Javadoc) * Method declared on SourceViewerConfiguration */ +// public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) { +// return new String[] { "\t", " " }; //$NON-NLS-1$ //$NON-NLS-2$ +// } + + /* + * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String) + */ public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) { - return new String[] { "\t", " " }; //$NON-NLS-1$ //$NON-NLS-2$ - } + Vector vector= new Vector(); + + // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces + + final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); + + int tabWidth= store.getInt(PHPeclipsePlugin.FORMATTER_TAB_SIZE); + boolean useSpaces= store.getBoolean(PHPeclipsePlugin.SPACES_FOR_TABS); + + for (int i= 0; i <= tabWidth; i++) { + StringBuffer prefix= new StringBuffer(); + + if (useSpaces) { + for (int j= 0; j + i < tabWidth; j++) + prefix.append(' '); + + if (i != 0) + prefix.append('\t'); + } else { + for (int j= 0; j < i; j++) + prefix.append(' '); + + if (i != tabWidth) + prefix.append('\t'); + } + + vector.add(prefix.toString()); + } + + vector.add(""); //$NON-NLS-1$ + + return (String[]) vector.toArray(new String[vector.size()]); + } /* (non-Javadoc) * Method declared on SourceViewerConfiguration */ diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCodeScanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCodeScanner.java index 8c0d37a..160925c 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCodeScanner.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCodeScanner.java @@ -161,10 +161,15 @@ public class PHPCodeScanner extends RuleBasedScanner implements IPreferenceConst // //for (int i = 0; i < PHPFunctionNames.FUNCTION_NAMES.length; i++) // // wordRule.addWord(PHPFunctionNames.FUNCTION_NAMES[i], functionName); // //<--choochter - for (int i = 0; i < PHPFunctionNames.FUNCTION_NAMES.length; i++) + for (int i = 0; i < PHPKeywords.PHP_KEYWORS.length; i++) { + wordRule.addWord(PHPKeywords.PHP_KEYWORS[i], keyword); + } + for (int i = 0; i < PHPFunctionNames.FUNCTION_NAMES.length; i++) { wordRule.addWord(PHPFunctionNames.FUNCTION_NAMES[i], functionName); - for (int i = 0; i < fgConstants.length; i++) - wordRule.addWord(fgConstants[i], functionName); + } + for (int i = 0; i < fgConstants.length; i++) { + wordRule.addWord(fgConstants[i], keyword); + } rules.add(wordRule); IRule[] result = new IRule[rules.size()]; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java index 40e2fce..cfceb5e 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java @@ -14,29 +14,26 @@ Contributors: import java.io.IOException; import java.io.InputStream; -import java.text.MessageFormat; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.actions.PHPActionMessages; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.TextViewer; -import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.IWorkbenchWindowActionDelegate; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; -import sun.security.krb5.internal.crypto.e; /** * The PHPConsole is used to display the output if you start MySQL/Apache @@ -64,6 +61,29 @@ public class PHPConsole extends ViewPart { GridData viewerData = new GridData(GridData.FILL_BOTH); viewer.getControl().setLayoutData(viewerData); viewer.setEditable(false); + + StyledText widget = viewer.getTextWidget(); + widget.setFont(JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT)); + Action cutAction = new Action() { + public void run() { + viewer.getTextWidget().cut(); + } + }; + Action copyAction = new Action() { + public void run() { + viewer.getTextWidget().copy(); + } + }; + Action pasteAction = new Action() { + public void run() { + viewer.getTextWidget().paste(); + } + }; + + IActionBars bars = this.getViewSite().getActionBars(); + bars.setGlobalActionHandler(IWorkbenchActionConstants.CUT, cutAction); + bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction); + bars.setGlobalActionHandler(IWorkbenchActionConstants.PASTE, pasteAction); } /**