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.ide.IDE;
79 import org.eclipse.ui.plugin.AbstractUIPlugin;
80 import org.eclipse.ui.texteditor.IDocumentProvider;
81 import org.eclipse.ui.texteditor.ITextEditor;
84 * The main plugin class to be used in the desktop.
86 public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceConstants {
88 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
90 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
93 * id of builder - matches plugin.xml (concatenate pluginid.builderid)
95 public static final String BUILDER_PARSER_ID = PLUGIN_ID + ".parserbuilder";
96 //public static final String BUILDER_INDEX_ID = PLUGIN_ID + ".indexbuilder";
98 /** General debug flag*/
99 public static final boolean DEBUG = false;
102 * The maximum number of allowed proposals by category
104 public final static int MAX_PROPOSALS = 200;
106 private static ExternalToolsPlugin externalTools;
109 * The Java virtual machine that we are running on.
111 private static int jvm;
114 private static final int MRJ_2_0 = 0;
116 /** MRJ 2.1 or later */
117 private static final int MRJ_2_1 = 1;
119 /** Java on Mac OS X 10.0 (MRJ 3.0) */
120 private static final int MRJ_3_0 = 3;
123 private static final int MRJ_3_1 = 4;
125 /** JVM constant for any other platform */
126 private static final int OTHER = -1;
128 // public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID + ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
129 public static final String PHP_CODING_ACTION_SET_ID = PLUGIN_ID + ".ui.CodingActionSet"; //$NON-NLS-1$
130 public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
132 public static final String PHPPARSER_ORIGINAL = "net.sourceforge.phpdt.internal.compiler.parser.Parser";
134 public static final String PHPPARSER_NEW = "test.PHPParser";
136 /** Change this if you want to switch PHP Parser. */
137 public static final String PHPPARSER = PHPPARSER_ORIGINAL;
139 //The shared instance.
140 private static PHPeclipsePlugin plugin;
143 private static final int WINDOWS_9x = 6;
146 private static final int WINDOWS_NT = 5;
148 private ImageDescriptorRegistry fImageDescriptorRegistry;
149 private HashMap fIndexManagerMap = new HashMap();
151 private IWorkingCopyManager fWorkingCopyManager;
152 private PHPDocumentProvider fCompilationUnitDocumentProvider;
153 private JavaTextTools fJavaTextTools;
154 private ProblemMarkerManager fProblemMarkerManager;
155 private MembersOrderPreferenceCache fMembersOrderPreferenceCache;
157 private IFile fLastEditorFile = null;
159 private JavaEditorTextHoverDescriptor[] fJavaEditorTextHoverDescriptors;
164 public PHPeclipsePlugin(IPluginDescriptor descriptor) {
168 externalTools = new ExternalToolsPlugin();
170 // resourceBundle = ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
171 // } catch (MissingResourceException x) {
172 // resourceBundle = null;
176 * Returns all Java editor text hovers contributed to the workbench.
178 * @return an array of JavaEditorTextHoverDescriptor
181 public JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors() {
182 if (fJavaEditorTextHoverDescriptors == null)
183 fJavaEditorTextHoverDescriptors= JavaEditorTextHoverDescriptor.getContributedHovers();
184 return fJavaEditorTextHoverDescriptors;
188 * Resets the Java editor text hovers contributed to the workbench.
190 * This will force a rebuild of the descriptors the next time
191 * a client asks for them.
194 * @return an array of JavaEditorTextHoverDescriptor
197 public void resetJavaEditorTextHoverDescriptors() {
198 fJavaEditorTextHoverDescriptors= null;
201 * Creates the PHP plugin standard groups in a context menu.
203 public static void createStandardGroups(IMenuManager menu) {
207 menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
208 menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
209 menu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
210 menu.add(new GroupMarker(IContextMenuConstants.GROUP_SHOW));
211 menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
212 menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
213 menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
214 menu.add(new Separator(IContextMenuConstants.GROUP_BUILD));
215 menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
216 menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
217 menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
219 public static IWorkbenchPage getActivePage() {
220 return getDefault().internalGetActivePage();
223 public static Shell getActiveWorkbenchShell() {
224 return getActiveWorkbenchWindow().getShell();
228 * Returns an array of all editors that have an unsaved content. If the identical content is
229 * presented in more than one editor, only one of those editor parts is part of the result.
231 * @return an array of all dirty editor parts.
233 public static IEditorPart[] getDirtyEditors() {
234 Set inputs = new HashSet();
235 List result = new ArrayList(0);
236 IWorkbench workbench = getDefault().getWorkbench();
237 IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
238 for (int i = 0; i < windows.length; i++) {
239 IWorkbenchPage[] pages = windows[i].getPages();
240 for (int x = 0; x < pages.length; x++) {
241 IEditorPart[] editors = pages[x].getDirtyEditors();
242 for (int z = 0; z < editors.length; z++) {
243 IEditorPart ep = editors[z];
244 IEditorInput input = ep.getEditorInput();
245 if (!inputs.contains(input)) {
252 return (IEditorPart[]) result.toArray(new IEditorPart[result.size()]);
255 public static IWorkbenchWindow getActiveWorkbenchWindow() {
256 return getDefault().getWorkbench().getActiveWorkbenchWindow();
259 * Returns the shared instance.
261 public static PHPeclipsePlugin getDefault() {
265 public static ImageDescriptorRegistry getImageDescriptorRegistry() {
266 return getDefault().internalGetImageDescriptorRegistry();
269 static IPath getInstallLocation() {
270 return new Path(getDefault().getDescriptor().getInstallURL().getFile());
272 public static int getJVM() {
276 public static String getPluginId() {
277 return getDefault().getDescriptor().getUniqueIdentifier();
281 * Returns the standard display to be used. The method first checks, if
282 * the thread calling this method has an associated display. If so, this
283 * display is returned. Otherwise the method returns the default display.
285 public static Display getStandardDisplay() {
286 Display display = Display.getCurrent();
287 if (display == null) {
288 display = Display.getDefault();
293 // public static ExternalToolsPlugin getExternalTools() {
294 // return externalTools;
297 * Returns the workspace instance.
299 public static IWorkspace getWorkspace() {
300 return ResourcesPlugin.getWorkspace();
303 public static boolean isDebug() {
304 return getDefault().isDebugging();
307 // public static void logErrorMessage(String message) {
308 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null));
311 // public static void logErrorStatus(String message, IStatus status) {
312 // if (status == null) {
313 // logErrorMessage(message);
316 // MultiStatus multi= new MultiStatus(getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null);
317 // multi.add(status);
321 // public static void log(Throwable e) {
322 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
325 public static void log(int severity, String message) {
326 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
330 public static void log(IStatus status) {
331 getDefault().getLog().log(status);
333 public static void log(Throwable e) {
334 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
337 private static void setJVM() {
338 String osName = System.getProperty("os.name");
340 if (osName.startsWith("Mac OS")) {
341 String mrjVersion = System.getProperty("mrj.version");
342 String majorMRJVersion = mrjVersion.substring(0, 3);
346 double version = Double.valueOf(majorMRJVersion).doubleValue();
350 } else if (version >= 2.1 && version < 3) {
352 } else if (version == 3.0) {
354 } else if (version >= 3.1) {
358 } catch (NumberFormatException nfe) {
362 } else if (osName.startsWith("Windows")) {
363 if (osName.indexOf("9") != -1) {
371 // TODO: refactor this into a better method name !
372 public synchronized PHPDocumentProvider getCompilationUnitDocumentProvider() {
373 if (fCompilationUnitDocumentProvider == null)
374 fCompilationUnitDocumentProvider = new PHPDocumentProvider();
375 return fCompilationUnitDocumentProvider;
379 * Get the identifier index manager for the given project
381 * @param iProject the current project
384 public IdentifierIndexManager getIndexManager(IProject iProject) {
385 String indexFilename = iProject.getLocation() + File.separator + "project.index";
386 IdentifierIndexManager indexManager = (IdentifierIndexManager) fIndexManagerMap.get(indexFilename);
387 if (indexManager == null) {
388 indexManager = new IdentifierIndexManager(indexFilename);
389 fIndexManagerMap.put(indexFilename, indexManager);
394 public synchronized IWorkingCopyManager getWorkingCopyManager() {
395 if (fWorkingCopyManager == null) {
396 PHPDocumentProvider provider = getCompilationUnitDocumentProvider();
397 fWorkingCopyManager = new WorkingCopyManager(provider);
399 return fWorkingCopyManager;
402 public synchronized MembersOrderPreferenceCache getMemberOrderPreferenceCache() {
403 if (fMembersOrderPreferenceCache == null)
404 fMembersOrderPreferenceCache= new MembersOrderPreferenceCache();
405 return fMembersOrderPreferenceCache;
408 public synchronized ProblemMarkerManager getProblemMarkerManager() {
409 if (fProblemMarkerManager == null)
410 fProblemMarkerManager = new ProblemMarkerManager();
411 return fProblemMarkerManager;
414 public synchronized JavaTextTools getJavaTextTools() {
415 if (fJavaTextTools == null)
416 fJavaTextTools = new JavaTextTools(getPreferenceStore());
417 return fJavaTextTools;
420 public IFile getLastEditorFile() {
421 return fLastEditorFile;
425 * Returns the string from the plugin's resource bundle,
426 * or 'key' if not found.
428 // public static String getResourceString(String key) {
429 // ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
431 // return bundle.getString(key);
432 // } catch (MissingResourceException e) {
438 * Returns the plugin's resource bundle,
440 // public ResourceBundle getResourceBundle() {
441 // return resourceBundle;
444 protected void initializeDefaultPreferences(IPreferenceStore store) {
445 // windows preferences:
446 store.setDefault(LOCALHOST_PREF, "http://localhost");
448 store.setDefault(SHOW_EXTERNAL_PREVIEW_PREF, "true");
449 store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
450 store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
452 String windowsSystem = BootLoader.getWS();
454 if (jvm == WINDOWS_9x) {
455 store.setDefault(EXTERNAL_BROWSER_PREF, "command.com /c start iexplore {0}");
456 } else if (windowsSystem.equals(BootLoader.WS_WIN32)) {
457 store.setDefault(EXTERNAL_BROWSER_PREF, "rundll32 url.dll,FileProtocolHandler {0}");
458 } else if (windowsSystem.equals(BootLoader.WS_CARBON)) {
459 // TODO How do we start Safari on Mac OS X ?
460 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
462 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
464 store.setDefault(DOCUMENTROOT_PREF, getWorkspace().getRoot().getLocation().toString());
466 // if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
468 if (windowsSystem.equals(BootLoader.WS_WIN32)) {
469 store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
470 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
471 store.setDefault(MYSQL_RUN_PREF, "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
472 store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
475 store.setDefault(PHP_RUN_PREF, "/apache/php/php");
476 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
477 store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
478 store.setDefault(APACHE_RUN_PREF, "/apache/apache");
481 store.setDefault(MYSQL_PREF, "--standalone");
482 store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot \"{0}\"\"");
483 store.setDefault(APACHE_STOP_PREF, "-k shutdown");
484 store.setDefault(APACHE_RESTART_PREF, "-k restart");
486 store.setDefault(MYSQL_START_BACKGROUND, "true");
487 store.setDefault(APACHE_START_BACKGROUND, "true");
488 store.setDefault(APACHE_STOP_BACKGROUND, "true");
489 store.setDefault(APACHE_RESTART_BACKGROUND, "true");
491 store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER);
492 store.setDefault(PHP_INTERNAL_PARSER, "false");
493 store.setDefault(PHP_EXTERNAL_PARSER, "true");
495 // store.setDefault(PHP_PARSE_ON_SAVE, "true");
497 // show line numbers:
498 // store.setDefault(LINE_NUMBER_RULER, "false");
499 // store.setDefault(FORMATTER_TAB_SIZE, "4");
501 // php syntax highlighting
502 store.setDefault(PHP_USERDEF_XMLFILE, "");
503 //assume there is none chooA
505 PreferenceConverter.setDefault(store, PHP_MULTILINE_COMMENT, PHPColorProvider.MULTI_LINE_COMMENT);
506 PreferenceConverter.setDefault(store, PHP_SINGLELINE_COMMENT, PHPColorProvider.SINGLE_LINE_COMMENT);
507 PreferenceConverter.setDefault(store, PHP_TAG, PHPColorProvider.TAG);
508 PreferenceConverter.setDefault(store, PHP_KEYWORD, PHPColorProvider.KEYWORD);
509 PreferenceConverter.setDefault(store, PHP_VARIABLE, PHPColorProvider.VARIABLE);
510 PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME, PHPColorProvider.FUNCTION_NAME);
511 PreferenceConverter.setDefault(store, PHP_CONSTANT, PHPColorProvider.CONSTANT);
512 PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
513 PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
514 PreferenceConverter.setDefault(store, PHP_DEFAULT, PHPColorProvider.DEFAULT);
516 PreferenceConverter.setDefault(store, PHPDOC_KEYWORD, PHPColorProvider.PHPDOC_KEYWORD);
517 PreferenceConverter.setDefault(store, PHPDOC_TAG, PHPColorProvider.PHPDOC_TAG);
518 PreferenceConverter.setDefault(store, PHPDOC_LINK, PHPColorProvider.PHPDOC_LINK);
519 PreferenceConverter.setDefault(store, PHPDOC_DEFAULT, PHPColorProvider.PHPDOC_DEFAULT);
521 // PreferenceConverter.setDefault(
523 // PHP_EDITOR_BACKGROUND,
524 // PHPColorProvider.BACKGROUND);
525 // PreferenceConverter.setDefault(
527 // LINKED_POSITION_COLOR,
528 // PHPColorProvider.LINKED_POSITION_COLOR);
529 // PreferenceConverter.setDefault(
531 // LINE_NUMBER_COLOR,
532 // PHPColorProvider.LINE_NUMBER_COLOR);
534 // // set default PHPDoc colors:
535 // PreferenceConverter.setDefault(
538 // PHPColorProvider.PHPDOC_KEYWORD);
539 // PreferenceConverter.setDefault(
542 // PHPColorProvider.PHPDOC_LINK);
543 // PreferenceConverter.setDefault(
546 // PHPColorProvider.PHPDOC_DEFAULT);
547 // PreferenceConverter.setDefault(
550 // PHPColorProvider.PHPDOC_TAG);
552 // store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
553 // PreferenceConverter.setDefault(
555 // PREFERENCE_COLOR_BACKGROUND,
556 // PHPColorProvider.BACKGROUND_COLOR);
559 // store.setDefault(RESOURCE_BUNDLE, LANGUAGE_DEFAULT);
560 // store.setDefault(RESOURCE_BUNDLE_EN_GB, "true");
561 // store.setDefault(RESOURCE_BUNDLE_DE, "false");
562 // store.setDefault(RESOURCE_BUNDLE_FR, "false");
563 // store.setDefault(RESOURCE_BUNDLE_ES, "false");
565 store.setDefault(PHP_OUTLINE_CLASS, "true"); //$NON-NLS-1$
566 store.setDefault(PHP_OUTLINE_FUNC, "true"); //$NON-NLS-1$
567 store.setDefault(PHP_OUTLINE_VAR, "true"); //$NON-NLS-1$
569 TemplatePreferencePage.initDefaults(store);
570 //this will initialize the static fields in the syntaxrdr class
573 PHPCore.initializeDefaultPluginPreferences();
574 PreferenceConstants.initializeDefaultValues(store);
576 externalTools.initializeDefaultPreferences(store);
579 private IWorkbenchPage internalGetActivePage() {
580 IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
582 return window.getActivePage();
586 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
587 if (fImageDescriptorRegistry == null)
588 fImageDescriptorRegistry = new ImageDescriptorRegistry();
589 return fImageDescriptorRegistry;
592 * Open a file in the Workbench that may or may not exist in the workspace.
593 * Must be run on the UI thread.
595 * @throws CoreException
597 public ITextEditor openFileInTextEditor(String filename) throws CoreException {
599 // reject directories
600 if (new File(filename).isDirectory())
603 IWorkbench workbench = PlatformUI.getWorkbench();
604 IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
605 IWorkbenchPage page = window.getActivePage();
606 IPath path = new Path(filename);
608 // If the file exists in the workspace, open it
609 IFile file = getWorkspace().getRoot().getFileForLocation(path);
611 ITextEditor textEditor;
612 if (file != null && file.exists()) {
613 editor = IDE.openEditor(page, file, true);
614 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
616 // Otherwise open the stream directly
619 FileStorage storage = new FileStorage(path);
620 IEditorRegistry registry = getWorkbench().getEditorRegistry();
621 IEditorDescriptor desc = registry.getDefaultEditor(filename);
623 desc = registry.getDefaultEditor();
625 IEditorInput input = new ExternalEditorInput(storage);
626 editor = page.openEditor(input, desc.getId());
627 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
629 // If the storage provider is not ours, we can't guarantee read/write.
630 if (textEditor != null) {
631 IDocumentProvider documentProvider = textEditor.getDocumentProvider();
632 if (!(documentProvider instanceof ExternalStorageDocumentProvider)) {
633 storage.setReadOnly();
640 * Open a file in the Workbench that may or may not exist in the workspace.
641 * Must be run on the UI thread.
644 * @throws CoreException
646 public void openFileAndGotoLine(String filename, int line) throws CoreException {
648 ITextEditor textEditor = openFileInTextEditor(filename);
649 if (textEditor != null) {
650 // If a line number was given, go to it
653 line--; // document is 0 based
654 IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
655 textEditor.selectAndReveal(document.getLineOffset(line), document.getLineLength(line));
657 } catch (BadLocationException e) {
658 // invalid text position -> do nothing
665 * Open a file in the Workbench that may or may not exist in the workspace.
666 * Must be run on the UI thread.
669 * @throws CoreException
671 public void openFileAndGotoOffset(String filename, int offset, int length) throws CoreException {
673 ITextEditor textEditor = openFileInTextEditor(filename);
674 if (textEditor != null) {
675 // If a line number was given, go to it
677 IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
678 textEditor.selectAndReveal(offset, length);
683 public void openFileAndFindString(String filename, String findString) throws CoreException {
685 ITextEditor textEditor = openFileInTextEditor(filename);
686 if (textEditor != null) {
687 // If a string was given, go to it
688 if (findString != null) {
690 IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
691 int offset = document.search(0, findString, true, false, true);
692 textEditor.selectAndReveal(offset, findString.length());
694 } catch (BadLocationException e) {
695 // invalid text position -> do nothing
701 public void setLastEditorFile(IFile textEditor) {
702 this.fLastEditorFile = textEditor;
706 * @see org.eclipse.ui.plugin.AbstractUIPlugin#shutdown()
708 public void shutdown() throws CoreException {
712 // externalTools.shutDown();
713 ColorManager.getDefault().dispose();
715 // save the information from the php index files if necessary
716 Collection collection = fIndexManagerMap.values();
717 Iterator iterator = collection.iterator();
718 IdentifierIndexManager indexManager = null;
719 while (iterator.hasNext()) {
720 indexManager = (IdentifierIndexManager) iterator.next();
721 indexManager.writeFile();
724 if (fImageDescriptorRegistry != null)
725 fImageDescriptorRegistry.dispose();
727 // unregisterAdapters();
731 if (fWorkingCopyManager != null) {
732 fWorkingCopyManager.shutdown();
733 fWorkingCopyManager = null;
736 if (fCompilationUnitDocumentProvider != null) {
737 fCompilationUnitDocumentProvider.shutdown();
738 fCompilationUnitDocumentProvider = null;
741 if (fJavaTextTools != null) {
742 fJavaTextTools.dispose();
743 fJavaTextTools = null;
746 // JavaDocLocations.shutdownJavadocLocations();
748 // JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
752 public void startup() throws CoreException {
754 IAdapterManager manager = Platform.getAdapterManager();
755 manager.registerAdapters(new PHPElementAdapterFactory(), PHPElement.class);
756 manager.registerAdapters(new ResourceAdapterFactory(), IResource.class);
757 // externalTools.startUp();
758 getStandardDisplay().asyncExec(new Runnable() {
760 //initialize the variable context manager
761 VariableContextManager.getDefault();