]> source.dussan.org Git - gitblit.git/commitdiff
Add a checkbox to control whitespace diff preference on the compare page 33/233/2
authorJames Moger <james.moger@gitblit.com>
Sat, 7 Mar 2015 17:21:59 +0000 (12:21 -0500)
committerJames Moger <james.moger@gitblit.com>
Sat, 7 Mar 2015 17:21:59 +0000 (12:21 -0500)
src/main/java/com/gitblit/wicket/pages/ComparePage.html
src/main/java/com/gitblit/wicket/pages/ComparePage.java

index d7df717c11b3932eeb05e984de42021293b0891f..74c9831003695eb64afb7dd36861422a48cf49f5 100644 (file)
@@ -18,6 +18,7 @@
                                        <select wicket:id="fromRef" class="span3" />\r
                                        <i class="icon-arrow-right"></i>\r
                                        <select wicket:id="toRef" class="span3" />\r
+                      <label style="padding:0px 5px;" class="checkbox"><input type="checkbox" wicket:id="ignoreWhitespaceCheckbox" /> <span wicket:id="ignoreWhitespaceLabel"></span></label>\r
                                        <button class="btn" type="submit"><wicket:message key="gb.compare"></wicket:message></button>\r
                                </form>\r
                        </div>\r
@@ -26,6 +27,7 @@
                                        <input wicket:id="fromId" type="text" class="span3" />\r
                                        <i class="icon-arrow-right"></i>\r
                                        <input wicket:id="toId" type="text" class="span3" />\r
+                    <label style="padding:0px 5px;" class="checkbox"><input type="checkbox" wicket:id="ignoreWhitespaceCheckbox" /> <span wicket:id="ignoreWhitespaceLabel"></span></label>\r
                                        <button class="btn" type="submit"><wicket:message key="gb.compare"></wicket:message></button>\r
                                </form>\r
                        </div>\r
index 76bf1c504178983027e9bce4293382577e46b1b3..d17104466abf9b193fcf586f2a0cc2f86672dd76 100644 (file)
@@ -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();