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;
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.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
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();
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);
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) {
String text = fCommandCombo.getItem(fCommandCombo.getSelectionIndex());
if (text.length() > 0) {
fCommandCombo.setText(text);
- // executeCommand(text);
+ // executeCommand(text);
}
}
public void widgetDefaultSelected(SelectionEvent e) {
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;
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);
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"));
* @see ViewPart#setFocus
*/
public void setFocus() {
+ fCommandCombo.forceFocus();
}
/**
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) {
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);
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;
+ }
}