The Unified and Autonomous Development Platform
Almost finished with FileEditPanel pretty
robin shine629d8c02d20b
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/blob-view.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/blob-view.jsindex 68e960491d..eca74de3f5 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/blob-view.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/blob-view.js@@ -20,7 +20,7 @@ gitplex.blobView = function(containerId) {height = $blobView.height()-$head.outerHeight();$body.outerWidth(width).outerHeight(height);- $body.closestDescendant(".autofit").trigger("autofit", [$body.width(), $body.height()]);+ $body.closestDescendant(".autofit:visible").trigger("autofit", [$body.width(), $body.height()]);var scrollPos = pmease.commons.history.getScrollPos();if (scrollPos) {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/editsave/edit-save.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/editsave/edit-save.jsindex 6201064a1a..f13f703062 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/editsave/edit-save.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/editsave/edit-save.js@@ -14,6 +14,8 @@ gitplex.editSave = {$editSave.on("autofit", function(event, width, height) {event.stopPropagation();++ $editSave.closest(".body").css("overflow", "hidden");$editSave.outerWidth(width);$editSave.outerHeight(height);diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/FileEditPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/FileEditPanel.htmlindex cf29f27240..44f5327728 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/FileEditPanel.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/FileEditPanel.html@@ -1,13 +1,17 @@<wicket:panel>- <div class="file-edit">+ <div class="file-edit autofit"><div class="head clearfix">- <a class="active tab edit pull-left"><i class="fa fa-pencil"></i> Edit</a>- <a wicket:id="previewLink" class="tab preview pull-left"><i class="fa fa-eye"></i> Preview</a>+ <a class="active tab edit pull-left"><i class="fa fa-pencil"></i> Edit file</a>+ <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">Cancel</a></div><div class="body">- <form class="edit leave-confirm"></form>+ <!-- below form is for dirty checking purpose and we can not use it as containing+ element of codemirror as otherwise the dirty flag will be cleared by codemirror+ upon changing -->+ <form class="edit leave-confirm hidden"></form>+ <div class="edit"></div><div wicket:id="preview" class="preview">TBD</div><div wicket:id="save" class="save"></div></div>diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/file-edit.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/file-edit.cssindex 686ee3cc38..042f487370 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/file-edit.css+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/file-edit.css@@ -1,21 +1,35 @@.file-edit>.head {border-bottom: 1px solid #BBB;+ height: 36px;+ background: #F2F2F2;}.file-edit>.head a.tab {- display: inline-block;- height: 35px;color: #666;- padding: 6px 12px;+ margin-top: 6px;+ padding: 4px 12px;text-decoration: none;}+.file-edit>.head a.edit {+ margin-left: 12px;+}.file-edit>.head a.active.tab {- background: #E8E8E8;+ background: white;+ border: 1px solid #BBB;+ border-radius: 4px 4px 0 0;+ border-bottom: 1px solid white;font-weight: bold;color: #333;}.file-edit>.head a.cancel {- margin: 6px 12px;+ margin-top: 10px;+ margin-left: 12px;+}+.file-edit>.body {+ overflow: auto;}.file-edit>.body>.preview, .file-edit>.body>.save {display: none;-}\ No newline at end of file+}+.file-edit>.body>.save>.edit-save {+ overflow: hidden;+}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/file-edit.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/file-edit.jsindex 5f216b7edd..6e5f628b19 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/file-edit.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/file-edit.js@@ -1,8 +1,11 @@gitplex.fileEdit = {init: function(containerId, filePath, fileContent, previewCallback, saveCallback) {var $container = $("#" + containerId);- var $code = $container.find(">.file-edit>.body>.edit");- var cm = CodeMirror($code[0], {+ var $fileEdit = $container.find(">.file-edit");+ var $head = $fileEdit.find(">.head");+ var $body = $fileEdit.find(">.body");+ var $edit = $body.find(">div.edit");+ var cm = CodeMirror($edit[0], {value: fileContent,theme: "eclipse",lineNumbers: true,@@ -16,46 +19,97 @@ gitplex.fileEdit = {});cm.on("change", function() {- $container.find(">.file-edit>.body>.edit").addClass("dirty");+ $body.find(">form.edit").addClass("dirty");});cm.focus();+ cm.on("scroll", function() {+ var scrollInfo = cm.getScrollInfo();+ pmease.commons.history.setScrollPos({left: scrollInfo.left, top: scrollInfo.top});+ });++ var scrollPos = pmease.commons.history.getScrollPos();+ if (scrollPos)+ cm.scrollTo(scrollPos.left, scrollPos.top);+gitplex.fileEdit.setMode(cm, filePath);- $container.find(">.file-edit>.head a.edit").click(function() {- $container.find(">.file-edit>.head a.tab").removeClass("active");+ $head.find("a.edit").click(function() {+ $head.find("a.tab").removeClass("active");$(this).addClass("active");- $container.find(">.file-edit>.body>.preview").hide();- $container.find(">.file-edit>.body>.save").hide();- $container.find(">.file-edit>.body>.edit").show();+ $body.find(".preview").hide();+ $body.find(".save").hide();+ $edit.show();+ $(window).resize();});- $container.find(">.file-edit>.head a.preview").click(function() {+ $head.find("a.preview").click(function() {previewCallback(cm.getValue());- $container.find(">.file-edit>.head a.tab").removeClass("active");- $(this).addClass("active");});- $container.find(">.file-edit>.head a.save").click(function() {+ $head.find("a.save").click(function() {saveCallback(cm.getValue());- $container.find(">.file-edit>.head a.tab").removeClass("active");+ $head.find("a.tab").removeClass("active");$(this).addClass("active");});- $container.find("form.edit").submit(false);++ $fileEdit.on("autofit", function(event, width, height) {+ console.log("autofit");+ event.stopPropagation();+ $fileEdit.outerWidth(width);+ $fileEdit.outerHeight(height);++ height = $fileEdit.height()-$head.outerHeight();+ $body.outerWidth(width).outerHeight(height);++ if ($edit.is(":visible")) {+ $body.css("overflow", "hidden");+ $edit.outerHeight($body.height());+ $edit.outerWidth($body.width());+ cm.setSize($edit.width(), $edit.height());+ } else {+ $body.css("overflow", "auto");+ }+ });++ gitplex.expandable.getScrollTop = function() {+ if ($edit.is(":visible"))+ return cm.getScrollInfo().top;+ else+ return $body.scrollTop();+ };++ gitplex.expandable.setScrollTop = function(scrollTop) {+ if ($edit.is(":visible"))+ cm.scrollTo(undefined, scrollTop);+ else+ $body.scrollTop(scrollTop);+ };+},save: function(containerId) {var $container = $("#" + containerId);- $container.find(">.file-edit>.body>.edit").hide();++ $container.find(">.file-edit>.head a.tab").removeClass("active");+ $container.find(">.file-edit>.head a.save").addClass("active");++ $container.find(">.file-edit>.body>div.edit").hide();$container.find(">.file-edit>.body>.preview").hide();$container.find(">.file-edit>.body>.save").show();+ $(window).resize();},preview: function(containerId) {var $container = $("#" + containerId);- $container.find(">.file-edit>.body>.edit").hide();++ $container.find(">.file-edit>.head a.tab").removeClass("active");+ $container.find(">.file-edit>.head a.preview").addClass("active");++ $container.find(">.file-edit>.body>div.edit").hide();$container.find(">.file-edit>.body>.save").hide();$container.find(">.file-edit>.body>.preview").show();+ $(window).resize();},setMode: function(cm, filePath) {if (typeof cm === "string")- cm = $("#"+ cm + ">.file-edit>.body>.edit>.CodeMirror")[0].CodeMirror;+ cm = $("#"+ cm + ">.file-edit>.body>div.edit>.CodeMirror")[0].CodeMirror;var modeInfo = CodeMirror.findModeByFileName(filePath);if (modeInfo) {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.javaindex b4eb6fd8b2..7244e61b83 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java@@ -376,6 +376,8 @@ public class RepoFilePage extends RepositoryPage {lastCommit.setVisibilityAllowed(false);target.add(lastCommit);newFileNavigator(target, callback);++ target.appendJavaScript("$(window).resize();");}private void onSelect(AjaxRequestTarget target, BlobIdent blobIdent, TokenPosition tokenPos) {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/repo-file.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/repo-file.jsindex 3a65b9026b..79dd2b219f 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/repo-file.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/repo-file.js@@ -69,7 +69,7 @@ $(window).load(function() {-$("#search-result-resize-handle").outerHeight());}$fileViewer.outerWidth(width).outerHeight(height);- $fileViewer.closestDescendant(".autofit").trigger("autofit", [$fileViewer.width(), $fileViewer.height()]);+ $fileViewer.closestDescendant(".autofit:visible").trigger("autofit", [$fileViewer.width(), $fileViewer.height()]);});$(window).resize();});\ No newline at end of file