Skip to content

The Unified and Autonomous Development Platform

midwork

robin shine2081ab601ceb
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/CommonResourceReference.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/CommonResourceReference.java
index 70648823fd..c1a9589200 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/CommonResourceReference.java
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/CommonResourceReference.java
@@ -12,7 +12,6 @@ import org.apache.wicket.request.resource.JavaScriptResourceReference;
import com.google.common.collect.Lists;
import com.pmease.commons.wicket.assets.Assets;
-import com.pmease.commons.wicket.assets.uri.URIResourceReference;
import de.agilecoders.wicket.core.Bootstrap;
import de.agilecoders.wicket.webjars.request.resource.WebjarsCssResourceReference;
@@ -89,8 +88,6 @@ public class CommonResourceReference extends JavaScriptResourceReference {
dependencies.add(JavaScriptHeaderItem.forReference(Assets.ARE_YOU_SURE_JS));
- dependencies.add(JavaScriptHeaderItem.forReference(URIResourceReference.INSTANCE));
-
dependencies.add(CssHeaderItem.forReference(Assets.COMMON_CSS));
return dependencies;
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 46bd3cebbd..9f1bbd3a2c 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
@@ -13,6 +13,7 @@ import org.apache.wicket.request.resource.ResourceReference;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.pmease.commons.util.StringUtils;
+import com.pmease.commons.wicket.assets.uri.URIResourceReference;
import de.agilecoders.wicket.webjars.request.resource.WebjarsCssResourceReference;
import de.agilecoders.wicket.webjars.request.resource.WebjarsJavaScriptResourceReference;
@@ -55,6 +56,7 @@ public class CodeMirrorResourceReference extends JavaScriptResourceReference {
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")),
JavaScriptHeaderItem.forReference(meta),
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.css b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.css
index 5c86aa17cc..19ec395e75 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.css
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.css
@@ -4,9 +4,6 @@
.CodeMirror-highlight {
background: #E2C7F3;
}
-.CodeMirror-highlight.cm-identifierhighlight {
- background: #ACF0A6;
-}
.CodeMirror {
font-size: 13px;
}
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 c59742af80..cf686c0e51 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
@@ -14,6 +14,10 @@ pmease.commons.codemirror = {
{line: highlight.beginLine, ch: highlight.beginChar},
{line: highlight.endLine, ch: highlight.endChar},
{className: "CodeMirror-highlight"});
+ cm.setCursor({line:highlight.beginLine, ch:highlight.beginChar});
+ setTimeout(function() {
+ cm.focus();
+ }, 10);
},
setMode: function(cm, filePath) {
var modeInfo = CodeMirror.findModeByFileName(filePath);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobsearch/instant/InstantSearchPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobsearch/instant/InstantSearchPanel.java
index 4f9f029084..b77b94cd59 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobsearch/instant/InstantSearchPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobsearch/instant/InstantSearchPanel.java
@@ -36,6 +36,7 @@ import org.apache.wicket.request.resource.JavaScriptResourceReference;
import org.apache.wicket.request.resource.ResourceReference;
import com.pmease.commons.util.StringUtils;
+import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;
import com.pmease.commons.wicket.assets.hotkeys.HotkeysResourceReference;
import com.pmease.commons.wicket.behavior.RunTaskBehavior;
import com.pmease.commons.wicket.behavior.dropdown.DropdownBehavior;
@@ -51,7 +52,6 @@ import com.pmease.gitplex.search.query.SymbolQuery;
import com.pmease.gitplex.search.query.TextQuery;
import com.pmease.gitplex.search.query.TooGeneralQueryException;
import com.pmease.gitplex.web.component.repofile.blobsearch.result.SearchResultPanel;
-import com.pmease.gitplex.web.page.repository.file.ConfirmSwitchFileListener;
import com.pmease.gitplex.web.page.repository.file.Highlight;
import com.pmease.gitplex.web.page.repository.file.HistoryState;
import com.pmease.gitplex.web.page.repository.file.RepoFilePage;
@@ -137,7 +137,7 @@ public abstract class InstantSearchPanel extends Panel {
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
- attributes.getAjaxCallListeners().add(new ConfirmSwitchFileListener());
+ attributes.getAjaxCallListeners().add(new ConfirmLeaveListener());
}
@Override
@@ -260,7 +260,7 @@ public abstract class InstantSearchPanel extends Panel {
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
- attributes.getAjaxCallListeners().add(new ConfirmSwitchFileListener());
+ attributes.getAjaxCallListeners().add(new ConfirmLeaveListener());
}
@Override
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/ConfirmSwitchFileListener.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobsearch/result/ConfirmSwitchFileListener.java
similarity index 56%
rename from gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/ConfirmSwitchFileListener.java
rename to gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobsearch/result/ConfirmSwitchFileListener.java
index 1bd90898c1..d9736ca80e 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/ConfirmSwitchFileListener.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobsearch/result/ConfirmSwitchFileListener.java
@@ -1,11 +1,19 @@
-package com.pmease.gitplex.web.page.repository.file;
+package com.pmease.gitplex.web.component.repofile.blobsearch.result;
+import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.attributes.IAjaxCallListener;
-public class ConfirmSwitchFileListener implements IAjaxCallListener {
+class ConfirmSwitchFileListener implements IAjaxCallListener {
+ private final String path;
+
public ConfirmSwitchFileListener() {
+ path = null;
+ }
+
+ public ConfirmSwitchFileListener(String path) {
+ this.path = path;
}
@Override
@@ -15,8 +23,13 @@ public class ConfirmSwitchFileListener implements IAjaxCallListener {
@Override
public CharSequence getPrecondition(Component component) {
- return String.format("return gitplex.repofile.confirmSwitchFile('%s');",
- component.getMarkupId(true));
+ if (path != null) {
+ return String.format("return gitplex.searchresult.confirmSwitchFileByPath('%s');",
+ StringEscapeUtils.escapeEcmaScript(path));
+ } else {
+ return String.format("return gitplex.searchresult.confirmSwitchFileByLink('%s');",
+ component.getMarkupId(true));
+ }
}
@Override
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobsearch/result/SearchResultPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobsearch/result/SearchResultPanel.java
index e3e228e0c0..59411ed9f2 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobsearch/result/SearchResultPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobsearch/result/SearchResultPanel.java
@@ -10,17 +10,14 @@ import java.util.Map;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.MetaDataKey;
-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
import org.apache.wicket.ajax.AjaxChannel;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
-import org.apache.wicket.ajax.attributes.CallbackParameter;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
-import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
@@ -28,7 +25,6 @@ import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.LoadableDetachableModel;
-import org.apache.wicket.request.IRequestParameters;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.request.resource.CssResourceReference;
@@ -36,14 +32,12 @@ import org.apache.wicket.request.resource.JavaScriptResourceReference;
import org.eclipse.jgit.lib.FileMode;
import com.pmease.commons.git.BlobIdent;
-import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;
-import com.pmease.commons.wicket.assets.hotkeys.HotkeysResourceReference;
+import com.pmease.commons.wicket.assets.uri.URIResourceReference;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.search.hit.FileHit;
import com.pmease.gitplex.search.hit.QueryHit;
import com.pmease.gitplex.search.hit.TextHit;
import com.pmease.gitplex.web.component.repofile.blobview.BlobViewContext;
-import com.pmease.gitplex.web.page.repository.file.ConfirmSwitchFileListener;
import com.pmease.gitplex.web.page.repository.file.Highlight;
import com.pmease.gitplex.web.page.repository.file.HistoryState;
import com.pmease.gitplex.web.page.repository.file.RepoFilePage;
@@ -124,7 +118,7 @@ public abstract class SearchResultPanel extends Panel {
String script = String.format(""
+ "$('#%s').find('.selectable').removeClass('active');"
+ "$('#%s').addClass('active');"
- + "gitplex.blobSearchResult.scrollIfNecessary('%s');",
+ + "gitplex.searchresult.scrollIfNecessary('%s');",
getMarkupId(), activeLinkId, getMarkupId());
target.appendJavaScript(script);
@@ -144,45 +138,78 @@ public abstract class SearchResultPanel extends Panel {
context.onSelect(target, selected, hit.getTokenPos());
}
- private void onPrevMatch(AjaxRequestTarget target) {
- if (prevMatchLink.isEnabled()) {
- if (activeHitIndex>0) {
- activeHitIndex--;
+ private String getActiveBlobPath(ActiveIndex activeIndex) {
+ MatchedBlob activeBlob = blobs.get(activeIndex.blob);
+ if (activeIndex.hit != -1)
+ return activeBlob.getHits().get(activeIndex.hit).getBlobPath();
+ else
+ return activeBlob.getBlobPath();
+ }
+
+ private ActiveIndex getPrevMatch() {
+ if (prevMatchLink.isEnabled()) {
+ ActiveIndex activeIndex = new ActiveIndex(activeBlobIndex, activeHitIndex);
+ if (activeIndex.hit>0) {
+ activeIndex.hit--;
+ return activeIndex;
} else {
- activeBlobIndex--;
- MatchedBlob activeBlob = blobs.get(activeBlobIndex);
+ activeIndex.blob--;
+ MatchedBlob activeBlob = blobs.get(activeIndex.blob);
if (activeBlob.getHits().isEmpty())
- activeHitIndex = -1;
+ activeIndex.hit = -1;
else
- activeHitIndex = activeBlob.getHits().size()-1;
+ activeIndex.hit = activeBlob.getHits().size()-1;
+ return activeIndex;
}
-
+ } else {
+ return null;
+ }
+ }
+
+ private void onPrevMatch(AjaxRequestTarget target) {
+ ActiveIndex activeIndex = getPrevMatch();
+
+ if (activeIndex != null) {
+ activeBlobIndex = activeIndex.blob;
+ activeHitIndex = activeIndex.hit;
onActiveIndexChange(target);
}
}
- private void onNextMatch(AjaxRequestTarget target) {
+ private ActiveIndex getNextMatch() {
if (nextMatchLink.isEnabled()) {
- if (activeBlobIndex == -1) {
- activeBlobIndex = 0;
- MatchedBlob activeBlob = blobs.get(activeBlobIndex);
+ ActiveIndex activeIndex = new ActiveIndex(activeBlobIndex, activeHitIndex);
+ if (activeIndex.blob == -1) {
+ activeIndex.blob = 0;
+ MatchedBlob activeBlob = blobs.get(activeIndex.blob);
if (activeBlob.getHits().isEmpty())
- activeHitIndex = -1;
+ activeIndex.hit = -1;
else
- activeHitIndex = 0;
+ activeIndex.hit = 0;
} else {
- MatchedBlob activeBlob = blobs.get(activeBlobIndex);
- activeHitIndex++;
- if (activeHitIndex==activeBlob.getHits().size()) {
- activeBlobIndex++;
- activeBlob = blobs.get(activeBlobIndex);
+ MatchedBlob activeBlob = blobs.get(activeIndex.blob);
+ activeIndex.hit++;
+ if (activeIndex.hit==activeBlob.getHits().size()) {
+ activeIndex.blob++;
+ activeBlob = blobs.get(activeIndex.blob);
if (activeBlob.getHits().isEmpty())
- activeHitIndex = -1;
+ activeIndex.hit = -1;
else
- activeHitIndex = 0;
+ activeIndex.hit = 0;
}
}
-
+ return activeIndex;
+ } else {
+ return null;
+ }
+ }
+
+ private void onNextMatch(AjaxRequestTarget target) {
+ ActiveIndex activeIndex = getNextMatch();
+
+ if (activeIndex != null) {
+ activeBlobIndex = activeIndex.blob;
+ activeHitIndex = activeIndex.hit;
onActiveIndexChange(target);
}
}
@@ -199,7 +226,9 @@ public abstract class SearchResultPanel extends Panel {
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
- attributes.getAjaxCallListeners().add(new ConfirmLeaveListener());
+ ActiveIndex activeIndex = getPrevMatch();
+ if (activeIndex != null)
+ attributes.getAjaxCallListeners().add(new ConfirmSwitchFileListener(getActiveBlobPath(activeIndex)));
}
@Override
@@ -222,7 +251,9 @@ public abstract class SearchResultPanel extends Panel {
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
- attributes.getAjaxCallListeners().add(new ConfirmLeaveListener());
+ ActiveIndex activeIndex = getNextMatch();
+ if (activeIndex != null)
+ attributes.getAjaxCallListeners().add(new ConfirmSwitchFileListener(getActiveBlobPath(activeIndex)));
}
@Override
@@ -476,49 +507,6 @@ public abstract class SearchResultPanel extends Panel {
add(new WebMarkupContainer("noMatchingResult").setVisible(blobs.isEmpty()));
- add(new AbstractDefaultAjaxBehavior() {
-
- @Override
- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
- super.updateAjaxAttributes(attributes);
- attributes.setChannel(new AjaxChannel(NAV_CHANNEL, AjaxChannel.Type.DROP));
- }
-
- @Override
- protected void respond(AjaxRequestTarget target) {
- IRequestParameters params = RequestCycle.get().getRequest().getQueryParameters();
- String key = params.getParameterValue("key").toString();
-
- if (key.equals("up"))
- onPrevMatch(target);
- else if (key.equals("down"))
- onNextMatch(target);
- else
- throw new IllegalStateException("Unrecognized key: " + key);
- }
-
- @Override
- public void renderHead(Component component, IHeaderResponse response) {
- super.renderHead(component, response);
-
- response.render(JavaScriptHeaderItem.forReference(
- new JavaScriptResourceReference(SearchResultPanel.class, "search-result.js")));
- response.render(CssHeaderItem.forReference(
- new CssResourceReference(SearchResultPanel.class, "search-result.css")));
-
- response.render(JavaScriptHeaderItem.forReference(HotkeysResourceReference.INSTANCE));
-
- String script = String.format(""
- + "var $body = $('#%s>.search-result>.body');"
- + "var callback = %s;"
- + "$body.bind('keydown', 'up', function(e) {e.preventDefault(); if (pmease.commons.form.confirmLeave()) callback('up');});"
- + "$body.bind('keydown', 'down', function(e) {e.preventDefault(); if (pmease.commons.form.confirmLeave()) callback('down');});",
- getMarkupId(), getCallbackFunction(CallbackParameter.explicit("key")));
- response.render(OnDomReadyHeaderItem.forScript(script));
- }
-
- });
-
setOutputMarkupId(true);
}
@@ -527,4 +515,29 @@ public abstract class SearchResultPanel extends Panel {
private static class ExpandStatusKey extends MetaDataKey<ExpandStatus> {
static final ExpandStatusKey INSTANCE = new ExpandStatusKey();
};
+
+ @Override
+ public void renderHead(IHeaderResponse response) {
+ super.renderHead(response);
+
+ // to be used by ConfirmSwitchFileListener
+ response.render(JavaScriptHeaderItem.forReference(URIResourceReference.INSTANCE));
+
+ response.render(JavaScriptHeaderItem.forReference(
+ new JavaScriptResourceReference(SearchResultPanel.class, "search-result.js")));
+ response.render(CssHeaderItem.forReference(
+ new CssResourceReference(SearchResultPanel.class, "search-result.css")));
+ }
+
+ private static class ActiveIndex {
+ int blob;
+
+ int hit;
+
+ public ActiveIndex(int blob, int hit) {
+ this.blob = blob;
+ this.hit = hit;
+ }
+ }
+
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobsearch/result/search-result.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobsearch/result/search-result.js
deleted file mode 100644
index 823bede17e..0000000000
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobsearch/result/search-result.js
+++ /dev/null
@@ -1,16 +0,0 @@
-gitplex.blobSearchResult = {
- scrollIfNecessary: function(containerId) {
- var margin = 25;
- var $body = $("#" + containerId + ">.search-result>.body");
-
- var $active = $body.find("a.selectable.active");
- var contentTop = $body.offset().top;
- var activeTop = $active.offset().top;
- if (activeTop-margin<contentTop)
- $body.scrollTop($body.scrollTop()-(contentTop-activeTop+margin));
- var contentBottom = contentTop + $body.height();
- var activeBottom = activeTop + $active.height();
- if (activeBottom+margin>contentBottom)
- $body.scrollTop($body.scrollTop()+(activeBottom+margin-contentBottom));
- }
-}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewPanel.java
index 05b5a65af6..febba28115 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewPanel.java
@@ -169,10 +169,12 @@ public abstract class BlobViewPanel extends Panel {
protected void onInitialize() {
super.onInitialize();
- if (context.isAtSourceBranchHead())
+ if (context.isAtSourceBranchHead()) {
add(new Label("label", "Edit on source branch"));
- else
+ add(AttributeAppender.append("target", "_blank"));
+ } else {
add(new Label("label", "Edit"));
+ }
PageParameters params;
if (context.isOnBranch()) {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/base/base.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/base/base.js
index c7dbb1f52c..8385e1ee7c 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/base/base.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/base/base.js
@@ -1,29 +1,8 @@
var gitplex = {
- utils: {
- /**
- * Trigger a callback when the selected images are loaded:
- * @param {String} selector
- * @param {Function} callback
- */
- onImageLoad: function(selector, callback){
- $(selector).each(function(){
- if (this.complete || /*for IE 10-*/ $(this).height() > 0) {
- callback.apply(this);
- }
- else {
- $(this).on('load', function(){
- callback.apply(this);
- });
- }
- });
- }
- },
-
mouseState: {
pressed: false,
moved: false
}
-
};
$(document).ready(function() {
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.js
index 6499b0cda6..92c55e3ca8 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
@@ -89,14 +89,3 @@ $(window).load(function() {
});
$(window).resize();
});
-
-gitplex.repofile = {
- confirmSwitchFile: function(linkId) {
- var linkURI = new URI(document.getElementById(linkId));
- var currentURI = new URI(window.location.href);
- if (linkURI.search(true).path != currentURI.search(true).path)
- return pmease.commons.form.confirmLeave();
- else
- return true;
- }
-};
\ No newline at end of file