SideBySide2: Add NavLinks2
Implementing a new NavLinks. The current implementation is simple and hasn't taken care of PatchValidator yet. Added sortFileInfoByPath() to FileInfo. Change-Id: Ia3e07c613abff391533508f2d553f6b720d9f0db
This commit is contained in:
@@ -23,7 +23,6 @@ import com.google.gerrit.client.diff.FileInfo;
|
|||||||
import com.google.gerrit.client.patches.PatchUtil;
|
import com.google.gerrit.client.patches.PatchUtil;
|
||||||
import com.google.gerrit.client.rpc.CallbackGroup;
|
import com.google.gerrit.client.rpc.CallbackGroup;
|
||||||
import com.google.gerrit.client.rpc.NativeMap;
|
import com.google.gerrit.client.rpc.NativeMap;
|
||||||
import com.google.gerrit.client.rpc.Natives;
|
|
||||||
import com.google.gerrit.client.rpc.RestApi;
|
import com.google.gerrit.client.rpc.RestApi;
|
||||||
import com.google.gerrit.client.ui.NavigationTable;
|
import com.google.gerrit.client.ui.NavigationTable;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
@@ -53,8 +52,6 @@ import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder;
|
|||||||
import com.google.gwtorm.client.KeyUtil;
|
import com.google.gwtorm.client.KeyUtil;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
|
|
||||||
class FileTable extends FlowPanel {
|
class FileTable extends FlowPanel {
|
||||||
static final FileTableResources R = GWT
|
static final FileTableResources R = GWT
|
||||||
@@ -150,17 +147,7 @@ class FileTable extends FlowPanel {
|
|||||||
NativeMap<JsArray<CommentInfo>> comments,
|
NativeMap<JsArray<CommentInfo>> comments,
|
||||||
NativeMap<JsArray<CommentInfo>> drafts) {
|
NativeMap<JsArray<CommentInfo>> drafts) {
|
||||||
JsArray<FileInfo> list = fileMap.values();
|
JsArray<FileInfo> list = fileMap.values();
|
||||||
Collections.sort(Natives.asList(list), new Comparator<FileInfo>() {
|
FileInfo.sortFileInfoByPath(list);
|
||||||
@Override
|
|
||||||
public int compare(FileInfo a, FileInfo b) {
|
|
||||||
if (Patch.COMMIT_MSG.equals(a.path())) {
|
|
||||||
return -1;
|
|
||||||
} else if (Patch.COMMIT_MSG.equals(b.path())) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return a.path().compareTo(b.path());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
DisplayCommand cmd = new DisplayCommand(fileMap, list,
|
DisplayCommand cmd = new DisplayCommand(fileMap, list,
|
||||||
myLastReply, comments, drafts);
|
myLastReply, comments, drafts);
|
||||||
|
|||||||
@@ -14,7 +14,13 @@
|
|||||||
|
|
||||||
package com.google.gerrit.client.diff;
|
package com.google.gerrit.client.diff;
|
||||||
|
|
||||||
|
import com.google.gerrit.client.rpc.Natives;
|
||||||
|
import com.google.gerrit.reviewdb.client.Patch;
|
||||||
import com.google.gwt.core.client.JavaScriptObject;
|
import com.google.gwt.core.client.JavaScriptObject;
|
||||||
|
import com.google.gwt.core.client.JsArray;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
public class FileInfo extends JavaScriptObject {
|
public class FileInfo extends JavaScriptObject {
|
||||||
public final native String path() /*-{ return this.path; }-*/;
|
public final native String path() /*-{ return this.path; }-*/;
|
||||||
@@ -26,6 +32,20 @@ public class FileInfo extends JavaScriptObject {
|
|||||||
public final native int _row() /*-{ return this._row }-*/;
|
public final native int _row() /*-{ return this._row }-*/;
|
||||||
public final native void _row(int r) /*-{ this._row = r }-*/;
|
public final native void _row(int r) /*-{ this._row = r }-*/;
|
||||||
|
|
||||||
|
public static void sortFileInfoByPath(JsArray<FileInfo> list) {
|
||||||
|
Collections.sort(Natives.asList(list), new Comparator<FileInfo>() {
|
||||||
|
@Override
|
||||||
|
public int compare(FileInfo a, FileInfo b) {
|
||||||
|
if (Patch.COMMIT_MSG.equals(a.path())) {
|
||||||
|
return -1;
|
||||||
|
} else if (Patch.COMMIT_MSG.equals(b.path())) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return a.path().compareTo(b.path());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
protected FileInfo() {
|
protected FileInfo() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,128 @@
|
|||||||
|
// Copyright (C) 2010 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package com.google.gerrit.client.diff;
|
||||||
|
|
||||||
|
import com.google.gerrit.client.Gerrit;
|
||||||
|
import com.google.gerrit.client.changes.ChangeApi;
|
||||||
|
import com.google.gerrit.client.changes.Util;
|
||||||
|
import com.google.gerrit.client.patches.PatchUtil;
|
||||||
|
import com.google.gerrit.client.rpc.GerritCallback;
|
||||||
|
import com.google.gerrit.client.rpc.NativeMap;
|
||||||
|
import com.google.gerrit.client.ui.InlineHyperlink;
|
||||||
|
import com.google.gerrit.common.PageLinks;
|
||||||
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
|
import com.google.gerrit.reviewdb.client.Patch;
|
||||||
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
|
import com.google.gwt.core.client.GWT;
|
||||||
|
import com.google.gwt.core.client.JsArray;
|
||||||
|
import com.google.gwt.event.dom.client.KeyPressEvent;
|
||||||
|
import com.google.gwt.uibinder.client.UiBinder;
|
||||||
|
import com.google.gwt.uibinder.client.UiField;
|
||||||
|
import com.google.gwt.user.client.ui.Composite;
|
||||||
|
import com.google.gwt.user.client.ui.HTMLPanel;
|
||||||
|
import com.google.gwtexpui.globalkey.client.KeyCommand;
|
||||||
|
import com.google.gwtexpui.globalkey.client.KeyCommandSet;
|
||||||
|
import com.google.gwtexpui.safehtml.client.SafeHtml;
|
||||||
|
import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder;
|
||||||
|
import com.google.gwtorm.client.KeyUtil;
|
||||||
|
|
||||||
|
class NavLinks2 extends Composite {
|
||||||
|
interface Binder extends UiBinder<HTMLPanel, NavLinks2> {}
|
||||||
|
private static final Binder uiBinder = GWT.create(Binder.class);
|
||||||
|
|
||||||
|
@UiField InlineHyperlink prevLink;
|
||||||
|
@UiField InlineHyperlink nextLink;
|
||||||
|
@UiField InlineHyperlink upLink;
|
||||||
|
|
||||||
|
private final KeyCommandSet keys;
|
||||||
|
private final PatchSet.Id patchSetId;
|
||||||
|
private final String path;
|
||||||
|
|
||||||
|
NavLinks2(KeyCommandSet keys, PatchSet.Id patchSetId, String path) {
|
||||||
|
initWidget(uiBinder.createAndBindUi(this));
|
||||||
|
this.keys = keys;
|
||||||
|
this.patchSetId = patchSetId;
|
||||||
|
this.path = path;
|
||||||
|
upLink.setTargetHistoryToken(PageLinks.toChange2(
|
||||||
|
patchSetId.getParentKey(),
|
||||||
|
String.valueOf(patchSetId.get())));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLoad() {
|
||||||
|
ChangeApi.revision(patchSetId).view("files").get(
|
||||||
|
new GerritCallback<NativeMap<FileInfo>>() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(NativeMap<FileInfo> result) {
|
||||||
|
result.copyKeysIntoChildren("path");
|
||||||
|
JsArray<FileInfo> files = result.values();
|
||||||
|
FileInfo.sortFileInfoByPath(files);
|
||||||
|
int index = 0; // TODO: Maybe use patchIndex.
|
||||||
|
for (int i = 0; i < files.length(); i++) {
|
||||||
|
if (path.equals(files.get(i).path())) {
|
||||||
|
index = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setupNav('[', PatchUtil.C.previousFileHelp(),
|
||||||
|
index == 0 ? null : files.get(index - 1));
|
||||||
|
setupNav(']', PatchUtil.C.nextFileHelp(),
|
||||||
|
index == files.length() - 1 ? null : files.get(index + 1));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private String url(FileInfo info) {
|
||||||
|
Change.Id c = patchSetId.getParentKey();
|
||||||
|
StringBuilder p = new StringBuilder();
|
||||||
|
p.append("/c/").append(c).append('/');
|
||||||
|
p.append(patchSetId.get()).append('/').append(KeyUtil.encode(info.path()));
|
||||||
|
p.append(info.binary() ? ",unified" : ",cm");
|
||||||
|
return p.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupNav(int key, String help, FileInfo info) {
|
||||||
|
if (info != null) {
|
||||||
|
final String url = url(info);
|
||||||
|
String fileName = getFileNameOnly(info.path());
|
||||||
|
if (key == '[') {
|
||||||
|
prevLink.setTargetHistoryToken(url);
|
||||||
|
prevLink.setHTML(new SafeHtmlBuilder()
|
||||||
|
.append(SafeHtml.asis(Util.C.prevPatchLinkIcon()))
|
||||||
|
.append(fileName));
|
||||||
|
} else {
|
||||||
|
nextLink.setTargetHistoryToken(url);
|
||||||
|
nextLink.setHTML(new SafeHtmlBuilder()
|
||||||
|
.append(fileName)
|
||||||
|
.append(SafeHtml.asis(Util.C.nextPatchLinkIcon())));
|
||||||
|
}
|
||||||
|
keys.add(new KeyCommand(0, key, help) {
|
||||||
|
@Override
|
||||||
|
public void onKeyPress(KeyPressEvent event) {
|
||||||
|
Gerrit.display(url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
keys.add(new UpToChangeCommand2(patchSetId, 0, key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getFileNameOnly(String path) {
|
||||||
|
String fileName = Patch.COMMIT_MSG.equals(path)
|
||||||
|
? Util.C.commitMessage()
|
||||||
|
: path;
|
||||||
|
int s = fileName.lastIndexOf('/');
|
||||||
|
return s >= 0 ? fileName.substring(s + 1) : fileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2013 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
<ui:UiBinder
|
||||||
|
xmlns:ui='urn:ui:com.google.gwt.uibinder'
|
||||||
|
xmlns:g='urn:import:com.google.gwt.user.client.ui'
|
||||||
|
xmlns:ge='urn:import:com.google.gerrit.client.ui'>
|
||||||
|
<ui:style>
|
||||||
|
.table {
|
||||||
|
table-layout: fixed;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.prev {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
.up {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.next {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
</ui:style>
|
||||||
|
<g:HTMLPanel>
|
||||||
|
<table ui:field='table' class='{style.table}'>
|
||||||
|
<tr>
|
||||||
|
<td class='{style.prev}'>
|
||||||
|
<ge:InlineHyperlink ui:field='prevLink'/>
|
||||||
|
</td>
|
||||||
|
<td class='{style.up}'>
|
||||||
|
<ge:InlineHyperlink ui:field='upLink'>
|
||||||
|
<ui:msg>⇧Up to change</ui:msg>
|
||||||
|
</ge:InlineHyperlink>
|
||||||
|
</td>
|
||||||
|
<td class='{style.next}'>
|
||||||
|
<ge:InlineHyperlink ui:field='nextLink'/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</g:HTMLPanel>
|
||||||
|
</ui:UiBinder>
|
||||||
@@ -94,6 +94,9 @@ public class SideBySide2 extends Screen {
|
|||||||
@UiField(provided = true)
|
@UiField(provided = true)
|
||||||
ReviewedPanel reviewed;
|
ReviewedPanel reviewed;
|
||||||
|
|
||||||
|
@UiField(provided = true)
|
||||||
|
NavLinks2 navLinks;
|
||||||
|
|
||||||
@UiField(provided = true)
|
@UiField(provided = true)
|
||||||
DiffTable diffTable;
|
DiffTable diffTable;
|
||||||
|
|
||||||
@@ -137,6 +140,8 @@ public class SideBySide2 extends Screen {
|
|||||||
// TODO: Re-implement necessary GlobalKey bindings.
|
// TODO: Re-implement necessary GlobalKey bindings.
|
||||||
addDomHandler(GlobalKey.STOP_PROPAGATION, KeyPressEvent.getType());
|
addDomHandler(GlobalKey.STOP_PROPAGATION, KeyPressEvent.getType());
|
||||||
reviewed = new ReviewedPanel(revision, path);
|
reviewed = new ReviewedPanel(revision, path);
|
||||||
|
keysNavigation = new KeyCommandSet(Gerrit.C.sectionNavigation());
|
||||||
|
add(navLinks = new NavLinks2(keysNavigation, revision, path));
|
||||||
add(diffTable = new DiffTable(this, path));
|
add(diffTable = new DiffTable(this, path));
|
||||||
add(uiBinder.createAndBindUi(this));
|
add(uiBinder.createAndBindUi(this));
|
||||||
}
|
}
|
||||||
@@ -276,13 +281,7 @@ public class SideBySide2 extends Screen {
|
|||||||
public void registerKeys() {
|
public void registerKeys() {
|
||||||
super.registerKeys();
|
super.registerKeys();
|
||||||
|
|
||||||
keysNavigation = new KeyCommandSet(Gerrit.C.sectionNavigation());
|
keysNavigation.add(new UpToChangeCommand2(revision, 0, 'u'));
|
||||||
keysNavigation.add(new KeyCommand(0, 'u', PatchUtil.C.upToChange()) {
|
|
||||||
@Override
|
|
||||||
public void onKeyPress(KeyPressEvent event) {
|
|
||||||
upToChange().run();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
keysNavigation.add(new NoOpKeyCommand(0, 'j', PatchUtil.C.lineNext()));
|
keysNavigation.add(new NoOpKeyCommand(0, 'j', PatchUtil.C.lineNext()));
|
||||||
keysNavigation.add(new NoOpKeyCommand(0, 'k', PatchUtil.C.linePrev()));
|
keysNavigation.add(new NoOpKeyCommand(0, 'k', PatchUtil.C.linePrev()));
|
||||||
|
|
||||||
@@ -1029,7 +1028,7 @@ public class SideBySide2 extends Screen {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int h = Gerrit.getHeaderFooterHeight() + reviewed.getOffsetHeight() +
|
int h = Gerrit.getHeaderFooterHeight() + reviewed.getOffsetHeight() +
|
||||||
diffTable.getHeaderHeight() + 10; // Estimate
|
navLinks.getOffsetHeight() + diffTable.getHeaderHeight() + 10; // Estimate
|
||||||
cmA.setHeight(Window.getClientHeight() - h);
|
cmA.setHeight(Window.getClientHeight() - h);
|
||||||
cmA.refresh();
|
cmA.refresh();
|
||||||
cmB.setHeight(Window.getClientHeight() - h);
|
cmB.setHeight(Window.getClientHeight() - h);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ limitations under the License.
|
|||||||
xmlns:d='urn:import:com.google.gerrit.client.diff'>
|
xmlns:d='urn:import:com.google.gerrit.client.diff'>
|
||||||
<g:HTMLPanel>
|
<g:HTMLPanel>
|
||||||
<d:ReviewedPanel ui:field='reviewed'/>
|
<d:ReviewedPanel ui:field='reviewed'/>
|
||||||
<d:DiffTable ui:field='diffTable' />
|
<d:NavLinks2 ui:field='navLinks'/>
|
||||||
|
<d:DiffTable ui:field='diffTable'/>
|
||||||
</g:HTMLPanel>
|
</g:HTMLPanel>
|
||||||
</ui:UiBinder>
|
</ui:UiBinder>
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
// Copyright (C) 2013 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package com.google.gerrit.client.diff;
|
||||||
|
|
||||||
|
import com.google.gerrit.client.Gerrit;
|
||||||
|
import com.google.gerrit.client.patches.PatchUtil;
|
||||||
|
import com.google.gerrit.common.PageLinks;
|
||||||
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
|
import com.google.gwt.event.dom.client.KeyPressEvent;
|
||||||
|
import com.google.gwtexpui.globalkey.client.KeyCommand;
|
||||||
|
|
||||||
|
class UpToChangeCommand2 extends KeyCommand {
|
||||||
|
private final PatchSet.Id revision;
|
||||||
|
|
||||||
|
UpToChangeCommand2(PatchSet.Id revision, int mask, int key) {
|
||||||
|
super(mask, key, PatchUtil.C.upToChange());
|
||||||
|
this.revision = revision;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onKeyPress(final KeyPressEvent event) {
|
||||||
|
Gerrit.display(PageLinks.toChange2(
|
||||||
|
revision.getParentKey(),
|
||||||
|
String.valueOf(revision.get())));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,6 +33,13 @@ public class InlineHyperlink extends
|
|||||||
super(text, token);
|
super(text, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an empty link.
|
||||||
|
*/
|
||||||
|
public InlineHyperlink() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBrowserEvent(final Event event) {
|
public void onBrowserEvent(final Event event) {
|
||||||
if (DOM.eventGetType(event) == Event.ONCLICK && impl.handleAsClick(event)) {
|
if (DOM.eventGetType(event) == Event.ONCLICK && impl.handleAsClick(event)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user