Enable inline edit in side by side view
Switch CodeMirror to edit mode in "B" side to enable inline edit. In edit mode, CodeMirror is switched to "default" mode because "vim" mode was sometimes not responsive. Also commenting is disabled in this mode. During testing I've discovered a small bug in CodeMirror. A JS exception is thrown after entering a text and going to the new line. Everything looks and works fine afterwards, but an error stays in the JS console. Therefore it was suppressed in JSNI code. Edit icon is taken from the Tango project: http://tango.freedesktop.org/Tango_Icon_Library Specifically, 16x16/devices/media-floppy.png from http://tango.freedesktop.org/releases/tango-icon-theme-0.8.90.tar.gz Change-Id: Ie9b2c5f2b362da5ffbead57a241756a45e9eb60c Signed-off-by: Dariusz Luksza <dariusz@luksza.org>
This commit is contained in:
committed by
Dave Borowitz
parent
93ca7e03b9
commit
00356c2c78
@@ -37,6 +37,9 @@ public interface GerritResources extends ClientBundle {
|
||||
@Source("editText.png")
|
||||
public ImageResource edit();
|
||||
|
||||
@Source("mediaFloppy.png")
|
||||
public ImageResource save();
|
||||
|
||||
@Source("starOpen.gif")
|
||||
public ImageResource starOpen();
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ package com.google.gerrit.client.diff;
|
||||
|
||||
import com.google.gerrit.client.Dispatcher;
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.VoidResult;
|
||||
import com.google.gerrit.client.WebLinkInfo;
|
||||
import com.google.gerrit.client.change.EditFileAction;
|
||||
import com.google.gerrit.client.changes.ChangeFileApi;
|
||||
import com.google.gerrit.client.changes.ChangeInfo.RevisionInfo;
|
||||
import com.google.gerrit.client.patches.PatchUtil;
|
||||
@@ -139,21 +139,35 @@ class PatchSetSelectBox2 extends Composite {
|
||||
}
|
||||
|
||||
private Widget createEditIcon() {
|
||||
Anchor anchor = new Anchor(
|
||||
final Anchor anchor = new Anchor(
|
||||
new ImageResourceRenderer().render(Gerrit.RESOURCES.edit()));
|
||||
anchor.addClickHandler(new ClickHandler() {
|
||||
boolean editing = false;
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
final PatchSet.Id id = (idActive == null) ? other.idActive : idActive;
|
||||
ChangeFileApi.getContent(id, path,
|
||||
new GerritCallback<String>() {
|
||||
@Override
|
||||
public void onSuccess(String result) {
|
||||
EditFileAction edit = new EditFileAction(
|
||||
id, result, path, style.replyBox(), null, icon);
|
||||
edit.onEdit();
|
||||
}
|
||||
});
|
||||
editing = !editing;
|
||||
parent.editSideB(editing);
|
||||
|
||||
if (editing) {
|
||||
ChangeFileApi.getContent(id, path,
|
||||
new GerritCallback<String>() {
|
||||
@Override
|
||||
public void onSuccess(String content) {
|
||||
parent.setSideBContent(content);
|
||||
}
|
||||
});
|
||||
anchor.setHTML(new ImageResourceRenderer().render(Gerrit.RESOURCES.save()));
|
||||
} else {
|
||||
anchor.setHTML(new ImageResourceRenderer().render(Gerrit.RESOURCES.edit()));
|
||||
String siteBContent = parent.getSideBContent();
|
||||
ChangeFileApi.putContent(id, path, siteBContent,
|
||||
new GerritCallback<VoidResult>() {
|
||||
@Override
|
||||
public void onSuccess(VoidResult result) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
anchor.setTitle(PatchUtil.C.edit());
|
||||
|
||||
@@ -132,6 +132,8 @@ public class SideBySide2 extends Screen {
|
||||
private List<HandlerRegistration> handlers;
|
||||
private PreferencesAction prefsAction;
|
||||
private int reloadVersionId;
|
||||
private KeyMap sbsKeyMap;
|
||||
private boolean isEdited = false;
|
||||
|
||||
public SideBySide2(
|
||||
PatchSet.Id base,
|
||||
@@ -338,7 +340,7 @@ public class SideBySide2 extends Screen {
|
||||
cm.on("cursorActivity", updateActiveLine(cm));
|
||||
cm.on("gutterClick", onGutterClick(cm));
|
||||
cm.on("focus", updateActiveLine(cm));
|
||||
cm.addKeyMap(KeyMap.create()
|
||||
sbsKeyMap = KeyMap.create()
|
||||
.on("A", upToChange(true))
|
||||
.on("U", upToChange(false))
|
||||
.on("[", header.navigate(Direction.PREV))
|
||||
@@ -403,7 +405,8 @@ public class SideBySide2 extends Screen {
|
||||
public void run() {
|
||||
cm.execCommand("selectAll");
|
||||
}
|
||||
}));
|
||||
});
|
||||
cm.addKeyMap(sbsKeyMap);
|
||||
if (prefs.renderEntireFile()) {
|
||||
cm.addKeyMap(RENDER_ENTIRE_FILE_KEYMAP);
|
||||
}
|
||||
@@ -415,6 +418,9 @@ public class SideBySide2 extends Screen {
|
||||
|
||||
@Override
|
||||
public void handle(CodeMirror cm, LineCharacter anchor, LineCharacter head) {
|
||||
if (isEdited) {
|
||||
return;
|
||||
}
|
||||
if (anchor == head
|
||||
|| (anchor.getLine() == head.getLine()
|
||||
&& anchor.getCh() == head.getCh())) {
|
||||
@@ -533,6 +539,30 @@ public class SideBySide2 extends Screen {
|
||||
}));
|
||||
}
|
||||
|
||||
public void editSideB(boolean state) {
|
||||
isEdited = state;
|
||||
cmB.setOption("readOnly", !state);
|
||||
JumpKeys.enable(!state);
|
||||
if (state) {
|
||||
removeKeyHandlerRegistrations();
|
||||
cmB.removeKeyMap(sbsKeyMap);
|
||||
cmB.setOption("keyMap", "default");
|
||||
cmB.focus();
|
||||
} else {
|
||||
cmB.setOption("keyMap", "vim_ro");
|
||||
cmB.addKeyMap(sbsKeyMap);
|
||||
registerKeys();
|
||||
}
|
||||
}
|
||||
|
||||
public String getSideBContent() {
|
||||
return cmB.getValue();
|
||||
}
|
||||
|
||||
public void setSideBContent(String content) {
|
||||
cmB.setValue(content);
|
||||
}
|
||||
|
||||
private void display(final CommentsCollections comments) {
|
||||
setThemeStyles(prefs.theme().isDark());
|
||||
setShowTabs(prefs.showTabs());
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 561 B |
Reference in New Issue
Block a user