action menus shown when listener links clicked

cvs
Slava Pestov 2004-08-18 01:57:45 +00:00
parent 5c00ef85dd
commit f7b77cbba7
9 changed files with 138 additions and 31 deletions

View File

@ -10,7 +10,6 @@
- multitasking
- review doc formatting with latex2html
- sidekick: error source not removed
- array index out of bounds
[error] AWT-EventQueue-0: java.lang.NullPointerException
[error] AWT-EventQueue-0: at sidekick.SideKickParsedData.getTreePathForPosition(Unknown Source)
@ -40,8 +39,11 @@
+ listener/plugin:
- lineno/file for shuffle defs
- balance needs USE:
- input style after clicking link
- completion: enter no good
- completion: don't show automatically
- debug sidekick
- completion in the listener
- special completion for USE:/IN:
- fedit broken with listener
@ -60,6 +62,8 @@
+ JVM compiler:
- compiled stack traces broken
- save classes to disk
- tail call optimization broken again
- don't compile inline words
- recursive words with code after ifte
@ -71,7 +75,6 @@
+ misc:
- compiled stack traces broken
- namespace clone drops static var bindings
- ditch map
- ditch expand
@ -85,7 +88,6 @@
- log-client: fix for native
- if user clicks stop in browser, doesn't stop sending?
- log with date
- log user agent
- add a socket timeout
- if a directory is requested and URL does not end with /, redirect
- return more header fields, like Content-Length, Last-Modified, and so on

View File

@ -40,7 +40,7 @@
</ACTION>
<ACTION NAME="factor-edit">
<CODE>
factorWordOperation(view,"USE: jedit jedit");
factorWordOperation(view,"jedit");
</CODE>
</ACTION>
<ACTION NAME="factor-usages">
@ -55,7 +55,7 @@
else
{
factorEval(view,
"[ " + textArea.selectedText + " ] balance");
"[ " + textArea.selectedText + " ] balance .");
}
</CODE>
</ACTION>

View File

@ -35,7 +35,7 @@ import java.io.*;
public class FactorInterpreter implements FactorObject, Runnable
{
public static final String VERSION = "0.63";
public static final String VERSION = "0.64";
// command line arguments are stored here.
public Cons args;

32
factor/jedit/factor.bsh Normal file
View File

@ -0,0 +1,32 @@
factorEval(view,str)
{
factor.jedit.FactorPlugin.eval(view,str);
}
/* Build a Factor expression for pushing the selected word on the stack */
factorWord(view)
{
textArea = view.textArea;
data = sidekick.SideKickParsedData.getParsedData(view);
if(data instanceof factor.jedit.FactorParsedData)
{
if(textArea.selectionCount == 0)
textArea.selectWord();
return "\""
+ MiscUtilities.charsToEscapes(textArea.selectedText)
+ "\" " + factor.FactorReader.unparseObject(data.use)
+ " search";
}
else
return null;
}
/* Apply a Factor word to the selected word */
factorWordOperation(view,op)
{
word = factorWord(view);
if(word == null)
view.toolkit.beep();
else
factorEval(view,word + " " + op);
}

View File

@ -49,6 +49,7 @@ public class FactorListener extends JTextPane
(Cursor.WAIT_CURSOR);
public static final Object Link = new Object();
public static final Object Actions = new Object();
private EventListenerList listenerList;
@ -145,6 +146,7 @@ public class FactorListener extends JTextPane
try
{
StyledDocument doc = (StyledDocument)getDocument();
setCaretPosition(doc.getLength());
doc.insertString(doc.getLength(),eval + "\n",
getCharacterAttributes());
}
@ -174,27 +176,77 @@ public class FactorListener extends JTextPane
}
} //}}}
//{{{ getLinkAt() method
private String getLinkAt(int pos)
//{{{ getAttributes() method
private AttributeSet getAttributes(int pos)
{
StyledDocument doc = (StyledDocument)getDocument();
Element e = doc.getCharacterElement(pos);
AttributeSet a = e.getAttributes();
return e.getAttributes();
} //}}}
//{{{ getActions() method
private Cons getActions(int pos)
{
AttributeSet a = getAttributes(pos);
if(a == null)
return null;
else
return (String)a.getAttribute(Link);
return (Cons)a.getAttribute(Actions);
} //}}}
//{{{ getActionsPopup() method
private JPopupMenu getActionsPopup(int pos)
{
Cons actions = getActions(pos);
if(actions == null)
return null;
JPopupMenu popup = new JPopupMenu();
while(actions != null)
{
Cons action = (Cons)actions.car;
JMenuItem item = new JMenuItem((String)action.cdr);
item.setActionCommand((String)action.car);
item.addActionListener(new EvalAction());
popup.add(item);
actions = actions.next();
}
return popup;
} //}}}
//{{{ showPopupMenu() method
private void showPopupMenu(int pos)
{
JPopupMenu actions = getActionsPopup(pos);
if(actions == null)
return;
try
{
StyledDocument doc = (StyledDocument)getDocument();
Element e = doc.getCharacterElement(pos);
Point pt = modelToView(e.getStartOffset())
.getLocation();
FontMetrics fm = getFontMetrics(getFont());
actions.show(this,pt.x,pt.y + fm.getHeight());
}
catch(Exception e)
{
e.printStackTrace();
}
} //}}}
//{{{ MouseHandler class
class MouseHandler extends MouseInputAdapter
{
public void mouseClicked(MouseEvent e)
public void mousePressed(MouseEvent e)
{
Point pt = new Point(e.getX(), e.getY());
int pos = viewToModel(pt);
if(pos >= 0)
eval(getLinkAt(pos));
showPopupMenu(pos);
}
public void mouseMoved(MouseEvent e)
@ -204,7 +256,7 @@ public class FactorListener extends JTextPane
if(pos >= 0)
{
Cursor cursor;
if(getLinkAt(pos) != null)
if(getActions(pos) != null)
cursor = MoveCursor;
else
cursor = DefaultCursor;
@ -215,12 +267,20 @@ public class FactorListener extends JTextPane
}
} //}}}
//{{{ EvalAction class
class EvalAction extends AbstractAction
{
public void actionPerformed(ActionEvent evt)
{
eval(evt.getActionCommand());
}
} //}}}
//{{{ EnterAction class
class EnterAction extends AbstractAction
{
public void actionPerformed(ActionEvent evt)
{
setCaretPosition(getDocument().getLength());
replaceSelection("\n");
try

View File

@ -36,5 +36,5 @@ USE: httpd-responder
: inspect-responder ( argument -- )
serving-html dup [
describe-object-path
describe-path
] simple-html-document ;

View File

@ -99,11 +99,13 @@ USE: words
"builtins"
"combinators"
"compiler"
"continuations"
"errors"
"debugger"
"hashtables"
"inspector"
"interpreter"
"jedit"
"kernel"
"lists"
"logic"
@ -112,6 +114,7 @@ USE: words
"parser"
"prettyprint"
"stack"
"streams"
"stdio"
"strings"
"test"

View File

@ -109,8 +109,8 @@ USE: vectors
[ prettyprint ]
] cond ;
: describe-object-path ( string -- )
[
dup "object-path" set
"'" split global [ object-path ] bind describe
] with-scope ;
: lookup ( str -- object )
global [ "'" split object-path ] bind ;
: describe-path ( string -- )
[ dup "object-path" set lookup describe ] with-scope ;

View File

@ -64,20 +64,30 @@ USE: unparser
"java.awt.Color"
jnew ;
: link-key ( -- attr )
"factor.listener.FactorListener" "Link" jvar-static-get
: actions-key ( -- attr )
"factor.listener.FactorListener" "Actions" jvar-static-get
; inline
: obj>listener-link ( obj -- link )
#! Listener links are quotations.
dup string? [
! Inspector link.
unparse " describe-object-path" cat2
] when ;
: actions ( -- list )
[
[ "describe-path" | "Describe" ]
[ "lookup" | "Push" ]
[ "lookup jedit" | "jEdit" ]
[ "lookup usages." | "Usages" ]
] ;
: <action-menu-item> ( path pair -- pair )
uncons >r " " swap cat3 r> cons ;
: <actions-menu> ( path -- alist )
unparse actions [ dupd <action-menu-item> ] inject nip ;
: underline-attribute ( attribute-set -- )
t "Underline" swing-attribute+ ;
: link-attribute ( attribute-set target -- )
[ dup t "Underline" swing-attribute+ ] dip
obj>listener-link link-key attribute+ ;
over underline-attribute
<actions-menu> actions-key attribute+ ;
: style>attribute-set ( -- attribute-set )
<attribute-set>