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
9 IBM Corporation - Initial implementation
10 Klaus Hartlage - www.eclipseproject.de
11 **********************************************************************/
12 package net.sourceforge.phpeclipse;
15 import java.util.ArrayList;
16 import java.util.Collection;
17 import java.util.HashMap;
18 import java.util.HashSet;
19 import java.util.Iterator;
20 import java.util.List;
23 import net.sourceforge.phpdt.externaltools.internal.model.ColorManager;
24 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsPlugin;
25 import net.sourceforge.phpdt.externaltools.internal.model.VariableContextManager;
26 import net.sourceforge.phpdt.internal.ui.preferences.MembersOrderPreferenceCache;
27 import net.sourceforge.phpdt.internal.ui.preferences.TemplatePreferencePage;
28 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
29 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
30 import net.sourceforge.phpdt.internal.ui.viewsupport.ProblemMarkerManager;
31 import net.sourceforge.phpdt.ui.IContextMenuConstants;
32 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
33 import net.sourceforge.phpdt.ui.PreferenceConstants;
34 import net.sourceforge.phpdt.ui.text.JavaTextTools;
35 import net.sourceforge.phpeclipse.builder.ExternalEditorInput;
36 import net.sourceforge.phpeclipse.builder.ExternalStorageDocumentProvider;
37 import net.sourceforge.phpeclipse.builder.FileStorage;
38 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
39 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
40 import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
41 import net.sourceforge.phpeclipse.phpeditor.WorkingCopyManager;
42 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
43 import net.sourceforge.phpeclipse.resourcesview.PHPElement;
44 import net.sourceforge.phpeclipse.resourcesview.PHPElementAdapterFactory;
45 import net.sourceforge.phpeclipse.resourcesview.ResourceAdapterFactory;
47 import org.eclipse.core.boot.BootLoader;
48 import org.eclipse.core.resources.IFile;
49 import org.eclipse.core.resources.IProject;
50 import org.eclipse.core.resources.IResource;
51 import org.eclipse.core.resources.IWorkspace;
52 import org.eclipse.core.resources.ResourcesPlugin;
53 import org.eclipse.core.runtime.CoreException;
54 import org.eclipse.core.runtime.IAdapterManager;
55 import org.eclipse.core.runtime.IPath;
56 import org.eclipse.core.runtime.IPluginDescriptor;
57 import org.eclipse.core.runtime.IStatus;
58 import org.eclipse.core.runtime.Path;
59 import org.eclipse.core.runtime.Platform;
60 import org.eclipse.core.runtime.Status;
61 import org.eclipse.jface.action.GroupMarker;
62 import org.eclipse.jface.action.IMenuManager;
63 import org.eclipse.jface.action.Separator;
64 import org.eclipse.jface.preference.IPreferenceStore;
65 import org.eclipse.jface.preference.PreferenceConverter;
66 import org.eclipse.jface.text.BadLocationException;
67 import org.eclipse.jface.text.IDocument;
68 import org.eclipse.swt.widgets.Display;
69 import org.eclipse.swt.widgets.Shell;
70 import org.eclipse.ui.IEditorDescriptor;
71 import org.eclipse.ui.IEditorInput;
72 import org.eclipse.ui.IEditorPart;
73 import org.eclipse.ui.IEditorRegistry;
74 import org.eclipse.ui.IWorkbench;
75 import org.eclipse.ui.IWorkbenchPage;
76 import org.eclipse.ui.IWorkbenchWindow;
77 import org.eclipse.ui.PlatformUI;
78 import org.eclipse.ui.plugin.AbstractUIPlugin;
79 import org.eclipse.ui.texteditor.IDocumentProvider;
80 import org.eclipse.ui.texteditor.ITextEditor;
83 * The main plugin class to be used in the desktop.
85 public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceConstants {
87 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
89 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
92 * id of builder - matches plugin.xml (concatenate pluginid.builderid)
94 public static final String BUILDER_PARSER_ID = PLUGIN_ID + ".parserbuilder";
95 //public static final String BUILDER_INDEX_ID = PLUGIN_ID + ".indexbuilder";
97 /** General debug flag*/
98 public static final boolean DEBUG = false;
101 * The maximum number of allowed proposals by category
103 public final static int MAX_PROPOSALS = 200;
105 private static ExternalToolsPlugin externalTools;
108 * The Java virtual machine that we are running on.
110 private static int jvm;
113 private static final int MRJ_2_0 = 0;
115 /** MRJ 2.1 or later */
116 private static final int MRJ_2_1 = 1;
118 /** Java on Mac OS X 10.0 (MRJ 3.0) */
119 private static final int MRJ_3_0 = 3;
122 private static final int MRJ_3_1 = 4;
124 /** JVM constant for any other platform */
125 private static final int OTHER = -1;
127 // public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID + ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
128 public static final String PHP_CODING_ACTION_SET_ID = PLUGIN_ID + ".ui.CodingActionSet"; //$NON-NLS-1$
129 public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
131 public static final String PHPPARSER_ORIGINAL = "net.sourceforge.phpdt.internal.compiler.parser.Parser";
133 public static final String PHPPARSER_NEW = "test.PHPParser";
135 /** Change this if you want to switch PHP Parser. */
136 public static final String PHPPARSER = PHPPARSER_ORIGINAL;
138 //The shared instance.
139 private static PHPeclipsePlugin plugin;
142 private static final int WINDOWS_9x = 6;
145 private static final int WINDOWS_NT = 5;
147 private ImageDescriptorRegistry fImageDescriptorRegistry;
148 private HashMap fIndexManagerMap = new HashMap();
150 private IWorkingCopyManager fWorkingCopyManager;
151 private PHPDocumentProvider fCompilationUnitDocumentProvider;
152 private JavaTextTools fJavaTextTools;
153 private ProblemMarkerManager fProblemMarkerManager;
154 private MembersOrderPreferenceCache fMembersOrderPreferenceCache;
156 private IFile fLastEditorFile = null;
158 private JavaEditorTextHoverDescriptor[] fJavaEditorTextHoverDescriptors;
163 public PHPeclipsePlugin(IPluginDescriptor descriptor) {
167 externalTools = new ExternalToolsPlugin();
169 // resourceBundle = ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
170 // } catch (MissingResourceException x) {
171 // resourceBundle = null;
175 * Returns all Java editor text hovers contributed to the workbench.
177 * @return an array of JavaEditorTextHoverDescriptor
180 public JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors() {
181 if (fJavaEditorTextHoverDescriptors == null)
182 fJavaEditorTextHoverDescriptors= JavaEditorTextHoverDescriptor.getContributedHovers();
183 return fJavaEditorTextHoverDescriptors;
187 * Resets the Java editor text hovers contributed to the workbench.
189 * This will force a rebuild of the descriptors the next time
190 * a client asks for them.
193 * @return an array of JavaEditorTextHoverDescriptor
196 public void resetJavaEditorTextHoverDescriptors() {
197 fJavaEditorTextHoverDescriptors= null;
200 * Creates the PHP plugin standard groups in a context menu.
202 public static void createStandardGroups(IMenuManager menu) {
206 menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
207 menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
208 menu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
209 menu.add(new GroupMarker(IContextMenuConstants.GROUP_SHOW));
210 menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
211 menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
212 menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
213 menu.add(new Separator(IContextMenuConstants.GROUP_BUILD));
214 menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
215 menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
216 menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
218 public static IWorkbenchPage getActivePage() {
219 return getDefault().internalGetActivePage();
222 public static Shell getActiveWorkbenchShell() {
223 return getActiveWorkbenchWindow().getShell();
227 * Returns an array of all editors that have an unsaved content. If the identical content is
228 * presented in more than one editor, only one of those editor parts is part of the result.
230 * @return an array of all dirty editor parts.
232 public static IEditorPart[] getDirtyEditors() {
233 Set inputs = new HashSet();
234 List result = new ArrayList(0);
235 IWorkbench workbench = getDefault().getWorkbench();
236 IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
237 for (int i = 0; i < windows.length; i++) {
238 IWorkbenchPage[] pages = windows[i].getPages();
239 for (int x = 0; x < pages.length; x++) {
240 IEditorPart[] editors = pages[x].getDirtyEditors();
241 for (int z = 0; z < editors.length; z++) {
242 IEditorPart ep = editors[z];
243 IEditorInput input = ep.getEditorInput();
244 if (!inputs.contains(input)) {
251 return (IEditorPart[]) result.toArray(new IEditorPart[result.size()]);
254 public static IWorkbenchWindow getActiveWorkbenchWindow() {
255 return getDefault().getWorkbench().getActiveWorkbenchWindow();
258 * Returns the shared instance.
260 public static PHPeclipsePlugin getDefault() {
264 public static ImageDescriptorRegistry getImageDescriptorRegistry() {
265 return getDefault().internalGetImageDescriptorRegistry();
268 static IPath getInstallLocation() {
269 return new Path(getDefault().getDescriptor().getInstallURL().getFile());
271 public static int getJVM() {
275 public static String getPluginId() {
276 return getDefault().getDescriptor().getUniqueIdentifier();
280 * Returns the standard display to be used. The method first checks, if
281 * the thread calling this method has an associated display. If so, this
282 * display is returned. Otherwise the method returns the default display.
284 public static Display getStandardDisplay() {
285 Display display = Display.getCurrent();
286 if (display == null) {
287 display = Display.getDefault();
292 // public static ExternalToolsPlugin getExternalTools() {
293 // return externalTools;
296 * Returns the workspace instance.
298 public static IWorkspace getWorkspace() {
299 return ResourcesPlugin.getWorkspace();
302 public static boolean isDebug() {
303 return getDefault().isDebugging();
306 // public static void logErrorMessage(String message) {
307 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null));
310 // public static void logErrorStatus(String message, IStatus status) {
311 // if (status == null) {
312 // logErrorMessage(message);
315 // MultiStatus multi= new MultiStatus(getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null);
316 // multi.add(status);
320 // public static void log(Throwable e) {
321 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
324 public static void log(int severity, String message) {
325 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
329 public static void log(IStatus status) {
330 getDefault().getLog().log(status);
332 public static void log(Throwable e) {
333 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
336 private static void setJVM() {
337 String osName = System.getProperty("os.name");
339 if (osName.startsWith("Mac OS")) {
340 String mrjVersion = System.getProperty("mrj.version");
341 String majorMRJVersion = mrjVersion.substring(0, 3);
345 double version = Double.valueOf(majorMRJVersion).doubleValue();
349 } else if (version >= 2.1 && version < 3) {
351 } else if (version == 3.0) {
353 } else if (version >= 3.1) {
357 } catch (NumberFormatException nfe) {
361 } else if (osName.startsWith("Windows")) {
362 if (osName.indexOf("9") != -1) {
370 // TODO: refactor this into a better method name !
371 public synchronized PHPDocumentProvider getCompilationUnitDocumentProvider() {
372 if (fCompilationUnitDocumentProvider == null)
373 fCompilationUnitDocumentProvider = new PHPDocumentProvider();
374 return fCompilationUnitDocumentProvider;
378 * Get the identifier index manager for the given project
380 * @param iProject the current project
383 public IdentifierIndexManager getIndexManager(IProject iProject) {
384 String indexFilename = iProject.getLocation() + File.separator + "project.index";
385 IdentifierIndexManager indexManager = (IdentifierIndexManager) fIndexManagerMap.get(indexFilename);
386 if (indexManager == null) {
387 indexManager = new IdentifierIndexManager(indexFilename);
388 fIndexManagerMap.put(indexFilename, indexManager);
393 public synchronized IWorkingCopyManager getWorkingCopyManager() {
394 if (fWorkingCopyManager == null) {
395 PHPDocumentProvider provider = getCompilationUnitDocumentProvider();
396 fWorkingCopyManager = new WorkingCopyManager(provider);
398 return fWorkingCopyManager;
401 public synchronized MembersOrderPreferenceCache getMemberOrderPreferenceCache() {
402 if (fMembersOrderPreferenceCache == null)
403 fMembersOrderPreferenceCache= new MembersOrderPreferenceCache();
404 return fMembersOrderPreferenceCache;
407 public synchronized ProblemMarkerManager getProblemMarkerManager() {
408 if (fProblemMarkerManager == null)
409 fProblemMarkerManager = new ProblemMarkerManager();
410 return fProblemMarkerManager;
413 public synchronized JavaTextTools getJavaTextTools() {
414 if (fJavaTextTools == null)
415 fJavaTextTools = new JavaTextTools(getPreferenceStore());
416 return fJavaTextTools;
419 public IFile getLastEditorFile() {
420 return fLastEditorFile;
424 * Returns the string from the plugin's resource bundle,
425 * or 'key' if not found.
427 // public static String getResourceString(String key) {
428 // ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
430 // return bundle.getString(key);
431 // } catch (MissingResourceException e) {
437 * Returns the plugin's resource bundle,
439 // public ResourceBundle getResourceBundle() {
440 // return resourceBundle;
443 protected void initializeDefaultPreferences(IPreferenceStore store) {
444 // windows preferences:
445 store.setDefault(LOCALHOST_PREF, "http://localhost");
447 store.setDefault(SHOW_EXTERNAL_PREVIEW_PREF, "true");
448 store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
449 store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
451 String windowsSystem = BootLoader.getWS();
453 if (jvm == WINDOWS_9x) {
454 store.setDefault(EXTERNAL_BROWSER_PREF, "command.com /c start iexplore {0}");
455 } else if (windowsSystem.equals(BootLoader.WS_WIN32)) {
456 store.setDefault(EXTERNAL_BROWSER_PREF, "rundll32 url.dll,FileProtocolHandler {0}");
457 } else if (windowsSystem.equals(BootLoader.WS_CARBON)) {
458 // TODO How do we start Safari on Mac OS X ?
459 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
461 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
463 store.setDefault(DOCUMENTROOT_PREF, getWorkspace().getRoot().getLocation().toString());
465 // if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
467 if (windowsSystem.equals(BootLoader.WS_WIN32)) {
468 store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
469 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
470 store.setDefault(MYSQL_RUN_PREF, "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
471 store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
474 store.setDefault(PHP_RUN_PREF, "/apache/php/php");
475 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
476 store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
477 store.setDefault(APACHE_RUN_PREF, "/apache/apache");
480 store.setDefault(MYSQL_PREF, "--standalone");
481 store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot \"{0}\"\"");
482 store.setDefault(APACHE_STOP_PREF, "-k shutdown");
483 store.setDefault(APACHE_RESTART_PREF, "-k restart");
485 store.setDefault(MYSQL_START_BACKGROUND, "true");
486 store.setDefault(APACHE_START_BACKGROUND, "true");
487 store.setDefault(APACHE_STOP_BACKGROUND, "true");
488 store.setDefault(APACHE_RESTART_BACKGROUND, "true");
490 store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER);
491 store.setDefault(PHP_INTERNAL_PARSER, "false");
492 store.setDefault(PHP_EXTERNAL_PARSER, "true");
494 // store.setDefault(PHP_PARSE_ON_SAVE, "true");
496 // show line numbers:
497 // store.setDefault(LINE_NUMBER_RULER, "false");
498 // store.setDefault(FORMATTER_TAB_SIZE, "4");
500 // php syntax highlighting
501 store.setDefault(PHP_USERDEF_XMLFILE, "");
502 //assume there is none chooA
504 PreferenceConverter.setDefault(store, PHP_MULTILINE_COMMENT, PHPColorProvider.MULTI_LINE_COMMENT);
505 PreferenceConverter.setDefault(store, PHP_SINGLELINE_COMMENT, PHPColorProvider.SINGLE_LINE_COMMENT);
506 PreferenceConverter.setDefault(store, PHP_TAG, PHPColorProvider.TAG);
507 PreferenceConverter.setDefault(store, PHP_KEYWORD, PHPColorProvider.KEYWORD);
508 PreferenceConverter.setDefault(store, PHP_VARIABLE, PHPColorProvider.VARIABLE);
509 PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME, PHPColorProvider.FUNCTION_NAME);
510 PreferenceConverter.setDefault(store, PHP_CONSTANT, PHPColorProvider.CONSTANT);
511 PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
512 PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
513 PreferenceConverter.setDefault(store, PHP_DEFAULT, PHPColorProvider.DEFAULT);
515 PreferenceConverter.setDefault(store, PHPDOC_KEYWORD, PHPColorProvider.PHPDOC_KEYWORD);
516 PreferenceConverter.setDefault(store, PHPDOC_TAG, PHPColorProvider.PHPDOC_TAG);
517 PreferenceConverter.setDefault(store, PHPDOC_LINK, PHPColorProvider.PHPDOC_LINK);
518 PreferenceConverter.setDefault(store, PHPDOC_DEFAULT, PHPColorProvider.PHPDOC_DEFAULT);
520 // PreferenceConverter.setDefault(
522 // PHP_EDITOR_BACKGROUND,
523 // PHPColorProvider.BACKGROUND);
524 // PreferenceConverter.setDefault(
526 // LINKED_POSITION_COLOR,
527 // PHPColorProvider.LINKED_POSITION_COLOR);
528 // PreferenceConverter.setDefault(
530 // LINE_NUMBER_COLOR,
531 // PHPColorProvider.LINE_NUMBER_COLOR);
533 // // set default PHPDoc colors:
534 // PreferenceConverter.setDefault(
537 // PHPColorProvider.PHPDOC_KEYWORD);
538 // PreferenceConverter.setDefault(
541 // PHPColorProvider.PHPDOC_LINK);
542 // PreferenceConverter.setDefault(
545 // PHPColorProvider.PHPDOC_DEFAULT);
546 // PreferenceConverter.setDefault(
549 // PHPColorProvider.PHPDOC_TAG);
551 // store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
552 // PreferenceConverter.setDefault(
554 // PREFERENCE_COLOR_BACKGROUND,
555 // PHPColorProvider.BACKGROUND_COLOR);
558 // store.setDefault(RESOURCE_BUNDLE, LANGUAGE_DEFAULT);
559 // store.setDefault(RESOURCE_BUNDLE_EN_GB, "true");
560 // store.setDefault(RESOURCE_BUNDLE_DE, "false");
561 // store.setDefault(RESOURCE_BUNDLE_FR, "false");
562 // store.setDefault(RESOURCE_BUNDLE_ES, "false");
564 store.setDefault(PHP_OUTLINE_CLASS, "true"); //$NON-NLS-1$
565 store.setDefault(PHP_OUTLINE_FUNC, "true"); //$NON-NLS-1$
566 store.setDefault(PHP_OUTLINE_VAR, "true"); //$NON-NLS-1$
568 TemplatePreferencePage.initDefaults(store);
569 //this will initialize the static fields in the syntaxrdr class
572 PHPCore.initializeDefaultPluginPreferences();
573 PreferenceConstants.initializeDefaultValues(store);
575 externalTools.initializeDefaultPreferences(store);
578 private IWorkbenchPage internalGetActivePage() {
579 IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
581 return window.getActivePage();
585 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
586 if (fImageDescriptorRegistry == null)
587 fImageDescriptorRegistry = new ImageDescriptorRegistry();
588 return fImageDescriptorRegistry;
591 * Open a file in the Workbench that may or may not exist in the workspace.
592 * Must be run on the UI thread.
594 * @throws CoreException
596 public ITextEditor openFileInTextEditor(String filename) throws CoreException {
598 // reject directories
599 if (new File(filename).isDirectory())
602 IWorkbench workbench = PlatformUI.getWorkbench();
603 IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
604 IWorkbenchPage page = window.getActivePage();
605 IPath path = new Path(filename);
607 // If the file exists in the workspace, open it
608 IFile file = getWorkspace().getRoot().getFileForLocation(path);
610 ITextEditor textEditor;
611 if (file != null && file.exists()) {
612 editor = page.openEditor(file);
613 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
615 // Otherwise open the stream directly
618 FileStorage storage = new FileStorage(path);
619 IEditorRegistry registry = getWorkbench().getEditorRegistry();
620 IEditorDescriptor desc = registry.getDefaultEditor(filename);
622 desc = registry.getDefaultEditor();
624 IEditorInput input = new ExternalEditorInput(storage);
625 editor = page.openEditor(input, desc.getId());
626 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
628 // If the storage provider is not ours, we can't guarantee read/write.
629 if (textEditor != null) {
630 IDocumentProvider documentProvider = textEditor.getDocumentProvider();
631 if (!(documentProvider instanceof ExternalStorageDocumentProvider)) {
632 storage.setReadOnly();
639 * Open a file in the Workbench that may or may not exist in the workspace.
640 * Must be run on the UI thread.
643 * @throws CoreException
645 public void openFileAndGotoLine(String filename, int line) throws CoreException {
647 ITextEditor textEditor = openFileInTextEditor(filename);
648 if (textEditor != null) {
649 // If a line number was given, go to it
652 line--; // document is 0 based
653 IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
654 textEditor.selectAndReveal(document.getLineOffset(line), document.getLineLength(line));
656 } catch (BadLocationException e) {
657 // invalid text position -> do nothing
664 * Open a file in the Workbench that may or may not exist in the workspace.
665 * Must be run on the UI thread.
668 * @throws CoreException
670 public void openFileAndGotoOffset(String filename, int offset, int length) throws CoreException {
672 ITextEditor textEditor = openFileInTextEditor(filename);
673 if (textEditor != null) {
674 // If a line number was given, go to it
676 IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
677 textEditor.selectAndReveal(offset, length);
682 public void openFileAndFindString(String filename, String findString) throws CoreException {
684 ITextEditor textEditor = openFileInTextEditor(filename);
685 if (textEditor != null) {
686 // If a string was given, go to it
687 if (findString != null) {
689 IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
690 int offset = document.search(0, findString, true, false, true);
691 textEditor.selectAndReveal(offset, findString.length());
693 } catch (BadLocationException e) {
694 // invalid text position -> do nothing
700 public void setLastEditorFile(IFile textEditor) {
701 this.fLastEditorFile = textEditor;
705 * @see org.eclipse.ui.plugin.AbstractUIPlugin#shutdown()
707 public void shutdown() throws CoreException {
711 // externalTools.shutDown();
712 ColorManager.getDefault().dispose();
714 // save the information from the php index files if necessary
715 Collection collection = fIndexManagerMap.values();
716 Iterator iterator = collection.iterator();
717 IdentifierIndexManager indexManager = null;
718 while (iterator.hasNext()) {
719 indexManager = (IdentifierIndexManager) iterator.next();
720 indexManager.writeFile();
723 if (fImageDescriptorRegistry != null)
724 fImageDescriptorRegistry.dispose();
726 // unregisterAdapters();
730 if (fWorkingCopyManager != null) {
731 fWorkingCopyManager.shutdown();
732 fWorkingCopyManager = null;
735 if (fCompilationUnitDocumentProvider != null) {
736 fCompilationUnitDocumentProvider.shutdown();
737 fCompilationUnitDocumentProvider = null;
740 if (fJavaTextTools != null) {
741 fJavaTextTools.dispose();
742 fJavaTextTools = null;
745 // JavaDocLocations.shutdownJavadocLocations();
747 // JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
751 public void startup() throws CoreException {
753 IAdapterManager manager = Platform.getAdapterManager();
754 manager.registerAdapters(new PHPElementAdapterFactory(), PHPElement.class);
755 manager.registerAdapters(new ResourceAdapterFactory(), IResource.class);
756 // externalTools.startUp();
757 getStandardDisplay().asyncExec(new Runnable() {
759 //initialize the variable context manager
760 VariableContextManager.getDefault();