Add ui preference to render entire file.

This will cause all lines in the file to be added to the DOM.
While being slower (especially for large files) it allows the
browser handle searching the file contents.

Change-Id: I31a9ebb079ec38ecf4fdb62ec073043723fe586f
This commit is contained in:
Colby Ranger 2014-01-07 14:33:23 -08:00
parent be84639566
commit eee28b5caa
11 changed files with 91 additions and 2 deletions

View File

@ -36,6 +36,7 @@ public class DiffPreferences extends JavaScriptObject {
p.hideLineNumbers(in.isHideLineNumbers());
p.expandAllComments(in.isExpandAllComments());
p.manualReview(in.isManualReview());
p.renderEntireFile(in.isRenderEntireFile());
return p;
}
@ -52,6 +53,7 @@ public class DiffPreferences extends JavaScriptObject {
p.setHideLineNumbers(hideLineNumbers());
p.setExpandAllComments(expandAllComments());
p.setManualReview(manualReview());
p.setRenderEntireFile(renderEntireFile());
}
public final void ignoreWhitespace(Whitespace i) {
@ -70,6 +72,7 @@ public class DiffPreferences extends JavaScriptObject {
public final native void hideLineNumbers(boolean s) /*-{ this.hide_line_numbers = s }-*/;
public final native void expandAllComments(boolean e) /*-{ this.expand_all_comments = e }-*/;
public final native void manualReview(boolean r) /*-{ this.manual_review = r }-*/;
public final native void renderEntireFile(boolean r) /*-{ this.render_entire_file = r }-*/;
public final void showLineNumbers(boolean s) { hideLineNumbers(!s); }
public final Whitespace ignoreWhitespace() {
@ -89,6 +92,7 @@ public class DiffPreferences extends JavaScriptObject {
public final native boolean hideLineNumbers() /*-{ return this.hide_line_numbers || false }-*/;
public final native boolean expandAllComments() /*-{ return this.expand_all_comments || false }-*/;
public final native boolean manualReview() /*-{ return this.manual_review || false }-*/;
public final native boolean renderEntireFile() /*-{ return this.render_entire_file || false }-*/;
public final boolean showLineNumbers() { return !hideLineNumbers(); }
public final boolean autoReview() { return !manualReview(); }

View File

@ -79,6 +79,7 @@ class PreferencesBox extends Composite {
@UiField ToggleButton topMenu;
@UiField ToggleButton manualReview;
@UiField ToggleButton expandAllComments;
@UiField ToggleButton renderEntireFile;
@UiField Button apply;
@UiField Button save;
@ -126,6 +127,7 @@ class PreferencesBox extends Composite {
topMenu.setValue(!prefs.hideTopMenu());
manualReview.setValue(prefs.manualReview());
expandAllComments.setValue(prefs.expandAllComments());
renderEntireFile.setValue(prefs.renderEntireFile());
switch (view.getIntraLineStatus()) {
case OFF:
@ -272,6 +274,12 @@ class PreferencesBox extends Composite {
});
}
@UiHandler("renderEntireFile")
void onRenderEntireFile(ValueChangeEvent<Boolean> e) {
prefs.renderEntireFile(e.getValue());
view.updateRenderEntireFile();
}
@UiHandler("apply")
void onApply(ClickEvent e) {
close();

View File

@ -235,6 +235,13 @@ limitations under the License.
<g:downFace><ui:msg>Expand</ui:msg></g:downFace>
</g:ToggleButton></td>
</tr>
<tr>
<th><ui:msg>Render</ui:msg></th>
<td><g:ToggleButton ui:field='renderEntireFile'>
<g:upFace><ui:msg>Fast</ui:msg></g:upFace>
<g:downFace><ui:msg>Slow</ui:msg></g:downFace>
</g:ToggleButton></td>
</tr>
<tr>
<td></td>
<td>

View File

@ -14,6 +14,8 @@
package com.google.gerrit.client.diff;
import static java.lang.Double.POSITIVE_INFINITY;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.account.DiffPreferences;
import com.google.gerrit.client.change.ChangeScreen2;
@ -71,6 +73,9 @@ import java.util.EnumSet;
import java.util.List;
public class SideBySide2 extends Screen {
private static final KeyMap RENDER_ENTIRE_FILE_KEYMAP = KeyMap.create()
.on("Ctrl-F", false);
interface Binder extends UiBinder<FlowPanel, SideBySide2> {}
private static final Binder uiBinder = GWT.create(Binder.class);
@ -344,6 +349,9 @@ public class SideBySide2 extends Screen {
cm.execCommand("selectAll");
}
}));
if (prefs.renderEntireFile()) {
cm.addKeyMap(RENDER_ENTIRE_FILE_KEYMAP);
}
}
private BeforeSelectionChangeHandler onSelectionChange(final CodeMirror cm) {
@ -511,7 +519,8 @@ public class SideBySide2 extends Screen {
.set("styleSelectedText", true)
.set("showTrailingSpace", prefs.showWhitespaceErrors())
.set("keyMap", "vim_ro")
.set("value", meta != null ? contents : ""));
.set("value", meta != null ? contents : "")
.set("viewportMargin", prefs.renderEntireFile() ? POSITIVE_INFINITY : 10));
}
DiffInfo.IntraLineStatus getIntraLineStatus() {
@ -747,6 +756,18 @@ public class SideBySide2 extends Screen {
};
}
void updateRenderEntireFile() {
cmA.removeKeyMap(RENDER_ENTIRE_FILE_KEYMAP);
cmB.removeKeyMap(RENDER_ENTIRE_FILE_KEYMAP);
if (prefs.renderEntireFile()) {
cmA.addKeyMap(RENDER_ENTIRE_FILE_KEYMAP);
cmB.addKeyMap(RENDER_ENTIRE_FILE_KEYMAP);
}
cmA.setOption("viewportMargin", prefs.renderEntireFile() ? POSITIVE_INFINITY : 10);
cmB.setOption("viewportMargin", prefs.renderEntireFile() ? POSITIVE_INFINITY : 10);
}
void resizeCodeMirror() {
int height = getCodeMirrorHeight();
cmA.setHeight(height);

View File

@ -253,6 +253,7 @@ public class CodeMirror extends JavaScriptObject {
}-*/;
public final native void addKeyMap(KeyMap map) /*-{ this.addKeyMap(map); }-*/;
public final native void removeKeyMap(KeyMap map) /*-{ this.removeKeyMap(map); }-*/;
public static final native LineCharacter pos(int line, int ch) /*-{
return $wnd.CodeMirror.Pos(line, ch);

View File

@ -27,6 +27,11 @@ public class KeyMap extends JavaScriptObject {
return this;
}-*/;
public final native KeyMap on(String key, boolean b) /*-{
this[key] = b;
return this;
}-*/;
public final native KeyMap remove(String key) /*-{ delete this[key]; }-*/;
protected KeyMap() {

View File

@ -122,6 +122,9 @@ public class AccountDiffPreference {
@Column(id = 17)
protected boolean hideLineNumbers;
@Column(id = 18)
protected boolean renderEntireFile;
protected AccountDiffPreference() {
}
@ -147,6 +150,7 @@ public class AccountDiffPreference {
this.manualReview = p.manualReview;
this.hideTopMenu = p.hideTopMenu;
this.hideLineNumbers = p.hideLineNumbers;
this.renderEntireFile = p.renderEntireFile;
}
public Account.Id getAccountId() {
@ -283,4 +287,12 @@ public class AccountDiffPreference {
public void setHideLineNumbers(boolean hide) {
hideLineNumbers = hide;
}
public boolean isRenderEntireFile() {
return renderEntireFile;
}
public void setRenderEntireFile(boolean render) {
renderEntireFile = render;
}
}

View File

@ -70,6 +70,7 @@ public class GetDiffPreferences implements RestReadView<AccountResource> {
info.hideLineNumbers = p.isHideLineNumbers() ? true : null;
info.syntaxHighlighting = p.isSyntaxHighlighting() ? true : null;
info.tabSize = p.getTabSize();
info.renderEntireFile = p.isRenderEntireFile() ? true : null;
return info;
}
@ -88,6 +89,7 @@ public class GetDiffPreferences implements RestReadView<AccountResource> {
Boolean syntaxHighlighting;
Boolean hideTopMenu;
Boolean hideLineNumbers;
Boolean renderEntireFile;
int tabSize;
}
}

View File

@ -46,6 +46,7 @@ public class SetDiffPreferences implements RestModifyView<AccountResource, Input
Boolean syntaxHighlighting;
Boolean hideTopMenu;
Boolean hideLineNumbers;
Boolean renderEntireFile;
Integer tabSize;
}
@ -124,6 +125,9 @@ public class SetDiffPreferences implements RestModifyView<AccountResource, Input
if (input.hideLineNumbers != null) {
p.setHideLineNumbers(input.hideLineNumbers);
}
if (input.renderEntireFile != null) {
p.setRenderEntireFile(input.renderEntireFile);
}
if (input.tabSize != null) {
p.setTabSize(input.tabSize);
}

View File

@ -32,7 +32,7 @@ import java.util.List;
/** A version of the database schema. */
public abstract class SchemaVersion {
/** The current schema version. */
public static final Class<Schema_91> C = Schema_91.class;
public static final Class<Schema_92> C = Schema_92.class;
public static class Module extends AbstractModule {
@Override

View File

@ -0,0 +1,25 @@
// Copyright (C) 2014 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.server.schema;
import com.google.inject.Inject;
import com.google.inject.Provider;
public class Schema_92 extends SchemaVersion {
@Inject
Schema_92(Provider<Schema_91> prior) {
super(prior);
}
}