4444import java .util .Iterator ;
4545
4646import org .eclipse .core .runtime .Preferences ;
47+ import org .eclipse .jface .action .IAction ;
4748import org .eclipse .jface .action .Action ;
4849import org .eclipse .jface .dialogs .IInputValidator ;
4950import org .eclipse .jface .dialogs .InputDialog ;
5051import org .eclipse .jface .resource .JFaceResources ;
52+ import org .eclipse .jface .resource .ImageDescriptor ;
5153import org .eclipse .jface .util .IPropertyChangeListener ;
5254import org .eclipse .jface .util .PropertyChangeEvent ;
5355import org .eclipse .swt .SWT ;
5456import org .eclipse .swt .custom .StyledText ;
5557import org .eclipse .swt .custom .VerifyKeyListener ;
56- import org .eclipse .swt .dnd .Clipboard ;
58+ /// import org.eclipse.swt.dnd.Clipboard;
5759import org .eclipse .swt .dnd .TextTransfer ;
5860import org .eclipse .swt .dnd .Transfer ;
5961import org .eclipse .swt .events .ModifyEvent ;
6466import org .eclipse .swt .graphics .Color ;
6567import org .eclipse .swt .widgets .Display ;
6668import org .eclipse .ui .IWorkbenchActionConstants ;
69+ import org .eclipse .ui .IWorkbenchWindow ;
70+ import org .eclipse .ui .actions .ActionFactory ;
6771
6872import edu .rice .cs .drjava .plugins .eclipse .DrJavaConstants ;
6973import edu .rice .cs .drjava .plugins .eclipse .EclipsePlugin ;
@@ -203,7 +207,7 @@ public void dispose() {
203207 _colorDarkGreen .dispose ();
204208 _colorDarkBlue .dispose ();
205209 _colorYellow .dispose ();
206- _clipboard .dispose ();
210+ /// _clipboard.dispose();
207211
208212 // Remove preference listener
209213 Preferences store = EclipsePlugin .getDefault ().getPluginPreferences ();
@@ -243,8 +247,8 @@ private void _updatePreferences() {
243247 String confirmMessage =
244248 "Specifying the command-line arguments to the Interactions JVM is an\n " +
245249 "advanced option, and incorrect arguments may cause the Interactions\n " +
246- "Pane to stop responding. Are you sure you want to set this option?\n " +
247- "(You must reset the Interactions Pane before changes will take effect.)" ;
250+ "View to stop responding. Are you sure you want to set this option?\n " +
251+ "(You must reset the Interactions View before changes will take effect.)" ;
248252 if (_view .showConfirmDialog ("Setting JVM Arguments" , confirmMessage )) {
249253 _model .setOptionArgs (jvmArgs );
250254 }
@@ -445,45 +449,38 @@ public void run() {
445449 _view .getTextPane ().addVerifyKeyListener (new KeyUpdateListener ());
446450// _view.getTextPane().setKeyBinding(((int) '\t') | SWT.SHIFT, SWT.NULL);
447451
448- _clipboard = new Clipboard (_view .getSite ().getShell ().getDisplay ());
449-
450452 // Set up menu
451453 _setupMenu ();
452454 }
453455
454- Clipboard _clipboard ;
455456 /** Adds actions to the toolbar menu. */
456457 protected void _setupMenu () {
457- final Action copyAction = new CopyAction (_view .getTextPane (), _clipboard );
458+ IWorkbenchWindow window = _view .getSite ().getWorkbenchWindow ();
459+ final IAction copyAction = ActionFactory .COPY .create (window );
458460 copyAction .setEnabled (false );
459-
460- _view .addAction (IWorkbenchActionConstants .COPY , copyAction );
461-
462- _view .addAction (IWorkbenchActionConstants .PASTE ,
463- new PasteAction (_view .getTextPane (), _clipboard ));
464461 _view .addSelectionListener (new SelectionAdapter () {
465462 public void widgetSelected (SelectionEvent e ) {
466- //System.out.println("About to Show:" +
467- // _view.getTextPane().getSelectionCount());
468- copyAction .setEnabled (
469- (_view .getTextPane ().getSelectionCount () > 0 ));
463+ copyAction .setEnabled (_view .getTextPane ().getSelectionCount () > 0 );
470464 }
471465 });
466+ _view .addMenuItem (copyAction );
472467
473- Action resetInteractionsAction = new Action () {
468+ IAction resetInteractionsAction = new Action () {
474469 public void run () {
475470 String title = "Confirm Reset Interactions" ;
476- String message = "Are you sure you want to reset the Interactions Pane ?" ;
471+ String message = "Are you sure you want to reset the Interactions View ?" ;
477472 if (!_promptToReset || _view .showConfirmDialog (title , message )) {
478473 _model .resetInterpreter (EclipseInteractionsModel .WORKING_DIR );
479474 }
480475 }
481476 };
482477 resetInteractionsAction .setText ("Reset Interactions" );
483- resetInteractionsAction .setToolTipText ("Resets the Interactions Pane" );
478+ resetInteractionsAction .setToolTipText ("Reset the Interactions View" );
479+ resetInteractionsAction .setImageDescriptor (_getStandardIcon (ActionFactory .DELETE , window ));
484480 _view .addMenuItem (resetInteractionsAction );
481+ _view .addToolbarItem (resetInteractionsAction );
485482
486- Action showClasspathAction = new Action () {
483+ IAction showClasspathAction = new Action () {
487484 public void run () {
488485 String title = "Interpreter Classpath" ;
489486 StringBuffer cpBuf = new StringBuffer ();
@@ -497,10 +494,20 @@ public void run() {
497494 }
498495 };
499496 showClasspathAction .setText ("Show Interpreter Classpath" );
500- showClasspathAction .setToolTipText ("Shows the classpath used in the interactions pane. " );
497+ showClasspathAction .setToolTipText ("Show the classpath used in the Interactions View " );
501498 _view .addMenuItem (showClasspathAction );
502499 }
503500
501+ /**
502+ * Get the icon used by a standard action. (There may be a better way to get to standard icons,
503+ * but I haven't found it.) Note that many standard ActionFactories don't produce actions with icons.
504+ */
505+ private ImageDescriptor _getStandardIcon (ActionFactory f , IWorkbenchWindow w ) {
506+ ActionFactory .IWorkbenchAction a = f .create (w );
507+ try { return a .getImageDescriptor (); }
508+ finally { a .dispose (); }
509+ }
510+
504511 /**
505512 * Listener to perform the correct action when a key is pressed.
506513 */
@@ -711,55 +718,4 @@ public void propertyChange(Preferences.PropertyChangeEvent event) {
711718 }
712719 }
713720
714-
715- public class CopyAction extends Action {
716- protected StyledText _text ;
717- protected Clipboard _clipboard ;
718- public CopyAction (StyledText text , Clipboard cp ) {
719- _text = text ;
720- _clipboard = cp ;
721- setText ("Copy" );
722- setAccelerator (SWT .CTRL | 'C' );
723- }
724-
725-
726- public void run () {
727- //get selection
728- //TODO: need to disable Copy if selection is empty
729- if (_text .getSelectionCount () > 0 ) {
730- String selection = _text .getSelectionText ();
731-
732- _clipboard .setContents (
733- new Object [] { selection },
734- new Transfer [] {TextTransfer .getInstance () }
735- );
736- }
737- }
738- }
739-
740- public class PasteAction extends Action {
741- protected StyledText _text ;
742- protected Clipboard _clipboard ;
743- public PasteAction (StyledText text , Clipboard cp ) {
744- _text = text ;
745- _clipboard = cp ;
746- setText ("Paste" );
747- setAccelerator (SWT .CTRL | 'V' );
748- }
749-
750-
751- public void run () {
752- //get selection
753- Object selection = _clipboard .getContents (TextTransfer .getInstance ());
754- if (selection != null ) {
755- _text .insert (selection .toString ());
756- }
757- //if (selection instanceof String) {
758- //_text.insert( (String)selection);
759- //}
760-
761- }
762- }
763-
764-
765721}
0 commit comments