Skip to content

Commit 21fabb9

Browse files
author
dlsmith
committed
Eclipse: Always uses user.home as the working directory; added a top-level reset toolbar button; cleaned up deprecated copy/paste code.
git-svn-id: file:///tmp/test-svn/trunk@4695 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 201b599 commit 21fabb9

File tree

3 files changed

+50
-80
lines changed

3 files changed

+50
-80
lines changed

eclipse/src/edu/rice/cs/drjava/plugins/eclipse/repl/EclipseInteractionsModel.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public EclipseInteractionsModel(SWTDocumentAdapter adapter) /* throws RemoteExce
122122
* @param adapter SWTDocumentAdapter to use for the document
123123
*/
124124
public EclipseInteractionsModel(MainJVM control, SWTDocumentAdapter adapter) {
125-
super(control, adapter, null, HISTORY_SIZE, WRITE_DELAY); // null has type java.io.File; working directory
125+
super(control, adapter, WORKING_DIR, HISTORY_SIZE, WRITE_DELAY);
126126
_listeners = new LinkedList<InteractionsListener>();
127127
_warnedToReset = false;
128128
if (DEBUG) _debugSystemOutAndErr();
@@ -161,8 +161,10 @@ protected void _interpreterResetFailed(Throwable t) {
161161

162162
/** Called when the Java interpreter is ready to use. Adds any open documents to the classpath. */
163163
public void interpreterReady(File wd) {
164+
debug.logStart();
164165
_resetInteractionsClasspath();
165166
super.interpreterReady(wd);
167+
debug.logEnd();
166168
}
167169

168170
/** Resets the warning flag after the Interactions Pane is reset. */

eclipse/src/edu/rice/cs/drjava/plugins/eclipse/views/InteractionsController.java

Lines changed: 29 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,18 @@
4444
import java.util.Iterator;
4545

4646
import org.eclipse.core.runtime.Preferences;
47+
import org.eclipse.jface.action.IAction;
4748
import org.eclipse.jface.action.Action;
4849
import org.eclipse.jface.dialogs.IInputValidator;
4950
import org.eclipse.jface.dialogs.InputDialog;
5051
import org.eclipse.jface.resource.JFaceResources;
52+
import org.eclipse.jface.resource.ImageDescriptor;
5153
import org.eclipse.jface.util.IPropertyChangeListener;
5254
import org.eclipse.jface.util.PropertyChangeEvent;
5355
import org.eclipse.swt.SWT;
5456
import org.eclipse.swt.custom.StyledText;
5557
import org.eclipse.swt.custom.VerifyKeyListener;
56-
import org.eclipse.swt.dnd.Clipboard;
58+
///import org.eclipse.swt.dnd.Clipboard;
5759
import org.eclipse.swt.dnd.TextTransfer;
5860
import org.eclipse.swt.dnd.Transfer;
5961
import org.eclipse.swt.events.ModifyEvent;
@@ -64,6 +66,8 @@
6466
import org.eclipse.swt.graphics.Color;
6567
import org.eclipse.swt.widgets.Display;
6668
import org.eclipse.ui.IWorkbenchActionConstants;
69+
import org.eclipse.ui.IWorkbenchWindow;
70+
import org.eclipse.ui.actions.ActionFactory;
6771

6872
import edu.rice.cs.drjava.plugins.eclipse.DrJavaConstants;
6973
import 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
}

eclipse/src/edu/rice/cs/drjava/plugins/eclipse/views/InteractionsView.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@
4040
package edu.rice.cs.drjava.plugins.eclipse.views;
4141

4242

43-
import org.eclipse.jface.action.Action;
43+
import org.eclipse.jface.action.IAction;
4444
import org.eclipse.jface.action.IMenuManager;
4545
import org.eclipse.jface.action.MenuManager;
46+
import org.eclipse.jface.action.IToolBarManager;
4647
import org.eclipse.jface.dialogs.MessageDialog;
4748
import org.eclipse.jface.resource.JFaceResources;
4849
import org.eclipse.swt.SWT;
@@ -94,9 +95,14 @@ public class InteractionsView extends ViewPart {
9495
* A runnable command to sound a beep as an alert.
9596
*/
9697
protected Runnable _beep;
98+
99+
/**
100+
* Toolbar for this view.
101+
*/
102+
protected IToolBarManager _toolbar;
97103

98104
/**
99-
* Toolbar menu for this view.
105+
* Drop-down toolbar menu for this view.
100106
*/
101107
protected IMenuManager _toolbarMenu;
102108

@@ -182,6 +188,7 @@ public void createPartControl(Composite parent) {
182188
new CutAction(_styledText, _clipboard));
183189
*/
184190

191+
_toolbar = _bars.getToolBarManager();
185192
_toolbarMenu = _bars.getMenuManager();
186193
_contextMenu = new MenuManager("#PopupMenu");
187194
Menu menu = _contextMenu.createContextMenu(_styledText);
@@ -286,12 +293,12 @@ public void setFocus() {
286293
* Add a menu item to both the toolbar menu and context menu.
287294
* @param action Menu item to add
288295
*/
289-
public void addMenuItem(Action action) {
296+
public void addMenuItem(IAction action) {
290297
addToolbarMenuItem(action);
291298
addContextMenuItem(action);
292299
}
293300

294-
public void addAction(String op, Action action) {
301+
public void addAction(String op, IAction action) {
295302
_bars.setGlobalActionHandler(op, action);
296303
addToolbarMenuItem(action);
297304
addContextMenuItem(action);
@@ -301,7 +308,7 @@ public void addAction(String op, Action action) {
301308
* Add a menu item to the toolbar.
302309
* @param action Menu item to add
303310
*/
304-
public void addToolbarMenuItem(Action action) {
311+
public void addToolbarMenuItem(IAction action) {
305312
_toolbarMenu.add(action);
306313
}
307314

@@ -313,8 +320,13 @@ public void addSelectionListener(SelectionListener listener) {
313320
* Add a menu item to the context menu.
314321
* @param action Menu item to add
315322
*/
316-
public void addContextMenuItem(Action action) {
323+
public void addContextMenuItem(IAction action) {
317324
_contextMenu.add(action);
318325
}
326+
327+
/** Add a top-level action to the toolbar. */
328+
public void addToolbarItem(IAction action) {
329+
_toolbar.add(action);
330+
}
319331

320332
}

0 commit comments

Comments
 (0)