Defined a limit for code completion list entries PHPeclipsePlugin.MAX_PROPOSALS
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / PHPeclipsePlugin.java
1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
7
8 Contributors:
9     IBM Corporation - Initial implementation
10     Klaus Hartlage - www.eclipseproject.de
11 **********************************************************************/
12 package net.sourceforge.phpeclipse;
13
14 import java.io.File;
15 import java.util.Collection;
16 import java.util.HashMap;
17 import java.util.Iterator;
18
19 import net.sourceforge.phpdt.externaltools.internal.model.ColorManager;
20 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsPlugin;
21 import net.sourceforge.phpdt.externaltools.internal.model.VariableContextManager;
22 import net.sourceforge.phpdt.internal.ui.preferences.TemplatePreferencePage;
23 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
24 import net.sourceforge.phpdt.ui.PreferenceConstants;
25 import net.sourceforge.phpdt.ui.text.JavaTextTools;
26 import net.sourceforge.phpeclipse.builder.ExternalEditorInput;
27 import net.sourceforge.phpeclipse.builder.ExternalStorageDocumentProvider;
28 import net.sourceforge.phpeclipse.builder.FileStorage;
29 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
30 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
31 import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
32 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
33 import net.sourceforge.phpeclipse.resourcesview.PHPElement;
34 import net.sourceforge.phpeclipse.resourcesview.PHPElementAdapterFactory;
35 import net.sourceforge.phpeclipse.resourcesview.ResourceAdapterFactory;
36
37 import org.eclipse.core.boot.BootLoader;
38 import org.eclipse.core.resources.IFile;
39 import org.eclipse.core.resources.IProject;
40 import org.eclipse.core.resources.IResource;
41 import org.eclipse.core.resources.IWorkspace;
42 import org.eclipse.core.resources.ResourcesPlugin;
43 import org.eclipse.core.runtime.CoreException;
44 import org.eclipse.core.runtime.IAdapterManager;
45 import org.eclipse.core.runtime.IPath;
46 import org.eclipse.core.runtime.IPluginDescriptor;
47 import org.eclipse.core.runtime.IStatus;
48 import org.eclipse.core.runtime.Path;
49 import org.eclipse.core.runtime.Platform;
50 import org.eclipse.core.runtime.Status;
51 import org.eclipse.jface.preference.IPreferenceStore;
52 import org.eclipse.jface.preference.PreferenceConverter;
53 import org.eclipse.jface.text.BadLocationException;
54 import org.eclipse.jface.text.IDocument;
55 import org.eclipse.swt.widgets.Display;
56 import org.eclipse.swt.widgets.Shell;
57 import org.eclipse.ui.IEditorDescriptor;
58 import org.eclipse.ui.IEditorInput;
59 import org.eclipse.ui.IEditorPart;
60 import org.eclipse.ui.IEditorRegistry;
61 import org.eclipse.ui.IWorkbench;
62 import org.eclipse.ui.IWorkbenchPage;
63 import org.eclipse.ui.IWorkbenchWindow;
64 import org.eclipse.ui.PlatformUI;
65 import org.eclipse.ui.plugin.AbstractUIPlugin;
66 import org.eclipse.ui.texteditor.IDocumentProvider;
67 import org.eclipse.ui.texteditor.ITextEditor;
68
69 /**
70  * The main plugin class to be used in the desktop.
71  */
72 public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceConstants {
73   /**
74    * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
75    */
76   public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
77
78   /** 
79    * id of builder - matches plugin.xml (concatenate pluginid.builderid) 
80    */
81   public static final String BUILDER_INDEX_ID = PLUGIN_ID + ".indexbuilder";
82   public static final String BUILDER_PARSER_ID = PLUGIN_ID + ".parserbuilder";
83
84   /** General debug flag*/
85   public static final boolean DEBUG = false;
86
87         /**
88          * The maximum number of allowed proposals by category
89          */
90         public final static int MAX_PROPOSALS = 200;
91         
92   private static ExternalToolsPlugin externalTools;
93
94   /**
95   * The Java virtual machine that we are running on.
96   */
97   private static int jvm;
98
99   /** MRJ 2.0 */
100   private static final int MRJ_2_0 = 0;
101
102   /** MRJ 2.1 or later */
103   private static final int MRJ_2_1 = 1;
104
105   /** Java on Mac OS X 10.0 (MRJ 3.0) */
106   private static final int MRJ_3_0 = 3;
107
108   /** MRJ 3.1 */
109   private static final int MRJ_3_1 = 4;
110
111   /** JVM constant for any other platform */
112   private static final int OTHER = -1;
113
114   // public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID + ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
115   public static final String PHP_CODING_ACTION_SET_ID = PLUGIN_ID + ".ui.CodingActionSet"; //$NON-NLS-1$
116   public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
117
118   public static final String PHPPARSER_ORIGINAL = "net.sourceforge.phpdt.internal.compiler.parser.Parser";
119
120   public static final String PHPPARSER_NEW = "test.PHPParser";
121
122   /** Change this if you want to switch PHP Parser. */
123   public static final String PHPPARSER = PHPPARSER_ORIGINAL;
124
125   //The shared instance.
126   private static PHPeclipsePlugin plugin;
127
128   /** Windows 9x  */
129   private static final int WINDOWS_9x = 6;
130
131   /** Windows NT  */
132   private static final int WINDOWS_NT = 5;
133   private PHPDocumentProvider fCompilationUnitDocumentProvider;
134  
135   private ImageDescriptorRegistry fImageDescriptorRegistry;
136   private HashMap fIndexManagerMap = new HashMap();
137
138   private JavaTextTools fJavaTextTools;
139   private IFile fLastEditorFile = null;
140
141   /**
142    * The constructor.
143    */
144   public PHPeclipsePlugin(IPluginDescriptor descriptor) {
145     super(descriptor);
146     plugin = this;
147     setJVM();
148     externalTools = new ExternalToolsPlugin();
149     //    try {
150     //      resourceBundle = ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
151     //    } catch (MissingResourceException x) {
152     //      resourceBundle = null;
153     //    }
154   }
155
156   public static IWorkbenchPage getActivePage() {
157     return getDefault().internalGetActivePage();
158   }
159
160   public static Shell getActiveWorkbenchShell() {
161     return getActiveWorkbenchWindow().getShell();
162   }
163
164   public static IWorkbenchWindow getActiveWorkbenchWindow() {
165     return getDefault().getWorkbench().getActiveWorkbenchWindow();
166   }
167   /**
168    * Returns the shared instance.
169    */
170   public static PHPeclipsePlugin getDefault() {
171     return plugin;
172   }
173
174   public static ImageDescriptorRegistry getImageDescriptorRegistry() {
175     return getDefault().internalGetImageDescriptorRegistry();
176   }
177
178   static IPath getInstallLocation() {
179     return new Path(getDefault().getDescriptor().getInstallURL().getFile());
180   }
181   public static int getJVM() {
182     return jvm;
183   }
184
185   public static String getPluginId() {
186     return getDefault().getDescriptor().getUniqueIdentifier();
187   }
188
189   /**
190    * Returns the standard display to be used. The method first checks, if
191    * the thread calling this method has an associated display. If so, this
192    * display is returned. Otherwise the method returns the default display.
193    */
194   public static Display getStandardDisplay() {
195     Display display = Display.getCurrent();
196     if (display == null) {
197       display = Display.getDefault();
198     }
199     return display;
200   }
201
202   //  public static ExternalToolsPlugin getExternalTools() {
203   //    return externalTools;
204   //  }
205   /**
206    * Returns the workspace instance.
207    */
208   public static IWorkspace getWorkspace() {
209     return ResourcesPlugin.getWorkspace();
210   }
211
212   public static boolean isDebug() {
213     return getDefault().isDebugging();
214   }
215
216   //  public static void logErrorMessage(String message) {
217   //    log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null));
218   //  }
219   //
220   //  public static void logErrorStatus(String message, IStatus status) {
221   //    if (status == null) {
222   //      logErrorMessage(message);
223   //      return;
224   //    }
225   //    MultiStatus multi= new MultiStatus(getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null);
226   //    multi.add(status);
227   //    log(multi);
228   //  }
229   //
230   //  public static void log(Throwable e) {
231   //    log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
232   //  }
233
234   public static void log(int severity, String message) {
235     Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
236     log(status);
237   }
238
239   public static void log(IStatus status) {
240     getDefault().getLog().log(status);
241   }
242   public static void log(Throwable e) {
243     log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
244   }
245
246   private static void setJVM() {
247     String osName = System.getProperty("os.name");
248
249     if (osName.startsWith("Mac OS")) {
250       String mrjVersion = System.getProperty("mrj.version");
251       String majorMRJVersion = mrjVersion.substring(0, 3);
252       jvm = OTHER;
253       try {
254
255         double version = Double.valueOf(majorMRJVersion).doubleValue();
256
257         if (version == 2) {
258           jvm = MRJ_2_0;
259         } else if (version >= 2.1 && version < 3) {
260           jvm = MRJ_2_1;
261         } else if (version == 3.0) {
262           jvm = MRJ_3_0;
263         } else if (version >= 3.1) {
264           jvm = MRJ_3_1;
265         }
266
267       } catch (NumberFormatException nfe) {
268
269       }
270
271     } else if (osName.startsWith("Windows")) {
272       if (osName.indexOf("9") != -1) {
273         jvm = WINDOWS_9x;
274       } else {
275         jvm = WINDOWS_NT;
276       }
277     }
278   }
279
280   // TODO: refactor this into a better method name !
281   public synchronized PHPDocumentProvider getCompilationUnitDocumentProvider() {
282     if (fCompilationUnitDocumentProvider == null)
283       fCompilationUnitDocumentProvider = new PHPDocumentProvider();
284     return fCompilationUnitDocumentProvider;
285   }
286
287   /**
288    * Get the identifier index manager for the given project
289    * 
290    * @param iProject the current project
291    * @return
292    */
293   public IdentifierIndexManager getIndexManager(IProject iProject) {
294     String indexFilename = iProject.getLocation() + File.separator + "project.index";
295     IdentifierIndexManager indexManager = (IdentifierIndexManager) fIndexManagerMap.get(indexFilename);
296     if (indexManager == null) {
297       indexManager = new IdentifierIndexManager(indexFilename);
298       fIndexManagerMap.put(indexFilename, indexManager);
299     }
300     return indexManager;
301   }
302
303   public synchronized JavaTextTools getJavaTextTools() {
304     if (fJavaTextTools == null)
305       fJavaTextTools = new JavaTextTools(getPreferenceStore());
306     return fJavaTextTools;
307   }
308
309   public IFile getLastEditorFile() {
310     return fLastEditorFile;
311   }
312
313   /**
314    * Returns the string from the plugin's resource bundle,
315    * or 'key' if not found.
316    */
317   //  public static String getResourceString(String key) {
318   //    ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
319   //    try {
320   //      return bundle.getString(key);
321   //    } catch (MissingResourceException e) {
322   //      return key;
323   //    }
324   //  }
325
326   /**
327    * Returns the plugin's resource bundle,
328    */
329   //  public ResourceBundle getResourceBundle() {
330   //    return resourceBundle;
331   //  }
332
333   protected void initializeDefaultPreferences(IPreferenceStore store) {
334     // windows preferences:
335     store.setDefault(LOCALHOST_PREF, "http://localhost");
336
337     store.setDefault(SHOW_EXTERNAL_PREVIEW_PREF, "true");
338     store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
339     store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
340
341     String windowsSystem = BootLoader.getWS();
342
343     if (jvm == WINDOWS_9x) {
344       store.setDefault(EXTERNAL_BROWSER_PREF, "command.com /c start iexplore {0}");
345     } else if (windowsSystem.equals(BootLoader.WS_WIN32)) {
346       store.setDefault(EXTERNAL_BROWSER_PREF, "rundll32 url.dll,FileProtocolHandler {0}");
347     } else if (windowsSystem.equals(BootLoader.WS_CARBON)) {
348       // TODO How do we start Safari on Mac OS X ?
349       store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
350     } else {
351       store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
352     }
353     store.setDefault(DOCUMENTROOT_PREF, getWorkspace().getRoot().getLocation().toString());
354
355     //  if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
356     //  
357     if (windowsSystem.equals(BootLoader.WS_WIN32)) {
358       store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
359       store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
360       store.setDefault(MYSQL_RUN_PREF, "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
361       store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
362     } else {
363
364       store.setDefault(PHP_RUN_PREF, "/apache/php/php");
365       store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
366       store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
367       store.setDefault(APACHE_RUN_PREF, "/apache/apache");
368
369     }
370     store.setDefault(MYSQL_PREF, "--standalone");
371     store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot \"{0}\"\"");
372     store.setDefault(APACHE_STOP_PREF, "-k shutdown");
373     store.setDefault(APACHE_RESTART_PREF, "-k restart");
374
375     store.setDefault(MYSQL_START_BACKGROUND, "true");
376     store.setDefault(APACHE_START_BACKGROUND, "true");
377     store.setDefault(APACHE_STOP_BACKGROUND, "true");
378     store.setDefault(APACHE_RESTART_BACKGROUND, "true");
379
380     store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER);
381     store.setDefault(PHP_INTERNAL_PARSER, "false");
382     store.setDefault(PHP_EXTERNAL_PARSER, "true");
383
384     //    store.setDefault(PHP_PARSE_ON_SAVE, "true");
385
386     // show line numbers:
387     //   store.setDefault(LINE_NUMBER_RULER, "false");
388     //    store.setDefault(FORMATTER_TAB_SIZE, "4");
389
390     // php syntax highlighting
391     store.setDefault(PHP_USERDEF_XMLFILE, "");
392     //assume there is none  chooA
393
394     PreferenceConverter.setDefault(store, PHP_MULTILINE_COMMENT, PHPColorProvider.MULTI_LINE_COMMENT);
395     PreferenceConverter.setDefault(store, PHP_SINGLELINE_COMMENT, PHPColorProvider.SINGLE_LINE_COMMENT);
396     PreferenceConverter.setDefault(store, PHP_KEYWORD, PHPColorProvider.KEYWORD);
397     PreferenceConverter.setDefault(store, PHP_VARIABLE, PHPColorProvider.VARIABLE);
398     PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME, PHPColorProvider.FUNCTION_NAME);
399     PreferenceConverter.setDefault(store, PHP_CONSTANT, PHPColorProvider.CONSTANT);
400     PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
401     PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
402     PreferenceConverter.setDefault(store, PHP_DEFAULT, PHPColorProvider.DEFAULT);
403     
404                 PreferenceConverter.setDefault(store, PHPDOC_KEYWORD, PHPColorProvider.PHPDOC_KEYWORD);
405                 PreferenceConverter.setDefault(store, PHPDOC_TAG, PHPColorProvider.PHPDOC_TAG);
406                 PreferenceConverter.setDefault(store, PHPDOC_LINK, PHPColorProvider.PHPDOC_LINK);
407                 PreferenceConverter.setDefault(store, PHPDOC_DEFAULT, PHPColorProvider.PHPDOC_DEFAULT);
408                         
409     //    PreferenceConverter.setDefault(
410     //      store,
411     //      PHP_EDITOR_BACKGROUND,
412     //      PHPColorProvider.BACKGROUND);
413     //    PreferenceConverter.setDefault(
414     //      store,
415     //      LINKED_POSITION_COLOR,
416     //      PHPColorProvider.LINKED_POSITION_COLOR);
417     //    PreferenceConverter.setDefault(
418     //      store,
419     //      LINE_NUMBER_COLOR,
420     //      PHPColorProvider.LINE_NUMBER_COLOR);
421
422     //    // set default PHPDoc colors:
423     //    PreferenceConverter.setDefault(
424     //      store,
425     //      PHPDOC_KEYWORD, 
426     //      PHPColorProvider.PHPDOC_KEYWORD);
427     //    PreferenceConverter.setDefault(
428     //      store,
429     //      PHPDOC_LINK, 
430     //      PHPColorProvider.PHPDOC_LINK);      
431     //    PreferenceConverter.setDefault(
432     //      store,
433     //      PHPDOC_DEFAULT, 
434     //      PHPColorProvider.PHPDOC_DEFAULT);
435     //    PreferenceConverter.setDefault(
436     //      store,
437     //      PHPDOC_TAG, 
438     //      PHPColorProvider.PHPDOC_TAG);
439
440     //    store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
441     //    PreferenceConverter.setDefault(
442     //      store,
443     //      PREFERENCE_COLOR_BACKGROUND,
444     //      PHPColorProvider.BACKGROUND_COLOR);
445
446     //language stuff
447     store.setDefault(RESOURCE_BUNDLE, LANGUAGE_DEFAULT);
448     store.setDefault(RESOURCE_BUNDLE_EN_GB, "true");
449     store.setDefault(RESOURCE_BUNDLE_DE, "false");
450     store.setDefault(RESOURCE_BUNDLE_FR, "false");
451     store.setDefault(RESOURCE_BUNDLE_ES, "false");
452
453     store.setDefault(PHP_OUTLINE_CLASS, "true"); //$NON-NLS-1$
454     store.setDefault(PHP_OUTLINE_FUNC, "true"); //$NON-NLS-1$
455     store.setDefault(PHP_OUTLINE_VAR, "true"); //$NON-NLS-1$
456
457     TemplatePreferencePage.initDefaults(store);
458     //this will initialize the static fields in the syntaxrdr class
459     new PHPSyntaxRdr();
460
461     PHPCore.initializeDefaultPluginPreferences();
462     PreferenceConstants.initializeDefaultValues(store);
463
464     externalTools.initializeDefaultPreferences(store);
465   }
466
467   private IWorkbenchPage internalGetActivePage() {
468     IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
469     if (window != null)
470       return window.getActivePage();
471     return null;
472   }
473
474   private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
475     if (fImageDescriptorRegistry == null)
476       fImageDescriptorRegistry = new ImageDescriptorRegistry();
477     return fImageDescriptorRegistry;
478   }
479   /**
480         * Open a file in the Workbench that may or may not exist in the workspace.
481         * Must be run on the UI thread.
482         * @param filename
483         * @throws CoreException
484         */
485   public ITextEditor openFileInTextEditor(String filename) throws CoreException {
486
487     //  reject directories
488     if (new File(filename).isDirectory())
489       return null;
490
491     IWorkbench workbench = PlatformUI.getWorkbench();
492     IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
493     IWorkbenchPage page = window.getActivePage();
494     IPath path = new Path(filename);
495
496     // If the file exists in the workspace, open it
497     IFile file = getWorkspace().getRoot().getFileForLocation(path);
498     IEditorPart editor;
499     ITextEditor textEditor;
500     if (file != null && file.exists()) {
501       editor = page.openEditor(file);
502       textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
503     } else {
504       // Otherwise open the stream directly
505       if (page == null)
506         return null;
507       FileStorage storage = new FileStorage(path);
508       IEditorRegistry registry = getWorkbench().getEditorRegistry();
509       IEditorDescriptor desc = registry.getDefaultEditor(filename);
510       if (desc == null) {
511         desc = registry.getDefaultEditor();
512       }
513       IEditorInput input = new ExternalEditorInput(storage);
514       editor = page.openEditor(input, desc.getId());
515       textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
516
517       // If the storage provider is not ours, we can't guarantee read/write.
518       if (textEditor != null) {
519         IDocumentProvider documentProvider = textEditor.getDocumentProvider();
520         if (!(documentProvider instanceof ExternalStorageDocumentProvider)) {
521           storage.setReadOnly();
522         }
523       }
524     }
525     return textEditor;
526   }
527   /**
528         * Open a file in the Workbench that may or may not exist in the workspace.
529         * Must be run on the UI thread.
530         * @param filename
531         * @param line
532         * @throws CoreException
533         */
534   public void openFileAndGotoLine(String filename, int line) throws CoreException {
535
536     ITextEditor textEditor = openFileInTextEditor(filename);
537     if (textEditor != null) {
538       // If a line number was given, go to it
539       if (line > 0) {
540         try {
541           line--; // document is 0 based
542           IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
543           textEditor.selectAndReveal(document.getLineOffset(line), document.getLineLength(line));
544
545         } catch (BadLocationException e) {
546           // invalid text position -> do nothing
547         }
548       }
549     }
550   }
551
552   /**
553         * Open a file in the Workbench that may or may not exist in the workspace.
554         * Must be run on the UI thread.
555         * @param filename
556         * @param offset
557         * @throws CoreException
558         */
559   public void openFileAndGotoOffset(String filename, int offset, int length) throws CoreException {
560
561     ITextEditor textEditor = openFileInTextEditor(filename);
562     if (textEditor != null) {
563       // If a line number was given, go to it
564       if (offset >= 0) {
565         IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
566         textEditor.selectAndReveal(offset, length);
567       }
568     }
569   }
570
571   public void openFileAndFindString(String filename, String findString) throws CoreException {
572
573     ITextEditor textEditor = openFileInTextEditor(filename);
574     if (textEditor != null) {
575       //                If a string was given, go to it
576       if (findString != null) {
577         try {
578           IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
579           int offset = document.search(0, findString, true, false, true);
580           textEditor.selectAndReveal(offset, findString.length());
581
582         } catch (BadLocationException e) {
583           // invalid text position -> do nothing
584         }
585
586       }
587     }
588   }
589   public void setLastEditorFile(IFile textEditor) {
590     this.fLastEditorFile = textEditor;
591   }
592
593   /**
594    * @see org.eclipse.ui.plugin.AbstractUIPlugin#shutdown()
595    */
596   public void shutdown() throws CoreException {
597     super.shutdown();
598
599     //  externalTools.shutDown();
600     ColorManager.getDefault().dispose();
601
602     // save the information from the php index files if necessary
603     Collection collection = fIndexManagerMap.values();
604     Iterator iterator = collection.iterator();
605     IdentifierIndexManager indexManager = null;
606     while (iterator.hasNext()) {
607       indexManager = (IdentifierIndexManager) iterator.next();
608       indexManager.writeFile();
609     }
610
611   }
612
613   public void startup() throws CoreException {
614     super.startup();
615     IAdapterManager manager = Platform.getAdapterManager();
616     manager.registerAdapters(new PHPElementAdapterFactory(), PHPElement.class);
617     manager.registerAdapters(new ResourceAdapterFactory(), IResource.class);
618     //  externalTools.startUp(); 
619     getStandardDisplay().asyncExec(new Runnable() {
620       public void run() {
621         //initialize the variable context manager
622         VariableContextManager.getDefault();
623       }
624     });
625   }
626
627 }