Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Watch expression action

  • Loading branch information...
commit 2c2c5a60e35a67525390ce2c85bfe7ef9dc51fd6 1 parent 1269c3e
@JPMoresmau authored
View
BIN  net.sf.eclipsefp.haskell.ui/icons/etool16/watch_exp.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
3  net.sf.eclipsefp.haskell.ui/plugin.properties
@@ -120,6 +120,9 @@ openDefinitionCommand_name = &Open Declaration
openDefinitionCommand_desc = Opens an editor on the declaration of the selected element
# NOTE: open declaration is referred to as open definition in the code
+watchExpressionCommand_name=Watch
+watchExpressionCommand_desc=Add the selected code to the watched expressions
+
searchHoogleAction_label = Search in &Hoogle
searchHoogleAction_tooltip = Search for the select element in Hoogle
searchHoogleCommand_name = Search in &Hoogle
View
39 net.sf.eclipsefp.haskell.ui/plugin.xml
@@ -476,6 +476,11 @@
name="%references_project_label"
id="net.sf.eclipsefp.ui.commands.references.project"/>
<command
+ description="%watchExpressionCommand_desc"
+ categoryId="org.eclipse.debug.ui.category.run"
+ name="%watchExpressionCommand_name"
+ id="net.sf.eclipsefp.ui.commands.run.watchExpression"/>
+ <command
description="%HaddockDocumentFollowing.description"
categoryId="net.sf.eclipsefp.haskell.ui.category.source"
name="%HaddockDocumentFollowing.name"
@@ -511,6 +516,14 @@
</command>
</menuContribution>
<menuContribution
+ locationURI="menu:org.eclipse.ui.run?after=emptyBreakpointGroup">
+ <command
+ commandId="net.sf.eclipsefp.ui.commands.run.watchExpression"
+ icon="icons/etool16/watch_exp.gif">
+ <visibleWhen checkEnabled="true"/>
+ </command>
+ </menuContribution>
+ <menuContribution
locationURI="menu:navigate?after=open.ext">
<command
commandId="net.sf.eclipsefp.ui.commands.navigate.searchHoogle">
@@ -524,6 +537,14 @@
<visibleWhen checkEnabled="true"/>
</command>
</menuContribution>
+ <menuContribution
+ locationURI="popup:#HaskellEditorContext?after=additions">
+ <command
+ commandId="net.sf.eclipsefp.ui.commands.run.watchExpression"
+ icon="icons/etool16/watch_exp.gif">
+ <visibleWhen checkEnabled="true"/>
+ </command>
+ </menuContribution>
<menuContribution
locationURI="popup:#HaskellEditorContext?after=group.open">
<command
@@ -657,6 +678,7 @@
</reference>
</activeWhen>
</handler>
+ <!-- handler for the references in project action when invoked from the HaskellEditor -->
<handler
class="net.sf.eclipsefp.haskell.ui.handlers.ReferencesProjectHandler"
commandId="net.sf.eclipsefp.ui.commands.references.project">
@@ -666,6 +688,23 @@
</reference>
</activeWhen>
</handler>
+ <!-- handler for the Watch expression action when invoked from the HaskellEditor -->
+ <handler
+ class="net.sf.eclipsefp.haskell.ui.handlers.WatchExpressionHandler"
+ commandId="net.sf.eclipsefp.ui.commands.run.watchExpression">
+ <activeWhen>
+ <and>
+ <reference
+ definitionId="net.sf.eclipsefp.haskell.ui.internal.editors.haskell.HaskellEditor.active">
+ </reference>
+ <with variable="selection">
+ <iterate operator="or">
+ <instanceof value="org.eclipse.jface.text.ITextSelection"/>
+ </iterate>
+ </with>
+ </and>
+ </activeWhen>
+ </handler>
</extension>
<extension
point="org.eclipse.core.expressions.definitions">
View
83 ...eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/handlers/WatchExpressionHandler.java
@@ -0,0 +1,83 @@
+/**
+ * Copyright (c) 2012 by JP Moresmau
+ * This code is made available under the terms of the Eclipse Public License,
+ * version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
+ */
+package net.sf.eclipsefp.haskell.ui.handlers;
+
+import net.sf.eclipsefp.haskell.ui.internal.editors.haskell.HaskellEditor;
+import net.sf.eclipsefp.haskell.ui.util.text.WordFinder;
+import net.sf.eclipsefp.haskell.ui.util.text.WordFinder.EditorThing;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.IDebugElement;
+import org.eclipse.debug.core.model.IWatchExpression;
+import org.eclipse.debug.ui.DebugUITools;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+
+/**
+ * Handler for watch expression
+ * @author JP Moresmau
+ *
+ */
+public class WatchExpressionHandler extends AbstractHandler {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ @Override
+ public Object execute( final ExecutionEvent event ) {
+ IEditorPart editor = HandlerUtil.getActiveEditor( event );
+
+ if( !( editor instanceof HaskellEditor ) ) {
+ return null;
+ }
+ final HaskellEditor hEditor=(HaskellEditor)editor;
+ // cast is safe because we have a guard in plugin.xml
+ final ITextSelection sel=(ITextSelection)HandlerUtil.getActiveMenuSelection( event );
+ String s=sel.getText();
+ // find word at location
+ if (s.length()==0){
+ WordFinder.getEditorThing( hEditor,new WordFinder.EditorThingHandler() {
+
+ @Override
+ public void handle( final EditorThing thing ) {
+ if (thing!=null && thing.getThing()!=null){
+ String name = thing.getThing().getName();
+ addExpression( name );
+ } else {
+ String s=WordFinder.findWord( hEditor.getDocument(), sel.getOffset() );
+ if (s.length()>0){
+ addExpression( s );
+ }
+ }
+ }
+ });
+ } else {
+ addExpression( s );
+ }
+
+ return null;
+ }
+
+ protected void addExpression(final String s){
+ if (s.length()>0){
+ IWatchExpression expression= DebugPlugin.getDefault().getExpressionManager().newWatchExpression(s);
+ DebugPlugin.getDefault().getExpressionManager().addExpression(expression);
+ IAdaptable object = DebugUITools.getDebugContext();
+ IDebugElement context= null;
+ if (object instanceof IDebugElement) {
+ context= (IDebugElement) object;
+ } else if (object instanceof ILaunch) {
+ context= ((ILaunch) object).getDebugTarget();
+ }
+ expression.setExpressionContext(context);
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.