From 27d9942766884f40f5804057dfc10c27a9447789 Mon Sep 17 00:00:00 2001 From: khartlage Date: Wed, 7 May 2003 19:14:31 +0000 Subject: [PATCH] added command line (Combobox) to PHPConsole - no functionality yet --- .../sourceforge/phpeclipse/views/PHPConsole.java | 463 +++++++++++--------- 1 files changed, 266 insertions(+), 197 deletions(-) diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java index e2e1395..8406b8e 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java @@ -33,8 +33,15 @@ import org.eclipse.jface.text.Document; import org.eclipse.jface.text.TextViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Menu; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IWorkbenchActionConstants; @@ -49,202 +56,264 @@ 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; - 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(); - } + public static final String CONSOLE_ID = "net.sourceforge.phpeclipse.views.phpconsoleview"; + private int COMMAND_COMBO_SIZE = 10; + + private TextViewer fViewer = null; + private Document fDocument = null; + private StyledText fStyledText; + private Combo fCommandCombo; + // private Action goAction; + + private Action cutAction = new Action() { + public void run() { + fViewer.getTextWidget().cut(); + } + }; + private Action copyAction = new Action() { + public void run() { + fStyledText.copy(); + } + }; + private Action pasteAction = new Action() { + public void run() { + fViewer.getTextWidget().paste(); + } + }; + private Action selectAllAction = new Action() { + public void run() { + fStyledText.selectAll(); + } + }; + private Action clearAction = new Action() { + public void run() { + fStyledText.setText(""); + } + }; + /** + * The constructor. + */ + public PHPConsole() { + } + + /** + * Insert the method's description here. + * @see ViewPart#createPartControl + */ + public void createPartControl(Composite parent) { + Composite container = new Composite(parent, SWT.NULL); + // control = container; + GridLayout layout = new GridLayout(); + layout.marginWidth = 0; + layout.marginHeight = 0; + layout.verticalSpacing = 0; + container.setLayout(layout); + Composite navContainer = new Composite(container, SWT.NONE); + layout = new GridLayout(); + layout.numColumns = 2; + layout.marginHeight = 1; + navContainer.setLayout(layout); + createCommandBar(navContainer); + navContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + fViewer = new TextViewer(container, SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL); + GridData viewerData = new GridData(GridData.FILL_BOTH); + fViewer.getControl().setLayoutData(viewerData); + fViewer.setEditable(true); + + fStyledText = fViewer.getTextWidget(); + fStyledText.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 createCommandBar(Composite parent) { + Label addressLabel = new Label(parent, SWT.NONE); + addressLabel.setText("Command:"); + + fCommandCombo = new Combo(parent, SWT.DROP_DOWN | SWT.BORDER); + fCommandCombo.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + String text = fCommandCombo.getText(); + // goAction.setEnabled(text.length() > 0); + } + }); + fCommandCombo.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + String text = fCommandCombo.getItem(fCommandCombo.getSelectionIndex()); + if (text.length() > 0) { + fCommandCombo.setText(text); + // executeCommand(text); + } + } + public void widgetDefaultSelected(SelectionEvent e) { + executeCommand(fCommandCombo.getText()); + } + }); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + fCommandCombo.setLayoutData(gd); + // ToolBar toolbar = new ToolBar(parent, SWT.FLAT | SWT.HORIZONTAL); + // toolBarManager = new ToolBarManager(toolbar); + // makeActions(); + // IToolBarManager localBar = + // getViewSite().getActionBars().getToolBarManager(); + // localBar.add(backwardAction); + // localBar.add(forwardAction); + } + + private void executeCommand(String command) { + command.trim(); + write( "Test: "+command ); + String[] items = fCommandCombo.getItems(); + int loc = -1; + String normURL = command; + for (int i = 0; i < items.length; i++) { + String normItem = items[i]; + if (normURL.equals(normItem)) { + // match + loc = i; + break; + } + } + if (loc != -1) { + fCommandCombo.remove(loc); + } + fCommandCombo.add(command, 0); + if (fCommandCombo.getItemCount() > COMMAND_COMBO_SIZE) { + fCommandCombo.remove(fCommandCombo.getItemCount() - 1); + } + fCommandCombo.getParent().layout(true); + } + + 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(fViewer.getControl()); + fViewer.getControl().setMenu(menu); + getSite().registerContextMenu(menuMgr, fViewer); + } + + 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) { + fDocument = new Document(text); + fViewer.setDocument(fDocument); + } + + public void appendOutputText(String text) { + try { + if (fDocument == null) { + fDocument = new Document(text); + fViewer.setDocument(fDocument); + } else { + fDocument.replace(fDocument.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(); + } } -- 1.7.1