Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2007-07-04 18:13:06 +0000
committerMichael Valenta2007-07-04 18:13:06 +0000
commitf98d89a8144e4b1e241665c5c00941a371091d8b (patch)
tree7ee4fa2afcb39a9aaa8207d025c0233760a92836
parent90fac6f35dc520793e77c9ae883ac6857061228c (diff)
downloadeclipse.platform.team-f98d89a8144e4b1e241665c5c00941a371091d8b.tar.gz
eclipse.platform.team-f98d89a8144e4b1e241665c5c00941a371091d8b.tar.xz
eclipse.platform.team-f98d89a8144e4b1e241665c5c00941a371091d8b.zip
Bug 194992 Display quick assists on context menu of commit dialog
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java4
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CommitCommentArea.java138
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties4
3 files changed, 141 insertions, 5 deletions
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java
index 92645c0c7..083c58523 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java
@@ -47,6 +47,10 @@ public class CVSUIMessages extends NLS {
public static String CommitAction_3;
public static String CommitAction_1;
public static String CommitAction_2;
+ public static String CommitCommentArea_10;
+ public static String CommitCommentArea_7;
+ public static String CommitCommentArea_8;
+ public static String CommitCommentArea_9;
public static String CommitWizard_10;
public static String CommitWizard_11;
public static String CommitWizard_12;
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CommitCommentArea.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CommitCommentArea.java
index 01a56460e..6fbc08cdf 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CommitCommentArea.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CommitCommentArea.java
@@ -17,13 +17,15 @@ package org.eclipse.team.internal.ccvs.ui;
import java.util.*;
import org.eclipse.core.resources.IProject;
-import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.*;
import org.eclipse.jface.commands.ActionHandler;
import org.eclipse.jface.dialogs.*;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.*;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.source.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
@@ -36,10 +38,13 @@ import org.eclipse.team.internal.ccvs.core.*;
import org.eclipse.team.internal.ccvs.core.util.Util;
import org.eclipse.team.internal.ui.SWTUtils;
import org.eclipse.team.internal.ui.dialogs.DialogArea;
-import org.eclipse.ui.*;
+import org.eclipse.ui.ActiveShellExpression;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PreferencesUtil;
-import org.eclipse.ui.editors.text.*;
-import org.eclipse.ui.handlers.*;
+import org.eclipse.ui.editors.text.EditorsUI;
+import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
+import org.eclipse.ui.handlers.IHandlerActivation;
+import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.texteditor.*;
@@ -67,7 +72,7 @@ public class CommitCommentArea extends DialogArea {
cc.setLayout(new FillLayout());
cc.setLayoutData(new GridData(GridData.FILL_BOTH));
- SourceViewer sourceViewer = new SourceViewer(cc, null, null, true, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
+ final SourceViewer sourceViewer = new SourceViewer(cc, null, null, true, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);
fTextField = sourceViewer.getTextWidget();
fTextField.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));
@@ -85,6 +90,123 @@ public class CommitCommentArea extends DialogArea {
final IHandlerService handlerService= (IHandlerService)PlatformUI.getWorkbench().getService(IHandlerService.class);
final IHandlerActivation handlerActivation= installQuickFixActionHandler(handlerService, sourceViewer);
+ final TextViewerAction cutAction = new TextViewerAction(sourceViewer, ITextOperationTarget.CUT);
+ cutAction.setText(CVSUIMessages.CommitCommentArea_7);
+ cutAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.CUT);
+
+ final TextViewerAction copyAction = new TextViewerAction(sourceViewer, ITextOperationTarget.COPY);
+ copyAction.setText(CVSUIMessages.CommitCommentArea_8);
+ copyAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.COPY);
+
+ final TextViewerAction pasteAction = new TextViewerAction(sourceViewer, ITextOperationTarget.PASTE);
+ pasteAction.setText(CVSUIMessages.CommitCommentArea_9);
+ pasteAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.PASTE);
+
+ final TextViewerAction selectAllAction = new TextViewerAction(sourceViewer, ITextOperationTarget.SELECT_ALL);
+ selectAllAction.setText(CVSUIMessages.CommitCommentArea_10);
+ selectAllAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.SELECT_ALL);
+
+ MenuManager contextMenu = new MenuManager();
+ contextMenu.add(cutAction);
+ contextMenu.add(copyAction);
+ contextMenu.add(pasteAction);
+ contextMenu.add(selectAllAction);
+ contextMenu.add(new Separator());
+
+ final SubMenuManager quickFixMenu = new SubMenuManager(contextMenu);
+ quickFixMenu.setVisible(true);
+ quickFixMenu.addMenuListener(new IMenuListener() {
+
+ public void menuAboutToShow(IMenuManager manager) {
+ quickFixMenu.removeAll();
+
+ IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
+ Iterator annotationIterator = annotationModel.getAnnotationIterator();
+ while (annotationIterator.hasNext()) {
+ Annotation annotation = (Annotation) annotationIterator.next();
+ if (!annotation.isMarkedDeleted() && includes(annotationModel.getPosition(annotation), sourceViewer.getTextWidget().getCaretOffset()) && sourceViewer.getQuickAssistAssistant().canFix(annotation)) {
+ ICompletionProposal[] computeQuickAssistProposals = sourceViewer.getQuickAssistAssistant().getQuickAssistProcessor().computeQuickAssistProposals(sourceViewer.getQuickAssistInvocationContext());
+ for (int i = 0; i < computeQuickAssistProposals.length; i++) {
+ final ICompletionProposal proposal = computeQuickAssistProposals[i];
+ quickFixMenu.add(new Action(proposal.getDisplayString()) {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ public void run() {
+ proposal.apply(sourceViewer.getDocument());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#getImageDescriptor()
+ */
+ public ImageDescriptor getImageDescriptor() {
+ if (proposal.getImage() != null) {
+ return ImageDescriptor.createFromImage(proposal.getImage());
+ }
+ return null;
+ }
+ });
+ }
+ }
+ }
+ }
+
+ });
+
+ fTextField.addFocusListener(new FocusListener() {
+
+ private IHandlerActivation cutHandlerActivation;
+ private IHandlerActivation copyHandlerActivation;
+ private IHandlerActivation pasteHandlerActivation;
+ private IHandlerActivation selectAllHandlerActivation;
+
+ public void focusGained(FocusEvent e) {
+ cutAction.update();
+ copyAction.update();
+ IHandlerService service = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
+ this.cutHandlerActivation = service.activateHandler(IWorkbenchActionDefinitionIds.CUT, new ActionHandler(cutAction), new ActiveShellExpression(getComposite().getShell()));
+ this.copyHandlerActivation = service.activateHandler(IWorkbenchActionDefinitionIds.COPY, new ActionHandler(copyAction), new ActiveShellExpression(getComposite().getShell()));
+ this.pasteHandlerActivation = service.activateHandler(IWorkbenchActionDefinitionIds.PASTE, new ActionHandler(pasteAction), new ActiveShellExpression(getComposite().getShell()));
+ this.selectAllHandlerActivation = service.activateHandler(IWorkbenchActionDefinitionIds.SELECT_ALL, new ActionHandler(selectAllAction), new ActiveShellExpression(getComposite().getShell()));
+
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.FocusAdapter#focusLost(org.eclipse.swt.events.FocusEvent)
+ */
+ public void focusLost(FocusEvent e) {
+ IHandlerService service = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
+
+ if (cutHandlerActivation != null) {
+ service.deactivateHandler(cutHandlerActivation);
+ }
+
+ if (copyHandlerActivation != null) {
+ service.deactivateHandler(copyHandlerActivation);
+ }
+
+ if (pasteHandlerActivation != null) {
+ service.deactivateHandler(pasteHandlerActivation);
+ }
+
+ if (selectAllHandlerActivation != null) {
+ service.deactivateHandler(selectAllHandlerActivation);
+ }
+ }
+
+ });
+
+ fTextField.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ cutAction.update();
+ copyAction.update();
+ }
+
+ });
+
sourceViewer.getTextWidget().addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
@@ -105,8 +227,14 @@ public class CommitCommentArea extends DialogArea {
fTextField.addModifyListener(this);
fTextField.addFocusListener(this);
+ fTextField.setMenu(contextMenu.createContextMenu(fTextField));
+
}
+ protected boolean includes(Position position, int caretOffset) {
+ return position.includes(caretOffset) || (position.offset + position.length) == caretOffset;
+ }
+
/**
* Installs the quick fix action handler
* and returns the handler activation.
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties
index 384ae5963..ff99db831 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties
@@ -910,11 +910,15 @@ CommitAction_2=Should change sets be consulted in order to determine which resou
CommitCommentArea_0=<Click here to enter a commit comment>
CommitCommentArea_1=<Choose a previously entered comment>
+CommitCommentArea_10=Select &All
CommitCommentArea_2=Empty commit comment
CommitCommentArea_3=The commit comment is empty. Are you sure you would like to continue with an empty comment?
CommitCommentArea_4=Re&member decision?
CommitCommentArea_5=Configure Comment Templates...
CommitCommentArea_6=Template
+CommitCommentArea_7=C&ut
+CommitCommentArea_8=&Copy
+CommitCommentArea_9=&Paste
CheckoutProjectOperation_8=Checking out ''{0}'' into project ''{1}''
CheckoutProjectOperation_9=Checking out ''{0}'' into {1} projects

Back to the top