Changeset 405

Show
Ignore:
Timestamp:
09/27/08 19:38:33 (3 months ago)
Author:
tjas..@bitfauna.com
Message:

Tim Jasko
-Added right-click menus to inspectables. You can now copy the inspectable item to the REPL. This is probably the only instance where our implementation is less pretty than Slime's, but at least it works.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • jasko.tim.lisp/src/jasko/tim/lisp/inspector/InspectorGadget.java

    r33 r405  
    11package jasko.tim.lisp.inspector; 
    22 
     3import org.eclipse.swt.SWT; 
     4import org.eclipse.swt.events.SelectionEvent; 
     5import org.eclipse.swt.events.SelectionListener; 
    36import org.eclipse.swt.widgets.Composite; 
     7import org.eclipse.swt.widgets.Menu; 
     8import org.eclipse.swt.widgets.MenuItem; 
    49 
    510import jasko.tim.lisp.LispPlugin; 
     
    1924        } 
    2025         
     26        protected void showInspectableMenu(final InspectableRegion region) { 
     27                Menu menu = new Menu (this.getControl()); 
     28                MenuItem inspect = new MenuItem(menu, SWT.PUSH); 
     29                inspect.setText("Inspect"); 
     30                inspect.addSelectionListener(new SelectionListener () { 
     31                        public void widgetDefaultSelected(SelectionEvent e) { 
     32 
     33                        } 
     34                        public void widgetSelected(SelectionEvent e) { 
     35                                sendInspect(region.id); 
     36                        } 
     37                }); 
     38                menu.setVisible(true); 
     39        } 
     40         
    2141} 
  • jasko.tim.lisp/src/jasko/tim/lisp/views/ReplView.java

    r402 r405  
    881881        } 
    882882         
     883        public void appendToInputArea(String text) { 
     884                in.getTextWidget().append(text); 
     885        } 
     886         
     887        public void insertInInputArea(String text) { 
     888                StyledText st = in.getTextWidget(); 
     889                st.insert(text); 
     890        } 
     891         
    883892         
    884893        /** 
  • jasko.tim.lisp/src/jasko/tim/lisp/views/repl/ReplHistory.java

    r279 r405  
    99import jasko.tim.lisp.inspector.InspectorRunnable; 
    1010import jasko.tim.lisp.preferences.PreferenceConstants; 
     11import jasko.tim.lisp.views.ReplView; 
    1112 
    1213import org.eclipse.jface.preference.IPreferenceStore; 
     
    1819import org.eclipse.swt.SWT; 
    1920import org.eclipse.swt.custom.StyleRange; 
     21import org.eclipse.swt.dnd.*; 
    2022import org.eclipse.swt.events.*; 
    2123import org.eclipse.swt.graphics.*; 
     
    3234        private Color inputFore; 
    3335        private Color commentFore; 
    34      
     36         
    3537    private boolean applyInspectableStyles; 
    3638    private boolean underlineInspectables; 
     
    258260        public void mouseUp(MouseEvent e) { 
    259261                Point p = new Point(e.x, e.y); 
    260         int offset; 
    261         try { 
    262               offset = getTextWidget().getOffsetAtLocation(p); 
    263         } catch (IllegalArgumentException ex) { 
    264             return; 
    265        
     262               int offset; 
     263               try { 
     264                      offset = getTextWidget().getOffsetAtLocation(p); 
     265               } catch (IllegalArgumentException ex) { 
     266                       return; 
     267               
    266268                InspectableRegion region = getRegion(offset); 
    267                 if (region != null) sendInspect(region.id); 
     269                if (region != null) { 
     270                        if (e.button == 1) { // left click 
     271                                sendInspect(region.id); 
     272                        } else if (e.button == 3) { // right click 
     273                                showInspectableMenu(region); 
     274                        } 
     275                } 
     276        } 
     277         
     278        protected void showInspectableMenu(final InspectableRegion region) { 
     279                Menu menu = new Menu (this.getControl()); 
     280                MenuItem inspect = new MenuItem(menu, SWT.PUSH); 
     281                inspect.setText("Inspect"); 
     282                inspect.addSelectionListener(new SelectionListener () { 
     283                        public void widgetDefaultSelected(SelectionEvent e) { 
     284 
     285                        } 
     286                        public void widgetSelected(SelectionEvent e) { 
     287                                sendInspect(region.id); 
     288                        } 
     289                }); 
     290                MenuItem copyRepl = new MenuItem(menu, SWT.PUSH); 
     291                copyRepl.setText("Copy to REPL"); 
     292                copyRepl.addSelectionListener(new SelectionListener () { 
     293                        public void widgetDefaultSelected(SelectionEvent e) { 
     294 
     295                        } 
     296                        public void widgetSelected(SelectionEvent e) { 
     297                                ReplView.getInstance().insertInInputArea("#.(swank:get-repl-result #10r" + region.id + ")"); 
     298                        } 
     299                }); 
     300                MenuItem copy = new MenuItem(menu, SWT.PUSH); 
     301                copy.setText("Copy to clipboard"); 
     302                copy.addSelectionListener(new SelectionListener () { 
     303                        public void widgetDefaultSelected(SelectionEvent e) { 
     304 
     305                        } 
     306                        public void widgetSelected(SelectionEvent e) { 
     307                                String data = "#.(swank:get-repl-result #10r" + region.id + ")"; 
     308 
     309                                Clipboard cb = new Clipboard(getControl().getDisplay()); 
     310                                TextTransfer textTransfer = TextTransfer.getInstance(); 
     311                                cb.setContents(new Object[] { data }, 
     312                                                new Transfer[] { textTransfer }); 
     313                                cb.dispose(); 
     314                        } 
     315                }); 
     316                //menu.setLocation(p); 
     317                menu.setVisible(true); 
    268318        } 
    269319         
     
    280330        public void mouseDown(MouseEvent e) {} 
    281331     
    282     private class InspectableRegion extends Region { 
     332    protected class InspectableRegion extends Region { 
    283333        public final String id; 
    284334