From: khartlage Date: Sun, 11 May 2003 21:50:09 +0000 (+0000) Subject: added a first php $f command to the PHP console X-Git-Url: http://secure.phpeclipse.com?hp=ec195d2a7ad882a7ba76f185c173ac22dcf01702 added a first php $f command to the PHP console --- diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java index 25c7648..cc44585 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/IPreferenceConstants.java @@ -24,7 +24,8 @@ public interface IPreferenceConstants { public static final String APACHE_START_PREF = "_apache_start"; public static final String APACHE_STOP_PREF = "_apache_stop"; public static final String APACHE_RESTART_PREF = "_apache_restart"; - public static final String SHOW_OUTPUT_IN_CONSOLE = "_sho_output_in_console"; + public static final String SHOW_OUTPUT_IN_CONSOLE = "_show_output_in_console"; + public static final String PHP_RUN_PREF = "_php_run_pref"; public static final String EXTERNAL_PARSER_PREF = "_external_parser"; public static final String PHP_PARSER_DEFAULT = "_php_parser_default"; public static final String PHP_INTERNAL_PARSER = "_php_internal_parser"; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPEclipseBasePreferencePage.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPEclipseBasePreferencePage.java index 7042c26..000a10e 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPEclipseBasePreferencePage.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPEclipseBasePreferencePage.java @@ -42,6 +42,7 @@ public class PHPEclipseBasePreferencePage extends PreferencePage implements IWor StringFieldEditor apacheStopSFE; StringFieldEditor apacheRestartSFE; StringFieldEditor mySQLCommandSFE; + StringFieldEditor phpRunSFE; RadioGroupFieldEditor chooseParser; StringFieldEditor externalParserSFE; BooleanFieldEditor parseOnSave; @@ -63,6 +64,7 @@ public class PHPEclipseBasePreferencePage extends PreferencePage implements IWor apacheStopSFE.loadDefault(); apacheRestartSFE.loadDefault(); mySQLCommandSFE.loadDefault(); + phpRunSFE.loadDefault(); chooseParser.loadDefault(); externalParserSFE.loadDefault(); parseOnSave.loadDefault(); @@ -79,6 +81,7 @@ public class PHPEclipseBasePreferencePage extends PreferencePage implements IWor apacheStopSFE.store(); apacheRestartSFE.store(); mySQLCommandSFE.store(); + phpRunSFE.store(); chooseParser.store(); externalParserSFE.store(); parseOnSave.store(); @@ -176,6 +179,15 @@ public class PHPEclipseBasePreferencePage extends PreferencePage implements IWor apacheRestartSFE.setPreferencePage(this); apacheRestartSFE.setPreferenceStore(getPreferenceStore()); apacheRestartSFE.load(); + + phpRunSFE = + new StringFieldEditor( + IPreferenceConstants.PHP_RUN_PREF, + PHPPreferencesMessages.getString("PHPBasePreferencePage.console.php"), + apacheSettingsGroup); + phpRunSFE.setPreferencePage(this); + phpRunSFE.setPreferenceStore(getPreferenceStore()); + phpRunSFE.load(); //Create mySQL Composite mySQLSettingsComposite = new Composite(composite, SWT.NULL); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java index 1cbed97..b9f2df5 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java @@ -40,6 +40,7 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.ui.texteditor.ITextEditor; /** * The main plugin class to be used in the desktop. @@ -80,6 +81,7 @@ public class PHPeclipsePlugin private ImageDescriptorRegistry fImageDescriptorRegistry; private PHPDocumentProvider fCompilationUnitDocumentProvider; + private ITextEditor fTextEditor = null; private JavaTextTools fJavaTextTools; @@ -301,8 +303,10 @@ public class PHPeclipsePlugin store.setDefault( DOCUMENTROOT_PREF, getWorkspace().getRoot().getLocation().toString()); + // if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) { if (windowsSystem.equals(BootLoader.WS_WIN32)) { + store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe"); store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}"); store.setDefault( MYSQL_PREF, @@ -315,6 +319,7 @@ public class PHPeclipsePlugin APACHE_RESTART_PREF, "c:\\apache\\apache.exe -k restart"); } else { + store.setDefault(PHP_RUN_PREF, "/apache/php/php"); store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}"); store.setDefault(MYSQL_PREF, "/apache/mysql/bin/mysqld --standalone"); store.setDefault( @@ -430,4 +435,12 @@ public class PHPeclipsePlugin manager.registerAdapters(new PHPElementAdapterFactory(), PHPElement.class); manager.registerAdapters(new ResourceAdapterFactory(), IResource.class); } + + public void setTextEditor(ITextEditor textEditor) { + this.fTextEditor = textEditor; + } + + public ITextEditor getTextEditor() { + return fTextEditor; + } } \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java index c03103d..18b7858 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java @@ -150,7 +150,7 @@ public class PHPEclipseShowAction implements IObjectActionDelegate { store = PHPeclipsePlugin.getDefault().getPreferenceStore(); } - IPath path = file.getFullPath(); + // IPath path = file.getFullPath(); String localhostURL = file.getLocation().toString(); String lowerCaseFileName = localhostURL.toLowerCase(); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartApacheAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartApacheAction.java index 4082d14..69b0b2d 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartApacheAction.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartApacheAction.java @@ -100,6 +100,7 @@ public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate { if (console!=null) { console.write(consoleMessage + command + "\n"); } + Runtime runtime = Runtime.getRuntime(); // runs the command diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/newPHPPreferencesMessages_DE.properties b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/newPHPPreferencesMessages_DE.properties index c7765b1..c24da8c 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/newPHPPreferencesMessages_DE.properties +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/newPHPPreferencesMessages_DE.properties @@ -29,6 +29,7 @@ PHPBasePreferencePage.apacheGroup=Apache Einstellungen PHPBasePreferencePage.apacheGroup.start=Start Apache PHPBasePreferencePage.apacheGroup.stop=Stop Apache PHPBasePreferencePage.apacheGroup.restart=Restart Apache +PHPBasePreferencePage.console.php=PHP Datei ausführen PHPBasePreferencePage.mySQLGroup=MySQL Einstellungen PHPBasePreferencePage.mySQLGroup.command=MySQL Kommando PHPBasePreferencePage.parsers=Parser Einstellungen diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/newPHPPreferencesMessages_FR.properties b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/newPHPPreferencesMessages_FR.properties index 1ab93fc..84ddaa1 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/newPHPPreferencesMessages_FR.properties +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/newPHPPreferencesMessages_FR.properties @@ -29,6 +29,7 @@ PHPBasePreferencePage.apacheGroup=Configuration Apache PHPBasePreferencePage.apacheGroup.start=Lancer Apache PHPBasePreferencePage.apacheGroup.stop=Stopper Apache PHPBasePreferencePage.apacheGroup.restart=Relancer Apache +PHPBasePreferencePage.console.php=Run PHP command PHPBasePreferencePage.mySQLGroup=Configuration MySQL PHPBasePreferencePage.mySQLGroup.command=Commande MySQL PHPBasePreferencePage.parsers=Configuration de parsing diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/newPHPPreferencesMessages_en_GB.properties b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/newPHPPreferencesMessages_en_GB.properties index bca7333..8372e22 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/newPHPPreferencesMessages_en_GB.properties +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/newPHPPreferencesMessages_en_GB.properties @@ -29,6 +29,7 @@ PHPBasePreferencePage.apacheGroup=Apache Settings PHPBasePreferencePage.apacheGroup.start=Start Apache PHPBasePreferencePage.apacheGroup.stop=Stop Apache PHPBasePreferencePage.apacheGroup.restart=Restart Apache +PHPBasePreferencePage.console.php=Run PHP command PHPBasePreferencePage.mySQLGroup=MySQL Settings PHPBasePreferencePage.mySQLGroup.command=MySQL command PHPBasePreferencePage.parsers=Parsing settings diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/newPHPPreferencesMessages_es_ES.properties b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/newPHPPreferencesMessages_es_ES.properties index a6804ca..63beb7a 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/newPHPPreferencesMessages_es_ES.properties +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/newPHPPreferencesMessages_es_ES.properties @@ -29,6 +29,7 @@ PHPBasePreferencePage.apacheGroup=Configuraci PHPBasePreferencePage.apacheGroup.start=Arrancar Apache PHPBasePreferencePage.apacheGroup.stop=Parar Apache PHPBasePreferencePage.apacheGroup.restart=Reiniciar Apache +PHPBasePreferencePage.console.php=Run PHP command PHPBasePreferencePage.mySQLGroup=Configuración MySQL PHPBasePreferencePage.mySQLGroup.command=comando MySQL PHPBasePreferencePage.parsers=Configuración Parser diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionContributor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionContributor.java index 9cbd2c9..5fa5d64 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionContributor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionContributor.java @@ -50,8 +50,8 @@ public class PHPActionContributor extends BasicTextEditorActionContributor { private RetargetTextEditorAction fGotoMatchingBracket; private List fRetargetToolbarActions = new ArrayList(); - protected PHPParserAction parserAction; - protected ShowExternalPreviewAction showExternalPreviewAction; + protected PHPParserAction fParserAction; + protected ShowExternalPreviewAction fShowExternalPreviewAction; /** * Default constructor. @@ -77,9 +77,10 @@ public class PHPActionContributor extends BasicTextEditorActionContributor { // fContentAssistTip = new RetargetTextEditorAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$ // fTogglePresentation = new PresentationAction(); - parserAction = PHPParserAction.getInstance(); + fParserAction = PHPParserAction.getInstance(); + if (SWT.getPlatform().equals("win32")) { - showExternalPreviewAction = ShowExternalPreviewAction.getInstance(); + fShowExternalPreviewAction = ShowExternalPreviewAction.getInstance(); } } @@ -178,12 +179,13 @@ public class PHPActionContributor extends BasicTextEditorActionContributor { // fTogglePresentation.setEditor(editor); // fTogglePresentation.update(); - parserAction.setEditor(textEditor); - parserAction.update(); + PHPeclipsePlugin.getDefault().setTextEditor(textEditor); + fParserAction.setEditor(textEditor); + fParserAction.update(); if (SWT.getPlatform().equals("win32") && textEditor instanceof AbstractTextEditor) { - showExternalPreviewAction.setEditor(textEditor); - showExternalPreviewAction.update(); + fShowExternalPreviewAction.setEditor(textEditor); + fShowExternalPreviewAction.update(); IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); if (store.getBoolean(PHPeclipsePlugin.SHOW_EXTERNAL_PREVIEW_PREF)) { IAction a = ShowExternalPreviewAction.getInstance(); 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 8406b8e..e3408c8 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java @@ -12,13 +12,18 @@ Contributors: Klaus Hartlage - www.eclipseproject.de **********************************************************************/ +import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.io.StreamTokenizer; +import java.io.StringReader; +import java.util.ArrayList; 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; @@ -27,6 +32,7 @@ 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; @@ -44,11 +50,14 @@ 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 @@ -75,11 +84,11 @@ public class PHPConsole extends ViewPart { fStyledText.copy(); } }; - private Action pasteAction = new Action() { - public void run() { - fViewer.getTextWidget().paste(); - } - }; + // private Action pasteAction = new Action() { + // public void run() { + // fViewer.getTextWidget().paste(); + // } + // }; private Action selectAllAction = new Action() { public void run() { fStyledText.selectAll(); @@ -119,14 +128,14 @@ public class PHPConsole extends ViewPart { 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); + fViewer.setEditable(false); fStyledText = fViewer.getTextWidget(); fStyledText.setFont(JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT)); cutAction.setText("Cut"); copyAction.setText("Copy"); - pasteAction.setText("Paste"); + // pasteAction.setText("Paste"); selectAllAction.setText("Select All"); clearAction.setText("Clear PHP Console"); clearAction.setImageDescriptor(PHPUiImages.DESC_CLEAR); @@ -135,12 +144,15 @@ public class PHPConsole extends ViewPart { IActionBars bars = this.getViewSite().getActionBars(); bars.setGlobalActionHandler(IWorkbenchActionConstants.CUT, cutAction); bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction); - bars.setGlobalActionHandler(IWorkbenchActionConstants.PASTE, pasteAction); + // bars.setGlobalActionHandler(IWorkbenchActionConstants.PASTE, pasteAction); hookContextMenu(); // hookDoubleClickAction(); contributeToActionBars(); + appendOutputText("This is the PHP console.\n"); + appendOutputText("Type: \"php $f\" to run the current editor file.\n"); + } private void createCommandBar(Composite parent) { @@ -159,7 +171,7 @@ public class PHPConsole extends ViewPart { String text = fCommandCombo.getItem(fCommandCombo.getSelectionIndex()); if (text.length() > 0) { fCommandCombo.setText(text); - // executeCommand(text); + // executeCommand(text); } } public void widgetDefaultSelected(SelectionEvent e) { @@ -179,7 +191,14 @@ public class PHPConsole extends ViewPart { private void executeCommand(String command) { command.trim(); - write( "Test: "+command ); + if (command.equals("")) { + fCommandCombo.forceFocus(); + return; + } + execute(command); + + fCommandCombo.forceFocus(); + // add to Combo history String[] items = fCommandCombo.getItems(); int loc = -1; String normURL = command; @@ -201,6 +220,95 @@ public class PHPConsole extends ViewPart { 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(); + 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 hookContextMenu() { MenuManager menuMgr = new MenuManager("#PopupMenu"); menuMgr.setRemoveAllWhenShown(true); @@ -223,14 +331,14 @@ public class PHPConsole extends ViewPart { private void fillLocalPullDown(IMenuManager manager) { manager.add(cutAction); manager.add(copyAction); - manager.add(pasteAction); + // manager.add(pasteAction); manager.add(selectAllAction); } private void fillContextMenu(IMenuManager manager) { manager.add(cutAction); manager.add(copyAction); - manager.add(pasteAction); + // manager.add(pasteAction); manager.add(selectAllAction); // Other plug-ins can contribute there actions here manager.add(new Separator("Additions")); @@ -244,6 +352,7 @@ public class PHPConsole extends ViewPart { * @see ViewPart#setFocus */ public void setFocus() { + fCommandCombo.forceFocus(); } /** @@ -272,7 +381,6 @@ public class PHPConsole extends ViewPart { 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) { @@ -287,13 +395,12 @@ public class PHPConsole extends ViewPart { PHPActionMessages.getString("PHPStartApacheAction.consoleViewOpeningProblem"), e)); } - } return console; } /** - * Prints out the string represented by the string buffer + * Prints out the string represented by the string */ public synchronized void write(String output) { appendOutputText(output); @@ -316,4 +423,21 @@ public class PHPConsole extends ViewPart { return buffer.toString(); } + /** + * Finds the file that's currently opened in the PHP Text Editor + */ + protected IFile getFile() { + ITextEditor editor = PHPeclipsePlugin.getDefault().getTextEditor(); + + 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; + } }