Skip to content

The Unified and Autonomous Development Platform

midwork

robin shine6a048980dd14
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/CodeMirrorResourceReference.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/CodeMirrorResourceReference.java
index 67f60ba063..fed9580908 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/CodeMirrorResourceReference.java
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/CodeMirrorResourceReference.java
@@ -1,61 +1,59 @@
-package com.pmease.commons.wicket.assets.codemirror;
-
-import org.apache.wicket.markup.head.CssHeaderItem;
-import org.apache.wicket.markup.head.HeaderItem;
-import org.apache.wicket.markup.head.JavaScriptHeaderItem;
-import org.apache.wicket.request.resource.CssResourceReference;
-import org.apache.wicket.request.resource.JavaScriptResourceReference;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import com.pmease.commons.wicket.assets.uri.URIResourceReference;
-
-import de.agilecoders.wicket.webjars.request.resource.WebjarsCssResourceReference;
-import de.agilecoders.wicket.webjars.request.resource.WebjarsJavaScriptResourceReference;
-
-public class CodeMirrorResourceReference extends JavaScriptResourceReference {
-
- private static final long serialVersionUID = 1L;
-
- public static final CodeMirrorResourceReference INSTANCE = new CodeMirrorResourceReference();
-
- private CodeMirrorResourceReference() {
- super(CodeMirrorResourceReference.class, "codemirror.js");
- }
-
- @Override
- public Iterable<? extends HeaderItem> getDependencies() {
- return Iterables.concat(super.getDependencies(), ImmutableList.<HeaderItem>of(
- JavaScriptHeaderItem.forReference(CodeMirrorCoreResourceReference.INSTANCE),
- JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/dialog/dialog.js")),
- JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/fold/foldcode.js")),
- JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/fold/foldgutter.js")),
- JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/fold/brace-fold.js")),
- JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/fold/xml-fold.js")),
- JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/fold/markdown-fold.js")),
- JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/fold/comment-fold.js")),
- JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/search/searchcursor.js")),
- JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/search/search.js")),
- JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/search/matchesonscrollbar.js")),
- JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(CodeMirrorResourceReference.class, "matchesonscrollbar2.js")),
- JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/selection/active-line.js")),
- JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/scroll/annotatescrollbar.js")),
- JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/display/fullscreen.js")),
- JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(CodeMirrorResourceReference.class, "annotatescrollbar2.js")),
- JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(CodeMirrorResourceReference.class, "simplescrollbars.js")),
- JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(CodeMirrorResourceReference.class, "gotoline.js")),
-
- JavaScriptHeaderItem.forReference(URIResourceReference.INSTANCE),
- JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(CodeMirrorResourceReference.class, "identifier-highlighter.js")),
-
- CssHeaderItem.forReference(new WebjarsCssResourceReference("codemirror/current/addon/dialog/dialog.css")),
- CssHeaderItem.forReference(new WebjarsCssResourceReference("codemirror/current/addon/fold/foldgutter.css")),
- CssHeaderItem.forReference(new WebjarsCssResourceReference("codemirror/current/addon/scroll/simplescrollbars.css")),
- CssHeaderItem.forReference(new WebjarsCssResourceReference("codemirror/current/addon/search/matchesonscrollbar.css")),
- CssHeaderItem.forReference(new WebjarsCssResourceReference("codemirror/current/addon/display/fullscreen.css")),
-
- CssHeaderItem.forReference(new CssResourceReference(CodeMirrorResourceReference.class, "codemirror.css"))
- ));
- }
-
-}
+package com.pmease.commons.wicket.assets.codemirror;
+
+import org.apache.wicket.markup.head.CssHeaderItem;
+import org.apache.wicket.markup.head.HeaderItem;
+import org.apache.wicket.markup.head.JavaScriptHeaderItem;
+import org.apache.wicket.request.resource.CssResourceReference;
+import org.apache.wicket.request.resource.JavaScriptResourceReference;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+
+import de.agilecoders.wicket.webjars.request.resource.WebjarsCssResourceReference;
+import de.agilecoders.wicket.webjars.request.resource.WebjarsJavaScriptResourceReference;
+
+public class CodeMirrorResourceReference extends JavaScriptResourceReference {
+
+ private static final long serialVersionUID = 1L;
+
+ public static final CodeMirrorResourceReference INSTANCE = new CodeMirrorResourceReference();
+
+ private CodeMirrorResourceReference() {
+ super(CodeMirrorResourceReference.class, "codemirror.js");
+ }
+
+ @Override
+ public Iterable<? extends HeaderItem> getDependencies() {
+ return Iterables.concat(super.getDependencies(), ImmutableList.<HeaderItem>of(
+ JavaScriptHeaderItem.forReference(CodeMirrorCoreResourceReference.INSTANCE),
+ JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/dialog/dialog.js")),
+ JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/fold/foldcode.js")),
+ JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/fold/foldgutter.js")),
+ JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/fold/brace-fold.js")),
+ JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/fold/xml-fold.js")),
+ JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/fold/markdown-fold.js")),
+ JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/fold/comment-fold.js")),
+ JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/search/searchcursor.js")),
+ JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/search/search.js")),
+ JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/search/matchesonscrollbar.js")),
+ JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(CodeMirrorResourceReference.class, "matchesonscrollbar2.js")),
+ JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/selection/active-line.js")),
+ JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/scroll/annotatescrollbar.js")),
+ JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/addon/display/fullscreen.js")),
+ JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(CodeMirrorResourceReference.class, "annotatescrollbar2.js")),
+ JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(CodeMirrorResourceReference.class, "simplescrollbars.js")),
+ JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(CodeMirrorResourceReference.class, "gotoline.js")),
+
+ JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(CodeMirrorResourceReference.class, "identifier-highlighter.js")),
+
+ CssHeaderItem.forReference(new WebjarsCssResourceReference("codemirror/current/addon/dialog/dialog.css")),
+ CssHeaderItem.forReference(new WebjarsCssResourceReference("codemirror/current/addon/fold/foldgutter.css")),
+ CssHeaderItem.forReference(new WebjarsCssResourceReference("codemirror/current/addon/scroll/simplescrollbars.css")),
+ CssHeaderItem.forReference(new WebjarsCssResourceReference("codemirror/current/addon/search/matchesonscrollbar.css")),
+ CssHeaderItem.forReference(new WebjarsCssResourceReference("codemirror/current/addon/display/fullscreen.css")),
+
+ CssHeaderItem.forReference(new CssResourceReference(CodeMirrorResourceReference.class, "codemirror.css"))
+ ));
+ }
+
+}
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.js
index ab1b2027ae..3f1ff7a9ca 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.js
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.js
@@ -30,89 +30,32 @@ pmease.commons.codemirror = {
CodeMirror.autoLoadMode(cm, modeInfo.mode);
}
},
- initState: function(cm, clientStateStr) {
+ initState: function(cm, viewState) {
+ if (viewState) {
+ pmease.commons.history.setViewState(viewState);
+ }
+
// use timer to minimize performance impact
- var cursorTimer;
- cm.on("cursorActivity", function() {
- if (cursorTimer)
- clearTimeout(cursorTimer);
- cursorTimer = setTimeout(function() {
- cursorTimer = undefined;
+ var timer;
+ function onViewStateChange() {
+ if (timer)
+ clearTimeout(timer);
+ timer = setTimeout(function() {
+ timer = undefined;
var cursor = cm.getCursor();
- pmease.commons.history.setCursor(cursor);
- $("a.preserve-cm-state").each(function() {
- if (!$(this).is('[disabled=disabled]')) {
- var clientState = $(this).data("client_state");
- if (!clientState)
- clientState = {};
- clientState.cursor = cursor;
- $(this).data("client_state", clientState);
-
- var uri = new URI(this);
- uri.removeSearch("client_state");
- uri.addSearch("client_state", JSON.stringify(clientState));
- $(this).attr("href", uri.href());
- }
- });
-
- var $selectionPermalink = $(".selection-permalink");
- if (cm.somethingSelected() && $selectionPermalink.length != 0) {
- $selectionPermalink.show();
- var fromCursor = cm.getCursor("from");
- var toCursor = cm.getCursor("to");
- var mark = (fromCursor.line+1) + "," + (fromCursor.ch+1) + "-"
- + (toCursor.line+1) + "," + (toCursor.ch+1);
- var uri = new URI($selectionPermalink[0]);
- uri.removeSearch("mark");
- uri.addSearch("mark", mark);
- $selectionPermalink.attr("href", uri.href());
- } else {
- $selectionPermalink.hide();
- }
- }, 500);
- });
-
- var cursor = pmease.commons.history.getCursor();
- if (cursor)
- cm.setCursor(cursor);
-
- // use timer to minimize performance impact
- var scrollTimer;
- cm.on("scroll", function() {
- gitplex.mouseState.moved = false;
- if (scrollTimer)
- clearTimeout(scrollTimer);
- scrollTimer = setTimeout(function() {
- scrollTimer = undefined;
- var scrollInfo = cm.getScrollInfo();
- var scroll = {left: scrollInfo.left, top: scrollInfo.top};
- pmease.commons.history.setScroll(scroll);
- $("a.preserve-cm-state").each(function() {
- if (!$(this).is('[disabled=disabled]')) {
- var clientState = $(this).data("client_state");
- if (!clientState)
- clientState = {};
- clientState.scroll = scroll;
- $(this).data("client_state", clientState);
-
- var uri = new URI(this);
- uri.removeSearch("client_state");
- uri.addSearch("client_state", JSON.stringify(clientState));
- $(this).attr("href", uri.href());
- }
- });
+ var scrollInfo = cm.getScrollInfo();
+ var scroll = {left: scrollInfo.left, top: scrollInfo.top};
+ pmease.commons.history.setViewState({cursor: cursor, scroll: scroll});
}, 500);
- });
- var scroll = pmease.commons.history.getScroll();
- if (scroll)
- cm.scrollTo(scroll.left, scroll.top);
+ };
- if (clientStateStr) {
- var clientState = JSON.parse(clientStateStr);
- if (clientState.cursor)
- cm.setCursor(clientState.cursor);
- if (clientState.scroll)
- cm.scrollTo(clientState.scroll.left, clientState.scroll.top);
+ cm.on("cursorActivity", onViewStateChange);
+ cm.on("scroll", onViewStateChange);
+
+ var viewState = pmease.commons.history.getViewState();
+ if (viewState) {
+ cm.setCursor(viewState.cursor);
+ cm.scrollTo(viewState.scroll.left, viewState.scroll.top);
}
CodeMirror.keyMap.default["Ctrl-L"] = "gotoLine";
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.js
index a26d2c1dfe..e4bdf7db80 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.js
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.js
@@ -516,37 +516,20 @@ pmease.commons = {
history.replaceState(state, '', url);
pmease.commons.history.urlWithoutHash = location.pathname+(location.search?location.search:'');
},
- setScroll: function(scroll) {
+ setViewState: function(viewState) {
var state = history.state;
if (!state)
state = {};
- var newState = {scroll: scroll, cursor: state.cursor, data: state.data};
+ var newState = {viewState: viewState, data: state.data};
history.replaceState(newState, '', window.location.href );
pmease.commons.history.current = {
state: newState,
url: window.location.href
};
},
- setCursor: function(cursor) {
- var state = history.state;
- if (!state)
- state = {};
- var newState = {cursor: cursor, scroll: state.scroll, data: state.data};
- history.replaceState(newState, '', window.location.href );
- pmease.commons.history.current = {
- state: newState,
- url: window.location.href
- };
- },
- getScroll: function() {
- if (history.state && history.state.scroll)
- return history.state.scroll;
- else
- return undefined;
- },
- getCursor: function() {
- if (history.state && history.state.cursor)
- return history.state.cursor;
+ getViewState: function() {
+ if (history.state && history.state.viewState)
+ return history.state.viewState;
else
return undefined;
}
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/ViewStateAwareBehavior.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/ViewStateAwareBehavior.java
new file mode 100644
index 0000000000..213298f7aa
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/ViewStateAwareBehavior.java
@@ -0,0 +1,31 @@
+package com.pmease.commons.wicket.behavior;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.behavior.Behavior;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.JavaScriptHeaderItem;
+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
+
+import com.pmease.commons.wicket.assets.uri.URIResourceReference;
+
+@SuppressWarnings("serial")
+public class ViewStateAwareBehavior extends Behavior {
+
+ @Override
+ public void renderHead(Component component, IHeaderResponse response) {
+ super.renderHead(component, response);
+
+ response.render(JavaScriptHeaderItem.forReference(URIResourceReference.INSTANCE));
+ String script = String.format(""
+ + "var viewState = pmease.commons.history.getViewState();"
+ + "if (viewState) {"
+ + " var link = document.getElementById('%s');"
+ + " var uri = new URI(link);"
+ + " uri.removeSearch('view_state');"
+ + " uri.addSearch('view_state', JSON.stringify(viewState));"
+ + " $(link).attr('href', uri.href());"
+ + "}", component.getMarkupId(true));
+ response.render(OnDomReadyHeaderItem.forScript(script));
+ }
+
+}
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/DropdownLink.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/DropdownLink.java
index b14d3a9380..d93b98a5a5 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/DropdownLink.java
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/DropdownLink.java
@@ -130,6 +130,10 @@ public abstract class DropdownLink extends AjaxLink<Void> {
}
}
+ public String closeBeforeClick(CharSequence onClickScript) {
+ return getCloseScript() + (onClickScript!=null?onClickScript:"");
+ }
+
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/ClientStateAwareAjaxLink.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/ViewStateAwareAjaxLink.java
similarity index 65%
rename from commons.wicket/src/main/java/com/pmease/commons/wicket/component/ClientStateAwareAjaxLink.java
rename to commons.wicket/src/main/java/com/pmease/commons/wicket/component/ViewStateAwareAjaxLink.java
index 676d5e284d..de08237da3 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/ClientStateAwareAjaxLink.java
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/ViewStateAwareAjaxLink.java
@@ -1,46 +1,46 @@
-package com.pmease.commons.wicket.component;
-
-import javax.annotation.Nullable;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method;
-import org.apache.wicket.ajax.markup.html.AjaxLink;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.request.cycle.RequestCycle;
-
-@SuppressWarnings("serial")
-public abstract class ClientStateAwareAjaxLink<T> extends AjaxLink<T> {
-
- public ClientStateAwareAjaxLink(String id) {
- super(id);
- }
-
- @Override
- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
- super.updateAjaxAttributes(attributes);
- attributes.setMethod(Method.POST);
-
- String script = String.format(""
- + "var clientState = $('#%s').data('client_state');"
- + "return clientState?JSON.stringify(clientState):'';", getMarkupId());
- attributes.getDynamicExtraParameters().add("return {client_state: function() {" + script + "}}");
- }
-
- public ClientStateAwareAjaxLink(String id, IModel<T> model) {
- super(id, model);
- }
-
- @Override
- public final void onClick(AjaxRequestTarget target) {
- String value = RequestCycle.get().getRequest().getRequestParameters()
- .getParameterValue("client_state").toString();
- if (StringUtils.isNotBlank(value))
- onClick(target, value);
- else
- onClick(target, null);
- }
-
- protected abstract void onClick(AjaxRequestTarget target, @Nullable String clientState);
-}
+package com.pmease.commons.wicket.component;
+
+import javax.annotation.Nullable;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.request.cycle.RequestCycle;
+
+@SuppressWarnings("serial")
+public abstract class ViewStateAwareAjaxLink<T> extends AjaxLink<T> {
+
+ public ViewStateAwareAjaxLink(String id) {
+ super(id);
+ }
+
+ public ViewStateAwareAjaxLink(String id, IModel<T> model) {
+ super(id, model);
+ }
+
+ @Override
+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
+ super.updateAjaxAttributes(attributes);
+ attributes.setMethod(Method.POST);
+
+ String script = ""
+ + "var viewState = pmease.commons.history.getViewState();"
+ + "return viewState?JSON.stringify(viewState):'';";
+ attributes.getDynamicExtraParameters().add("return {view_state: function() {" + script + "}}");
+ }
+
+ @Override
+ public final void onClick(AjaxRequestTarget target) {
+ String value = RequestCycle.get().getRequest().getRequestParameters()
+ .getParameterValue("view_state").toString();
+ if (StringUtils.isNotBlank(value))
+ onClick(target, value);
+ else
+ onClick(target, null);
+ }
+
+ protected abstract void onClick(AjaxRequestTarget target, @Nullable String viewState);
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobRenderer.java
index fe27f7c18d..0fa259d81c 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobRenderer.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobRenderer.java
@@ -7,6 +7,6 @@ import com.pmease.commons.loader.ExtensionPoint;
@ExtensionPoint
public interface BlobRenderer {
- @Nullable BlobViewPanel render(String panelId, BlobViewContext context, @Nullable String clientState);
+ @Nullable BlobViewPanel render(String panelId, BlobViewContext context, @Nullable String viewState);
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewContext.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewContext.java
index 9b3b31eb9a..d7dd4984bd 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewContext.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewContext.java
@@ -44,11 +44,11 @@ public interface BlobViewContext extends Serializable {
void onSearchComplete(AjaxRequestTarget target, List<QueryHit> hits);
- void onBlameChange(AjaxRequestTarget target, @Nullable String clientState);
+ void onBlameChange(AjaxRequestTarget target, @Nullable String viewState);
void onDelete(AjaxRequestTarget target);
- void onEdit(AjaxRequestTarget target, @Nullable String clientState);
+ void onEdit(AjaxRequestTarget target, @Nullable String viewState);
List<MenuItem> getMenuItems(MenuLink menuLink);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/binary/BinaryRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/binary/BinaryRenderer.java
index 01292a4692..d949733172 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/binary/BinaryRenderer.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/binary/BinaryRenderer.java
@@ -8,7 +8,7 @@ import com.pmease.gitplex.web.component.repofile.blobview.BlobViewPanel;
public class BinaryRenderer implements BlobRenderer {
@Override
- public BlobViewPanel render(String panelId, BlobViewContext context, String clientState) {
+ public BlobViewPanel render(String panelId, BlobViewContext context, String viewState) {
Blob blob = context.getDepot().getBlob(context.getBlobIdent());
if (blob.getText() == null
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/blob-view.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/blob-view.js
index 963e85fc3d..55699401f3 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/blob-view.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/blob-view.js
@@ -2,7 +2,7 @@ gitplex.blobView = function(containerId) {
var $blobView = $("#" + containerId + ">.blob-view");
var $content = $blobView.find(">.content");
$content.scroll(function() {
- pmease.commons.history.setScroll({left: $content.scrollLeft(), top: $content.scrollTop()});
+ pmease.commons.history.setViewState({scroll:{left: $content.scrollLeft(), top: $content.scrollTop()}});
});
$blobView.on("autofit", function(event, width, height) {
@@ -14,10 +14,10 @@ gitplex.blobView = function(containerId) {
$content.outerWidth(width).outerHeight(height);
$content.closestDescendant(".autofit:visible").trigger("autofit", [$content.width(), $content.height()]);
- var scroll = pmease.commons.history.getScroll();
- if (scroll) {
- $content.scrollLeft(scroll.left);
- $content.scrollTop(scroll.top);
+ var viewState = pmease.commons.history.getViewState();
+ if (viewState) {
+ $content.scrollLeft(viewState.scroll.left);
+ $content.scrollTop(viewState.scroll.top);
}
});
}
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/gitlink/GitLinkRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/gitlink/GitLinkRenderer.java
index 8a15906406..5e1025b18c 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/gitlink/GitLinkRenderer.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/gitlink/GitLinkRenderer.java
@@ -7,7 +7,7 @@ import com.pmease.gitplex.web.component.repofile.blobview.BlobViewPanel;
public class GitLinkRenderer implements BlobRenderer {
@Override
- public BlobViewPanel render(String panelId, BlobViewContext context, String clientState) {
+ public BlobViewPanel render(String panelId, BlobViewContext context, String viewState) {
if (context.getBlobIdent().isGitLink())
return new GitLinkPanel(panelId, context);
else
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/image/ImageRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/image/ImageRenderer.java
index 8c7e99fa5a..5f5c04b744 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/image/ImageRenderer.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/image/ImageRenderer.java
@@ -8,7 +8,7 @@ import com.pmease.gitplex.web.component.repofile.blobview.BlobViewPanel;
public class ImageRenderer implements BlobRenderer {
@Override
- public BlobViewPanel render(String panelId, BlobViewContext context, String clientState) {
+ public BlobViewPanel render(String panelId, BlobViewContext context, String viewState) {
Blob blob = context.getDepot().getBlob(context.getBlobIdent());
if (blob.getMediaType().getType().equalsIgnoreCase("image"))
return new ImageViewPanel(panelId, context);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/markdown/MarkdownRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/markdown/MarkdownRenderer.java
index 47c2de9cd7..5db202595b 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/markdown/MarkdownRenderer.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/markdown/MarkdownRenderer.java
@@ -10,14 +10,14 @@ import com.pmease.gitplex.web.component.repofile.blobview.source.SourceViewPanel
public class MarkdownRenderer implements BlobRenderer {
@Override
- public BlobViewPanel render(String panelId, BlobViewContext context, String clientState) {
+ public BlobViewPanel render(String panelId, BlobViewContext context, String viewState) {
Blob blob = context.getDepot().getBlob(context.getBlobIdent());
if (context.getBlobIdent().isFile()
&& blob.getText() != null
&& context.getBlobIdent().path.endsWith(".md")) {
if (context.getMark() != null || context.getMode() == Mode.BLAME
|| context.getComment() != null && context.getComment().getBlobIdent().equals(context.getBlobIdent()))
- return new SourceViewPanel(panelId, context, clientState);
+ return new SourceViewPanel(panelId, context, viewState);
else
return new MarkdownFilePanel(panelId, context);
} else {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceRenderer.java
index dbecd67a52..4e4439557b 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceRenderer.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceRenderer.java
@@ -8,12 +8,12 @@ import com.pmease.gitplex.web.component.repofile.blobview.BlobViewPanel;
public class SourceRenderer implements BlobRenderer {
@Override
- public BlobViewPanel render(String panelId, BlobViewContext context, String clientState) {
+ public BlobViewPanel render(String panelId, BlobViewContext context, String viewState) {
Blob blob = context.getDepot().getBlob(context.getBlobIdent());
if (context.getBlobIdent().isFile()
&& blob.getText() != null
&& !context.getBlobIdent().path.endsWith(".md")) {
- return new SourceViewPanel(panelId, context, clientState);
+ return new SourceViewPanel(panelId, context, viewState);
} else {
return null;
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceViewPanel.java
index c1458eadbd..ad99f989a2 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceViewPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceViewPanel.java
@@ -94,7 +94,7 @@ public class SourceViewPanel extends BlobViewPanel {
private final List<Symbol> symbols = new ArrayList<>();
- private final String clientState;
+ private final String viewState;
private final IModel<List<Comment>> commentsModel = new LoadableDetachableModel<List<Comment>>() {
@@ -137,7 +137,7 @@ public class SourceViewPanel extends BlobViewPanel {
private AbstractDefaultAjaxBehavior addCommentBehavior;
- public SourceViewPanel(String id, BlobViewContext context, @Nullable String clientState) {
+ public SourceViewPanel(String id, BlobViewContext context, @Nullable String viewState) {
super(id, context);
Blob blob = context.getDepot().getBlob(context.getBlobIdent());
@@ -152,7 +152,7 @@ public class SourceViewPanel extends BlobViewPanel {
}
}
- this.clientState = clientState;
+ this.viewState = viewState;
}
@Override
@@ -439,7 +439,7 @@ public class SourceViewPanel extends BlobViewPanel {
blameCommitsJson,
context.getComment()!=null?context.getComment().getId():-1,
addCommentCallback,
- clientState!=null?"'"+clientState+"'":"undefined");
+ viewState!=null?"JSON.parse('"+viewState+"')":"undefined");
response.render(OnDomReadyHeaderItem.forScript(script));
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/source-view.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/source-view.js
index 4dec2bdcf5..26d0c429a4 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/source-view.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/source-view.js
@@ -1,6 +1,6 @@
gitplex.sourceview = {
init: function(codeId, fileContent, filePath, mark, symbolTooltipId, revision,
- blameCommits, commentId, addCommentCallback, cmState) {
+ blameCommits, commentId, addCommentCallback, viewState) {
var cm;
var $code = $("#" + codeId);
@@ -107,7 +107,7 @@ gitplex.sourceview = {
cm.setOption("fullScreen", false);
cm.setSize($code.width(), $code.height());
if (initState)
- pmease.commons.codemirror.initState(cm, cmState);
+ pmease.commons.codemirror.initState(cm, viewState);
});
},
mark: function(codeId, mark) {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/symbollink/SymbolLinkRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/symbollink/SymbolLinkRenderer.java
index eb0048ee05..042099c48b 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/symbollink/SymbolLinkRenderer.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/symbollink/SymbolLinkRenderer.java
@@ -7,7 +7,7 @@ import com.pmease.gitplex.web.component.repofile.blobview.BlobViewPanel;
public class SymbolLinkRenderer implements BlobRenderer {
@Override
- public BlobViewPanel render(String panelId, BlobViewContext context, String clientState) {
+ public BlobViewPanel render(String panelId, BlobViewContext context, String viewState) {
if (context.getBlobIdent().isSymbolLink())
return new SymbolLinkPanel(panelId, context);
else
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/editsave/edit-save.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/editsave/edit-save.js
index ae8804753c..11305f61d1 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/editsave/edit-save.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/editsave/edit-save.js
@@ -1,43 +1,43 @@
-gitplex.editsave = {
- init: function(containerId) {
- var $editSave = $("#" + containerId + ">.edit-save");
- $editSave.scroll(function() {
- pmease.commons.history.setScroll({left: $editSave.scrollLeft(), top: $editSave.scrollTop()});
- });
-
- $editSave.on("autofit", function(event, width, height) {
- event.stopPropagation();
-
- $editSave.closest(".body").css("overflow", "hidden");
- $editSave.outerWidth(width);
- $editSave.outerHeight(height);
-
- var scroll = pmease.commons.history.getScroll();
- if (scroll) {
- $editSave.scrollLeft(scroll.left);
- $editSave.scrollTop(scroll.top);
- }
- });
-
- $editSave.on("contentEdit", function(event, contentChanged) {
- event.stopPropagation();
- $editSave.data("contentChanged", contentChanged);
- gitplex.editsave.updateSubmitBtnState($editSave);
- });
- },
-
- updateSubmitBtnState: function($editSave) {
- var $submitBtn = $editSave.find("input[type=submit]");
- if ($editSave.data("contentChanged") === true || $editSave.data("pathChanged") === true)
- $submitBtn.removeAttr("disabled");
- else
- $submitBtn.attr("disabled", "disabled");
- },
-
- onPathChange: function(containerId, defaultCommitMessage, equalsOldPath) {
- var $editSave = $("#" + containerId + ">.edit-save");
- $editSave.find(".summary-commit-message").attr("placeholder", defaultCommitMessage);
- $editSave.data("pathChanged", !equalsOldPath);
- gitplex.editsave.updateSubmitBtnState($editSave);
- }
-}
+gitplex.editsave = {
+ init: function(containerId) {
+ var $editSave = $("#" + containerId + ">.edit-save");
+ $editSave.scroll(function() {
+ pmease.commons.history.setViewState({scroll:{left: $editSave.scrollLeft(), top: $editSave.scrollTop()}});
+ });
+
+ $editSave.on("autofit", function(event, width, height) {
+ event.stopPropagation();
+
+ $editSave.closest(".body").css("overflow", "hidden");
+ $editSave.outerWidth(width);
+ $editSave.outerHeight(height);
+
+ var viewState = pmease.commons.history.getViewState();
+ if (viewState) {
+ $editSave.scrollLeft(viewState.scroll.left);
+ $editSave.scrollTop(viewState.scroll.top);
+ }
+ });
+
+ $editSave.on("contentEdit", function(event, contentChanged) {
+ event.stopPropagation();
+ $editSave.data("contentChanged", contentChanged);
+ gitplex.editsave.updateSubmitBtnState($editSave);
+ });
+ },
+
+ updateSubmitBtnState: function($editSave) {
+ var $submitBtn = $editSave.find("input[type=submit]");
+ if ($editSave.data("contentChanged") === true || $editSave.data("pathChanged") === true)
+ $submitBtn.removeAttr("disabled");
+ else
+ $submitBtn.attr("disabled", "disabled");
+ },
+
+ onPathChange: function(containerId, defaultCommitMessage, equalsOldPath) {
+ var $editSave = $("#" + containerId + ">.edit-save");
+ $editSave.find(".summary-commit-message").attr("placeholder", defaultCommitMessage);
+ $editSave.data("pathChanged", !equalsOldPath);
+ gitplex.editsave.updateSubmitBtnState($editSave);
+ }
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/fileedit/FileEditPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/fileedit/FileEditPanel.java
index 4f20cf0188..7102b92d25 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/fileedit/FileEditPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/fileedit/FileEditPanel.java
@@ -64,7 +64,7 @@ public abstract class FileEditPanel extends Panel {
private final Mark mark;
- private final String clientState;
+ private final String viewState;
private AbstractDefaultAjaxBehavior previewBehavior;
@@ -74,7 +74,7 @@ public abstract class FileEditPanel extends Panel {
public FileEditPanel(String id, IModel<Depot> depotModel, String refName,
@Nullable String oldPath, String content, ObjectId prevCommitId,
- @Nullable Mark mark, @Nullable String clientState) {
+ @Nullable Mark mark, @Nullable String viewState) {
super(id);
this.depotModel = depotModel;
this.refName = refName;
@@ -82,7 +82,7 @@ public abstract class FileEditPanel extends Panel {
this.content = content;
this.prevCommitId = prevCommitId;
this.mark = mark;
- this.clientState = clientState;
+ this.viewState = viewState;
newPath = this.oldPath;
}
@@ -228,7 +228,7 @@ public abstract class FileEditPanel extends Panel {
previewBehavior.getCallbackFunction(CallbackParameter.explicit("content")),
saveBehavior.getCallbackFunction(CallbackParameter.explicit("content")),
mark!=null?mark.toJSON():"undefined",
- clientState!=null?"'"+clientState+"'":"undefined");
+ viewState!=null?"JSON.parse('"+viewState+"')":"undefined");
response.render(OnDomReadyHeaderItem.forScript(script));
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/fileedit/file-edit.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/fileedit/file-edit.js
index 94c86bfa1b..4da55c700f 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/fileedit/file-edit.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/fileedit/file-edit.js
@@ -1,189 +1,189 @@
-gitplex.fileedit = {
- init: function(containerId, filePath, fileContent, previewCallback, saveCallback, mark, cmState) {
- 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("autofit", function(event, width, height) {
- event.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, cmState);
- } 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;
- } else if (oldLine == endLine && oldChar == endChar) {
- newEndLine = newLine;
- newEndChar = newChar;
- }
-
- if (char == '\n') {
- oldLine++;
- oldChar = 0;
- newLine++;
- newChar = 0;
- } else {
- oldChar++;
- newChar++;
- }
- }
- if (oldLine>beginLine && !newBeginLine || oldLine>endLine) {
- quite = true;
- break;
- }
- }
- }
- }
-
- if (newBeginLine && newEndLine) {
- 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");
- $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) {
+ 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("autofit", function(event, width, height) {
+ event.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;
+ } else if (oldLine == endLine && oldChar == endChar) {
+ newEndLine = newLine;
+ newEndChar = newChar;
+ }
+
+ if (char == '\n') {
+ oldLine++;
+ oldChar = 0;
+ newLine++;
+ newChar = 0;
+ } else {
+ oldChar++;
+ newChar++;
+ }
+ }
+ if (oldLine>beginLine && !newBeginLine || oldLine>endLine) {
+ quite = true;
+ break;
+ }
+ }
+ }
+ }
+
+ if (newBeginLine && newEndLine) {
+ 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");
+ $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();
+ }
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/filelist/file-list.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/filelist/file-list.js
index e52f8348db..699e265ad2 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/filelist/file-list.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/filelist/file-list.js
@@ -1,50 +1,50 @@
-gitplex.filelist = {
- init: function(containerId, lastCommitsUrl) {
- var $container = $("#" + containerId);
- var $fileList = $container.find(">.file-list");
-
- $fileList.on("autofit", function(event, width, height) {
- event.stopPropagation();
- $fileList.outerWidth(width);
- $fileList.outerHeight(height);
-
- var scroll = pmease.commons.history.getScroll();
- if (scroll) {
- $fileList.scrollLeft(scroll.left);
- $fileList.scrollTop(scroll.top);
- }
- });
-
- $fileList.scroll(function() {
- pmease.commons.history.setScroll({left: $fileList.scrollLeft(), top: $fileList.scrollTop()});
- });
-
- $.ajax({
- url: lastCommitsUrl,
- cache: false,
- success: function(lastCommits) {
- if (jQuery.contains(document, $container[0])) { // add this check to avoid rendering last commits if directory is changed
- var $table = $container.find(".file-list>table");
- $table.find("tr.child").each(function() {
- var $row = $(this);
- var path = $row.find("td.path span").text();
- var index = path.indexOf('/');
- if (index != -1)
- path = path.substring(0, index);
- var lastCommit = lastCommits[path];
-
- var html = "<img src='" + lastCommit.authorAvatarUrl + "' class='avatar'/> ";
- if (lastCommit.authorUrl)
- html += "<a href='" + lastCommit.authorUrl + "'>" + lastCommit.authorName + "</a>";
- else
- html += "<span>" + lastCommit.authorName + "</span>";
-
- $row.children(".last-commit.author").empty().append(html);
- $row.children(".last-commit.when").append("<span class='when'>" + lastCommit.when + "</span>");
- $row.children(".last-commit.message").append("<a href='" + lastCommit.url + "'>" + lastCommit.summary + "</a>");
- });
- }
- }
- });
- }
+gitplex.filelist = {
+ init: function(containerId, lastCommitsUrl) {
+ var $container = $("#" + containerId);
+ var $fileList = $container.find(">.file-list");
+
+ $fileList.on("autofit", function(event, width, height) {
+ event.stopPropagation();
+ $fileList.outerWidth(width);
+ $fileList.outerHeight(height);
+
+ var viewState = pmease.commons.history.getViewState();
+ if (viewState) {
+ $fileList.scrollLeft(viewState.scroll.left);
+ $fileList.scrollTop(viewState.scroll.top);
+ }
+ });
+
+ $fileList.scroll(function() {
+ pmease.commons.history.setViewState({scroll:{left: $fileList.scrollLeft(), top: $fileList.scrollTop()}});
+ });
+
+ $.ajax({
+ url: lastCommitsUrl,
+ cache: false,
+ success: function(lastCommits) {
+ if (jQuery.contains(document, $container[0])) { // add this check to avoid rendering last commits if directory is changed
+ var $table = $container.find(".file-list>table");
+ $table.find("tr.child").each(function() {
+ var $row = $(this);
+ var path = $row.find("td.path span").text();
+ var index = path.indexOf('/');
+ if (index != -1)
+ path = path.substring(0, index);
+ var lastCommit = lastCommits[path];
+
+ var html = "<img src='" + lastCommit.authorAvatarUrl + "' class='avatar'/> ";
+ if (lastCommit.authorUrl)
+ html += "<a href='" + lastCommit.authorUrl + "'>" + lastCommit.authorName + "</a>";
+ else
+ html += "<span>" + lastCommit.authorName + "</span>";
+
+ $row.children(".last-commit.author").empty().append(html);
+ $row.children(".last-commit.when").append("<span class='when'>" + lastCommit.when + "</span>");
+ $row.children(".last-commit.message").append("<a href='" + lastCommit.url + "'>" + lastCommit.summary + "</a>");
+ });
+ }
+ }
+ });
+ }
}
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/filenavigator/FileNavigator.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/filenavigator/FileNavigator.java
index ad6256080f..b09cbb71a6 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/filenavigator/FileNavigator.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/filenavigator/FileNavigator.java
@@ -50,8 +50,9 @@ import com.google.common.base.Splitter;
import com.pmease.commons.git.BlobIdent;
import com.pmease.commons.util.StringUtils;
import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;
-import com.pmease.commons.wicket.component.ClientStateAwareAjaxLink;
+import com.pmease.commons.wicket.behavior.ViewStateAwareBehavior;
import com.pmease.commons.wicket.component.DropdownLink;
+import com.pmease.commons.wicket.component.ViewStateAwareAjaxLink;
import com.pmease.commons.wicket.component.floating.AlignPlacement;
import com.pmease.commons.wicket.component.floating.FloatingPanel;
import com.pmease.commons.wicket.component.menu.MenuItem;
@@ -370,7 +371,7 @@ public abstract class FileNavigator extends Panel {
@Override
protected CharSequence getOnClickScript(CharSequence url) {
- return getCloseScript() + super.getOnClickScript(url);
+ return closeBeforeClick(super.getOnClickScript(url));
}
};
@@ -393,7 +394,7 @@ public abstract class FileNavigator extends Panel {
@Override
public AbstractLink newLink(String id) {
- return new ClientStateAwareAjaxLink<Void>(id) {
+ AbstractLink link = new ViewStateAwareAjaxLink<Void>(id) {
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
@@ -402,12 +403,14 @@ public abstract class FileNavigator extends Panel {
}
@Override
- protected void onClick(AjaxRequestTarget target, String clientState) {
+ protected void onClick(AjaxRequestTarget target, String viewState) {
close();
- context.onBlameChange(target, clientState);
+ context.onBlameChange(target, viewState);
}
};
+ link.add(new ViewStateAwareBehavior());
+ return link;
}
});
@@ -476,11 +479,11 @@ public abstract class FileNavigator extends Panel {
@Override
protected CharSequence getOnClickScript(CharSequence url) {
- return getCloseScript() + super.getOnClickScript(url);
+ return closeBeforeClick(super.getOnClickScript(url));
}
};
-
+ link.add(new ViewStateAwareBehavior());
// open in a new tab by default to make sure user can continue to add reply to
// comments on current page after committing code
link.add(AttributeAppender.append("target", "_blank"));
@@ -506,7 +509,7 @@ public abstract class FileNavigator extends Panel {
@Override
public AbstractLink newLink(String id) {
- AbstractLink link = new ClientStateAwareAjaxLink<Void>(id) {
+ AbstractLink link = new ViewStateAwareAjaxLink<Void>(id) {
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
@@ -515,9 +518,9 @@ public abstract class FileNavigator extends Panel {
}
@Override
- public void onClick(AjaxRequestTarget target, String clientState) {
+ public void onClick(AjaxRequestTarget target, String viewState) {
close();
- context.onEdit(target, clientState);
+ context.onEdit(target, viewState);
}
};
@@ -529,6 +532,7 @@ public abstract class FileNavigator extends Panel {
params = DepotFilePage.paramsOf(context.getDepot(), state);
CharSequence url = RequestCycle.get().urlFor(DepotFilePage.class, params);
link.add(AttributeAppender.replace("href", url.toString()));
+ link.add(new ViewStateAwareBehavior());
return link;
}
@@ -559,7 +563,7 @@ public abstract class FileNavigator extends Panel {
@Override
protected CharSequence getOnClickScript(CharSequence url) {
- return getCloseScript() + super.getOnClickScript(url);
+ return closeBeforeClick(super.getOnClickScript(url));
}
};
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/branches/DepotBranchesPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/branches/DepotBranchesPage.java
index 3d82c53a5f..013ccd09b4 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/branches/DepotBranchesPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/branches/DepotBranchesPage.java
@@ -551,7 +551,7 @@ public class DepotBranchesPage extends DepotPage {
@Override
protected void onInitialize() {
super.onInitialize();
- if (aheadOpenRequestsModel.getObject().get(item.getModelObject()) != null)
+ if (aheadOpenRequestsModel.getObject().get(branch) != null)
add(AttributeAppender.append("class", " request"));
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java
index c59f3329a3..2b3b1f3240 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java
@@ -109,7 +109,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
private static final String PARAM_QUERY = "query";
- private static final String PARAM_CLIENT_STATE = "client_state";
+ private static final String PARAM_VIEW_STATE = "view_state";
private static final String PARAM_MARK = "mark";
@@ -170,7 +170,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
private transient List<QueryHit> queryHits;
// client state holding CodeMirror cursor, scroll, marks, etc.
- private transient String clientState;
+ private transient String viewState;
public DepotFilePage(final PageParameters params) {
super(params);
@@ -244,7 +244,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
}
}
- clientState = params.get(PARAM_CLIENT_STATE).toString();
+ viewState = params.get(PARAM_VIEW_STATE).toString();
}
@Override
@@ -371,7 +371,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
});
- newFileViewer(null, clientState);
+ newFileViewer(null, viewState);
add(searchResultContainer = new WebMarkupContainer("searchResultContainer"));
@@ -464,9 +464,9 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
}
}
- private BlobViewPanel renderBlobViewer(String panelId, @Nullable String clientState) {
+ private BlobViewPanel renderBlobViewer(String panelId, @Nullable String viewState) {
for (BlobRenderer renderer: GitPlex.getExtensions(BlobRenderer.class)) {
- BlobViewPanel panel = renderer.render(panelId, this, clientState);
+ BlobViewPanel panel = renderer.render(panelId, this, viewState);
if (panel != null)
return panel;
}
@@ -474,7 +474,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
throw new IllegalStateException("No applicable blob renderer found.");
}
- private void newFileViewer(@Nullable AjaxRequestTarget target, @Nullable String clientState) {
+ private void newFileViewer(@Nullable AjaxRequestTarget target, @Nullable String viewState) {
Component fileViewer;
if (mode == Mode.EDIT) {
final String refName = GitUtils.branch2ref(blobIdent.revision);
@@ -483,7 +483,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
FILE_VIEWER_ID, depotModel, refName,
blobIdent.isTree()?null:blobIdent.path,
blobIdent.isTree()?"":getDepot().getBlob(blobIdent).getText().getContent(),
- getDepot().getObjectId(blobIdent.revision), mark, clientState) {
+ getDepot().getObjectId(blobIdent.revision), mark, viewState) {
@Override
protected void onCommitted(AjaxRequestTarget target, ObjectId oldCommit, ObjectId newCommit) {
@@ -575,7 +575,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
};
} else {
- fileViewer = renderBlobViewer(FILE_VIEWER_ID, clientState);
+ fileViewer = renderBlobViewer(FILE_VIEWER_ID, viewState);
}
if (target != null) {
replace(fileViewer);
@@ -725,8 +725,8 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
params.set(PARAM_MODE, state.mode.name().toLowerCase());
if (state.query != null)
params.set(PARAM_QUERY, state.query);
- if (state.clientState != null)
- params.set(PARAM_CLIENT_STATE, state.clientState);
+ if (state.viewState != null)
+ params.set(PARAM_VIEW_STATE, state.viewState);
return params;
}
@@ -872,12 +872,12 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
}
@Override
- public void onBlameChange(AjaxRequestTarget target, @Nullable String cmState) {
+ public void onBlameChange(AjaxRequestTarget target, @Nullable String viewState) {
if (mode == null)
mode = Mode.BLAME;
else
mode = null;
- newFileViewer(target, cmState);
+ newFileViewer(target, viewState);
pushState(target);
resizeWindow(target);
}
@@ -892,11 +892,11 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
}
@Override
- public void onEdit(AjaxRequestTarget target, @Nullable String cmState) {
+ public void onEdit(AjaxRequestTarget target, @Nullable String viewState) {
mode = Mode.EDIT;
newFileNavigator(target);
- newFileViewer(target, cmState);
+ newFileViewer(target, viewState);
pushState(target);
resizeWindow(target);
}
@@ -941,7 +941,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
public transient String query;
- public transient String clientState;
+ public transient String viewState;
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
index 615b54a674..8a58f04c64 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java
@@ -111,7 +111,7 @@ public class TestPage extends BasePage {
@Override
protected CharSequence getOnClickScript(CharSequence url) {
- return getCloseScript() + super.getOnClickScript(url);
+ return closeBeforeClick(super.getOnClickScript(url));
}
};