Integrated PHP help files; Fixed some bugs
[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 org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.jface.action.MenuManager;
17 import org.eclipse.jface.text.source.ISourceViewer;
18 import org.eclipse.ui.IEditorInput;
19 import org.eclipse.ui.editors.text.TextEditor;
20 import org.eclipse.ui.texteditor.DefaultRangeIndicator;
21 import org.eclipse.ui.texteditor.TextOperationAction;
22 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
23
24 /**
25  * Java specific text editor.
26  */
27 public class PHPEditor extends TextEditor {
28
29   /** The outline page */
30   private PHPContentOutlinePage fOutlinePage;
31
32   /**
33    * Default constructor.
34    */
35   public PHPEditor() {
36     super();
37   }
38
39   /** The <code>JavaEditor</code> implementation of this 
40    * <code>AbstractTextEditor</code> method extend the 
41    * actions to add those specific to the receiver
42    */
43   protected void createActions() {
44     super.createActions();
45     setAction(
46       "ContentAssistProposal",
47       new TextOperationAction(
48         PHPEditorMessages.getResourceBundle(),
49         "ContentAssistProposal.",
50         this,
51         ISourceViewer.CONTENTASSIST_PROPOSALS));
52     setAction(
53       "ContentAssistTip",
54       new TextOperationAction(
55         PHPEditorMessages.getResourceBundle(),
56         "ContentAssistTip.",
57         this,
58         ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION));
59   }
60
61   /** The <code>JavaEditor</code> implementation of this 
62    * <code>AbstractTextEditor</code> method performs any extra 
63    * disposal actions required by the java editor.
64    */
65   public void dispose() {
66     PHPEditorEnvironment.disconnect(this);
67     if (fOutlinePage != null)
68       fOutlinePage.setInput(null);
69     super.dispose();
70   }
71
72   /** The <code>JavaEditor</code> implementation of this 
73    * <code>AbstractTextEditor</code> method performs any extra 
74    * revert behavior required by the java editor.
75    */
76   public void doRevertToSaved() {
77     super.doRevertToSaved();
78     if (fOutlinePage != null)
79       fOutlinePage.update();
80   }
81
82   /** The <code>JavaEditor</code> implementation of this 
83    * <code>AbstractTextEditor</code> method performs any extra 
84    * save behavior required by the java editor.
85    */
86   public void doSave(IProgressMonitor monitor) {
87     super.doSave(monitor);
88     if (fOutlinePage != null)
89       fOutlinePage.update();
90   }
91
92   /** The <code>JavaEditor</code> implementation of this 
93    * <code>AbstractTextEditor</code> method performs any extra 
94    * save as behavior required by the java editor.
95    */
96   public void doSaveAs() {
97     super.doSaveAs();
98     if (fOutlinePage != null)
99       fOutlinePage.update();
100   }
101
102   /** The <code>JavaEditor</code> implementation of this 
103    * <code>AbstractTextEditor</code> method performs sets the 
104    * input of the outline page after AbstractTextEditor has set input.
105    */
106   public void doSetInput(IEditorInput input) throws CoreException {
107     super.doSetInput(input);
108     if (fOutlinePage != null)
109       fOutlinePage.setInput(input);
110   }
111
112   /** The <code>JavaEditor</code> implementation of this 
113    * <code>AbstractTextEditor</code> method adds any 
114    * JavaEditor specific entries.
115    */
116   public void editorContextMenuAboutToShow(MenuManager menu) {
117     super.editorContextMenuAboutToShow(menu);
118     addAction(menu, "ContentAssistProposal"); //$NON-NLS-1$
119     addAction(menu, "ContentAssistTip"); //$NON-NLS-1$
120   }
121
122   /** The <code>JavaEditor</code> implementation of this 
123    * <code>AbstractTextEditor</code> method performs gets
124    * the java content outline page if request is for a an 
125    * outline page.
126    */
127   public Object getAdapter(Class required) {
128     if (IContentOutlinePage.class.equals(required)) {
129       if (fOutlinePage == null) {
130         fOutlinePage = new PHPContentOutlinePage(getDocumentProvider(), this);
131         if (getEditorInput() != null)
132           fOutlinePage.setInput(getEditorInput());
133       }
134       return fOutlinePage;
135     }
136     return super.getAdapter(required);
137   }
138
139   /* (non-Javadoc)
140    * Method declared on AbstractTextEditor
141    */
142   protected void initializeEditor() {
143
144     PHPEditorEnvironment.connect(this);
145
146     setSourceViewerConfiguration(new PHPSourceViewerConfiguration());
147     setRangeIndicator(new DefaultRangeIndicator());
148     setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$
149     setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$
150   }
151 }