Disable 'Syntax Highlighting' and 'Show Full File' on big files

If the file is huge, we disable these features.  A tooltip tells
the user why they cannot access them.

Change-Id: Icec1857844d62456c7abfd8b0d3dd753198330dd
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce 2010-03-04 17:43:38 -08:00
parent bd277faf35
commit 44a80aa4b5
6 changed files with 49 additions and 8 deletions

View File

@ -14,6 +14,8 @@
package com.google.gerrit.common.data; package com.google.gerrit.common.data;
import static com.google.gerrit.reviewdb.AccountGeneralPreferences.WHOLE_FILE_CONTEXT;
import com.google.gerrit.common.data.PatchScriptSettings.Whitespace; import com.google.gerrit.common.data.PatchScriptSettings.Whitespace;
import com.google.gerrit.prettify.client.ClientSideFormatter; import com.google.gerrit.prettify.client.ClientSideFormatter;
import com.google.gerrit.prettify.common.EditList; import com.google.gerrit.prettify.common.EditList;
@ -28,7 +30,6 @@ import com.google.gerrit.reviewdb.Patch.ChangeType;
import org.eclipse.jgit.diff.Edit; import org.eclipse.jgit.diff.Edit;
import java.util.List; import java.util.List;
import static com.google.gerrit.reviewdb.AccountGeneralPreferences.*;
public class PatchScript { public class PatchScript {
public static enum DisplayMethod { public static enum DisplayMethod {
@ -48,12 +49,13 @@ public class PatchScript {
protected DisplayMethod displayMethodB; protected DisplayMethod displayMethodB;
protected CommentDetail comments; protected CommentDetail comments;
protected List<Patch> history; protected List<Patch> history;
protected boolean hugeFile;
public PatchScript(final Change.Key ck, final ChangeType ct, final String on, public PatchScript(final Change.Key ck, final ChangeType ct, final String on,
final String nn, final List<String> h, final PatchScriptSettings s, final String nn, final List<String> h, final PatchScriptSettings s,
final SparseFileContent ca, final SparseFileContent cb, final SparseFileContent ca, final SparseFileContent cb,
final List<Edit> e, final DisplayMethod ma, final DisplayMethod mb, final List<Edit> e, final DisplayMethod ma, final DisplayMethod mb,
final CommentDetail cd, final List<Patch> hist) { final CommentDetail cd, final List<Patch> hist, final boolean hf) {
changeId = ck; changeId = ck;
changeType = ct; changeType = ct;
oldName = on; oldName = on;
@ -67,6 +69,7 @@ public class PatchScript {
displayMethodB = mb; displayMethodB = mb;
comments = cd; comments = cd;
history = hist; history = hist;
hugeFile = hf;
} }
protected PatchScript() { protected PatchScript() {
@ -116,6 +119,10 @@ public class PatchScript {
settings = s; settings = s;
} }
public boolean isHugeFile() {
return hugeFile;
}
public boolean isIgnoreWhitespace() { public boolean isIgnoreWhitespace() {
return settings.getWhitespace() != Whitespace.IGNORE_NONE; return settings.getWhitespace() != Whitespace.IGNORE_NONE;
} }

View File

@ -31,6 +31,7 @@ public interface PatchConstants extends Constants {
String patchHeaderNew(); String patchHeaderNew();
String patchHistoryTitle(); String patchHistoryTitle();
String disabledOnLargeFiles();
String upToChange(); String upToChange();
String linePrev(); String linePrev();

View File

@ -13,6 +13,7 @@ noDifference = No Differences
patchHeaderOld = Old Version patchHeaderOld = Old Version
patchHeaderNew = New Version patchHeaderNew = New Version
patchHistoryTitle = Patch History patchHistoryTitle = Patch History
disabledOnLargeFiles = Disabled on very large source files.
upToChange = Up to change upToChange = Up to change
linePrev = Previous line linePrev = Previous line

View File

@ -447,6 +447,7 @@ public abstract class PatchScreen extends Screen implements
contentTable.finishDisplay(); contentTable.finishDisplay();
} }
showPatch(hasDifferences); showPatch(hasDifferences);
settingsPanel.setEnableSmallFileFeatures(!script.isHugeFile());
settingsPanel.setEnabled(true); settingsPanel.setEnabled(true);
lastScript = script; lastScript = script;

View File

@ -54,6 +54,7 @@ public class PatchScriptSettingsPanel extends Composite implements
} }
private PatchScriptSettings value; private PatchScriptSettings value;
private boolean enableSmallFileFeatures = true;
@UiField @UiField
ListBox ignoreWhitespace; ListBox ignoreWhitespace;
@ -126,10 +127,33 @@ public class PatchScriptSettingsPanel extends Composite implements
((FocusWidget) w).setEnabled(on); ((FocusWidget) w).setEnabled(on);
} }
} }
toggleEnabledStatus(on);
} }
public CheckBox getSyntaxHighlightingCheckBox() { public void setEnableSmallFileFeatures(final boolean on) {
return syntaxHighlighting; enableSmallFileFeatures = on;
if (enableSmallFileFeatures) {
final PrettySettings p = getValue().getPrettySettings();
syntaxHighlighting.setValue(p.isSyntaxHighlighting());
showFullFile.setValue(getValue().getContext() == WHOLE_FILE_CONTEXT);
} else {
syntaxHighlighting.setValue(false);
showFullFile.setValue(false);
}
toggleEnabledStatus(update.isEnabled());
}
private void toggleEnabledStatus(boolean on) {
on &= enableSmallFileFeatures;
syntaxHighlighting.setEnabled(on);
showFullFile.setEnabled(on);
final String title =
enableSmallFileFeatures ? null : PatchUtil.C.disabledOnLargeFiles();
syntaxHighlighting.setTitle(title);
showFullFile.setTitle(title);
} }
public CheckBox getReviewedCheckBox() { public CheckBox getReviewedCheckBox() {
@ -144,11 +168,16 @@ public class PatchScriptSettingsPanel extends Composite implements
final PrettySettings p = s.getPrettySettings(); final PrettySettings p = s.getPrettySettings();
setIgnoreWhitespace(s.getWhitespace()); setIgnoreWhitespace(s.getWhitespace());
if (enableSmallFileFeatures) {
showFullFile.setValue(s.getContext() == WHOLE_FILE_CONTEXT); showFullFile.setValue(s.getContext() == WHOLE_FILE_CONTEXT);
syntaxHighlighting.setValue(p.isSyntaxHighlighting());
} else {
showFullFile.setValue(false);
syntaxHighlighting.setValue(false);
}
tabWidth.setIntValue(p.getTabSize()); tabWidth.setIntValue(p.getTabSize());
colWidth.setIntValue(p.getLineLength()); colWidth.setIntValue(p.getLineLength());
syntaxHighlighting.setValue(p.isSyntaxHighlighting());
intralineDifference.setValue(p.isIntralineDifference()); intralineDifference.setValue(p.isIntralineDifference());
whitespaceErrors.setValue(p.isShowWhiteSpaceErrors()); whitespaceErrors.setValue(p.isShowWhiteSpaceErrors());
showTabs.setValue(p.isShowTabs()); showTabs.setValue(p.isShowTabs());

View File

@ -118,7 +118,7 @@ class PatchScriptBuilder {
return new PatchScript(change.getKey(), content.getChangeType(), content return new PatchScript(change.getKey(), content.getChangeType(), content
.getOldName(), content.getNewName(), content.getHeaderLines(), .getOldName(), content.getNewName(), content.getHeaderLines(),
settings, a.dst, b.dst, Collections.<Edit> emptyList(), settings, a.dst, b.dst, Collections.<Edit> emptyList(),
a.displayMethod, b.displayMethod, comments, history); a.displayMethod, b.displayMethod, comments, history, false);
} }
a.path = oldName(content); a.path = oldName(content);
@ -130,6 +130,7 @@ class PatchScriptBuilder {
edits = new ArrayList<Edit>(content.getEdits()); edits = new ArrayList<Edit>(content.getEdits());
ensureCommentsVisible(comments); ensureCommentsVisible(comments);
boolean hugeFile = false;
if (a.mode == FileMode.GITLINK || b.mode == FileMode.GITLINK) { if (a.mode == FileMode.GITLINK || b.mode == FileMode.GITLINK) {
} else if (a.src == b.src && a.size() <= context } else if (a.src == b.src && a.size() <= context
@ -152,6 +153,7 @@ class PatchScriptBuilder {
settings.setContext(Math.min(25, context)); settings.setContext(Math.min(25, context));
settings.getPrettySettings().setSyntaxHighlighting(false); settings.getPrettySettings().setSyntaxHighlighting(false);
context = settings.getContext(); context = settings.getContext();
hugeFile = true;
} else if (settings.getPrettySettings().isSyntaxHighlighting()) { } else if (settings.getPrettySettings().isSyntaxHighlighting()) {
// In order to syntax highlight the file properly we need to // In order to syntax highlight the file properly we need to
@ -166,7 +168,7 @@ class PatchScriptBuilder {
return new PatchScript(change.getKey(), content.getChangeType(), content return new PatchScript(change.getKey(), content.getChangeType(), content
.getOldName(), content.getNewName(), content.getHeaderLines(), .getOldName(), content.getNewName(), content.getHeaderLines(),
settings, a.dst, b.dst, edits, a.displayMethod, b.displayMethod, settings, a.dst, b.dst, edits, a.displayMethod, b.displayMethod,
comments, history); comments, history, hugeFile);
} }
private static String oldName(final PatchListEntry entry) { private static String oldName(final PatchListEntry entry) {