add some actions to phpconsole
authorkhartlage <khartlage>
Sun, 4 May 2003 19:37:33 +0000 (19:37 +0000)
committerkhartlage <khartlage>
Sun, 4 May 2003 19:37:33 +0000 (19:37 +0000)
net.sourceforge.phpeclipse/icons/obj16/clear.gif [new file with mode: 0644]
net.sourceforge.phpeclipse/plugin.xml
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/PHPUiImages.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/resourcesview/PHPProject.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java

diff --git a/net.sourceforge.phpeclipse/icons/obj16/clear.gif b/net.sourceforge.phpeclipse/icons/obj16/clear.gif
new file mode 100644 (file)
index 0000000..5cdb88f
Binary files /dev/null and b/net.sourceforge.phpeclipse/icons/obj16/clear.gif differ
index 94fce9a..884496a 100644 (file)
@@ -147,13 +147,13 @@ Temporarily replaced until errors can be ironed out...
             objectClass="org.eclipse.core.resources.IProject"
             name="%propertyPagePHPProject.name"
             class="net.sourceforge.phpeclipse.preferences.PHPProjectPropertyPage"
-            id="net.sourceforge.phpeclipse.preferences.PropertyPagePHPProject">
+            id="net.sourceforge.phpeclipse.preferences.PHPProjectPropertyPage">
          <filter
                name="nature"
                value="net.sourceforge.phpeclipse.phpnature">
          </filter>
       </page>
-      <page
+  <!--    <page
             objectClass="net.sourceforge.phpeclipse.resourcesview.PHPProject"
             name="%propertyPagePHPProject.name"
             class="net.sourceforge.phpeclipse.preferences.PHPProjectPropertyPage"
@@ -162,7 +162,7 @@ Temporarily replaced until errors can be ironed out...
                name="nature"
                value="net.sourceforge.phpeclipse.phpnature">
          </filter>
-      </page>
+      </page> -->
    </extension>
 <!--   <extension
          point="org.eclipse.ui.views">
index 11fbe8e..b858d0b 100644 (file)
@@ -12,15 +12,22 @@ import org.eclipse.swt.graphics.Image;
 
 public class PHPUiImages {
 
-       protected static final String NAME_PREFIX = "net.sourceforge.phpdt.internal.ui.";
+       protected static final String NAME_PREFIX =
+               "net.sourceforge.phpdt.internal.ui.";
        protected static final int NAME_PREFIX_LENGTH = NAME_PREFIX.length();
-  
+
        protected static URL iconBaseURL;
 
        static {
                String pathSuffix = "icons/";
                try {
-                       iconBaseURL = new URL(PHPeclipsePlugin.getDefault().getDescriptor().getInstallURL(), pathSuffix);
+                       iconBaseURL =
+                               new URL(
+                                       PHPeclipsePlugin
+                                               .getDefault()
+                                               .getDescriptor()
+                                               .getInstallURL(),
+                                       pathSuffix);
                } catch (MalformedURLException e) {
                        PHPeclipsePlugin.log(e);
                }
@@ -32,31 +39,50 @@ public class PHPUiImages {
        protected static final String OVR_PREFIX = "ovr16";
        protected static final String CTOOL_PREFIX = "ctool16";
 
-  public static final String IMG_CLASS = NAME_PREFIX + "class_obj.gif";
-  public static final String IMG_BUILTIN = NAME_PREFIX + "builtin_obj.gif";
-  public static final String IMG_FUN = NAME_PREFIX + "fun_obj.gif";
-  public static final String IMG_INC = NAME_PREFIX + "impc_obj.gif";
-  public static final String IMG_VAR = NAME_PREFIX + "var_obj.gif";
+       public static final String IMG_CLASS = NAME_PREFIX + "class_obj.gif";
+       public static final String IMG_BUILTIN = NAME_PREFIX + "builtin_obj.gif";
+       public static final String IMG_FUN = NAME_PREFIX + "fun_obj.gif";
+       public static final String IMG_INC = NAME_PREFIX + "impc_obj.gif";
+       public static final String IMG_VAR = NAME_PREFIX + "var_obj.gif";
        public static final String IMG_OBJS_ERROR = NAME_PREFIX + "error_obj.gif";
-       public static final String IMG_OBJS_WARNING = NAME_PREFIX + "warning_obj.gif";
+       public static final String IMG_OBJS_WARNING =
+               NAME_PREFIX + "warning_obj.gif";
        public static final String IMG_OBJS_INFO = NAME_PREFIX + "info_obj.gif";
-       public static final String IMG_CTOOLS_PHP_PAGE = NAME_PREFIX + "php_page.gif";
+       public static final String IMG_CTOOLS_PHP_PAGE =
+               NAME_PREFIX + "php_page.gif";
        public static final String IMG_CTOOLS_PHP = NAME_PREFIX + "php.gif";
-  
-  public static final String IMG_OBJS_TEMPLATE= NAME_PREFIX + "template_obj.gif";   
-
-  public static final ImageDescriptor DESC_CLASS = createManaged(OBJ_PREFIX, IMG_CLASS);
-  public static final ImageDescriptor DESC_BUILTIN = createManaged(OBJ_PREFIX, IMG_BUILTIN);
-  public static final ImageDescriptor DESC_FUN = createManaged(OBJ_PREFIX, IMG_FUN);
-  public static final ImageDescriptor DESC_INC = createManaged(OBJ_PREFIX, IMG_INC);
-       public static final ImageDescriptor DESC_VAR = createManaged(OBJ_PREFIX, IMG_VAR);
-  public static final ImageDescriptor DESC_OBJS_ERROR = createManaged(OBJ_PREFIX, IMG_OBJS_ERROR);
-       public static final ImageDescriptor DESC_OBJS_WARNING = createManaged(OBJ_PREFIX, IMG_OBJS_WARNING);
-       public static final ImageDescriptor DESC_OBJS_INFO = createManaged(OBJ_PREFIX, IMG_OBJS_INFO);
-       public static final ImageDescriptor DESC_CTOOL_PHP_PAGE = createManaged(CTOOL_PREFIX, IMG_CTOOLS_PHP_PAGE);
-       public static final ImageDescriptor DESC_CTOOL_PHP = createManaged(CTOOL_PREFIX, IMG_CTOOLS_PHP);
-
-  public static final ImageDescriptor DESC_OBJS_TEMPLATE= createManaged(OBJ_PREFIX, IMG_OBJS_TEMPLATE);
+
+       public static final String IMG_OBJS_TEMPLATE =
+               NAME_PREFIX + "template_obj.gif";
+
+       public static final String IMG_CLEAR = NAME_PREFIX + "clear.gif"; 
+       
+       public static final ImageDescriptor DESC_CLASS =
+               createManaged(OBJ_PREFIX, IMG_CLASS);
+       public static final ImageDescriptor DESC_BUILTIN =
+               createManaged(OBJ_PREFIX, IMG_BUILTIN);
+       public static final ImageDescriptor DESC_FUN =
+               createManaged(OBJ_PREFIX, IMG_FUN);
+       public static final ImageDescriptor DESC_INC =
+               createManaged(OBJ_PREFIX, IMG_INC);
+       public static final ImageDescriptor DESC_VAR =
+               createManaged(OBJ_PREFIX, IMG_VAR);
+       public static final ImageDescriptor DESC_OBJS_ERROR =
+               createManaged(OBJ_PREFIX, IMG_OBJS_ERROR);
+       public static final ImageDescriptor DESC_OBJS_WARNING =
+               createManaged(OBJ_PREFIX, IMG_OBJS_WARNING);
+       public static final ImageDescriptor DESC_OBJS_INFO =
+               createManaged(OBJ_PREFIX, IMG_OBJS_INFO);
+       public static final ImageDescriptor DESC_CTOOL_PHP_PAGE =
+               createManaged(CTOOL_PREFIX, IMG_CTOOLS_PHP_PAGE);
+       public static final ImageDescriptor DESC_CTOOL_PHP =
+               createManaged(CTOOL_PREFIX, IMG_CTOOLS_PHP);
+
+       public static final ImageDescriptor DESC_OBJS_TEMPLATE =
+               createManaged(OBJ_PREFIX, IMG_OBJS_TEMPLATE);
+               
+       public static final ImageDescriptor DESC_CLEAR =
+                       createManaged(OBJ_PREFIX, IMG_CLEAR);
 
        /**
         * Returns the image managed under the given key in this registry.
@@ -72,7 +98,9 @@ public class PHPUiImages {
         * Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions
         * are retrieved from the *tool16 folders.
         */
-       public static void setToolImageDescriptors(IAction action, String iconName) {
+       public static void setToolImageDescriptors(
+               IAction action,
+               String iconName) {
                setImageDescriptors(action, "tool16", iconName);
        }
 
@@ -80,7 +108,9 @@ public class PHPUiImages {
         * Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions
         * are retrieved from the *lcl16 folders.
         */
-       public static void setLocalImageDescriptors(IAction action, String iconName) {
+       public static void setLocalImageDescriptors(
+               IAction action,
+               String iconName) {
                setImageDescriptors(action, "lcl16", iconName);
        }
 
@@ -90,26 +120,41 @@ public class PHPUiImages {
 
        //---- Helper methods to access icons on the file system --------------------------------------
 
-       protected static void setImageDescriptors(IAction action, String type, String relPath) {
+       protected static void setImageDescriptors(
+               IAction action,
+               String type,
+               String relPath) {
 
                try {
-                       ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL("d" + type, relPath));
+                       ImageDescriptor id =
+                               ImageDescriptor.createFromURL(
+                                       makeIconFileURL("d" + type, relPath));
                        if (id != null)
                                action.setDisabledImageDescriptor(id);
-               } catch (MalformedURLException e) {}
+               } catch (MalformedURLException e) {
+               }
 
                try {
-                       ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL("c" + type, relPath));
+                       ImageDescriptor id =
+                               ImageDescriptor.createFromURL(
+                                       makeIconFileURL("c" + type, relPath));
                        if (id != null)
                                action.setHoverImageDescriptor(id);
-               } catch (MalformedURLException e) {}
+               } catch (MalformedURLException e) {
+               }
 
                action.setImageDescriptor(create("e" + type, relPath));
        }
 
-       protected static ImageDescriptor createManaged(String prefix, String name) {
+       protected static ImageDescriptor createManaged(
+               String prefix,
+               String name) {
                try {
-                       ImageDescriptor result = ImageDescriptor.createFromURL(makeIconFileURL(prefix, name.substring(NAME_PREFIX_LENGTH)));
+                       ImageDescriptor result =
+                               ImageDescriptor.createFromURL(
+                                       makeIconFileURL(
+                                               prefix,
+                                               name.substring(NAME_PREFIX_LENGTH)));
                        IMAGE_REGISTRY.put(name, result);
                        return result;
                } catch (MalformedURLException e) {
@@ -125,7 +170,8 @@ public class PHPUiImages {
                }
        }
 
-       protected static URL makeIconFileURL(String prefix, String name) throws MalformedURLException {
+       protected static URL makeIconFileURL(String prefix, String name)
+               throws MalformedURLException {
                if (iconBaseURL == null)
                        throw new MalformedURLException();
 
index 7cff514..e903be5 100644 (file)
@@ -26,7 +26,7 @@ import org.xml.sax.SAXException;
 import org.xml.sax.XMLReader;
 
 public class PHPProject implements IProjectNature, PHPElement {
-       protected IProject project;
+       protected IProject fProject;
        protected List loadPathEntries;
        protected boolean scratched;
 
@@ -37,7 +37,7 @@ public class PHPProject implements IProjectNature, PHPElement {
        public void deconfigure() throws CoreException {}
 
        public IProject getProject() {
-               return project;
+               return fProject;
        }
 
        protected IProject getProject(String name) {
@@ -45,7 +45,7 @@ public class PHPProject implements IProjectNature, PHPElement {
        }
 
        public void setProject(IProject aProject) {
-               project = aProject;
+               fProject = aProject;
        }
 
        public void addLoadPathEntry(IProject anotherPHPProject) {
@@ -137,7 +137,7 @@ public class PHPProject implements IProjectNature, PHPElement {
        }
 
        protected IFile getLoadPathEntriesFile() {
-               return project.getFile(".loadpath");
+               return fProject.getFile(".loadpath");
        }
 
        public void save() throws CoreException {
@@ -167,8 +167,9 @@ public class PHPProject implements IProjectNature, PHPElement {
                buffer.append("</loadpath>");
                return buffer.toString();
        }
+       
        public IResource getUnderlyingResource() {
-               return project;
+               return fProject;
        }
 
 }
index f1c6e9a..e2e1395 100644 (file)
@@ -15,12 +15,18 @@ Contributors:
 import java.io.IOException;
 import java.io.InputStream;
 
+import net.sourceforge.phpdt.internal.ui.PHPUiImages;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 import net.sourceforge.phpeclipse.actions.PHPActionMessages;
 
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
 import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.Document;
@@ -29,6 +35,7 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.StyledText;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Menu;
 import org.eclipse.ui.IActionBars;
 import org.eclipse.ui.IWorkbenchActionConstants;
 import org.eclipse.ui.IWorkbenchPage;
@@ -42,126 +49,202 @@ import org.eclipse.ui.part.ViewPart;
  */
 public class PHPConsole extends ViewPart {
 
-  public static final String CONSOLE_ID = "net.sourceforge.phpeclipse.views.phpconsoleview";
-
-  private TextViewer viewer = null;
-  private Document document = null;
-
-  /**
-   * The constructor.
-   */
-  public PHPConsole() {
-  }
-
-  /**
-   * Insert the method's description here.
-   * @see ViewPart#createPartControl
-   */
-  public void createPartControl(Composite parent) {
-    viewer = new TextViewer(parent, SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL);
-    GridData viewerData = new GridData(GridData.FILL_BOTH);
-    viewer.getControl().setLayoutData(viewerData);
-    viewer.setEditable(false);
-
-    StyledText widget = viewer.getTextWidget();
-    widget.setFont(JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT));
-    Action cutAction = new Action() {
-      public void run() {
-        viewer.getTextWidget().cut();
-      }
-    };
-    Action copyAction = new Action() {
-      public void run() {
-        viewer.getTextWidget().copy();
-      }
-    };
-    Action pasteAction = new Action() {
-      public void run() {
-        viewer.getTextWidget().paste();
-      }
-    };
-
-    IActionBars bars = this.getViewSite().getActionBars();
-    bars.setGlobalActionHandler(IWorkbenchActionConstants.CUT, cutAction);
-    bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction);
-    bars.setGlobalActionHandler(IWorkbenchActionConstants.PASTE, pasteAction);
-  }
-
-  /**
-   * Insert the method's description here.
-   * @see ViewPart#setFocus
-   */
-  public void setFocus() {
-  }
-
-  /**
-   * Set the text for the viewer
-   */
-  public void setOutputText(String text) {
-    document = new Document(text);
-    viewer.setDocument(document);
-  }
-
-  public void appendOutputText(String text) {
-    try {
-      if (document == null) {
-        document = new Document(text);
-        viewer.setDocument(document);
-      } else {
-        document.replace(document.getLength(), 0, text);
-      }
-    } catch (BadLocationException e) {
-    }
-    //  viewer.setDocument(document);
-  }
-
-  public static PHPConsole getInstance() {
-    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
-    PHPConsole console = (PHPConsole) page.findView(PHPConsole.CONSOLE_ID);
-
-    if (PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) == true) {
-
-      try {
-        page.showView(PHPConsole.CONSOLE_ID);
-        if (console == null) {
-          console = (PHPConsole) page.findView(PHPConsole.CONSOLE_ID);
-        }
-      } catch (PartInitException e) {
-        PHPeclipsePlugin.getDefault().getLog().log(
-          new Status(
-            IStatus.ERROR,
-            PHPeclipsePlugin.getPluginId(),
-            0,
-            PHPActionMessages.getString("PHPStartApacheAction.consoleViewOpeningProblem"),
-            e));
-      }
-
-    }
-    return console;
-  }
-
-  /**
-   * Prints out the string represented by the string buffer
-   */
-  public synchronized void write(String output) {
-    appendOutputText(output);
-  }
-
-  /**
-   * Creates a string buffer from the given input stream
-   */
-  public static String getStringFromStream(InputStream stream) throws IOException {
-    StringBuffer buffer = new StringBuffer();
-    byte[] b = new byte[100];
-    int finished = 0;
-    while (finished != -1) {
-      finished = stream.read(b);
-      if (finished != -1) {
-        String current = new String(b, 0, finished);
-        buffer.append(current);
-      }
-    }
-    return buffer.toString();
-  }
+       public static final String CONSOLE_ID =
+               "net.sourceforge.phpeclipse.views.phpconsoleview";
+
+       private TextViewer viewer = null;
+       private Document document = null;
+       private StyledText widget;
+       private Action cutAction = new Action() {
+               public void run() {
+                       viewer.getTextWidget().cut();
+               }
+       };
+       private Action copyAction = new Action() {
+               public void run() {
+                       widget.copy();
+               }
+       };
+       private Action pasteAction = new Action() {
+               public void run() {
+                       viewer.getTextWidget().paste();
+               }
+       };
+       private Action selectAllAction = new Action() {
+               public void run() {
+                       widget.selectAll();
+               }
+       };
+       private Action clearAction = new Action() {
+               public void run() {
+                       widget.setText("");
+               }
+       };
+       /**
+        * The constructor.
+        */
+       public PHPConsole() {
+       }
+
+       /**
+        * Insert the method's description here.
+        * @see ViewPart#createPartControl
+        */
+       public void createPartControl(Composite parent) {
+               viewer = new TextViewer(parent, SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL);
+               GridData viewerData = new GridData(GridData.FILL_BOTH);
+               viewer.getControl().setLayoutData(viewerData);
+               viewer.setEditable(true);
+
+               widget = viewer.getTextWidget();
+               widget.setFont(
+                       JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT));
+
+               cutAction.setText("Cut");
+               copyAction.setText("Copy");
+               pasteAction.setText("Paste");
+               selectAllAction.setText("Select All");
+               clearAction.setText("Clear PHP Console");
+               clearAction.setImageDescriptor(PHPUiImages.DESC_CLEAR);
+        clearAction.setToolTipText("Clear PHP Console");
+                               
+               IActionBars bars = this.getViewSite().getActionBars();
+               bars.setGlobalActionHandler(IWorkbenchActionConstants.CUT, cutAction);
+               bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction);
+               bars.setGlobalActionHandler(
+                       IWorkbenchActionConstants.PASTE,
+                       pasteAction);
+
+               hookContextMenu();
+               //      hookDoubleClickAction();
+               contributeToActionBars();
+               
+               
+       }
+
+       private void hookContextMenu() {
+               MenuManager menuMgr = new MenuManager("#PopupMenu");
+               menuMgr.setRemoveAllWhenShown(true);
+               menuMgr.addMenuListener(new IMenuListener() {
+                       public void menuAboutToShow(IMenuManager manager) {
+                               PHPConsole.this.fillContextMenu(manager);
+                       }
+               });
+               Menu menu = menuMgr.createContextMenu(viewer.getControl());
+               viewer.getControl().setMenu(menu);
+               getSite().registerContextMenu(menuMgr, viewer);
+       }
+
+       private void contributeToActionBars() {
+               IActionBars bars = getViewSite().getActionBars();
+               fillLocalPullDown(bars.getMenuManager());
+               fillLocalToolBar(bars.getToolBarManager());
+       }
+
+       private void fillLocalPullDown(IMenuManager manager) {
+               manager.add(cutAction);
+               manager.add(copyAction);
+               manager.add(pasteAction);
+               manager.add(selectAllAction);
+       }
+       
+       private void fillContextMenu(IMenuManager manager) {
+               manager.add(cutAction);
+               manager.add(copyAction);
+               manager.add(pasteAction);
+               manager.add(selectAllAction);
+               // Other plug-ins can contribute there actions here
+               manager.add(new Separator("Additions"));
+       }
+       
+       private void fillLocalToolBar(IToolBarManager manager) {
+               manager.add(clearAction);
+       }
+       /**
+        * Insert the method's description here.
+        * @see ViewPart#setFocus
+        */
+       public void setFocus() {
+       }
+
+       /**
+        * Set the text for the viewer
+        */
+       public void setOutputText(String text) {
+               document = new Document(text);
+               viewer.setDocument(document);
+       }
+
+       public void appendOutputText(String text) {
+               try {
+                       if (document == null) {
+                               document = new Document(text);
+                               viewer.setDocument(document);
+                       } else {
+                               document.replace(document.getLength(), 0, text);
+                       }
+               } catch (BadLocationException e) {
+               }
+               //  viewer.setDocument(document);
+       }
+
+       public static PHPConsole getInstance() {
+               IWorkbenchPage page =
+                       PlatformUI
+                               .getWorkbench()
+                               .getActiveWorkbenchWindow()
+                               .getActivePage();
+               PHPConsole console = (PHPConsole) page.findView(PHPConsole.CONSOLE_ID);
+
+               if (PHPeclipsePlugin
+                       .getDefault()
+                       .getPreferenceStore()
+                       .getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE)
+                       == true) {
+
+                       try {
+                               page.showView(PHPConsole.CONSOLE_ID);
+                               if (console == null) {
+                                       console = (PHPConsole) page.findView(PHPConsole.CONSOLE_ID);
+                               }
+                       } catch (PartInitException e) {
+                               PHPeclipsePlugin.getDefault().getLog().log(
+                                       new Status(
+                                               IStatus.ERROR,
+                                               PHPeclipsePlugin.getPluginId(),
+                                               0,
+                                               PHPActionMessages.getString(
+                                                       "PHPStartApacheAction.consoleViewOpeningProblem"),
+                                               e));
+                       }
+
+               }
+               return console;
+       }
+
+       /**
+        * Prints out the string represented by the string buffer
+        */
+       public synchronized void write(String output) {
+               appendOutputText(output);
+       }
+
+       /**
+        * Creates a string buffer from the given input stream
+        */
+       public static String getStringFromStream(InputStream stream)
+               throws IOException {
+               StringBuffer buffer = new StringBuffer();
+               byte[] b = new byte[100];
+               int finished = 0;
+               while (finished != -1) {
+                       finished = stream.read(b);
+                       if (finished != -1) {
+                               String current = new String(b, 0, finished);
+                               buffer.append(current);
+                       }
+               }
+               return buffer.toString();
+       }
 
 }