summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2015-03-07 12:21:59 -0500
committerJames Moger <james.moger@gitblit.com>2015-03-07 12:21:59 -0500
commit520a470b22ea53bd8b418aaac498a8672e2c0779 (patch)
tree163f481fa095a5611665f65befae6227cf83c8e1
parent5d59b9ba3206894198a24807690fba00844c98f7 (diff)
downloadgitblit-520a470b22ea53bd8b418aaac498a8672e2c0779.tar.gz
gitblit-520a470b22ea53bd8b418aaac498a8672e2c0779.zip
Add a checkbox to control whitespace diff preference on the compare page
-rw-r--r--src/main/java/com/gitblit/wicket/pages/ComparePage.html2
-rw-r--r--src/main/java/com/gitblit/wicket/pages/ComparePage.java20
2 files changed, 22 insertions, 0 deletions
diff --git a/src/main/java/com/gitblit/wicket/pages/ComparePage.html b/src/main/java/com/gitblit/wicket/pages/ComparePage.html
index d7df717c..74c98310 100644
--- a/src/main/java/com/gitblit/wicket/pages/ComparePage.html
+++ b/src/main/java/com/gitblit/wicket/pages/ComparePage.html
@@ -18,6 +18,7 @@
<select wicket:id="fromRef" class="span3" />
<i class="icon-arrow-right"></i>
<select wicket:id="toRef" class="span3" />
+ <label style="padding:0px 5px;" class="checkbox"><input type="checkbox" wicket:id="ignoreWhitespaceCheckbox" /> <span wicket:id="ignoreWhitespaceLabel"></span></label>
<button class="btn" type="submit"><wicket:message key="gb.compare"></wicket:message></button>
</form>
</div>
@@ -26,6 +27,7 @@
<input wicket:id="fromId" type="text" class="span3" />
<i class="icon-arrow-right"></i>
<input wicket:id="toId" type="text" class="span3" />
+ <label style="padding:0px 5px;" class="checkbox"><input type="checkbox" wicket:id="ignoreWhitespaceCheckbox" /> <span wicket:id="ignoreWhitespaceLabel"></span></label>
<button class="btn" type="submit"><wicket:message key="gb.compare"></wicket:message></button>
</form>
</div>
diff --git a/src/main/java/com/gitblit/wicket/pages/ComparePage.java b/src/main/java/com/gitblit/wicket/pages/ComparePage.java
index 76bf1c50..d1710446 100644
--- a/src/main/java/com/gitblit/wicket/pages/ComparePage.java
+++ b/src/main/java/com/gitblit/wicket/pages/ComparePage.java
@@ -21,6 +21,7 @@ import java.util.List;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
@@ -70,6 +71,8 @@ public class ComparePage extends RepositoryPage {
IModel<String> fromRefId = new Model<String>("");
IModel<String> toRefId = new Model<String>("");
+ IModel<Boolean> ignoreWhitespace = Model.of(true);
+
public ComparePage(PageParameters params) {
super(params);
Repository r = getRepository();
@@ -214,6 +217,10 @@ public class ComparePage extends RepositoryPage {
comparison.add(new Label("diffText", diff.content).setEscapeModelStrings(false));
}
+ // set the default DiffComparator
+ DiffComparator diffComparator = WicketUtils.getDiffComparator(params);
+ ignoreWhitespace.setObject(DiffComparator.IGNORE_WHITESPACE == diffComparator);
+
//
// ref selection form
//
@@ -225,8 +232,13 @@ public class ComparePage extends RepositoryPage {
public void onSubmit() {
String from = ComparePage.this.fromRefId.getObject();
String to = ComparePage.this.toRefId.getObject();
+ boolean ignoreWS = ignoreWhitespace.getObject();
PageParameters params = WicketUtils.newRangeParameter(repositoryName, from, to);
+ if (ignoreWS) {
+ params.put("w", 1);
+ }
+
String relativeUrl = urlFor(ComparePage.class, params).toString();
String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
@@ -247,6 +259,8 @@ public class ComparePage extends RepositoryPage {
}
refsForm.add(new DropDownChoice<String>("fromRef", fromRefId, refs).setEnabled(refs.size() > 0));
refsForm.add(new DropDownChoice<String>("toRef", toRefId, refs).setEnabled(refs.size() > 0));
+ refsForm.add(new Label("ignoreWhitespaceLabel", getString(DiffComparator.IGNORE_WHITESPACE.getTranslationKey())));
+ refsForm.add(new CheckBox("ignoreWhitespaceCheckbox", ignoreWhitespace));
add(refsForm);
//
@@ -260,8 +274,12 @@ public class ComparePage extends RepositoryPage {
public void onSubmit() {
String from = ComparePage.this.fromCommitId.getObject();
String to = ComparePage.this.toCommitId.getObject();
+ boolean ignoreWS = ignoreWhitespace.getObject();
PageParameters params = WicketUtils.newRangeParameter(repositoryName, from, to);
+ if (ignoreWS) {
+ params.put("w", 1);
+ }
String relativeUrl = urlFor(ComparePage.class, params).toString();
String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
@@ -275,6 +293,8 @@ public class ComparePage extends RepositoryPage {
TextField<String> toIdField = new TextField<String>("toId", toCommitId);
WicketUtils.setInputPlaceholder(toIdField, getString("gb.to") + "...");
idsForm.add(toIdField);
+ idsForm.add(new Label("ignoreWhitespaceLabel", getString(DiffComparator.IGNORE_WHITESPACE.getTranslationKey())));
+ idsForm.add(new CheckBox("ignoreWhitespaceCheckbox", ignoreWhitespace));
add(idsForm);
r.close();