Added: PreferencePage; External Browser startup; extended syntax highlighting
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPEditor.java
1 package net.sourceforge.phpeclipse.phpeditor;
2
3 /**********************************************************************
4 Copyright (c) 2000, 2002 IBM Corp. and others.
5 All rights reserved. This program and the accompanying materials
6 are made available under the terms of the Common Public License v1.0
7 which accompanies this distribution, and is available at
8 http://www.eclipse.org/legal/cpl-v10.html
9
10 Contributors:
11     IBM Corporation - Initial implementation
12     Klaus Hartlage - www.eclipseproject.de
13 **********************************************************************/
14 import java.util.ResourceBundle;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.jface.action.MenuManager;
18 import org.eclipse.jface.text.source.ISourceViewer;
19 import org.eclipse.ui.IEditorInput;
20 import org.eclipse.ui.editors.text.TextEditor;
21 import org.eclipse.ui.texteditor.DefaultRangeIndicator;
22 import org.eclipse.ui.texteditor.TextOperationAction;
23 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
24
25 /**
26  * Java specific text editor.
27  */
28 public class PHPEditor extends TextEditor {
29
30         /** The outline page */
31         private PHPContentOutlinePage fOutlinePage;
32
33         /**
34          * Default constructor.
35          */
36         public PHPEditor() {
37                 super();
38         }
39         
40         /** The <code>JavaEditor</code> implementation of this 
41          * <code>AbstractTextEditor</code> method extend the 
42          * actions to add those specific to the receiver
43          */
44         protected void createActions() {
45                 super.createActions();
46                 setAction("ContentAssistProposal", new TextOperationAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal.", this, ISourceViewer.CONTENTASSIST_PROPOSALS)); 
47                 setAction("ContentAssistTip", new TextOperationAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip.", this, ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION)); 
48         }
49         
50         /** The <code>JavaEditor</code> implementation of this 
51          * <code>AbstractTextEditor</code> method performs any extra 
52          * disposal actions required by the java editor.
53          */
54         public void dispose() {
55                 PHPEditorEnvironment.disconnect(this);
56                 if (fOutlinePage != null)
57                         fOutlinePage.setInput(null);
58                 super.dispose();
59         }
60         
61         /** The <code>JavaEditor</code> implementation of this 
62          * <code>AbstractTextEditor</code> method performs any extra 
63          * revert behavior required by the java editor.
64          */
65         public void doRevertToSaved() {
66                 super.doRevertToSaved();
67                 if (fOutlinePage != null)
68                         fOutlinePage.update();
69         }
70         
71         /** The <code>JavaEditor</code> implementation of this 
72          * <code>AbstractTextEditor</code> method performs any extra 
73          * save behavior required by the java editor.
74          */
75         public void doSave(IProgressMonitor monitor) {
76                 super.doSave(monitor);
77                 if (fOutlinePage != null)
78                         fOutlinePage.update();
79         }
80         
81         /** The <code>JavaEditor</code> implementation of this 
82          * <code>AbstractTextEditor</code> method performs any extra 
83          * save as behavior required by the java editor.
84          */
85         public void doSaveAs() {
86                 super.doSaveAs();
87                 if (fOutlinePage != null)
88                         fOutlinePage.update();
89         }
90         
91         /** The <code>JavaEditor</code> implementation of this 
92          * <code>AbstractTextEditor</code> method performs sets the 
93          * input of the outline page after AbstractTextEditor has set input.
94          */ 
95         public void doSetInput(IEditorInput input) throws CoreException {
96                 super.doSetInput(input);
97                 if (fOutlinePage != null)
98                         fOutlinePage.setInput(input);
99         }
100         
101         /** The <code>JavaEditor</code> implementation of this 
102          * <code>AbstractTextEditor</code> method adds any 
103          * JavaEditor specific entries.
104          */ 
105         public void editorContextMenuAboutToShow(MenuManager menu) {
106                 super.editorContextMenuAboutToShow(menu);
107                 addAction(menu, "ContentAssistProposal"); //$NON-NLS-1$
108                 addAction(menu, "ContentAssistTip"); //$NON-NLS-1$
109         }
110         
111         /** The <code>JavaEditor</code> implementation of this 
112          * <code>AbstractTextEditor</code> method performs gets
113          * the java content outline page if request is for a an 
114          * outline page.
115          */ 
116         public Object getAdapter(Class required) {
117                 if (IContentOutlinePage.class.equals(required)) {
118                         if (fOutlinePage == null) {
119                                 fOutlinePage= new PHPContentOutlinePage(getDocumentProvider(), this);
120                                 if (getEditorInput() != null)
121                                         fOutlinePage.setInput(getEditorInput());
122                         }
123                         return fOutlinePage;
124                 }
125                 return super.getAdapter(required);
126         }
127                 
128         /* (non-Javadoc)
129          * Method declared on AbstractTextEditor
130          */
131         protected void initializeEditor() {
132
133                 PHPEditorEnvironment.connect(this);
134
135                 setSourceViewerConfiguration(new PHPSourceViewerConfiguration());
136                 setRangeIndicator(new DefaultRangeIndicator());
137                 setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$
138                 setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$
139         }
140 }