From 5d0dc44ff3cd15b721e8dac7d4aaa88d155a38e6 Mon Sep 17 00:00:00 2001 From: khartlage Date: Fri, 27 Dec 2002 21:18:43 +0000 Subject: [PATCH 1/1] misc changes --- .../plugin.xml | 7 + net.sourceforge.phpeclipse/.classpath | 3 +- net.sourceforge.phpeclipse/.project | 2 +- .../icons/obj16/apache_restart.gif | Bin 0 -> 889 bytes .../icons/obj16/apache_stop.gif | Bin 0 -> 896 bytes net.sourceforge.phpeclipse/icons/obj16/sql.gif | Bin 0 -> 896 bytes net.sourceforge.phpeclipse/plugin.properties | 6 +- net.sourceforge.phpeclipse/plugin.xml | 148 +++++++++---- .../internal/ui/text/template/BuiltInEngine.java | 90 +++++++ .../internal/ui/text/template/BuiltInProposal.java | 245 ++++++++++++++++++++ .../phpeclipse/phpeditor/PHPActionContributor.java | 49 ++-- .../phpeclipse/phpeditor/PHPEditor.java | 7 +- 12 files changed, 480 insertions(+), 77 deletions(-) create mode 100644 net.sourceforge.phpeclipse/icons/obj16/apache_restart.gif create mode 100644 net.sourceforge.phpeclipse/icons/obj16/apache_stop.gif create mode 100644 net.sourceforge.phpeclipse/icons/obj16/sql.gif create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInEngine.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInProposal.java diff --git a/net.sourceforge.phpeclipse.debug.phphelp/plugin.xml b/net.sourceforge.phpeclipse.debug.phphelp/plugin.xml index 8d80216..6af417e 100644 --- a/net.sourceforge.phpeclipse.debug.phphelp/plugin.xml +++ b/net.sourceforge.phpeclipse.debug.phphelp/plugin.xml @@ -29,4 +29,11 @@ + + + + diff --git a/net.sourceforge.phpeclipse/.classpath b/net.sourceforge.phpeclipse/.classpath index bee2fe3..af9f5e2 100644 --- a/net.sourceforge.phpeclipse/.classpath +++ b/net.sourceforge.phpeclipse/.classpath @@ -1,7 +1,7 @@ - + - diff --git a/net.sourceforge.phpeclipse/.project b/net.sourceforge.phpeclipse/.project index 8acc1f7..9020b50 100644 --- a/net.sourceforge.phpeclipse/.project +++ b/net.sourceforge.phpeclipse/.project @@ -3,7 +3,7 @@ net.sourceforge.phpeclipse - org.rubypeople.rdt.core + net.sourceforge.phpeclipse diff --git a/net.sourceforge.phpeclipse/icons/obj16/apache_restart.gif b/net.sourceforge.phpeclipse/icons/obj16/apache_restart.gif new file mode 100644 index 0000000000000000000000000000000000000000..5b3c0cbc09a78760a9ec8345ec9bbdf1ddc85cb7 GIT binary patch literal 889 zcmZ?wbhEHb6krfw_|5NPBp{cy$lR{LFB!?d-vYE$MBy4 zh%EmzRR3q#`ya?`VE8`@MnhnThk)Ww7Dfh!Qw%zwoB+xb3>;w$k{mJ~8x|aF<`9+= zxp08t5GO0QMni!>(m@Uu1rddejR{R0+;SEoHw+iGFmMYQ%m^@g#LUUTx5Xslz(J;I eoYqn^7#JK}=V+%(wP=)R1hlG5RO01eum%7&1oTJ% literal 0 HcmV?d00001 diff --git a/net.sourceforge.phpeclipse/icons/obj16/apache_stop.gif b/net.sourceforge.phpeclipse/icons/obj16/apache_stop.gif new file mode 100644 index 0000000000000000000000000000000000000000..462d170bb1b1a4ad0643f512154ed6e987577d60 GIT binary patch literal 896 zcmZ?wbhEHb6krfw_|5NPBp{cy$lR{LFB!?d-vYE$MBy4 zh%EmzRR3q#`=8RZaVGsg}KUo+V7)~+hfN}yTPcU%AGDvdBcx+g3u$hC^D&mF0 z!iH8BMX8bi2ga5TUT(7<2L>lbHeO@CGcyzpHL)wXHpxUdG&Qqwin#UsaA0a;)^>lT i^TEi$Z>|<^1IvQIrRO@eRFzUPOcq{V&dkijU=0948~eEc literal 0 HcmV?d00001 diff --git a/net.sourceforge.phpeclipse/icons/obj16/sql.gif b/net.sourceforge.phpeclipse/icons/obj16/sql.gif new file mode 100644 index 0000000000000000000000000000000000000000..dc857915dfd9f46a01716766c232325417bce3ab GIT binary patch literal 896 zcmdVZv1`;&90%}s*FvvS%>#uyu#l^REv1-jS8>P#W??Ur2d)FI}|S9P`ArgMIrvu|H2Q+d*Ao_O^;tksoUwejJaJGcn#gtb#KY=Ow+S0 zuj_hX+w*$d*EE0C@@?W%>NDoQ@cka=Gls02nuRnse?FnoVe@8 zoX0&L4@3+V02A5v65mf?Izl7|Wg$6AM*U!<)Cj`ysFbGZK&1OBJuYMVJsl6__;g%4 z&$2kqk|aAyveR(}&a=sAG)dD5gr5_TkH>kI<>y%rF7mu63Ro`k;uoZ%{22a2#h*Ni zKEl|`3l!+`9^0GiYtz-n%PP9L zfof0Z*A5rjujbG*JUsl--krO(Ywn23=YDnb{oiio{_@~p<;~gpm)lo1_PY-lu1wvz T+GxLh)c^Y7+urO{72W#>gI+&L literal 0 HcmV?d00001 diff --git a/net.sourceforge.phpeclipse/plugin.properties b/net.sourceforge.phpeclipse/plugin.properties index 8ef16ae..19fe179 100644 --- a/net.sourceforge.phpeclipse/plugin.properties +++ b/net.sourceforge.phpeclipse/plugin.properties @@ -22,12 +22,14 @@ phpConsoleView=PHP Console phpFileExtension=php php3FileExtension=php3 php4FileExtension=php4 +incFileExtension=inc +phtmlFileExtension=phtml # # Action sets # -php.menu.label=&PHP -phpActionSet.label=PHP Actions +php.menu.label=&Source +phpActionSet.label=Source Actions phpUncommentAction.label=&Uncomment@Ctrl+\\ phpCommentAction.label=&Comment@Ctrl+/ \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/plugin.xml b/net.sourceforge.phpeclipse/plugin.xml index b84555d..68bde16 100644 --- a/net.sourceforge.phpeclipse/plugin.xml +++ b/net.sourceforge.phpeclipse/plugin.xml @@ -49,6 +49,10 @@ + + - + + + + + + + + + + + + + + + + + + + @@ -408,6 +460,22 @@ + + + + + + + + - - - - - diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInEngine.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInEngine.java new file mode 100644 index 0000000..68d6a36 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInEngine.java @@ -0,0 +1,90 @@ +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ +package net.sourceforge.phpdt.internal.ui.text.template; + +import java.util.ArrayList; + +import net.sourceforge.phpdt.internal.corext.template.ContextType; +import net.sourceforge.phpdt.internal.corext.template.java.CompilationUnitContext; +import net.sourceforge.phpdt.internal.corext.template.java.CompilationUnitContextType; +import net.sourceforge.phpdt.internal.ui.PHPUiImages; +import net.sourceforge.phpdt.internal.ui.text.java.IJavaCompletionProposal; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.Region; +//import org.eclipse.jdt.internal.ui.text.link.LinkedPositionManager; + +public class BuiltInEngine { + + /** The context type. */ + private ContextType fContextType; + /** The result proposals. */ + private ArrayList fProposals= new ArrayList(); + + /** + * Creates the template engine for a particular context type. + * See TemplateContext for supported context types. + */ + public BuiltInEngine(ContextType contextType) { + // Assert.isNotNull(contextType); + fContextType= contextType; + } + + /** + * Empties the collector. + * + * @param viewer the text viewer + * @param unit the compilation unit (may be null) + */ + public void reset() { + fProposals.clear(); + } + + /** + * Returns the array of matching templates. + */ + public IJavaCompletionProposal[] getResults() { + return (IJavaCompletionProposal[]) fProposals.toArray(new IJavaCompletionProposal[fProposals.size()]); + } + + /** + * Inspects the context of the compilation unit around completionPosition + * and feeds the collector with proposals. + * @param viewer the text viewer + * @param completionPosition the context position in the document of the text viewer + * @param compilationUnit the compilation unit (may be null) + */ + public void complete(ITextViewer viewer, int completionPosition, Object[] identifiers) + //,ICompilationUnit compilationUnit) + //hrows JavaModelException + { + IDocument document= viewer.getDocument(); + + // prohibit recursion +// if (LinkedPositionManager.hasActiveManager(document)) +// return; + + if (!(fContextType instanceof CompilationUnitContextType)) + return; + + ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition);//mpilationUnit); + CompilationUnitContext context= (CompilationUnitContext) fContextType.createContext(); + int start= context.getStart(); + int end= context.getEnd(); + IRegion region= new Region(start, end - start); + +// Template[] templates= Templates.getInstance().getTemplates(); + String identifier = null; + for (int i= 0; i != identifiers.length; i++) { + identifier = (String) identifiers[i]; + if (context.canEvaluate(identifier)) { + fProposals.add(new BuiltInProposal(identifier, context, region, viewer, PHPUiImages.get(PHPUiImages.IMG_BUILTIN))); + } + } + } + +} + diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInProposal.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInProposal.java new file mode 100644 index 0000000..1ff6be7 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInProposal.java @@ -0,0 +1,245 @@ +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ +package net.sourceforge.phpdt.internal.ui.text.template; + +import net.sourceforge.phpdt.internal.corext.template.Template; +import net.sourceforge.phpdt.internal.corext.template.TemplateBuffer; +import net.sourceforge.phpdt.internal.corext.template.TemplateContext; +import net.sourceforge.phpdt.internal.corext.template.TemplateMessages; +import net.sourceforge.phpdt.internal.corext.template.TemplatePosition; +import net.sourceforge.phpdt.internal.corext.template.java.CompilationUnitContext; +import net.sourceforge.phpdt.internal.corext.template.java.JavaTemplateMessages; +import net.sourceforge.phpdt.internal.ui.text.java.IJavaCompletionProposal; +import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import org.eclipse.core.runtime.CoreException; +import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager; +import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.contentassist.IContextInformation; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Shell; +//import org.eclipse.jdt.internal.ui.text.link.LinkedPositionManager; +//import org.eclipse.jdt.internal.ui.text.link.LinkedPositionUI; +//import org.eclipse.jdt.internal.ui.util.ExceptionHandler; + +/** + * A PHP identifier proposal. + */ +public class BuiltInProposal implements IJavaCompletionProposal { + + private final String fTemplate; + private final TemplateContext fContext; + private final ITextViewer fViewer; + private final Image fImage_builtin; + + private final IRegion fRegion; + + //private TemplateBuffer fTemplateBuffer; + private String fOldText; + private IRegion fSelectedRegion; // initialized by apply() + + /** + * Creates a template proposal with a template and its context. + * @param template the template + * @param context the context in which the template was requested. + * @param image the icon of the proposal. + */ + public BuiltInProposal(String template, TemplateContext context, IRegion region, ITextViewer viewer, Image image_builtin) { + // Assert.isNotNull(template); + // Assert.isNotNull(context); + // Assert.isNotNull(region); + // Assert.isNotNull(viewer); + + fTemplate = template; + fContext = context; + fViewer = viewer; + fImage_builtin= image_builtin; + fRegion = region; + } + + /* + * @see ICompletionProposal#apply(IDocument) + */ + public void apply(IDocument document) { + try { + // if (fTemplateBuffer == null) + // fTemplateBuffer= fContext.evaluate(fTemplate); + + int start = fRegion.getOffset(); + int end = fRegion.getOffset() + fRegion.getLength(); + + // insert template string + // String templateString = fTemplate; // fTemplateBuffer.getString(); + document.replace(start, end - start, fTemplate); + + // translate positions + LinkedPositionManager manager = new LinkedPositionManager(document); + // TemplatePosition[] variables= fTemplateBuffer.getVariables(); + // for (int i= 0; i != variables.length; i++) { + // TemplatePosition variable= variables[i]; + // + // if (variable.isResolved()) + // continue; + // + // int[] offsets= variable.getOffsets(); + // int length= variable.getLength(); + // + // for (int j= 0; j != offsets.length; j++) + // manager.addPosition(offsets[j] + start, length); + // } + + LinkedPositionUI editor = new LinkedPositionUI(fViewer, manager); + editor.setFinalCaretOffset(fTemplate.length()+start); + // editor.setFinalCaretOffset(getCaretOffset(fTemplateBuffer) + start); + editor.enter(); + + fSelectedRegion = editor.getSelectedRegion(); + + } catch (BadLocationException e) { + PHPeclipsePlugin.log(e); + openErrorDialog(e); + + } + // catch (CoreException e) { + // handleException(e); + // } + } + +// private static int getCaretOffset(TemplateBuffer buffer) { +// TemplatePosition[] variables = buffer.getVariables(); +// for (int i = 0; i != variables.length; i++) { +// TemplatePosition variable = variables[i]; +// +// if (variable.getName().equals(JavaTemplateMessages.getString("GlobalVariables.variable.name.cursor"))) //$NON-NLS-1$ +// return variable.getOffsets()[0]; +// } +// +// return buffer.getString().length(); +// } + + /* + * @see ICompletionProposal#getSelection(IDocument) + */ + public Point getSelection(IDocument document) { + return new Point(fSelectedRegion.getOffset(), fSelectedRegion.getLength()); + // return null; + } + + /* + * @see ICompletionProposal#getAdditionalProposalInfo() + */ + public String getAdditionalProposalInfo() { + // try { + // if (fTemplateBuffer == null) + // fTemplateBuffer= fContext.evaluate(fTemplate); + + return textToHTML(fTemplate); // fTemplateBuffer.getString()); + + // } catch (CoreException e) { + // handleException(e); + // return null; + // } + } + + /* + * @see ICompletionProposal#getDisplayString() + */ + public String getDisplayString() { + return fTemplate + TemplateMessages.getString("TemplateProposal.delimiter") + fTemplate; // $NON-NLS-1$ //$NON-NLS-1$ + // return fTemplate.getName() + TemplateMessages.getString("TemplateProposal.delimiter") + fTemplate.getDescription(); // $NON-NLS-1$ //$NON-NLS-1$ + } + + /* + * @see ICompletionProposal#getImage() + */ + public Image getImage() { + return fImage_builtin; + } + + /* + * @see ICompletionProposal#getContextInformation() + */ + public IContextInformation getContextInformation() { + return null; + } + + private static String textToHTML(String string) { + StringBuffer buffer = new StringBuffer(string.length()); + buffer.append("
"); //$NON-NLS-1$
+
+    for (int i = 0; i != string.length(); i++) {
+      char ch = string.charAt(i);
+
+      switch (ch) {
+        case '&' :
+          buffer.append("&"); //$NON-NLS-1$
+          break;
+
+        case '<' :
+          buffer.append("<"); //$NON-NLS-1$
+          break;
+
+        case '>' :
+          buffer.append(">"); //$NON-NLS-1$
+          break;
+
+        case '\t' :
+          buffer.append("    "); //$NON-NLS-1$
+          break;
+
+        case '\n' :
+          buffer.append("
"); //$NON-NLS-1$ + break; + + default : + buffer.append(ch); + break; + } + } + + buffer.append("
"); //$NON-NLS-1$ + return buffer.toString(); + } + + private void openErrorDialog(BadLocationException e) { + Shell shell = fViewer.getTextWidget().getShell(); + MessageDialog.openError(shell, TemplateMessages.getString("TemplateEvaluator.error.title"), e.getMessage()); //$NON-NLS-1$ + } + + private void handleException(CoreException e) { + Shell shell = fViewer.getTextWidget().getShell(); + PHPeclipsePlugin.log(e); + // ExceptionHandler.handle(e, shell, TemplateMessages.getString("TemplateEvaluator.error.title"), null); //$NON-NLS-1$ + } + + /* + * @see IJavaCompletionProposal#getRelevance() + */ + public int getRelevance() { + + if (fContext instanceof CompilationUnitContext) { + CompilationUnitContext context = (CompilationUnitContext) fContext; + switch (context.getCharacterBeforeStart()) { + // high relevance after whitespace + case ' ' : + case '\r' : + case '\n' : + case '\t' : + return 90; + + default : + return 0; + } + } else { + return 90; + } + } + +} \ No newline at end of file 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 6f35ce5..84fdf1c 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionContributor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionContributor.java @@ -26,16 +26,13 @@ import org.eclipse.ui.texteditor.RetargetTextEditorAction; import org.eclipse.ui.texteditor.TextEditorAction; /** - * Contributes interesting Java actions to the desktop's Edit menu and the toolbar. + * Contributes interesting PHP actions to the desktop's Edit menu and the toolbar. */ -public class PHPActionContributor extends TextEditorActionContributor { +public class PHPActionContributor extends BasicTextEditorActionContributor implements PHPEditorActionDefinitionIds { - public static final String COMMENT = "net.sourceforge.phpeclipse.phpeditor.comment"; - public static final String UNCOMMENT = "net.sourceforge.phpeclipse.phpeditor.uncomment"; - protected RetargetTextEditorAction fContentAssistProposal; - protected RetargetTextEditorAction fContentAssistTip; - protected TextEditorAction fTogglePresentation; + // protected RetargetTextEditorAction fContentAssistTip; + // protected TextEditorAction fTogglePresentation; protected PHPParserAction parserAction; /** @@ -44,8 +41,8 @@ public class PHPActionContributor extends TextEditorActionContributor { public PHPActionContributor() { super(); fContentAssistProposal = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$ - fContentAssistTip = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$ - fTogglePresentation = new PresentationAction(); + // fContentAssistTip = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$ + // fTogglePresentation = new PresentationAction(); parserAction = PHPParserAction.getInstance(); } @@ -60,34 +57,34 @@ public class PHPActionContributor extends TextEditorActionContributor { if (editMenu != null) { editMenu.add(new Separator()); editMenu.add(fContentAssistProposal); - editMenu.add(fContentAssistTip); + // editMenu.add(fContentAssistTip); } - IToolBarManager toolBarManager = bars.getToolBarManager(); - if (toolBarManager != null) { - toolBarManager.add(new Separator()); - toolBarManager.add(fTogglePresentation); - } + // IToolBarManager toolBarManager = bars.getToolBarManager(); + // if (toolBarManager != null) { + // toolBarManager.add(new Separator()); + // toolBarManager.add(fTogglePresentation); + // } } private void doSetActiveEditor(IEditorPart part) { super.setActiveEditor(part); - ITextEditor editor = null; + ITextEditor textEditor = null; if (part instanceof ITextEditor) - editor = (ITextEditor) part; + textEditor = (ITextEditor) part; + + fContentAssistProposal.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$ + // fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$ - fContentAssistProposal.setAction(getAction(editor, "ContentAssistProposal")); //$NON-NLS-1$ - fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$ + IActionBars bars = getActionBars(); + bars.setGlobalActionHandler(COMMENT, getAction(textEditor, "Comment")); + bars.setGlobalActionHandler(UNCOMMENT, getAction(textEditor, "Uncomment")); - IActionBars bars= getActionBars(); - bars.setGlobalActionHandler(COMMENT, getAction(editor, "Comment")); - bars.setGlobalActionHandler(UNCOMMENT, getAction(editor, "Uncomment")); - - fTogglePresentation.setEditor(editor); - fTogglePresentation.update(); + // fTogglePresentation.setEditor(editor); + // fTogglePresentation.update(); - parserAction.setEditor(editor); + parserAction.setEditor(textEditor); parserAction.update(); } 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 adcf53d..04f7d9e 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java @@ -67,9 +67,10 @@ public class PHPEditor extends TextEditor { } public PHPContentOutlinePage getfOutlinePage() { - return fOutlinePage; + return fOutlinePage; } - /** The JavaEditor implementation of this + + /** The PHPEditor implementation of this * AbstractTextEditor method extend the * actions to add those specific to the receiver */ @@ -100,6 +101,8 @@ public class PHPEditor extends TextEditor { actionGroup = new PHPActionGroup(this, ITextEditorActionConstants.GROUP_EDIT); + markAsStateDependentAction("Comment", true); //$NON-NLS-1$ + markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$ } /** The JavaEditor implementation of this -- 1.7.1