From: khartlage Date: Wed, 28 May 2003 22:31:09 +0000 (+0000) Subject: added a php external tools launcher X-Git-Url: http://secure.phpeclipse.com added a php external tools launcher --- diff --git a/net.sourceforge.phpeclipse/plugin.xml b/net.sourceforge.phpeclipse/plugin.xml index c6dbf95..764b285 100644 --- a/net.sourceforge.phpeclipse/plugin.xml +++ b/net.sourceforge.phpeclipse/plugin.xml @@ -917,17 +917,17 @@ Temporarily replaced until errors can be ironed out... expanderClass="net.sourceforge.phpdt.externaltools.variable.WorkspaceExpander"> + expanderClass="net.sourceforge.phpdt.externaltools.variable.FileExpander"> + expanderClass="net.sourceforge.phpdt.externaltools.variable.UrlExpander"> diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/externaltools/internal/dialog/ExternalToolVariableForm.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/externaltools/internal/dialog/ExternalToolVariableForm.java index 957ba84..e9965a9 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/externaltools/internal/dialog/ExternalToolVariableForm.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/externaltools/internal/dialog/ExternalToolVariableForm.java @@ -32,7 +32,7 @@ import net.sourceforge.phpdt.externaltools.variable.IVariableComponent; * information. */ public class ExternalToolVariableForm { - private static final int VISIBLE_ITEM_COUNT = 6; + private static final int VISIBLE_ITEM_COUNT = 9; private String variableListLabelText; private ExternalToolVariable[] variables; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/externaltools/variable/LastPHPFileExpander.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/externaltools/variable/FileExpander.java similarity index 82% rename from net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/externaltools/variable/LastPHPFileExpander.java rename to net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/externaltools/variable/FileExpander.java index 28c1f9b..17779cb 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/externaltools/variable/LastPHPFileExpander.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/externaltools/variable/FileExpander.java @@ -8,12 +8,12 @@ import org.eclipse.core.runtime.IPath; * This class is not intended to be extended by clients. *

*/ -public class LastPHPFileExpander extends ResourceExpander { //implements IVariableTextExpander { +public class FileExpander extends ResourceExpander { //implements IVariableTextExpander { /** * Create an instance */ - public LastPHPFileExpander() { + public FileExpander() { super(); } @@ -28,7 +28,7 @@ public class LastPHPFileExpander extends ResourceExpander { //implements IVariab if (path != null) { return path.toString(); } - return null; + return ""; } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/externaltools/variable/LastPHPUrlExpander.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/externaltools/variable/UrlExpander.java similarity index 75% rename from net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/externaltools/variable/LastPHPUrlExpander.java rename to net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/externaltools/variable/UrlExpander.java index 0ee13f2..737d557 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/externaltools/variable/LastPHPUrlExpander.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/externaltools/variable/UrlExpander.java @@ -2,7 +2,6 @@ package net.sourceforge.phpdt.externaltools.variable; import net.sourceforge.phpeclipse.PHPeclipsePlugin; -import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; import org.eclipse.jface.preference.IPreferenceStore; @@ -12,12 +11,12 @@ import org.eclipse.jface.preference.IPreferenceStore; * This class is not intended to be extended by clients. *

*/ -public class LastPHPUrlExpander extends ResourceExpander { //implements IVariableTextExpander { +public class UrlExpander extends ResourceExpander { //implements IVariableTextExpander { /** * Create an instance */ - public LastPHPUrlExpander() { + public UrlExpander() { super(); } @@ -40,14 +39,13 @@ public class LastPHPUrlExpander extends ResourceExpander { //implements IVariabl if (lowerCaseFileName.startsWith(documentRoot)) { localhostURL = localhostURL.substring(documentRoot.length()); - } else { - return localhostURL; + localhostURL = store.getString(PHPeclipsePlugin.LOCALHOST_PREF)+ localhostURL; + System.out.println(localhostURL); + // localhostURL = store.getString(PHPeclipsePlugin.LOCALHOST_PREF)+ localhostURL;// + localhostURL.replaceAll(documentRoot, ""); } - - return store.getString(PHPeclipsePlugin.LOCALHOST_PREF) + localhostURL.replaceAll(documentRoot, ""); - + return localhostURL; } - return null; + return ""; } } 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 e3408c8..638ca71 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java @@ -12,18 +12,15 @@ Contributors: Klaus Hartlage - www.eclipseproject.de **********************************************************************/ -import java.io.File; +import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; -import java.io.StreamTokenizer; -import java.io.StringReader; -import java.util.ArrayList; +import java.io.InputStreamReader; import net.sourceforge.phpdt.internal.ui.PHPUiImages; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.actions.PHPActionMessages; -import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.action.Action; @@ -32,32 +29,23 @@ 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.preference.IPreferenceStore; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.BadLocationException; 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.IEditorInput; -import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; -import org.eclipse.ui.texteditor.ITextEditor; /** * The PHPConsole is used to display the output if you start MySQL/Apache @@ -71,7 +59,10 @@ public class PHPConsole extends ViewPart { private TextViewer fViewer = null; private Document fDocument = null; private StyledText fStyledText; - private Combo fCommandCombo; + // private Combo fCommandCombo; +// private ProcessOutputWriter consoleOut; +// private ProcessOutputWriter consoleErr; + // private Action goAction; private Action cutAction = new Action() { @@ -110,22 +101,22 @@ public class PHPConsole extends ViewPart { * @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); +// 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(parent, SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL); GridData viewerData = new GridData(GridData.FILL_BOTH); fViewer.getControl().setLayoutData(viewerData); fViewer.setEditable(false); @@ -150,164 +141,164 @@ public class PHPConsole extends ViewPart { // hookDoubleClickAction(); contributeToActionBars(); - appendOutputText("This is the PHP console.\n"); - appendOutputText("Type: \"php $f\" to run the current editor file.\n"); + // appendOutputText("This is the PHP console.\n"); + // appendOutputText("Type: \"php $f\" to run the current editor file.\n"); } 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()); - } - }); +// 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(); - if (command.equals("")) { - fCommandCombo.forceFocus(); - return; - } - execute(command); - - fCommandCombo.forceFocus(); - // add to Combo history - 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); + // fCommandCombo.setLayoutData(gd); } - private void execute(String command) { - ArrayList args = new ArrayList(); - - command = command.replace('\\', '§'); - - StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(command)); - tokenizer.resetSyntax(); - - tokenizer.whitespaceChars(0, ' '); - tokenizer.wordChars('!', 255); - - tokenizer.quoteChar('"'); - tokenizer.quoteChar('\''); - - int token; - try { - while ((token = tokenizer.nextToken()) != StreamTokenizer.TT_EOF) { - if (token == StreamTokenizer.TT_WORD) { - args.add(tokenizer.sval); - } - } - } catch (IOException e) { - // - } - String arg = ""; - // replace variables in arguments - - IFile file = getFile(); - if (file != null) { - String fileLocation = file.getLocation().toString(); - for (int i = 0; i < args.size(); i++) { - arg = args.get(i).toString(); - if (arg.equals("$f")) { - //current php editor file - if (File.separatorChar == '\\') { - fileLocation = fileLocation.replace('/', '\\'); - } - args.set(i, fileLocation); - } - } - } - - final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); - - String arg0 = ""; - String temp; - StringBuffer commandBuffer = new StringBuffer(1024); - // Program.launch(command); - if (args.size() > 0) { - arg0 = (String) args.get(0); - arg0 = arg0.replace('§', '\\'); - args.remove(0); - if (arg0.equals("php")) { - temp = store.getString(PHPeclipsePlugin.PHP_RUN_PREF); - if (temp != null) { - arg0 = temp; - } - } - commandBuffer.append(arg0 + " "); - } - String[] stringArgs = new String[args.size()]; - for (int i = 0; i < args.size(); i++) { - arg = (String) args.get(i); - arg = arg.replace('§', '\\'); - stringArgs[i] = arg; - commandBuffer.append(arg + " "); - } - commandBuffer.append("\n"); - - try { - command = commandBuffer.toString(); - write(command); - Runtime runtime = Runtime.getRuntime(); - - // runs the command - Process process = runtime.exec(command); - - //process.waitFor(); - InputStream in = process.getInputStream(); - String output = getStringFromStream(in); - write(output); - in.close(); -// } catch (InterruptedException e) { -// write(e.toString()); - } catch (IOException e) { - write(e.toString()); - } - } + // private void executeCommand(String command) { + // command.trim(); + // if (command.equals("")) { + // fCommandCombo.forceFocus(); + // return; + // } + // execute(command); + // + // fCommandCombo.forceFocus(); + // // add to Combo history + // 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 execute(String command) { + // + // ArrayList args = new ArrayList(); + // + // command = command.replace('\\', '§'); + // + // StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(command)); + // tokenizer.resetSyntax(); + // + // tokenizer.whitespaceChars(0, ' '); + // tokenizer.wordChars('!', 255); + // + // tokenizer.quoteChar('"'); + // tokenizer.quoteChar('\''); + // + // int token; + // try { + // while ((token = tokenizer.nextToken()) != StreamTokenizer.TT_EOF) { + // if (token == StreamTokenizer.TT_WORD) { + // args.add(tokenizer.sval); + // } + // } + // } catch (IOException e) { + // // + // } + // String arg = ""; + // // replace variables in arguments + // + //// IFile file = getFile(); + // IFile file = PHPeclipsePlugin.getDefault().getLastEditorFile(); + // if (file != null) { + // String fileLocation = file.getLocation().toString(); + // for (int i = 0; i < args.size(); i++) { + // arg = args.get(i).toString(); + // if (arg.equals("$f")) { + // //current php editor file + // if (File.separatorChar == '\\') { + // fileLocation = fileLocation.replace('/', '\\'); + // } + // args.set(i, fileLocation); + // } + // } + // } + // + // final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); + // + // String arg0 = ""; + // String temp; + // StringBuffer commandBuffer = new StringBuffer(1024); + // // Program.launch(command); + // if (args.size() > 0) { + // arg0 = (String) args.get(0); + // arg0 = arg0.replace('§', '\\'); + // args.remove(0); + // if (arg0.equals("php")) { + // temp = store.getString(PHPeclipsePlugin.PHP_RUN_PREF); + // if (temp != null) { + // arg0 = temp; + // } + // } + // commandBuffer.append(arg0 + " "); + // } + // String[] stringArgs = new String[args.size()]; + // for (int i = 0; i < args.size(); i++) { + // arg = (String) args.get(i); + // arg = arg.replace('§', '\\'); + // stringArgs[i] = arg; + // commandBuffer.append(arg + " "); + // } + // commandBuffer.append("\n"); + // + // try { + // command = commandBuffer.toString(); + // write(command+"\n"); + // Runtime runtime = Runtime.getRuntime(); + // + // // runs the command + // Process process = runtime.exec(command); + // + // consoleOut = new ProcessOutputWriter(process.getInputStream()); + // consoleOut.start(); + // consoleErr = new ProcessOutputWriter(process.getErrorStream()); + // consoleErr.start(); + // + // //process.waitFor(); + //// InputStream in = process.getInputStream(); + //// String output = getStringFromStream(in); + //// write(output); + //// in.close(); + //// } catch (InterruptedException e) { + //// write(e.toString()); + // } catch (IOException e) { + // write(e.toString()); + // } + // } private void hookContextMenu() { MenuManager menuMgr = new MenuManager("#PopupMenu"); @@ -352,7 +343,7 @@ public class PHPConsole extends ViewPart { * @see ViewPart#setFocus */ public void setFocus() { - fCommandCombo.forceFocus(); + // fCommandCombo.forceFocus(); } /** @@ -426,18 +417,55 @@ public class PHPConsole extends ViewPart { /** * Finds the file that's currently opened in the PHP Text Editor */ - protected IFile getFile() { - ITextEditor editor = PHPeclipsePlugin.getDefault().getTextEditor(); + // protected IFile getFile() { + // ITextEditor editor = PHPeclipsePlugin.getDefault().getLastEditorFile(); + // + // IEditorInput editorInput = null; + // if (editor != null) { + // editorInput = editor.getEditorInput(); + // } + // + // if (editorInput instanceof IFileEditorInput) + // return ((IFileEditorInput) editorInput).getFile(); + // + // // if nothing was found, which should never happen + // return null; + // } + + class ProcessOutputWriter extends Thread { + boolean fStreamClosed; + InputStream fInputStream; + + ProcessOutputWriter(InputStream inputStream) { + fInputStream = inputStream; + fStreamClosed = false; + } - IEditorInput editorInput = null; - if (editor != null) { - editorInput = editor.getEditorInput(); + public void closeStream() { + fStreamClosed = true; + try { + fInputStream.close(); + } catch (IOException io) { + } } - if (editorInput instanceof IFileEditorInput) - return ((IFileEditorInput) editorInput).getFile(); + public void run() { + try { + BufferedReader in = new BufferedReader(new InputStreamReader(fInputStream)); - // if nothing was found, which should never happen - return null; + String line; + while ((line = in.readLine()) != null) { + write(line); + } + in.close(); + } catch (Exception e) { + e.printStackTrace(System.out); + if (!fStreamClosed) { + // write("\nPHP Console Exception: "+ e.toString() ); + } + } finally { + } + } } + }