deletet because wrongly uploaded
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / actions / PHPOpenDeclarationEditorActon.java
index babeffc..3322c86 100644 (file)
@@ -27,12 +27,16 @@ import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.ITextSelection;
 import org.eclipse.jface.text.TextSelection;
 import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.window.Window;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.ui.IEditorActionDelegate;
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IFileEditorInput;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.actions.ActionDelegate;
+import org.eclipse.ui.dialogs.ListSelectionDialog;
+import org.eclipse.ui.internal.dialogs.ListContentProvider;
 
 public class PHPOpenDeclarationEditorActon extends ActionDelegate implements IEditorActionDelegate {
 
@@ -68,30 +72,65 @@ public class PHPOpenDeclarationEditorActon extends ActionDelegate implements IEd
       // determine the current Project from a (file-based) Editor
       IFile f = ((IFileEditorInput) fEditor.getEditorInput()).getFile();
       fProject = f.getProject();
-//      System.out.println(fProject.toString());
+      //      System.out.println(fProject.toString());
 
       ITextSelection selection = (ITextSelection) fEditor.getSelectionProvider().getSelection();
       IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
       int pos = selection.getOffset();
       String word = getPHPIdentifier(doc, pos);
       //      System.out.println(word);
-      if (word!=null && ! word.equals("")) {
-                               IdentifierIndexManager indexManager = PHPeclipsePlugin.getDefault().getIndexManager(fProject);
-                               List list = indexManager.getLocations(word);
-                               if (list!=null && list.size()>0) {
-                                       String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot().getLocation().toString();
-                                       // TODO show all entries of the list in a dialog box
-                                       // at the moment allways the first entry will be opened
-                                       PHPIdentifierLocation location = (PHPIdentifierLocation)list.get(0);
-                                       String filename = workspaceLocation + location.getFilename();
-//                                     System.out.println(filename);
-                                       try {
-            PHPeclipsePlugin.getDefault().openFileInTextEditor(filename, 0, word);
-          } catch (CoreException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
+      if (word != null && !word.equals("")) {
+        IdentifierIndexManager indexManager = PHPeclipsePlugin.getDefault().getIndexManager(fProject);
+        List list = indexManager.getLocations(word);
+        if (list != null && list.size() > 0) {
+          String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot().getLocation().toString();
+          // TODO show all entries of the list in a dialog box
+          // at the moment always the first entry will be opened
+          if (list.size() > 1) {
+            ListSelectionDialog listSelectionDialog =
+              new ListSelectionDialog(
+                PHPeclipsePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(),
+                list,
+                new ListContentProvider(),
+                new LabelProvider(),
+                "Select the resources to open.");
+            listSelectionDialog.setTitle("Multiple declarations found");
+            if (listSelectionDialog.open() == Window.OK) {
+              Object[] locations = listSelectionDialog.getResult();
+              if (locations != null) {
+                try {
+                  for (int i = 0; i < locations.length; i++) {
+                    PHPIdentifierLocation location = (PHPIdentifierLocation) locations[i];
+                    String filename = workspaceLocation + location.getFilename();
+                    //                                 System.out.println(filename);
+                    if (location.getOffset() >= 0) {
+                      PHPeclipsePlugin.getDefault().openFileAndGotoOffset(filename, location.getOffset(), word.length());
+                    } else {
+                      PHPeclipsePlugin.getDefault().openFileAndFindString(filename, word);
+                    }
+                  }
+                } catch (CoreException e) {
+                  // TODO Auto-generated catch block
+                  e.printStackTrace();
+                }
+              }
+            }
+          } else {
+            try {
+              PHPIdentifierLocation location = (PHPIdentifierLocation) list.get(0);
+              String filename = workspaceLocation + location.getFilename();
+              //                                       System.out.println(filename);
+              if (location.getOffset() >= 0) {
+                PHPeclipsePlugin.getDefault().openFileAndGotoOffset(filename, location.getOffset(), word.length());
+              } else {
+                PHPeclipsePlugin.getDefault().openFileAndFindString(filename, word);
+              }
+            } catch (CoreException e) {
+              // TODO Auto-generated catch block
+              e.printStackTrace();
+            }
           }
-                               }
+        }
       }
     }
   }
@@ -102,29 +141,6 @@ public class PHPOpenDeclarationEditorActon extends ActionDelegate implements IEd
     }
   }
 
-  //  public static void openContextHelp(String word) {
-  //    IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
-  //    if (store.getBoolean(PHPHelpPlugin.PHP_CHM_ENABLED)) {
-  //      String[] arguments = { store.getString(PHPHelpPlugin.PHP_CHM_FILE), word };
-  //      MessageFormat form = new MessageFormat(store.getString(PHPHelpPlugin.PHP_CHM_COMMAND));
-  //      try {
-  //        Runtime runtime = Runtime.getRuntime();
-  //        String command = form.format(arguments);
-  //
-  //        runtime.exec(command);
-  //      } catch (IOException e) {
-  //      }
-  //    } else {
-  //      IHelp help = WorkbenchHelp.getHelpSupport();
-  //      if (help != null) {
-  //        PHPFunctionHelpResource helpResource = new PHPFunctionHelpResource(word);
-  //        WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource);
-  //      } else {
-  //        //   showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$
-  //      }
-  //    }
-  //  }
-
   private String getPHPIdentifier(IDocument doc, int pos) {
     Point word = PHPWordExtractor.findWord(doc, pos);
     if (word != null) {