Merged "Open PHP Declaration" and "Open Include File" into one action "Open Declarati...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / actions / PHPOpenDeclarationEditorAction.java
index 2dd8a72..486f7cf 100644 (file)
@@ -7,11 +7,11 @@
  **********************************************************************************************************************************/
 package net.sourceforge.phpeclipse.actions;
 
-import java.io.File;
 import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 
+import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
 import net.sourceforge.phpeclipse.builder.PHPIdentifierLocation;
@@ -21,8 +21,9 @@ import net.sourceforge.phpeclipse.phpeditor.php.PHPWordExtractor;
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.internal.resources.File;
 import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.IPath;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
@@ -102,10 +103,18 @@ public class PHPOpenDeclarationEditorAction extends ActionDelegate implements IE
   private void openIncludeFile(String filename) {
     if (filename != null && !filename.equals("")) {
       try {
-        IFile file = getIncludeFile(fProject, (IFileEditorInput) fEditor.getEditorInput(), filename);
-        if (file != null && file.exists()) {
-          PHPeclipsePlugin.getDefault().openFileInTextEditor(file.getLocation().toString());
-          return;
+        IFile currentFile = ((IFileEditorInput) fEditor.getEditorInput()).getFile();
+        IPath path = PHPFileUtil.determineFilePath(filename, currentFile, fProject);
+        if (path != null) { 
+//          String projectPath = fProject.getLocation().toString();
+//          String filePath = path.toString().substring(projectPath.length()+1);
+//          IFile file = fProject.getFile(filePath);
+          IFile file = PHPFileUtil.createFile(path, fProject);
+          //        IFile file = getIncludeFile(fProject, (IFileEditorInput) fEditor.getEditorInput(), filename);
+          if (file != null && file.exists()) {
+            PHPeclipsePlugin.getDefault().openFileInTextEditor(file.getLocation().toString());
+            return;
+          }
         }
       } catch (Exception e) {
         // ignore
@@ -118,7 +127,7 @@ public class PHPOpenDeclarationEditorAction extends ActionDelegate implements IE
         List list = indexManager.getFileList(filename);
         if (list != null && list.size() > 0) {
           //String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot().getLocation().toString();
-          String workspaceLocation = fProject.getLocation().toString() + File.separatorChar;
+          String workspaceLocation = fProject.getLocation().toString() + java.io.File.separatorChar;
 
           ListSelectionDialog listSelectionDialog = new ListSelectionDialog(PHPeclipsePlugin.getDefault().getWorkbench()
               .getActiveWorkbenchWindow().getShell(), list, new ListContentProvider(), new LabelProvider(),
@@ -162,7 +171,7 @@ public class PHPOpenDeclarationEditorAction extends ActionDelegate implements IE
         //          String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot()
         //              .getLocation().toString();
 
-        String workspaceLocation = fProject.getLocation().toString() + File.separatorChar;
+        String workspaceLocation = fProject.getLocation().toString() + java.io.File.separatorChar;
         // TODO show all entries of the list in a dialog box
         // at the moment always the first entry will be opened
         if (locationsList.size() > 1) {
@@ -306,28 +315,28 @@ public class PHPOpenDeclarationEditorAction extends ActionDelegate implements IE
     return editorInput.getFile().getParent();
   }
 
-  private IFile getIncludeFile(IProject project, IFileEditorInput editorInput, String relativeFilename) {
-    IContainer container = getWorkingLocation(editorInput);
-    String fullPath = project.getLocation().toString();
-    IFile file = null;
-    if (relativeFilename.startsWith("../")) {
-      Path path = new Path(relativeFilename);
-      file = container.getFile(path);
-      return file;
-    }
-    int index = relativeFilename.lastIndexOf('/');
-
-    if (index >= 0) {
-      Path path = new Path(relativeFilename);
-      file = project.getFile(path);
-      if (file.exists()) {
-        return file;
-      }
-    }
-
-    Path path = new Path(relativeFilename);
-    file = container.getFile(path);
-
-    return file;
-  }
+  //  private IFile getIncludeFile(IProject project, IFileEditorInput editorInput, String relativeFilename) {
+  //    IContainer container = getWorkingLocation(editorInput);
+  //    String fullPath = project.getLocation().toString();
+  //    IFile file = null;
+  //    if (relativeFilename.startsWith("../")) {
+  //      Path path = new Path(relativeFilename);
+  //      file = container.getFile(path);
+  //      return file;
+  //    }
+  //    int index = relativeFilename.lastIndexOf('/');
+  //
+  //    if (index >= 0) {
+  //      Path path = new Path(relativeFilename);
+  //      file = project.getFile(path);
+  //      if (file.exists()) {
+  //        return file;
+  //      }
+  //    }
+  //
+  //    Path path = new Path(relativeFilename);
+  //    file = container.getFile(path);
+  //
+  //    return file;
+  //  }
 }
\ No newline at end of file