improved "Open Include"
authorkhartlage <khartlage>
Thu, 10 Jun 2004 17:32:16 +0000 (17:32 +0000)
committerkhartlage <khartlage>
Thu, 10 Jun 2004 17:32:16 +0000 (17:32 +0000)
net.sourceforge.phpeclipse/install.txt
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPOpenIncludeEditorAction.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java

index f22b411..44d60b4 100644 (file)
@@ -1,5 +1,5 @@
-PHPEclipse  Version 1.0.6alpha
-Copyright 2003 net.sourceforge.phpeclipse
+PHPEclipse  Version 1.1.0
+Copyright 2003-2004 net.sourceforge.phpeclipse
 http://www.phpeclipse.org
 Contributors:
     Klaus Hartlage (http://www.phpeclipse.de)
@@ -16,7 +16,7 @@ Contributors:
 This Plugin is released under the Common Public License v1.0 which is included
 in this distribution or can be viewed at http://www.eclipse.org/legal/cpl-v10.html.
 
-Look for updated versions of this plugin at http://www.phpeclipse.org -> Downloads
+Look for updated versions of this plugin at http://www.phpeclipse.de -> Install/Downloads
 
 1. Requirements
 2. Recommended
@@ -32,7 +32,7 @@ Look for updated versions of this plugin at http://www.phpeclipse.org -> Downloa
  1. Requirements
 ------------------------------------------
 Java Runtime 1.4.x or higher ( downloadable at http://java.sun.com )
-Eclipse 2.1 or higher ( downloadable at http://www.eclipse.org )
+Eclipse 3.0 or higher ( downloadable at http://www.eclipse.org )
 
 
 
@@ -53,7 +53,7 @@ Simply unzip the files to your eclipse plugins directory and (re)start eclipse.
 If you copy the files manually make sure all files are located in the
 net.sourceforge.phpeclipse folder in the plugins directory in your eclipse installation.
 
-After installation the directorystructure should look as follows:
+After installation the directorystructure should look as follows (example):
 
 |--<eclipse install>
 |     |
@@ -74,7 +74,8 @@ After installation the directorystructure should look as follows:
                             |-- install.txt         // this textfile
                             |
                             |-- cpl-v10.html        // common public licence
-                            
+                            |
+                            |-- icons               // Icons directory 
 
 
  4. Editing PHP
@@ -90,7 +91,7 @@ choose PHP from the list.
 
  5. Additional Help
 ------------------------------------------
-There is a help forum at http://sourceforge.net/projects/phpeclipse.
+There is a help forum at http://www.phpeclipse.de.
 Just follow the "Forums" link.
 
 
@@ -99,7 +100,6 @@ Just follow the "Forums" link.
 ------------------------------------------
 
 - PHPEclipse SQL Plugin : Helps create SQL statements
-- PHPEclipse JTidy Plugin : Checks and cleans up HTML.
 
 Both can be found at: http://sourceforge.net/projects/phpeclipse/
 
@@ -116,8 +116,6 @@ We need:
     Bundling
     ...
 
-See http://phpeclipse.sourceforge.net/en/get_involved.php for more information
-on how to contribute.
 
 BUT MOST IMPORTANT we need your help to find and fix those little bugs that
 seem to creep into the code.
@@ -132,5 +130,5 @@ If you find a bug see if it is allready listed in the bug database
 at http://sourceforge.net/projects/phpeclipse/ -> Bugs
 If it is not listed create a new bug report. Be sure to include your system
 information (e.g. W2K Pentium 4 512 MB RAM), your Eclipse version
-(e.g. Eclipse 2.1), the version of phpeclipse you are using and a detailed
+(e.g. Eclipse 3.0), the version of phpeclipse you are using and a detailed
 description of the bug and how it can be reproduced.
index b388f2f..fdb8907 100644 (file)
@@ -8,12 +8,16 @@
  ******************************************************************************/
 package net.sourceforge.phpeclipse.actions;
 
+import java.util.List;
+
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
 import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
 
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.text.BadLocationException;
@@ -21,6 +25,8 @@ 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;
@@ -28,152 +34,167 @@ import org.eclipse.ui.IFileEditorInput;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.actions.ActionDelegate;
-import org.eclipse.ui.ide.IDE;
-
-public class PHPOpenIncludeEditorAction extends ActionDelegate
-               implements
-                       IEditorActionDelegate {
-
-       private IWorkbenchWindow fWindow;
-       private PHPEditor fEditor;
-       private IProject fProject;
-
-       public void dispose() {
-       }
-
-       public void init(IWorkbenchWindow window) {
-               this.fWindow = window;
-       }
-
-       public void selectionChanged(IAction action, ISelection selection) {
-               if (!selection.isEmpty()) {
-                       if (selection instanceof TextSelection) {
-                               action.setEnabled(true);
-                       } else if (fWindow.getActivePage() != null
-                                       && fWindow.getActivePage().getActivePart() != null) {
-                               //
-                       }
-               }
-       }
-       private IWorkbenchPage getActivePage() {
-               IWorkbenchWindow workbenchWindow = fEditor.getEditorSite()
-                               .getWorkbenchWindow();
-               IWorkbenchPage page = workbenchWindow.getActivePage();
-               return page;
-       }
-       public IContainer getWorkingLocation(IFileEditorInput editorInput) {
-               if (editorInput == null || editorInput.getFile() == null) {
-                       return null;
-               }
-               return editorInput.getFile().getParent();
-       }
-       private IFile getIncludeFile(IProject project, IFileEditorInput editorInput, String relativeFilename) {
-//             IContainer container = getWorkingLocation(editorInput);
-//             String fullPath  = project.getLocation().toString();
-               Path path = new Path(relativeFilename);
-               IFile file = project.getFile(path);
-               return file;
-       }
-
-       public void run(IAction action) {
-               if (fEditor == null) {
-                       IEditorPart targetEditor = fWindow.getActivePage()
-                                       .getActiveEditor();
-                       if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
-                               fEditor = (PHPEditor) targetEditor;
-                       }
-               }
-               if (fEditor != null) {
-                       // determine the current Project from a (file-based) Editor
-                       IFile f = ((IFileEditorInput) fEditor.getEditorInput()).getFile();
-                       fProject = f.getProject();
-                       //      System.out.println(fProject.toString());
-
-                       ITextSelection selection = (ITextSelection) fEditor
-                                       .getSelectionProvider().getSelection();
-                       IDocument doc = fEditor.getDocumentProvider().getDocument(
-                                       fEditor.getEditorInput());
-                       int pos = selection.getOffset();
-                       //  System.out.println(selection.getText());
-                       String relativeFilename = getPHPIncludeText(doc, pos);
-                       //      System.out.println(word);
-                       if (relativeFilename != null && !relativeFilename.equals("")) {
-
-                               IFile file = getIncludeFile(fProject, (IFileEditorInput) fEditor
-                                               .getEditorInput(), relativeFilename);
-                               try {
-                                       //                      createNewFileIfNeeded(file);
-                                       //                      if
-                                       // (WikiPlugin.getDefault().getPreferenceStore().getBoolean(WikiConstants.REUSE_EDITOR))
-                                       // {
-                                       //                              saveIfNeeded();
-                                       //                              getActivePage().reuseEditor(reusableEditor, new
-                                       // FileEditorInput(file));
-                                       //                      } else {
-//                                     IDE.openEditor(getActivePage(), file, true);
-                                       PHPeclipsePlugin.getDefault().openFileInTextEditor(file.getLocation().toString());
-                                       //                              redrawText();
-                                       //                      }
-                               } catch (Exception e) {
-                                       //                      WikiPlugin.getDefault().logAndReport(WikiPlugin.getResourceString(WikiConstants.RESOURCE_WIKI_ERROR_DIALOGUE_OPEN_WIKI_FILE_TITLE),
-                                       // WikiPlugin.getResourceString(WikiConstants.RESOURCE_WIKI_ERROR_DIALOGUE_OPEN_WIKI_FILE_TEXT),
-                                       // e);
-                               }
-
-                       }
-               }
-       }
-
-       public void setActiveEditor(IAction action, IEditorPart targetEditor) {
-               if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
-                       fEditor = (PHPEditor) targetEditor;
-               }
-       }
-
-       private String getPHPIncludeText(IDocument doc, int pos) {
-               Point word = null;
-               int start = -1;
-               int end = -1;
-
-               try {
-
-                       int position = pos;
-                       char character;
-
-                       while (position >= 0) {
-                               character = doc.getChar(position);
-                               if ((character=='\"')||(character == '\'')|| (character == '\r')|| (character == '\n'))
-                                       break;
-                               --position;
-                       }
-
-                       start = position;
-
-                       position = pos;
-                       int length = doc.getLength();
-
-                       while (position < length) {
-                               character = doc.getChar(position);
-                               if ((character=='\"')||(character == '\'')|| (character == '\r')|| (character == '\n'))
-                                       break;
-                               ++position;
-                       }
-
-                       start++;
-                       end = position;
-
-                       if (end > start)
-                               word = new Point(start, end - start);
-
-               } catch (BadLocationException x) {
-               }
-
-               if (word != null) {
-                       try {
-                               return doc.get(word.x, word.y);
-                       } catch (BadLocationException e) {
-                       }
-               }
-               return "";
-       }
+import org.eclipse.ui.dialogs.ListSelectionDialog;
+import org.eclipse.ui.internal.dialogs.ListContentProvider;
+
+public class PHPOpenIncludeEditorAction extends ActionDelegate implements IEditorActionDelegate {
+
+  private IWorkbenchWindow fWindow;
+  private PHPEditor fEditor;
+  private IProject fProject;
+
+  public void dispose() {
+  }
+
+  public void init(IWorkbenchWindow window) {
+    this.fWindow = window;
+  }
+
+  public void selectionChanged(IAction action, ISelection selection) {
+    if (!selection.isEmpty()) {
+      if (selection instanceof TextSelection) {
+        action.setEnabled(true);
+      } else if (fWindow.getActivePage() != null && fWindow.getActivePage().getActivePart() != null) {
+        //
+      }
+    }
+  }
+  private IWorkbenchPage getActivePage() {
+    IWorkbenchWindow workbenchWindow = fEditor.getEditorSite().getWorkbenchWindow();
+    IWorkbenchPage page = workbenchWindow.getActivePage();
+    return page;
+  }
+  public IContainer getWorkingLocation(IFileEditorInput editorInput) {
+    if (editorInput == null || editorInput.getFile() == null) {
+      return null;
+    }
+    return editorInput.getFile().getParent();
+  }
+  private IFile getIncludeFile(IProject project, IFileEditorInput editorInput, String relativeFilename) {
+    //         IContainer container = getWorkingLocation(editorInput);
+    //         String fullPath = project.getLocation().toString();
+    Path path = new Path(relativeFilename);
+    IFile file = project.getFile(path);
+    return file;
+  }
+
+  public void run(IAction action) {
+    if (fEditor == null) {
+      IEditorPart targetEditor = fWindow.getActivePage().getActiveEditor();
+      if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
+        fEditor = (PHPEditor) targetEditor;
+      }
+    }
+    if (fEditor != null) {
+      // determine the current Project from a (file-based) Editor
+      IFile f = ((IFileEditorInput) fEditor.getEditorInput()).getFile();
+      fProject = f.getProject();
+      //      System.out.println(fProject.toString());
+
+      ITextSelection selection = (ITextSelection) fEditor.getSelectionProvider().getSelection();
+      IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
+      int pos = selection.getOffset();
+      //  System.out.println(selection.getText());
+      String filename = getPHPIncludeText(doc, pos);
+      //      System.out.println(word);
+      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;
+          }
+        } catch (Exception e) {
+// ignore
+        }
+
+        try {
+
+          IdentifierIndexManager indexManager = PHPeclipsePlugin.getDefault().getIndexManager(fProject);
+          //            filename = StringUtil.replaceRegExChars(filename);
+          List list = indexManager.getFileList(filename);
+          if (list != null && list.size() > 0) {
+            String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot().getLocation().toString();
+
+            ListSelectionDialog listSelectionDialog = new ListSelectionDialog(PHPeclipsePlugin.getDefault().getWorkbench()
+                .getActiveWorkbenchWindow().getShell(), list, new ListContentProvider(), new LabelProvider(),
+                "Select the includes to open.");
+            listSelectionDialog.setTitle("Multiple includes 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 openFilename = workspaceLocation + ((String) locations[i]);
+                    PHPeclipsePlugin.getDefault().openFileInTextEditor(openFilename);
+                  }
+                } catch (CoreException e) {
+                  // TODO Auto-generated catch block
+                  e.printStackTrace();
+                }
+              }
+            }
+
+          }
+        } catch (Exception e) {
+        }
+
+      }
+    }
+  }
+
+  public void setActiveEditor(IAction action, IEditorPart targetEditor) {
+    if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
+      fEditor = (PHPEditor) targetEditor;
+    }
+  }
+
+  private String getPHPIncludeText(IDocument doc, int pos) {
+    Point word = null;
+    int start = -1;
+    int end = -1;
+
+    try {
+
+      int position = pos;
+      char character;
+
+      while (position >= 0) {
+        character = doc.getChar(position);
+        if ((character == '\"') || (character == '\'') || (character == '\r') || (character == '\n'))
+          break;
+        --position;
+      }
+
+      start = position;
+
+      position = pos;
+      int length = doc.getLength();
+
+      while (position < length) {
+        character = doc.getChar(position);
+        if ((character == '\"') || (character == '\'') || (character == '\r') || (character == '\n'))
+          break;
+        ++position;
+      }
+
+      start++;
+      end = position;
+
+      if (end > start)
+        word = new Point(start, end - start);
+
+    } catch (BadLocationException x) {
+    }
+
+    if (word != null) {
+      try {
+        return doc.get(word.x, word.y);
+      } catch (BadLocationException e) {
+      }
+    }
+    return "";
+  }
 }
\ No newline at end of file
index 81a3928..4f92951 100644 (file)
@@ -12,15 +12,18 @@ import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 import java.util.SortedMap;
 import java.util.StringTokenizer;
 import java.util.TreeMap;
+
 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
 import net.sourceforge.phpdt.internal.compiler.parser.SyntaxError;
 import net.sourceforge.phpdt.internal.compiler.util.Util;
 import net.sourceforge.phpeclipse.obfuscator.PHPIdentifier;
+
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.runtime.CoreException;
 /**
@@ -191,7 +194,7 @@ public class IdentifierIndexManager {
         e.printStackTrace();
       }
     }
-    public void parseIdentifiers(char[] charArray, StringBuffer buf) {
+    synchronized public void parseIdentifiers(char[] charArray, StringBuffer buf) {
       char[] ident;
       String identifier;
       int counter = 0;
@@ -319,18 +322,6 @@ public class IdentifierIndexManager {
     //    InputStream iStream;
     LineCreator lineCreator = createLineCreator();
     try {
-      //      iStream = fileToParse.getContents();
-      //
-      //      StringBuffer buf = new StringBuffer();
-      //      int c0;
-      //      try {
-      //        while ((c0 = iStream.read()) != (-1)) {
-      //          buf.append((char) c0);
-      //        }
-      //      } catch (IOException e) {
-      //        return;
-      //      }
       addInputStream(new BufferedInputStream(fileToParse.getContents()), fileToParse.getFullPath().toString(), lineCreator);
     } catch (CoreException e1) {
       // TODO Auto-generated catch block
@@ -343,21 +334,18 @@ public class IdentifierIndexManager {
    * @throws CoreException
    */
   public void addInputStream(InputStream stream, String filePath, LineCreator lineCreator) throws CoreException {
-//    InputStream stream;
     try {
-     // stream = new BufferedInputStream(fileToParse.getContents());
       StringBuffer lineBuffer = new StringBuffer();
       lineBuffer.append(filePath);
       int lineLength = lineBuffer.length();
-      // lineCreator.parseIdentifiers(buf.toString().toCharArray(),
-      // lineBuffer);
       lineCreator.parseIdentifiers(Util.getInputStreamAsCharArray(stream, -1,
           null), lineBuffer);
-      if (lineLength != lineBuffer.length()) {
-        addLine(lineBuffer.toString());
-      }
-    } catch (IOException e) {
-      e.printStackTrace();
+//      if (lineLength != lineBuffer.length()) {
+      // always add the file for Open Include Action  
+      addLine(lineBuffer.toString());
+//      }
+    }  catch (IOException e) {
+        e.printStackTrace();
     } finally {
       try {
         if (stream != null) {
@@ -482,9 +470,9 @@ public class IdentifierIndexManager {
         }
       }
     }
-    if (tokenExists) {
+//    if (tokenExists) {
       fFileMap.put(phpFileName, line);
-    }
+//    } 
   }
   /**
    * Change the information for a given IFile resource
@@ -663,4 +651,22 @@ public class IdentifierIndexManager {
   public SortedMap getIdentifierMap() {
     return fIndentifierMap;
   }
+
+  synchronized public List getFileList(String filePattern) {
+    Set set = fFileMap.keySet();
+    if (set.isEmpty()) {
+      return null;
+    }
+    Iterator iter = set.iterator();
+    ArrayList list = new ArrayList();
+    String fileName;
+    int index;
+    while(iter.hasNext()) {
+      fileName = (String) iter.next();
+      if ((index=fileName.indexOf(filePattern))!=-1 && fileName.length()==(index+filePattern.length())) {
+        list.add(fileName);
+      }
+    }
+    return list;
+  }
 }
\ No newline at end of file