InlineEdit: Allow restoring of files in change edit

New undo edit icon from tango.freedesktop theme (PD) is used [1].

[1] https://www.iconfinder.com/icons/15282/edit_undo_icon#size=16

Change-Id: I32b374c3e6fbc75f5c02fc5512ddb984d5eb78c8
This commit is contained in:
David Ostrovsky
2013-12-20 21:02:59 +01:00
parent 7195aaa52a
commit 59e558f737
5 changed files with 47 additions and 9 deletions

View File

@@ -49,6 +49,9 @@ public interface GerritResources extends ClientBundle {
@Source("redNot.png")
public ImageResource redNot();
@Source("editUndo.png")
public ImageResource editUndo();
@Source("downloadIcon.png")
public ImageResource downloadIcon();

View File

@@ -23,6 +23,7 @@ interface ChangeConstants extends Constants {
String reviewedFileTitle();
String editFileInline();
String removeFileInline();
String restoreFileInline();
String openLastFile();
String openCommitMessage();

View File

@@ -4,6 +4,7 @@ openChange = Open related change
reviewedFileTitle = Mark file as reviewed (Shortcut: r)
editFileInline = Edit file inline
removeFileInline = Remove file inline
restoreFileInline = Restore file inline
openLastFile = Open last file
openCommitMessage = Open commit message

View File

@@ -99,6 +99,7 @@ class FileTable extends FlowPanel {
private static final String DELETE;
private static final String EDIT;
private static final String RESTORE;
private static final String REVIEWED;
private static final String OPEN;
private static final int C_PATH = 3;
@@ -107,18 +108,22 @@ class FileTable extends FlowPanel {
static {
DELETE = DOM.createUniqueId().replace('-', '_');
EDIT = DOM.createUniqueId().replace('-', '_');
RESTORE = DOM.createUniqueId().replace('-', '_');
REVIEWED = DOM.createUniqueId().replace('-', '_');
OPEN = DOM.createUniqueId().replace('-', '_');
init(DELETE, EDIT, REVIEWED, OPEN);
init(DELETE, EDIT, RESTORE, REVIEWED, OPEN);
}
private static final native void init(String d, String e, String r, String o) /*-{
private static final native void init(String d, String e, String t, String r, String o) /*-{
$wnd[d] = $entry(function(e,i) {
@com.google.gerrit.client.change.FileTable::onDelete(Lcom/google/gwt/dom/client/NativeEvent;I)(e,i)
});
$wnd[e] = $entry(function(e,i) {
@com.google.gerrit.client.change.FileTable::onEdit(Lcom/google/gwt/dom/client/NativeEvent;I)(e,i)
});
$wnd[t] = $entry(function(e,i) {
@com.google.gerrit.client.change.FileTable::onRestore(Lcom/google/gwt/dom/client/NativeEvent;I)(e,i)
});
$wnd[r] = $entry(function(e,i) {
@com.google.gerrit.client.change.FileTable::onReviewed(Lcom/google/gwt/dom/client/NativeEvent;I)(e,i)
});
@@ -141,6 +146,13 @@ class FileTable extends FlowPanel {
}
}
private static void onRestore(NativeEvent e, int idx) {
MyTable t = getMyTable(e);
if (t != null) {
t.onRestore(idx);
}
}
private static void onReviewed(NativeEvent e, int idx) {
MyTable t = getMyTable(e);
if (t != null) {
@@ -324,7 +336,7 @@ class FileTable extends FlowPanel {
}
void onDelete(int idx) {
final String path = list.get(idx).path();
String path = list.get(idx).path();
ChangeFileApi.deleteContent(curr, path,
new AsyncCallback<VoidResult>() {
@Override
@@ -338,6 +350,21 @@ class FileTable extends FlowPanel {
});
}
void onRestore(int idx) {
String path = list.get(idx).path();
ChangeFileApi.restoreContent(curr, path,
new AsyncCallback<VoidResult>() {
@Override
public void onSuccess(VoidResult result) {
Gerrit.display(PageLinks.toChange(curr.getParentKey()));
}
@Override
public void onFailure(Throwable caught) {
}
});
}
void onReviewed(InputElement checkbox, int idx) {
setReviewed(list.get(idx), checkbox.isChecked());
}
@@ -556,7 +583,7 @@ class FileTable extends FlowPanel {
columnReviewed(sb, info);
} else {
columnEdit(sb, info);
columnRemove(sb, info);
columnDeleteRestore(sb, info);
}
columnStatus(sb, info);
columnPath(sb, info);
@@ -592,14 +619,20 @@ class FileTable extends FlowPanel {
sb.closeTd();
}
private void columnRemove(SafeHtmlBuilder sb, FileInfo info) {
private void columnDeleteRestore(SafeHtmlBuilder sb, FileInfo info) {
sb.openTd().setStyleName(R.css().removeButton());
if (hasUser && isEditable(info)) {
if (hasUser) {
if (!Patch.COMMIT_MSG.equals(info.path())) {
boolean editable = isEditable(info);
sb.openElement("button")
.setAttribute("title", Resources.C.removeFileInline())
.setAttribute("onclick", DELETE + "(event," + info._row() + ")")
.append(new ImageResourceRenderer().render(Gerrit.RESOURCES.redNot()))
.setAttribute("title", editable
? Resources.C.removeFileInline()
: Resources.C.restoreFileInline())
.setAttribute("onclick", (editable ? DELETE : RESTORE)
+ "(event," + info._row() + ")")
.append(new ImageResourceRenderer().render(editable
? Gerrit.RESOURCES.redNot()
: Gerrit.RESOURCES.editUndo()))
.closeElement("button");
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 810 B