Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Davis2014-08-13 18:08:12 -0400
committerSam Davis2014-08-18 20:29:10 -0400
commitc7f0a7a7450aacf90cff60fb590c550b4cbf96d6 (patch)
treecd927564b7321320d38082fc1ce1cabc106fa51b /org.eclipse.mylyn.reviews.ui/src
parentdb2da8bfed93a729949b060617d40db1e4be2eed (diff)
downloadorg.eclipse.mylyn.reviews-c7f0a7a7450aacf90cff60fb590c550b4cbf96d6.tar.gz
org.eclipse.mylyn.reviews-c7f0a7a7450aacf90cff60fb590c550b4cbf96d6.tar.xz
org.eclipse.mylyn.reviews-c7f0a7a7450aacf90cff60fb590c550b4cbf96d6.zip
441739: support editing inline comments when hovering over annotation
Change-Id: Id3e50568bbfb84ecfacea813d4055435415b28ca Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=441739
Diffstat (limited to 'org.eclipse.mylyn.reviews.ui/src')
-rw-r--r--org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentPopupDialog.java134
-rw-r--r--org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/Messages.java2
-rw-r--r--org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/messages.properties1
-rw-r--r--org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareAnnotationSupport.java9
4 files changed, 70 insertions, 76 deletions
diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentPopupDialog.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentPopupDialog.java
index 2302b279..d2096ed1 100644
--- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentPopupDialog.java
+++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentPopupDialog.java
@@ -18,13 +18,14 @@ import java.util.List;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.PopupDialog;
-import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.PixelConverter;
import org.eclipse.jface.text.source.LineRange;
import org.eclipse.mylyn.commons.workbench.forms.CommonFormUtil;
import org.eclipse.mylyn.internal.reviews.ui.IReviewActionListener;
import org.eclipse.mylyn.internal.reviews.ui.dialogs.CommentInputDialog;
import org.eclipse.mylyn.internal.reviews.ui.editors.parts.CommentPart;
+import org.eclipse.mylyn.reviews.core.model.ILineLocation;
+import org.eclipse.mylyn.reviews.core.model.ILocation;
import org.eclipse.mylyn.reviews.core.model.IReviewItem;
import org.eclipse.mylyn.reviews.internal.core.model.Comment;
import org.eclipse.osgi.util.NLS;
@@ -39,11 +40,12 @@ import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.forms.IFormColors;
+import org.eclipse.ui.forms.events.HyperlinkAdapter;
+import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.Hyperlink;
/**
* Popup to show the information about the annotation in
@@ -63,8 +65,6 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList
private Composite composite;
- private Label focusLabel;
-
private ScrolledComposite scrolledComposite;
private CommentInformationControl informationControl;
@@ -77,19 +77,18 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList
private CommentInputDialog currentCommentInputDialog = null;
- public final boolean isHoverActive;
+ public final boolean openDialogOnHover;
- private int lineNumber = 0;
+ private List<Comment> commentList;
public CommentPopupDialog(Shell parent, int shellStyle) {
- super(parent, shellStyle, false, false, false, false, false, null, null);
- isHoverActive = true;
-
+ this(parent, shellStyle, false, null, null);
}
- public CommentPopupDialog(Shell parent, int shellStyle, boolean bHoverActive, IReviewItem reviewitm, LineRange range) {
+ public CommentPopupDialog(Shell parent, int shellStyle, boolean openDialogOnHover, IReviewItem reviewitm,
+ LineRange range) {
super(parent, shellStyle, false, false, false, false, false, null, null);
- this.isHoverActive = bHoverActive;
+ this.openDialogOnHover = openDialogOnHover;
this.reviewitem = reviewitm;
this.range = range;
}
@@ -120,10 +119,6 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList
public void setFocus() {
getShell().forceFocus();
- if (focusLabel != null) {
- focusLabel.dispose();
- }
-
if (composite.getChildren().length > 0) {
composite.getChildren()[0].setFocus();
}
@@ -203,8 +198,22 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList
currentPopupDialog = this;
- final List<Comment> commentList = new ArrayList<Comment>();
+ commentList = new ArrayList<Comment>();
for (CommentAnnotation annotation : annotationInput.getAnnotations()) {
+ if (reviewitem == null) {
+ if (annotation.getComment().getItem() instanceof IReviewItem) {
+ reviewitem = (IReviewItem) annotation.getComment().getItem();
+ }
+ }
+ if (range == null) {
+ List<ILocation> locations = annotation.getComment().getLocations();
+ if (!locations.isEmpty()) {
+ ILocation location = locations.get(0);
+ if (location instanceof ILineLocation) {
+ range = new LineRange(((ILineLocation) location).getRangeMin(), 1);
+ }
+ }
+ }
if ((reviewitem != null)
&& reviewitem.getReview() != null
@@ -222,62 +231,59 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList
toolkit.adapt(control, true, true);
}
+ if (openDialogOnHover) {
+ composite.addMouseTrackListener(new MouseTrackAdapter() {
+ @Override
+ public void mouseEnter(MouseEvent e) {
+ openCommentDialog();
+ }
+ });
+ } else {
+ Hyperlink hyperlink = toolkit.createHyperlink(composite,
+ Messages.CommentPopupDialog_Edit_discard_or_reply, SWT.NONE);
+ hyperlink.addHyperlinkListener(new HyperlinkAdapter() {
+ @Override
+ public void linkActivated(HyperlinkEvent e) {
+ openCommentDialog();
+ }
+ });
+ }
+
composite.setBackground(toolkit.getColors().getBackground());
scrolledComposite.layout(true, true);
scrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
-
- focusLabel = toolkit.createLabel(composite, ""); //$NON-NLS-1$
- focusLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
- GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(focusLabel);
-
- focusLabel.getParent().addMouseTrackListener(mouseTrackAdapter(commentList));
-
} else {
input = null;
}
}
- private MouseTrackAdapter mouseTrackAdapter(final List<Comment> commentList) {
+ private void openCommentDialog() {
PixelConverter Pc = new PixelConverter(composite.getFont());
final int lineHeight = Pc.convertHeightInCharsToPixels(1);
- return new MouseTrackAdapter() {
-
- @Override
- public void mouseEnter(MouseEvent e) {
- if (!isHoverActive && currentCommentInputDialog == null) {
-
- Point size = getShell().getSize();
- dispose();
- Shell ashell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
-
- currentCommentInputDialog = new CommentInputDialog(ashell, annotationInput.getBehavior(),
- reviewitem, range);
-
- currentCommentInputDialog.setComments(commentList);
- currentCommentInputDialog.create();
- currentCommentInputDialog.getShell().setText(
- NLS.bind(Messages.CommentInputDialog_LineNumber, getLineNumber(),
- new Path(reviewitem.getName()).lastSegment()));
-
- // adjust size to display maximum of 15 lines, which means 5 comments
- if (annotationInput.getAnnotations().size() < 5) {
- size.y = size.y + (annotationInput.getAnnotations().size() * 3 * lineHeight);
- } else {
- size.y = size.y + (15 * lineHeight);
- }
- currentCommentInputDialog.getShell().setSize(size);
- currentCommentInputDialog.open();
-
- }
+ if (range != null && reviewitem != null && currentCommentInputDialog == null) {
+ dispose();
+ Shell ashell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
+
+ currentCommentInputDialog = new CommentInputDialog(ashell, annotationInput.getBehavior(), reviewitem, range);
+
+ currentCommentInputDialog.setComments(commentList);
+ currentCommentInputDialog.create();
+ currentCommentInputDialog.getShell().setText(
+ NLS.bind(Messages.CommentInputDialog_LineNumber, range.getStartLine(),
+ new Path(reviewitem.getName()).lastSegment()));
+
+ // adjust size to display maximum of 15 lines, which means 5 comments
+ Point size = new Point(550, 150);
+ if (annotationInput.getAnnotations().size() < 5) {
+ size.y = size.y + (annotationInput.getAnnotations().size() * 3 * lineHeight);
+ } else {
+ size.y = size.y + (15 * lineHeight);
}
-
- @Override
- public void mouseExit(MouseEvent e) {
- //ignore
- };
- };
+ currentCommentInputDialog.getShell().setSize(size);
+ currentCommentInputDialog.open();
+ }
}
public void actionAboutToRun(Action action) {
@@ -300,12 +306,4 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList
return informationControl;
}
- public void setLineNumber(int lineOfOffset) {
- lineNumber = lineOfOffset + 1;
- }
-
- public int getLineNumber() {
- return lineNumber;
- }
-
}
diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/Messages.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/Messages.java
index ddfea557..98b44325 100644
--- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/Messages.java
+++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/Messages.java
@@ -22,6 +22,8 @@ public class Messages extends NLS {
public static String CommentInputDialog_LineNumber;
+ public static String CommentPopupDialog_Edit_discard_or_reply;
+
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/messages.properties b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/messages.properties
index 9e49b73a..dc6ef242 100644
--- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/messages.properties
+++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/messages.properties
@@ -12,3 +12,4 @@ CommentAnnotation_X_dash_Y={0} - {1}
CommentAnnotationHover_Multiple_comments=There are multiple comments on this line
CommentInputDialog_LineNumber=Comments for line {0} of {1}
+CommentPopupDialog_Edit_discard_or_reply=Edit, discard, or reply
diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareAnnotationSupport.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareAnnotationSupport.java
index d25153b6..0b876cc9 100644
--- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareAnnotationSupport.java
+++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareAnnotationSupport.java
@@ -321,12 +321,6 @@ public class ReviewCompareAnnotationSupport {
private void selectAndReveal(MergeSourceViewer sourceViewer, Position position) {
StyledText widget = sourceViewer.getSourceViewer().getTextWidget();
widget.setRedraw(false);
- int currentLineNumber = 0;
- try {
- currentLineNumber = sourceViewer.getSourceViewer().getDocument().getLineOfOffset(position.getOffset());
- } catch (BadLocationException e1) {
- StatusHandler.log(new Status(IStatus.ERROR, ReviewsUiPlugin.PLUGIN_ID, "Error displaying comment", e1)); //$NON-NLS-1$
- }
adjustHighlightRange(sourceViewer.getSourceViewer(), position.offset, position.length);
sourceViewer.getSourceViewer().revealRange(position.offset, position.length);
sourceViewer.getSourceViewer().setSelectedRange(position.offset, position.length);
@@ -356,12 +350,11 @@ public class ReviewCompareAnnotationSupport {
commentPopupDialog = new CommentPopupDialog(ReviewsUiPlugin.getDefault()
.getWorkbench()
.getActiveWorkbenchWindow()
- .getShell(), SWT.NO_FOCUS | SWT.ON_TOP, false, reviewitem, range);
+ .getShell(), SWT.NO_FOCUS | SWT.ON_TOP, true, reviewitem, range);
CommentAnnotationHoverInput input = new CommentAnnotationHoverInput(comments,
((ReviewAnnotationModel) srcViewer.getAnnotationModel()).getBehavior());
commentPopupDialog.create();
commentPopupDialog.setInput(input);
- commentPopupDialog.setLineNumber(currentLineNumber);
commentPopupDialog.setSize(50, 150);
Point location = sourceViewer.getSourceViewer().getControl().getLocation();

Back to the top