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:
parent
bd277faf35
commit
44a80aa4b5
@ -14,6 +14,8 @@
|
||||
|
||||
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.prettify.client.ClientSideFormatter;
|
||||
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 java.util.List;
|
||||
import static com.google.gerrit.reviewdb.AccountGeneralPreferences.*;
|
||||
|
||||
public class PatchScript {
|
||||
public static enum DisplayMethod {
|
||||
@ -48,12 +49,13 @@ public class PatchScript {
|
||||
protected DisplayMethod displayMethodB;
|
||||
protected CommentDetail comments;
|
||||
protected List<Patch> history;
|
||||
protected boolean hugeFile;
|
||||
|
||||
public PatchScript(final Change.Key ck, final ChangeType ct, final String on,
|
||||
final String nn, final List<String> h, final PatchScriptSettings s,
|
||||
final SparseFileContent ca, final SparseFileContent cb,
|
||||
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;
|
||||
changeType = ct;
|
||||
oldName = on;
|
||||
@ -67,6 +69,7 @@ public class PatchScript {
|
||||
displayMethodB = mb;
|
||||
comments = cd;
|
||||
history = hist;
|
||||
hugeFile = hf;
|
||||
}
|
||||
|
||||
protected PatchScript() {
|
||||
@ -116,6 +119,10 @@ public class PatchScript {
|
||||
settings = s;
|
||||
}
|
||||
|
||||
public boolean isHugeFile() {
|
||||
return hugeFile;
|
||||
}
|
||||
|
||||
public boolean isIgnoreWhitespace() {
|
||||
return settings.getWhitespace() != Whitespace.IGNORE_NONE;
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ public interface PatchConstants extends Constants {
|
||||
String patchHeaderNew();
|
||||
|
||||
String patchHistoryTitle();
|
||||
String disabledOnLargeFiles();
|
||||
|
||||
String upToChange();
|
||||
String linePrev();
|
||||
|
@ -13,6 +13,7 @@ noDifference = No Differences
|
||||
patchHeaderOld = Old Version
|
||||
patchHeaderNew = New Version
|
||||
patchHistoryTitle = Patch History
|
||||
disabledOnLargeFiles = Disabled on very large source files.
|
||||
|
||||
upToChange = Up to change
|
||||
linePrev = Previous line
|
||||
|
@ -447,6 +447,7 @@ public abstract class PatchScreen extends Screen implements
|
||||
contentTable.finishDisplay();
|
||||
}
|
||||
showPatch(hasDifferences);
|
||||
settingsPanel.setEnableSmallFileFeatures(!script.isHugeFile());
|
||||
settingsPanel.setEnabled(true);
|
||||
lastScript = script;
|
||||
|
||||
|
@ -54,6 +54,7 @@ public class PatchScriptSettingsPanel extends Composite implements
|
||||
}
|
||||
|
||||
private PatchScriptSettings value;
|
||||
private boolean enableSmallFileFeatures = true;
|
||||
|
||||
@UiField
|
||||
ListBox ignoreWhitespace;
|
||||
@ -126,10 +127,33 @@ public class PatchScriptSettingsPanel extends Composite implements
|
||||
((FocusWidget) w).setEnabled(on);
|
||||
}
|
||||
}
|
||||
toggleEnabledStatus(on);
|
||||
}
|
||||
|
||||
public CheckBox getSyntaxHighlightingCheckBox() {
|
||||
return syntaxHighlighting;
|
||||
public void setEnableSmallFileFeatures(final boolean on) {
|
||||
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() {
|
||||
@ -144,11 +168,16 @@ public class PatchScriptSettingsPanel extends Composite implements
|
||||
final PrettySettings p = s.getPrettySettings();
|
||||
|
||||
setIgnoreWhitespace(s.getWhitespace());
|
||||
showFullFile.setValue(s.getContext() == WHOLE_FILE_CONTEXT);
|
||||
if (enableSmallFileFeatures) {
|
||||
showFullFile.setValue(s.getContext() == WHOLE_FILE_CONTEXT);
|
||||
syntaxHighlighting.setValue(p.isSyntaxHighlighting());
|
||||
} else {
|
||||
showFullFile.setValue(false);
|
||||
syntaxHighlighting.setValue(false);
|
||||
}
|
||||
|
||||
tabWidth.setIntValue(p.getTabSize());
|
||||
colWidth.setIntValue(p.getLineLength());
|
||||
syntaxHighlighting.setValue(p.isSyntaxHighlighting());
|
||||
intralineDifference.setValue(p.isIntralineDifference());
|
||||
whitespaceErrors.setValue(p.isShowWhiteSpaceErrors());
|
||||
showTabs.setValue(p.isShowTabs());
|
||||
|
@ -118,7 +118,7 @@ class PatchScriptBuilder {
|
||||
return new PatchScript(change.getKey(), content.getChangeType(), content
|
||||
.getOldName(), content.getNewName(), content.getHeaderLines(),
|
||||
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);
|
||||
@ -130,6 +130,7 @@ class PatchScriptBuilder {
|
||||
edits = new ArrayList<Edit>(content.getEdits());
|
||||
ensureCommentsVisible(comments);
|
||||
|
||||
boolean hugeFile = false;
|
||||
if (a.mode == FileMode.GITLINK || b.mode == FileMode.GITLINK) {
|
||||
|
||||
} else if (a.src == b.src && a.size() <= context
|
||||
@ -152,6 +153,7 @@ class PatchScriptBuilder {
|
||||
settings.setContext(Math.min(25, context));
|
||||
settings.getPrettySettings().setSyntaxHighlighting(false);
|
||||
context = settings.getContext();
|
||||
hugeFile = true;
|
||||
|
||||
} else if (settings.getPrettySettings().isSyntaxHighlighting()) {
|
||||
// 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
|
||||
.getOldName(), content.getNewName(), content.getHeaderLines(),
|
||||
settings, a.dst, b.dst, edits, a.displayMethod, b.displayMethod,
|
||||
comments, history);
|
||||
comments, history, hugeFile);
|
||||
}
|
||||
|
||||
private static String oldName(final PatchListEntry entry) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user