summaryrefslogtreecommitdiffstats
path: root/webapp
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2008-12-19 18:58:39 -0800
committerShawn O. Pearce <sop@google.com>2008-12-19 18:58:39 -0800
commit91b1f7187a0696e83ef8b6dd3d9c61004beedf13 (patch)
treed07dddcbfddd2a106bc124a57d07f838198164d9 /webapp
parentf1f00d5a6c6ae35e1dc334884e4589ea3f117463 (diff)
Insert a new comment editor when a patch line is double clicked
The editor currently doesn't save state, but it does insert into the UI and the Cancel button removes it from the UI. Signed-off-by: Shawn O. Pearce <sop@google.com>
Diffstat (limited to 'webapp')
-rw-r--r--webapp/src/com/google/gerrit/client/patches/AbstractPatchContentTable.java87
-rw-r--r--webapp/src/com/google/gerrit/client/patches/CommentEditorPanel.java58
-rw-r--r--webapp/src/com/google/gerrit/client/patches/PatchUnifiedScreen.java1
-rw-r--r--webapp/src/com/google/gerrit/client/patches/SideBySideTable.java28
-rw-r--r--webapp/src/com/google/gerrit/client/patches/UnifiedDiffTable.java16
-rw-r--r--webapp/src/com/google/gerrit/client/reviewdb/PatchLineComment.java1
-rw-r--r--webapp/src/com/google/gerrit/client/ui/FancyFlexTable.java6
7 files changed, 194 insertions, 3 deletions
diff --git a/webapp/src/com/google/gerrit/client/patches/AbstractPatchContentTable.java b/webapp/src/com/google/gerrit/client/patches/AbstractPatchContentTable.java
index 86d3d836f0..177f888700 100644
--- a/webapp/src/com/google/gerrit/client/patches/AbstractPatchContentTable.java
+++ b/webapp/src/com/google/gerrit/client/patches/AbstractPatchContentTable.java
@@ -15,13 +15,20 @@
package com.google.gerrit.client.patches;
import com.google.gerrit.client.FormatUtil;
+import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.changes.Util;
import com.google.gerrit.client.data.AccountInfoCache;
+import com.google.gerrit.client.reviewdb.Patch;
import com.google.gerrit.client.reviewdb.PatchLineComment;
import com.google.gerrit.client.ui.ComplexDisclosurePanel;
import com.google.gerrit.client.ui.FancyFlexTable;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Element;
+import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
+import com.google.gwtjsonrpc.client.VoidResult;
import java.sql.Timestamp;
import java.util.ArrayList;
@@ -30,6 +37,7 @@ import java.util.List;
public abstract class AbstractPatchContentTable extends FancyFlexTable<Object> {
private static final long AGE = 7 * 24 * 60 * 60 * 1000L;
protected AccountInfoCache accountCache = AccountInfoCache.empty();
+ protected Patch.Id patchKey;
private final Timestamp aged =
new Timestamp(System.currentTimeMillis() - AGE);
@@ -38,10 +46,58 @@ public abstract class AbstractPatchContentTable extends FancyFlexTable<Object> {
}
@Override
+ protected MyFlexTable createFlexTable() {
+ return new DoubleClickFlexTable();
+ }
+
+ @Override
protected Object getRowItemKey(final Object item) {
return null;
}
+ /** Invoked when the user clicks on a table cell. */
+ protected abstract void onCellDoubleClick(int row, int column);
+
+ protected PatchLineComment newComment(final int line, final short side) {
+ final PatchLineComment r =
+ new PatchLineComment(new PatchLineComment.Id(patchKey, "blargh"), line,
+ Gerrit.getUserAccount().getId());
+ r.setSide(side);
+ r.setMessage("");
+ return r;
+ }
+
+ protected void createCommentEditor(final int row, final int column,
+ final int line, final short side) {
+ if (!Gerrit.isSignedIn()) {
+ Gerrit.doSignIn(new AsyncCallback<VoidResult>() {
+ public void onSuccess(final VoidResult result) {
+ createCommentEditor(row, column, line, side);
+ }
+
+ public void onFailure(Throwable caught) {
+ }
+ });
+ return;
+ }
+
+ final PatchLineComment newComment = newComment(line, side);
+ table.insertRow(row);
+ table.setWidget(row, column, new CommentEditorPanel(newComment) {
+ @Override
+ void onCancel() {
+ final int n = table.getRowCount();
+ for (int i = 0; i < n; i++) {
+ if (column < table.getCellCount(i)
+ && table.getWidget(i, column) == this) {
+ table.removeRow(i);
+ break;
+ }
+ }
+ }
+ });
+ }
+
@Override
protected void onOpenItem(final Object item) {
if (item instanceof CommentList) {
@@ -56,6 +112,10 @@ public abstract class AbstractPatchContentTable extends FancyFlexTable<Object> {
accountCache = aic;
}
+ public void setPatchKey(final Patch.Id id) {
+ patchKey = id;
+ }
+
protected void bindComment(final int row, final int col,
final PatchLineComment line, final boolean isLast) {
final LineCommentPanel mp = new LineCommentPanel(line);
@@ -104,4 +164,31 @@ public abstract class AbstractPatchContentTable extends FancyFlexTable<Object> {
final List<ComplexDisclosurePanel> panels =
new ArrayList<ComplexDisclosurePanel>();
}
+
+ protected class DoubleClickFlexTable extends MyFlexTable {
+ public DoubleClickFlexTable() {
+ sinkEvents(Event.ONDBLCLICK);
+ }
+
+ @Override
+ public void onBrowserEvent(final Event event) {
+ switch (DOM.eventGetType(event)) {
+ case Event.ONDBLCLICK: {
+ // Find out which cell was actually clicked.
+ Element td = getEventTargetCell(event);
+ if (td == null) {
+ return;
+ }
+ Element tr = DOM.getParent(td);
+ Element body = DOM.getParent(tr);
+ int row = DOM.getChildIndex(body, tr);
+ int column = DOM.getChildIndex(tr, td);
+ onCellDoubleClick(row, column);
+ break;
+ }
+ default:
+ super.onBrowserEvent(event);
+ }
+ }
+ }
}
diff --git a/webapp/src/com/google/gerrit/client/patches/CommentEditorPanel.java b/webapp/src/com/google/gerrit/client/patches/CommentEditorPanel.java
new file mode 100644
index 0000000000..b05484cfca
--- /dev/null
+++ b/webapp/src/com/google/gerrit/client/patches/CommentEditorPanel.java
@@ -0,0 +1,58 @@
+package com.google.gerrit.client.patches;
+
+import com.google.gerrit.client.reviewdb.PatchLineComment;
+import com.google.gwt.user.client.ui.Button;
+import com.google.gwt.user.client.ui.ClickListener;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.FlowPanel;
+import com.google.gwt.user.client.ui.TextArea;
+import com.google.gwt.user.client.ui.Widget;
+
+public class CommentEditorPanel extends Composite implements ClickListener {
+ private final PatchLineComment comment;
+ private final TextArea text;
+ private final Button save;
+ private final Button cancel;
+
+ public CommentEditorPanel(final PatchLineComment plc) {
+ comment = plc;
+
+ final FlowPanel body = new FlowPanel();
+ body.setStyleName("gerrit-CommentEditor");
+
+ text = new TextArea();
+ text.setCharacterWidth(60);
+ text.setVisibleLines(5);
+ body.add(text);
+
+ final FlowPanel buttons = new FlowPanel();
+ buttons.setStyleName("gerrit-CommentEditor-Buttons");
+ body.add(buttons);
+
+ save = new Button();
+ save.setText("Save");
+ save.addClickListener(this);
+ buttons.add(save);
+
+ cancel = new Button();
+ cancel.setText("Cancel");
+ cancel.addClickListener(this);
+ buttons.add(cancel);
+
+ initWidget(body);
+ }
+
+ public void onClick(Widget sender) {
+ if (sender == save) {
+ onSave();
+ } else if (sender == cancel) {
+ onCancel();
+ }
+ }
+
+ void onSave() {
+ }
+
+ void onCancel() {
+ }
+}
diff --git a/webapp/src/com/google/gerrit/client/patches/PatchUnifiedScreen.java b/webapp/src/com/google/gerrit/client/patches/PatchUnifiedScreen.java
index 5bf750908e..d95d0d5527 100644
--- a/webapp/src/com/google/gerrit/client/patches/PatchUnifiedScreen.java
+++ b/webapp/src/com/google/gerrit/client/patches/PatchUnifiedScreen.java
@@ -50,6 +50,7 @@ public class PatchUnifiedScreen extends PatchScreen {
}
private void display(final UnifiedPatchDetail detail) {
+ diffTable.setPatchKey(detail.getPatch().getKey());
diffTable.setAccountInfoCache(detail.getAccounts());
diffTable.display(detail.getLines());
}
diff --git a/webapp/src/com/google/gerrit/client/patches/SideBySideTable.java b/webapp/src/com/google/gerrit/client/patches/SideBySideTable.java
index ef73afa69a..ce68081e6c 100644
--- a/webapp/src/com/google/gerrit/client/patches/SideBySideTable.java
+++ b/webapp/src/com/google/gerrit/client/patches/SideBySideTable.java
@@ -28,8 +28,26 @@ public class SideBySideTable extends AbstractPatchContentTable {
private int fileCnt;
private int maxLineNumber;
+ @Override
+ protected void onCellDoubleClick(final int row, final int column) {
+ if (column > 1 && getRowItem(row) instanceof SideBySideLineList) {
+ final SideBySideLineList pl = (SideBySideLineList) getRowItem(row);
+ final short file = (short) ((column - 1) / 2);
+ final SideBySideLine line = pl.lines.get(file);
+ switch (line.getType()) {
+ case DELETE:
+ case EQUAL:
+ case INSERT: {
+ createCommentEditor(row + 1, column, line.getLineNumber(), file);
+ break;
+ }
+ }
+ }
+ }
+
public void display(final SideBySidePatchDetail detail) {
setAccountInfoCache(detail.getAccounts());
+ setPatchKey(detail.getPatch().getKey());
fileCnt = detail.getFileCount();
maxLineNumber = detail.getLineCount();
@@ -67,7 +85,7 @@ public class SideBySideTable extends AbstractPatchContentTable {
}
prior = pLine;
- setRowItem(row, pLine);
+ setRowItem(row, new SideBySideLineList(pLine));
int nextComment = row;
int lastComment = row;
@@ -226,4 +244,12 @@ public class SideBySideTable extends AbstractPatchContentTable {
nc.append("</tr>");
}
+
+ private static class SideBySideLineList {
+ final List<SideBySideLine> lines;
+
+ SideBySideLineList(final List<SideBySideLine> a) {
+ lines = a;
+ }
+ }
}
diff --git a/webapp/src/com/google/gerrit/client/patches/UnifiedDiffTable.java b/webapp/src/com/google/gerrit/client/patches/UnifiedDiffTable.java
index 5371d87165..b522e1538f 100644
--- a/webapp/src/com/google/gerrit/client/patches/UnifiedDiffTable.java
+++ b/webapp/src/com/google/gerrit/client/patches/UnifiedDiffTable.java
@@ -21,6 +21,22 @@ import java.util.Iterator;
import java.util.List;
public class UnifiedDiffTable extends AbstractPatchContentTable {
+ @Override
+ protected void onCellDoubleClick(final int row, final int column) {
+ if (column == 1 && getRowItem(row) instanceof PatchLine) {
+ final PatchLine pl = (PatchLine) getRowItem(row);
+ switch (pl.getType()) {
+ case PRE_IMAGE:
+ case CONTEXT:
+ createCommentEditor(row + 1, column, pl.getOldLineNumber(), (short) 0);
+ break;
+ case POST_IMAGE:
+ createCommentEditor(row + 1, column, pl.getOldLineNumber(), (short) 1);
+ break;
+ }
+ }
+ }
+
public void display(final List<PatchLine> list) {
final StringBuilder nc = new StringBuilder();
for (final PatchLine pLine : list) {
diff --git a/webapp/src/com/google/gerrit/client/reviewdb/PatchLineComment.java b/webapp/src/com/google/gerrit/client/reviewdb/PatchLineComment.java
index 3799c4d21c..f6a362662e 100644
--- a/webapp/src/com/google/gerrit/client/reviewdb/PatchLineComment.java
+++ b/webapp/src/com/google/gerrit/client/reviewdb/PatchLineComment.java
@@ -113,7 +113,6 @@ public final class PatchLineComment {
author = a;
writtenOn = new Timestamp(System.currentTimeMillis());
setStatus(Status.DRAFT);
- setSide((short) 1);
}
public PatchLineComment.Id getKey() {
diff --git a/webapp/src/com/google/gerrit/client/ui/FancyFlexTable.java b/webapp/src/com/google/gerrit/client/ui/FancyFlexTable.java
index 7a5b0e21a3..0530f8962b 100644
--- a/webapp/src/com/google/gerrit/client/ui/FancyFlexTable.java
+++ b/webapp/src/com/google/gerrit/client/ui/FancyFlexTable.java
@@ -60,7 +60,7 @@ public abstract class FancyFlexTable<RowItem> extends Composite implements
protected FancyFlexTable() {
pointer = Gerrit.ICONS.arrowRight().createImage();
- table = new MyFlexTable();
+ table = createFlexTable();
table.addStyleName(MY_STYLE);
focusy = new FocusPanel(table);
focusy.addKeyboardListener(new KeyboardListenerAdapter() {
@@ -89,6 +89,10 @@ public abstract class FancyFlexTable<RowItem> extends Composite implements
table.getCellFormatter().addStyleName(0, C_ARROW, S_ICON_HEADER);
}
+ protected MyFlexTable createFlexTable() {
+ return new MyFlexTable();
+ }
+
protected RowItem getRowItem(final int row) {
return FancyFlexTable.<RowItem> getRowItem(table.getCellFormatter()
.getElement(row, 0));