The Unified and Autonomous Development Platform
Add source code format options when view/edit file
robin shineda4631f75a7a
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewPanel.htmlindex be021d425f..df4fcd33cf 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewPanel.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewPanel.html@@ -1,18 +1,17 @@<wicket:panel><div class="blob-view autofit"><div class="head clearfix">- <div class="pull-left formats">- </div>- <div class="pull-right actions">- <div class="btn-group">- <a wicket:id="raw" class="btn btn-default btn-xs"><i class="fa fa-file-o"></i> Raw</a>- <wicket:container wicket:id="additionalActions"></wicket:container>- </div>+ <div class="pull-left actions"><div wicket:id="changeActions" class="btn-group"><a wicket:id="edit" class="btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a><a wicket:id="delete" class="btn btn-default btn-xs"><i class="fa fa-trash"></i> Delete</a></div>+ <div class="btn-group">+ <a wicket:id="raw" class="btn btn-default btn-xs"><i class="fa fa-file-o"></i> Raw</a>+ <wicket:container wicket:id="additionalActions"></wicket:container>+ </div></div>+ <div wicket:id="options" class="pull-right options"></div></div><div class="body scrollable"><wicket:child></wicket:child>diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewPanel.javaindex 3ade1c564c..41f9e5ecd5 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewPanel.java@@ -59,6 +59,10 @@ public abstract class BlobViewPanel extends Panel {}}+ protected WebMarkupContainer newOptions(String id) {+ return new WebMarkupContainer(id);+ }+protected WebMarkupContainer newAdditionalActions(String id) {return new WebMarkupContainer(id);}@@ -151,6 +155,8 @@ public abstract class BlobViewPanel extends Panel {protected void onInitialize() {super.onInitialize();+ add(newOptions("options"));+add(new ResourceLink<Void>("raw", new BlobResourceReference(),BlobResource.paramsOf(context.getDepot(), context.getBlobIdent())));add(newAdditionalActions("additionalActions"));diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/blob-view.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/blob-view.cssindex 79d60ab7a4..4e508c0814 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/blob-view.css+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/blob-view.css@@ -7,5 +7,5 @@height: 36px;}.blob-view>.head>.actions>.btn-group:FIRST-CHILD {- margin-right: 4px;+ margin-right: 8px;}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/blob-view.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/blob-view.jsindex efcbc1afa4..b308a64586 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/blob-view.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/blob-view.js@@ -14,7 +14,6 @@ gitplex.blobView = function(containerId) {$blobView.outerWidth(width);$blobView.outerHeight(height);- console.log($head.outerHeight());height = $blobView.height()-$head.outerHeight();$body.outerWidth(width).outerHeight(height);$body.find(".autofit:visible").first().trigger("autofit", [$body.width(), $body.height()]);diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.javaindex 678b7dc7cc..26c7db67e1 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java@@ -85,6 +85,8 @@ import com.pmease.gitplex.web.component.comment.comparecontext.CompareContextPanimport com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext;import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext.Mode;import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewPanel;+import com.pmease.gitplex.web.component.sourceformat.OptionChangeCallback;+import com.pmease.gitplex.web.component.sourceformat.SourceFormatPanel;import com.pmease.gitplex.web.component.symboltooltip.SymbolTooltipPanel;import com.pmease.gitplex.web.page.depot.commit.CommitDetailPage;import com.pmease.gitplex.web.page.depot.file.DepotFilePage;@@ -124,6 +126,8 @@ public class SourceViewPanel extends BlobViewPanel {private WebMarkupContainer outlineContainer;+ private SourceFormatPanel sourceFormat;+private SymbolTooltipPanel symbolTooltip;private AbstractPostAjaxBehavior ajaxBehavior;@@ -145,6 +149,28 @@ public class SourceViewPanel extends BlobViewPanel {}+ @Override+ protected WebMarkupContainer newOptions(String id) {+ sourceFormat = new SourceFormatPanel(id, null, new OptionChangeCallback() {++ @Override+ public void onOptioneChange(AjaxRequestTarget target) {+ String script = String.format("gitplex.sourceview.onTabSizeChange(%s);", sourceFormat.getTabSize());+ target.appendJavaScript(script);+ }++ }, new OptionChangeCallback() {++ @Override+ public void onOptioneChange(AjaxRequestTarget target) {+ String script = String.format("gitplex.sourceview.onLineWrapModeChange('%s');", sourceFormat.getLineWrapMode());+ target.appendJavaScript(script);+ }++ });+ return sourceFormat;+ }+@Overridepublic WebMarkupContainer newAdditionalActions(String id) {WebMarkupContainer actions = new Fragment(id, "actionsFrag", this);@@ -864,7 +890,7 @@ public class SourceViewPanel extends BlobViewPanel {explicit("param3"), explicit("param4"));String viewState = RequestCycle.get().getMetaData(DepotFilePage.VIEW_STATE_KEY);String script = String.format("gitplex.sourceview.init('%s', '%s', %s, %s, '%s', '%s', "- + "%s, %s, %s, %s, %s, %s);",+ + "%s, %s, %s, %s, %s, %s, %s, '%s');",JavaScriptEscape.escapeJavaScript(blob.getText().getContent()),JavaScriptEscape.escapeJavaScript(context.getBlobIdent().path),context.getOpenComment()!=null?getJsonOfComment(context.getOpenComment()):"undefined",@@ -876,7 +902,9 @@ public class SourceViewPanel extends BlobViewPanel {callback,viewState!=null?"JSON.parse('"+viewState+"')":"undefined",SecurityUtils.getAccount()!=null,- context.getAnchor()!=null?"'"+context.getAnchor()+"'":"undefined");+ context.getAnchor()!=null?"'"+context.getAnchor()+"'":"undefined",+ sourceFormat.getTabSize(),+ sourceFormat.getLineWrapMode());response.render(OnDomReadyHeaderItem.forScript(script));}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.jsindex 8ddbf8afb6..c20aa73352 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js@@ -1,6 +1,6 @@gitplex.sourceview = {init: function(fileContent, filePath, openComment, mark, symbolTooltipId,- revision, blameInfos, comments, markCallback, viewState, loggedIn, anchor) {+ revision, blameInfos, comments, markCallback, viewState, loggedIn, anchor, tabSize, lineWrapMode) {var cm;var $sourceView = $(".source-view");@@ -88,7 +88,8 @@ gitplex.sourceview = {readOnly: pmease.commons.isDevice()?"nocursor":true,theme: "eclipse",lineNumbers: true,- lineWrapping: true,+ lineWrapping: lineWrapMode == "Soft wrap",+ tabSize: tabSize,styleActiveLine: true,styleSelectedText: true,foldGutter: true,@@ -536,5 +537,13 @@ gitplex.sourceview = {scrollToCommentBottom: function() {var $body = $(".source-view>.comment>.content>.body");$body.scrollTop($body[0].scrollHeight);+ },+ onLineWrapModeChange: function(lineWrapMode) {+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;+ cm.setOption("lineWrapping", lineWrapMode == "Soft wrap");+ },+ onTabSizeChange: function(tabSize) {+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;+ cm.setOption("tabSize", tabSize);}};diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.htmlindex 4359df6a62..f2d3046469 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.html@@ -5,6 +5,7 @@<a wicket:id="previewLink" class="tab preview pull-left"><i class="fa fa-eye"></i> Preview changes</a><a wicket:id="saveLink" class="tab save pull-left"><i class="fa fa-floppy-o"></i> Save</a><a wicket:id="cancelLink" class="cancel pull-left" tabindex="-1">Cancel</a>+ <span wicket:id="sourceFormat" class="source-format pull-right"></span></div><div class="body"><!-- below form is for dirty checking purpose and we can not use it as containingdiff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.javaindex b1cc6b36a7..af6f27e019 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.java@@ -39,6 +39,8 @@ import com.pmease.gitplex.core.entity.support.TextRange;import com.pmease.gitplex.web.component.depotfile.editsave.EditSavePanel;import com.pmease.gitplex.web.component.diff.blob.BlobDiffPanel;import com.pmease.gitplex.web.component.diff.revision.DiffViewMode;+import com.pmease.gitplex.web.component.sourceformat.OptionChangeCallback;+import com.pmease.gitplex.web.component.sourceformat.SourceFormatPanel;import com.pmease.gitplex.web.page.depot.file.DepotFilePage;@SuppressWarnings("serial")@@ -66,6 +68,8 @@ public abstract class FileEditPanel extends Panel {private EditSavePanel editSavePanel;+ private SourceFormatPanel sourceFormat;+public FileEditPanel(String id, IModel<Depot> depotModel, String refName,@Nullable String oldPath, String content, ObjectId prevCommitId,@Nullable TextRange mark) {@@ -173,6 +177,35 @@ public abstract class FileEditPanel extends Panel {});+ add(sourceFormat = new SourceFormatPanel("sourceFormat", new OptionChangeCallback() {++ @Override+ public void onOptioneChange(AjaxRequestTarget target) {+ String script = String.format("gitplex.fileedit.onIndentTypeChange('%s', '%s');",+ FileEditPanel.this.getMarkupId(), sourceFormat.getIndentType());+ target.appendJavaScript(script);+ }++ }, new OptionChangeCallback() {++ @Override+ public void onOptioneChange(AjaxRequestTarget target) {+ String script = String.format("gitplex.fileedit.onTabSizeChange('%s', %s);",+ FileEditPanel.this.getMarkupId(), sourceFormat.getTabSize());+ target.appendJavaScript(script);+ }++ }, new OptionChangeCallback() {++ @Override+ public void onOptioneChange(AjaxRequestTarget target) {+ String script = String.format("gitplex.fileedit.onLineWrapModeChange('%s', '%s');",+ FileEditPanel.this.getMarkupId(), sourceFormat.getLineWrapMode());+ target.appendJavaScript(script);+ }++ }));+add(new WebMarkupContainer(PREVIEW_ID).setOutputMarkupId(true));PathAndContent newFile = new PathAndContent() {@@ -208,12 +241,15 @@ public abstract class FileEditPanel extends Panel {String viewState = RequestCycle.get().getMetaData(DepotFilePage.VIEW_STATE_KEY);- String script = String.format("gitplex.fileedit.init('%s', '%s', '%s', %s, %s, %s, %s);",+ String script = String.format("gitplex.fileedit.init('%s', '%s', '%s', %s, %s, %s, %s, '%s', %s, '%s');",getMarkupId(), getNewPathParam(), StringEscapeUtils.escapeEcmaScript(content),previewBehavior.getCallbackFunction(CallbackParameter.explicit("content")),saveBehavior.getCallbackFunction(CallbackParameter.explicit("content")),mark!=null?getJson(mark):"undefined",- viewState!=null?"JSON.parse('"+viewState+"')":"undefined");+ viewState!=null?"JSON.parse('"+viewState+"')":"undefined",+ sourceFormat.getIndentType(),+ sourceFormat.getTabSize(),+ sourceFormat.getLineWrapMode());response.render(OnDomReadyHeaderItem.forScript(script));}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/file-edit.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/file-edit.cssindex 2a8e439416..6159395308 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/file-edit.css+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/file-edit.css@@ -24,6 +24,9 @@margin-top: 11px;margin-left: 12px;}+.file-edit>.head>.source-format {+ margin: 8px 12px 0 0;+}.file-edit>.body {overflow: hidden;}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/file-edit.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/file-edit.jsindex 42874de2f0..e8233e1903 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/file-edit.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/file-edit.js@@ -1,205 +1,219 @@-gitplex.fileedit = {- init: function(containerId, filePath, fileContent, previewCallback, saveCallback, mark, viewState) {- var $container = $("#" + containerId);- var $fileEdit = $container.find(">.file-edit");- var $head = $fileEdit.find(">.head");- var $body = $fileEdit.find(">.body");- var $edit = $body.find(">div.edit");- var cm;-- $head.find("a.edit").click(function() {- gitplex.fileedit.selectTab($(this));- });- $head.find("a.preview").click(function() {- previewCallback(cm.getValue());- });- $head.find("a.save").click(function() {- saveCallback(cm.getValue());- });-- $fileEdit.on("storeViewState", function(e) {- e.stopPropagation();- if (cm) {- pmease.commons.history.setViewState(pmease.commons.codemirror.getViewState(cm));- }- });-- $fileEdit.on("autofit", function(e, width, height) {- e.stopPropagation();- $fileEdit.outerWidth(width);- $fileEdit.outerHeight(height);-- height = $fileEdit.height()-$head.outerHeight();- $body.outerWidth(width).outerHeight(height-1);-- /*- * initialize codemirror here when we know the container width and height- * as otherwise the annotatescrollbar addon is inaccurate when window- * initially loads- */- var initState = !cm;- if (!cm) {- cm = CodeMirror($edit[0], {- value: fileContent,- theme: "eclipse",- lineNumbers: true,- lineWrapping: true,- styleActiveLine: true,- styleSelectedText: true,- foldGutter: true,- matchBrackets: true,- scrollbarStyle: "simple",- highlightIdentifiers: {delay: 500},- extraKeys: {- "F11": function(cm) {- cm.setOption("fullScreen", !cm.getOption("fullScreen"));- },- "Esc": function(cm) {- if (cm.getOption("fullScreen"))- cm.setOption("fullScreen", false);- }- }- });-- cm.oldDocValue = cm.doc.getValue();- cm.on("change", function() {- var $form = $body.find(">form.edit");- if (cm.doc.getValue() != cm.oldDocValue) {- $form.addClass("dirty");- $fileEdit.data("contentChanged", true);- } else {- $form.removeClass("dirty");- $fileEdit.data("contentChanged", false);- }- });- pmease.commons.codemirror.setMode(cm, filePath);-- if (mark)- pmease.commons.codemirror.mark(cm, mark);- }-- if ($edit.is(":visible")) {- $body.css("overflow", "hidden");- $edit.outerHeight($body.height());- $edit.outerWidth($body.width());- if (cm.getOption("fullScreen"))- cm.setOption("fullScreen", false);- cm.setSize($edit.width(), $edit.height());- if (initState)- pmease.commons.codemirror.initState(cm, viewState);- } else {- $body.css("overflow", "auto");- }- });- },- save: function(containerId) {- gitplex.fileedit.selectTab($("#" + containerId + ">.file-edit>.head>.save"));- },- preview: function(containerId) {- gitplex.fileedit.selectTab($("#" + containerId + ">.file-edit>.head>.preview"));- },- setMode: function(containerId, filePath) {- var cm = $("#"+ containerId + ">.file-edit>.body>div.edit>.CodeMirror")[0].CodeMirror;- pmease.commons.codemirror.setMode(cm, filePath);- },- mark: function(containerId, mark) {- var cm = $("#"+ containerId + ">.file-edit>.body>div.edit>.CodeMirror")[0].CodeMirror;- if (cm.oldDocValue) {- var dmp = new diff_match_patch();- var diffs = dmp.diff_main(cm.oldDocValue, cm.doc.getValue());-- var beginLine = mark.beginLine, beginChar = mark.beginChar;- var endLine = mark.endLine, endChar = mark.endChar;- var newBeginLine, newBeginChar, newEndLine, newEndChar;- var oldLine = oldChar = newLine = newChar = 0;- for (var i=0; i<diffs.length; i++) {- var diff = diffs[i];- var chars = diff[1];- var quit = false;- for (var j=0; j<chars.length; j++) {- var char = chars[j];- if (diff[0] == -1) {- if (char == '\n') {- oldLine++;- oldChar = 0;- } else {- oldChar++;- }- } else if (diff[0] == 1) {- if (char == '\n') {- newLine++;- newChar = 0;- } else {- newChar++;- }- } else {- if (oldLine == beginLine && oldChar == beginChar) {- newBeginLine = newLine;- newBeginChar = newChar;- }- if (char == '\n') {- oldLine++;- oldChar = 0;- newLine++;- newChar = 0;- } else {- oldChar++;- newChar++;- }- if (oldLine == endLine && oldChar == endChar) {- newEndLine = newLine;- newEndChar = newChar;- }- }- if (oldLine>beginLine && newBeginLine==undefined || oldLine>endLine) {- quit = true;- break;- }- }- if (quit)- break;- }- }-- if (newBeginLine!=undefined && newEndLine!=undefined) {- var newMark = {- beginLine: newBeginLine,- beginChar: newBeginChar,- endLine: newEndLine,- endChar: newEndChar- };- pmease.commons.codemirror.mark(cm, newMark);- }- },- selectTab: function($tab) {- var $active = $tab.parent().find("a.tab.active");- $active[0].hideableVisible = $(".hideable").is(":visible");- $active.removeClass("active");- $tab.addClass("active");- if ($tab[0].hideableVisible != undefined) {- if ($tab[0].hideableVisible)- $(".hideable").show();- else- $(".hideable").hide();- }- var $fileEdit = $tab.closest(".file-edit");- var $body = $fileEdit.find(">.body");-- var $cm = $fileEdit.find(">.body>div.edit>.CodeMirror");- if ($cm.is(":visible")) {- var cm = $cm[0].CodeMirror;- $fileEdit.find(">.body>div.save").data("viewState", pmease.commons.codemirror.getViewState(cm));- }-- $body.find(">div").hide();- if ($tab.hasClass("edit")) {- $body.find(">div.edit").show().find(">.CodeMirror")[0].CodeMirror.focus();- } else if ($tab.hasClass("preview")) {- $body.find(">div.preview").show();- } else {- $body.find(">div.save").show();- $body.find(">div.save>.edit-save").trigger("contentEdit", [$fileEdit.data("contentChanged")]);- }- $(window).resize();- }-};+gitplex.fileedit = {+ init: function(containerId, filePath, fileContent, previewCallback, saveCallback, mark, viewState, indentType, tabSize, lineWrapMode) {+ var $container = $("#" + containerId);+ var $fileEdit = $container.find(">.file-edit");+ var $head = $fileEdit.find(">.head");+ var $body = $fileEdit.find(">.body");+ var $edit = $body.find(">div.edit");+ var cm;++ $head.find("a.edit").click(function() {+ gitplex.fileedit.selectTab($(this));+ });+ $head.find("a.preview").click(function() {+ previewCallback(cm.getValue());+ });+ $head.find("a.save").click(function() {+ saveCallback(cm.getValue());+ });++ $fileEdit.on("storeViewState", function(e) {+ e.stopPropagation();+ if (cm) {+ pmease.commons.history.setViewState(pmease.commons.codemirror.getViewState(cm));+ }+ });++ $fileEdit.on("autofit", function(e, width, height) {+ e.stopPropagation();+ $fileEdit.outerWidth(width);+ $fileEdit.outerHeight(height);++ height = $fileEdit.height()-$head.outerHeight();+ $body.outerWidth(width).outerHeight(height-1);++ /*+ * initialize codemirror here when we know the container width and height+ * as otherwise the annotatescrollbar addon is inaccurate when window+ * initially loads+ */+ var initState = !cm;+ if (!cm) {+ cm = CodeMirror($edit[0], {+ value: fileContent,+ theme: "eclipse",+ indentWithTabs: indentType == "Tabs",+ lineNumbers: true,+ lineWrapping: lineWrapMode == "Soft wrap",+ tabSize: tabSize,+ styleActiveLine: true,+ styleSelectedText: true,+ foldGutter: true,+ matchBrackets: true,+ scrollbarStyle: "simple",+ highlightIdentifiers: {delay: 500},+ extraKeys: {+ "F11": function(cm) {+ cm.setOption("fullScreen", !cm.getOption("fullScreen"));+ },+ "Esc": function(cm) {+ if (cm.getOption("fullScreen"))+ cm.setOption("fullScreen", false);+ }+ }+ });++ cm.oldDocValue = cm.doc.getValue();+ cm.on("change", function() {+ var $form = $body.find(">form.edit");+ if (cm.doc.getValue() != cm.oldDocValue) {+ $form.addClass("dirty");+ $fileEdit.data("contentChanged", true);+ } else {+ $form.removeClass("dirty");+ $fileEdit.data("contentChanged", false);+ }+ });+ pmease.commons.codemirror.setMode(cm, filePath);++ if (mark)+ pmease.commons.codemirror.mark(cm, mark);+ }++ if ($edit.is(":visible")) {+ $body.css("overflow", "hidden");+ $edit.outerHeight($body.height());+ $edit.outerWidth($body.width());+ if (cm.getOption("fullScreen"))+ cm.setOption("fullScreen", false);+ cm.setSize($edit.width(), $edit.height());+ if (initState)+ pmease.commons.codemirror.initState(cm, viewState);+ } else {+ $body.css("overflow", "auto");+ }+ });+ },+ save: function(containerId) {+ gitplex.fileedit.selectTab($("#" + containerId + ">.file-edit>.head>.save"));+ },+ preview: function(containerId) {+ gitplex.fileedit.selectTab($("#" + containerId + ">.file-edit>.head>.preview"));+ },+ setMode: function(containerId, filePath) {+ var cm = $("#"+ containerId + ">.file-edit>.body>div.edit>.CodeMirror")[0].CodeMirror;+ pmease.commons.codemirror.setMode(cm, filePath);+ },+ mark: function(containerId, mark) {+ var cm = $("#"+ containerId + ">.file-edit>.body>div.edit>.CodeMirror")[0].CodeMirror;+ if (cm.oldDocValue) {+ var dmp = new diff_match_patch();+ var diffs = dmp.diff_main(cm.oldDocValue, cm.doc.getValue());++ var beginLine = mark.beginLine, beginChar = mark.beginChar;+ var endLine = mark.endLine, endChar = mark.endChar;+ var newBeginLine, newBeginChar, newEndLine, newEndChar;+ var oldLine = oldChar = newLine = newChar = 0;+ for (var i=0; i<diffs.length; i++) {+ var diff = diffs[i];+ var chars = diff[1];+ var quit = false;+ for (var j=0; j<chars.length; j++) {+ var char = chars[j];+ if (diff[0] == -1) {+ if (char == '\n') {+ oldLine++;+ oldChar = 0;+ } else {+ oldChar++;+ }+ } else if (diff[0] == 1) {+ if (char == '\n') {+ newLine++;+ newChar = 0;+ } else {+ newChar++;+ }+ } else {+ if (oldLine == beginLine && oldChar == beginChar) {+ newBeginLine = newLine;+ newBeginChar = newChar;+ }+ if (char == '\n') {+ oldLine++;+ oldChar = 0;+ newLine++;+ newChar = 0;+ } else {+ oldChar++;+ newChar++;+ }+ if (oldLine == endLine && oldChar == endChar) {+ newEndLine = newLine;+ newEndChar = newChar;+ }+ }+ if (oldLine>beginLine && newBeginLine==undefined || oldLine>endLine) {+ quit = true;+ break;+ }+ }+ if (quit)+ break;+ }+ }++ if (newBeginLine!=undefined && newEndLine!=undefined) {+ var newMark = {+ beginLine: newBeginLine,+ beginChar: newBeginChar,+ endLine: newEndLine,+ endChar: newEndChar+ };+ pmease.commons.codemirror.mark(cm, newMark);+ }+ },+ selectTab: function($tab) {+ var $active = $tab.parent().find("a.tab.active");+ $active[0].hideableVisible = $(".hideable").is(":visible");+ $active.removeClass("active");+ $tab.addClass("active");+ if ($tab[0].hideableVisible != undefined) {+ if ($tab[0].hideableVisible)+ $(".hideable").show();+ else+ $(".hideable").hide();+ }+ var $fileEdit = $tab.closest(".file-edit");+ var $body = $fileEdit.find(">.body");++ var $cm = $fileEdit.find(">.body>div.edit>.CodeMirror");+ if ($cm.is(":visible")) {+ var cm = $cm[0].CodeMirror;+ $fileEdit.find(">.body>div.save").data("viewState", pmease.commons.codemirror.getViewState(cm));+ }++ $body.find(">div").hide();+ if ($tab.hasClass("edit")) {+ $body.find(">div.edit").show().find(">.CodeMirror")[0].CodeMirror.focus();+ } else if ($tab.hasClass("preview")) {+ $body.find(">div.preview").show();+ } else {+ $body.find(">div.save").show();+ $body.find(">div.save>.edit-save").trigger("contentEdit", [$fileEdit.data("contentChanged")]);+ }+ $(window).resize();+ },+ onIndentTypeChange: function(containerId, indentType) {+ var cm = $("#"+ containerId + ">.file-edit>.body>div.edit>.CodeMirror")[0].CodeMirror;+ cm.setOption("indentWithTabs", indentType == "Tabs");+ },+ onLineWrapModeChange: function(containerId, lineWrapMode) {+ var cm = $("#"+ containerId + ">.file-edit>.body>div.edit>.CodeMirror")[0].CodeMirror;+ cm.setOption("lineWrapping", lineWrapMode == "Soft wrap");+ },+ onTabSizeChange: function(containerId, tabSize) {+ var cm = $("#"+ containerId + ">.file-edit>.body>div.edit>.CodeMirror")[0].CodeMirror;+ cm.setOption("tabSize", tabSize);+ }+};diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceformat/OptionChangeCallback.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceformat/OptionChangeCallback.javanew file mode 100644index 0000000000..a796188e6e--- /dev/null+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceformat/OptionChangeCallback.java@@ -0,0 +1,11 @@+package com.pmease.gitplex.web.component.sourceformat;++import java.io.Serializable;++import org.apache.wicket.ajax.AjaxRequestTarget;++public interface OptionChangeCallback extends Serializable {++ void onOptioneChange(AjaxRequestTarget target);++}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceformat/SourceFormatPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceformat/SourceFormatPanel.htmlnew file mode 100644index 0000000000..63479bb9c9--- /dev/null+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceformat/SourceFormatPanel.html@@ -0,0 +1,7 @@+<wicket:panel>+ <div class="source-format">+ <select wicket:id="indentType" class="indent-type"></select>+ <select wicket:id="tabSize" class="tab-size"></select>+ <select wicket:id="lineWrapMode" class="line-wrap-mode"></select>+ </div>+</wicket:panel>\ No newline at end of filediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceformat/SourceFormatPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceformat/SourceFormatPanel.javanew file mode 100644index 0000000000..6e1c94cd09--- /dev/null+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceformat/SourceFormatPanel.java@@ -0,0 +1,181 @@+package com.pmease.gitplex.web.component.sourceformat;++import javax.annotation.Nullable;+import javax.servlet.http.Cookie;++import org.apache.wicket.ajax.AjaxRequestTarget;+import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;+import org.apache.wicket.markup.head.IHeaderResponse;+import org.apache.wicket.markup.head.JavaScriptReferenceHeaderItem;+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;+import org.apache.wicket.markup.html.form.DropDownChoice;+import org.apache.wicket.markup.html.panel.Panel;+import org.apache.wicket.model.IModel;+import org.apache.wicket.request.cycle.RequestCycle;+import org.apache.wicket.request.http.WebRequest;+import org.apache.wicket.request.http.WebResponse;++import com.google.common.collect.Lists;++@SuppressWarnings("serial")+public class SourceFormatPanel extends Panel {++ private static final String COOKIE_INDENT_TYPE = "sourceFormat.identType";++ private static final String COOKIE_TAB_SIZE = "sourceFormat.tabSize";++ private static final String COOKIE_LINE_WRAP_MODE = "sourceFormat.lineWrapMode";++ private final OptionChangeCallback indentTypeChangeCallback;++ private final OptionChangeCallback tabSizeChangeCallback;++ private final OptionChangeCallback lineWrapModeChangeCallback;++ private String indentType;++ private String tabSize;++ private String lineWrapMode;++ public SourceFormatPanel(String id,+ @Nullable OptionChangeCallback indentTypeChangeCallback,+ @Nullable OptionChangeCallback tabSizeChangeCallback,+ @Nullable OptionChangeCallback lineWrapModeChangeCallback) {+ super(id);++ this.indentTypeChangeCallback = indentTypeChangeCallback;+ this.tabSizeChangeCallback = tabSizeChangeCallback;+ this.lineWrapModeChangeCallback = lineWrapModeChangeCallback;++ WebRequest request = (WebRequest) RequestCycle.get().getRequest();+ Cookie cookie = request.getCookie(COOKIE_INDENT_TYPE);+ if (cookie != null)+ indentType = cookie.getValue();+ else+ indentType = "Spaces";++ cookie = request.getCookie(COOKIE_TAB_SIZE);+ if (cookie != null)+ tabSize = cookie.getValue();+ else+ tabSize = "4";++ cookie = request.getCookie(COOKIE_LINE_WRAP_MODE);+ if (cookie != null)+ lineWrapMode = cookie.getValue();+ else+ lineWrapMode = "Soft wrap";+ }++ @Override+ protected void onInitialize() {+ super.onInitialize();++ add(new DropDownChoice<String>("indentType", new IModel<String>() {++ @Override+ public void detach() {+ }++ @Override+ public String getObject() {+ return indentType;+ }++ @Override+ public void setObject(String object) {+ indentType = object;+ }++ }, Lists.newArrayList("Spaces", "Tabs")).add(new OnChangeAjaxBehavior() {++ @Override+ protected void onUpdate(AjaxRequestTarget target) {+ WebResponse response = (WebResponse) RequestCycle.get().getResponse();+ response.addCookie(new Cookie(COOKIE_INDENT_TYPE, indentType));+ indentTypeChangeCallback.onOptioneChange(target);+ }++ }).setVisible(indentTypeChangeCallback != null));++ add(new DropDownChoice<String>("tabSize", new IModel<String>() {++ @Override+ public void detach() {+ }++ @Override+ public String getObject() {+ return tabSize;+ }++ @Override+ public void setObject(String object) {+ tabSize = object;+ }++ }, Lists.newArrayList("2", "4", "8")).add(new OnChangeAjaxBehavior() {++ @Override+ protected void onUpdate(AjaxRequestTarget target) {+ WebResponse response = (WebResponse) RequestCycle.get().getResponse();+ response.addCookie(new Cookie(COOKIE_TAB_SIZE, tabSize));+ tabSizeChangeCallback.onOptioneChange(target);+ }++ }).setVisible(tabSizeChangeCallback != null));++ add(new DropDownChoice<String>("lineWrapMode", new IModel<String>() {++ @Override+ public void detach() {+ }++ @Override+ public String getObject() {+ return lineWrapMode;+ }++ @Override+ public void setObject(String object) {+ lineWrapMode = object;+ }++ }, Lists.newArrayList("No wrap", "Soft wrap")).add(new OnChangeAjaxBehavior() {++ @Override+ protected void onUpdate(AjaxRequestTarget target) {+ WebResponse response = (WebResponse) RequestCycle.get().getResponse();+ response.addCookie(new Cookie(COOKIE_LINE_WRAP_MODE, lineWrapMode));+ lineWrapModeChangeCallback.onOptioneChange(target);+ }++ }).setVisible(lineWrapModeChangeCallback != null));++ setOutputMarkupId(true);+ }++ @Override+ public void renderHead(IHeaderResponse response) {+ super.renderHead(response);++ response.render(JavaScriptReferenceHeaderItem.forReference(new SourceFormatResourceReference()));++ String script = String.format("gitplex.sourceFormat.init('%s');", getMarkupId());+ response.render(OnDomReadyHeaderItem.forScript(script));+ }++ public String getIndentType() {+ return indentType;+ }++ public String getTabSize() {+ return tabSize;+ }++ public String getLineWrapMode() {+ return lineWrapMode;+ }++}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceformat/SourceFormatResourceReference.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceformat/SourceFormatResourceReference.javanew file mode 100644index 0000000000..bc536989c9--- /dev/null+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceformat/SourceFormatResourceReference.java@@ -0,0 +1,26 @@+package com.pmease.gitplex.web.component.sourceformat;++import java.util.List;++import org.apache.wicket.markup.head.CssHeaderItem;+import org.apache.wicket.markup.head.HeaderItem;++import com.pmease.gitplex.web.page.base.BaseDependentCssResourceReference;+import com.pmease.gitplex.web.page.base.BaseDependentResourceReference;++public class SourceFormatResourceReference extends BaseDependentResourceReference {++ private static final long serialVersionUID = 1L;++ public SourceFormatResourceReference() {+ super(SourceFormatResourceReference.class, "source-format.js");+ }++ @Override+ public List<HeaderItem> getDependencies() {+ List<HeaderItem> dependencies = super.getDependencies();+ dependencies.add(CssHeaderItem.forReference(new BaseDependentCssResourceReference(SourceFormatResourceReference.class, "source-format.css")));+ return dependencies;+ }++}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceformat/source-format.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceformat/source-format.cssnew file mode 100644index 0000000000..8c318b9ea6--- /dev/null+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceformat/source-format.css@@ -0,0 +1,6 @@+.source-format select {+ margin-left: 8px;+ border: 1px solid #BBB;+ color: #444;+ border-radius: 2px;+}\ No newline at end of filediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceformat/source-format.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceformat/source-format.jsnew file mode 100644index 0000000000..bbcdf0a086--- /dev/null+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceformat/source-format.js@@ -0,0 +1,9 @@+gitplex.sourceFormat = {+ init: function(containerId) {+ var $container = $("#" + containerId);++ $container.find(".indent-type").prepend("<optgroup label='Indent type'></optgroup>");+ $container.find(".tab-size").prepend("<optgroup label='Tab size'></optgroup>");+ $container.find(".line-wrap-mode").prepend("<optgroup label='Line wrap mode'></optgroup>");+ }+};\ No newline at end of file