Skip to content

The Unified and Autonomous Development Platform

Adjust width and height of outline panel so that it co-exist with sourceviewpanel better.

robin shinecdaca3a54b7b
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/GitPlexSession.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/GitPlexSession.java
index 2cb8578910..3a4ae3518e 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/GitPlexSession.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/GitPlexSession.java
@@ -16,6 +16,8 @@ public class GitPlexSession extends WebSession {
private static final long serialVersionUID = 1L;
+ private boolean displayOutline;
+
public GitPlexSession(Request request) {
super(request);
}
@@ -57,4 +59,12 @@ public class GitPlexSession extends WebSession {
currentUser.login(token);
}
+ public boolean isDisplayOutline() {
+ return displayOutline;
+ }
+
+ public void setDisplayOutline(boolean displayOutline) {
+ this.displayOutline = displayOutline;
+ }
+
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/OutlinePanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/OutlinePanel.java
index 69824f4fc8..fd9bcae973 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/OutlinePanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/OutlinePanel.java
@@ -12,19 +12,16 @@ import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.extensions.markup.html.repeater.tree.ITreeProvider;
import org.apache.wicket.extensions.markup.html.repeater.tree.NestedTree;
import org.apache.wicket.extensions.markup.html.repeater.tree.theme.HumanTheme;
-import org.apache.wicket.markup.head.CssHeaderItem;
-import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
-import org.apache.wicket.request.resource.CssResourceReference;
import com.pmease.commons.lang.Symbol;
@SuppressWarnings("serial")
-public class OutlinePanel extends Panel {
+class OutlinePanel extends Panel {
private final List<Symbol> symbols;
@@ -84,7 +81,7 @@ public class OutlinePanel extends Panel {
@Override
protected Component newContentComponent(String id, IModel<Symbol> nodeModel) {
Fragment fragment = new Fragment(id, "nodeFrag", OutlinePanel.this);
- Symbol symbol = nodeModel.getObject();
+ final Symbol symbol = nodeModel.getObject();
fragment.add(new Image("icon", symbol.getIcon()));
@@ -92,6 +89,9 @@ public class OutlinePanel extends Panel {
@Override
public void onClick(AjaxRequestTarget target) {
+ String script = String.format("gitplex.sourceview.gotoSymbol('%s', %d);",
+ OutlinePanel.this.getMarkupId(), symbol.getLineNo());
+ target.appendJavaScript(script);
}
};
@@ -105,14 +105,8 @@ public class OutlinePanel extends Panel {
for (Symbol root: getChildSymbols(null))
tree.expand(root);
+
+ setOutputMarkupId(true);
}
- @Override
- public void renderHead(IHeaderResponse response) {
- super.renderHead(response);
-
- response.render(CssHeaderItem.forReference(
- new CssResourceReference(SourceViewPanel.class, "source-view.css")));
- }
-
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/Source.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/Source.java
index c148cfbe7b..7af6a8b621 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/Source.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/Source.java
@@ -2,8 +2,6 @@ package com.pmease.gitplex.web.component.sourceview;
import java.io.Serializable;
-import javax.annotation.Nullable;
-
@SuppressWarnings("serial")
public class Source implements Serializable {
@@ -13,9 +11,9 @@ public class Source implements Serializable {
private final String content;
- private final Integer activeLine;
+ private final int activeLine;
- public Source(String revision, String path, String content, @Nullable Integer activeLine) {
+ public Source(String revision, String path, String content, int activeLine) {
this.revision = revision;
this.path = path;
this.content = content;
@@ -34,7 +32,7 @@ public class Source implements Serializable {
return content;
}
- public Integer getActiveLine() {
+ public int getActiveLine() {
return activeLine;
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/SourceViewPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/SourceViewPanel.html
index 4d4be2d9eb..d698615348 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/SourceViewPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/SourceViewPanel.html
@@ -3,12 +3,10 @@
<div class="head">
<a wicket:id="outlineToggle" title="Toggle outline"><i class="fa fa-list-ul"></i></a>
</div>
- <table class="body">
- <tr>
- <td class="code"><div wicket:id="code"></div></td>
- <td class="outline"><div wicket:id="outline"></div></td>
- </tr>
- </table>
+ <div class="body clearfix">
+ <div wicket:id="code" class="code pull-left"></div>
+ <div wicket:id="outline" class="outline pull-left"></div>
+ </div>
<div wicket:id="symbols" class="hidden">
<wicket:enclosure child="declarations">
<div>Declaration occurrences of this name</div>
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/SourceViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/SourceViewPanel.java
index 4d85c8a32f..e5e6eb6c8e 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/SourceViewPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/SourceViewPanel.java
@@ -9,6 +9,7 @@ import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
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;
@@ -41,6 +42,7 @@ import com.pmease.gitplex.search.hit.QueryHit;
import com.pmease.gitplex.search.query.BlobQuery;
import com.pmease.gitplex.search.query.SymbolQuery;
import com.pmease.gitplex.search.query.TextQuery;
+import com.pmease.gitplex.web.GitPlexSession;
@SuppressWarnings("serial")
public abstract class SourceViewPanel extends Panel {
@@ -63,8 +65,6 @@ public abstract class SourceViewPanel extends Panel {
private List<QueryHit> symbolHits = new ArrayList<>();
- private boolean displayOutline;
-
private final List<Symbol> symbols;
public SourceViewPanel(String id, IModel<Repository> repoModel, Source source) {
@@ -88,8 +88,9 @@ public abstract class SourceViewPanel extends Panel {
@Override
public void onClick(AjaxRequestTarget target) {
- displayOutline = !displayOutline;
- target.add(outlinePanel);
+ GitPlexSession session = GitPlexSession.get();
+ session.setDisplayOutline(!session.isDisplayOutline());
+ target.appendJavaScript(String.format("gitplex.sourceview.toggleOutline('%s');", outlinePanel.getMarkupId()));
}
@Override
@@ -104,17 +105,9 @@ public abstract class SourceViewPanel extends Panel {
add(codeContainer = new WebMarkupContainer("code"));
codeContainer.setOutputMarkupId(true);
- add(outlinePanel = new OutlinePanel("outline", symbols) {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
-
- setVisible(displayOutline);
- }
-
- });
- outlinePanel.setOutputMarkupPlaceholderTag(true);
+ add(outlinePanel = new OutlinePanel("outline", symbols));
+ if (!GitPlexSession.get().isDisplayOutline())
+ outlinePanel.add(AttributeAppender.append("style", "display:none;"));
add(symbolsContainer = new WebMarkupContainer("symbols"));
symbolsContainer.setOutputMarkupId(true);
@@ -234,7 +227,7 @@ public abstract class SourceViewPanel extends Panel {
codeContainer.getMarkupId(),
StringEscapeUtils.escapeEcmaScript(source.getContent()),
source.getPath(),
- source.getActiveLine()!=null?source.getActiveLine():"undefined",
+ source.getActiveLine(),
RequestCycle.get().urlFor(ajaxIndicator, new PageParameters()),
getCallbackFunction(CallbackParameter.explicit("symbol")));
response.render(OnDomReadyHeaderItem.forScript(script));
@@ -256,12 +249,4 @@ public abstract class SourceViewPanel extends Panel {
super.onDetach();
}
- public boolean isDisplayOutline() {
- return displayOutline;
- }
-
- public void setDisplayOutline(boolean displayOutline) {
- this.displayOutline = displayOutline;
- }
-
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/source-view.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/source-view.css
index f131b32c45..72280ef3c7 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/source-view.css
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/source-view.css
@@ -1,7 +1,5 @@
-.source-view>table.body {width: 100%;}
-.source-view>table.body>tbody>tr>td.code {width: 75%;}
-
-.source-view .CodeMirror {height: 800px;}
+.source-view>.body>.outline {overflow: auto;}
+.source-view {height: 600px; border: 1px solid red;}
.CodeMirror-tokentooltip table.declarations td {vertical-align: top; padding: 2px 4px; white-space: nowrap;}
.CodeMirror-tokentooltip table.declarations .scope {color: #666;}
.CodeMirror-tokentooltip>div {font-weight: bold;}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/source-view.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/source-view.js
index c996d087fe..583b14692b 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/source-view.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/sourceview/source-view.js
@@ -1,6 +1,6 @@
gitplex.sourceview = {
- init: function(codeContainerId, fileContent, filePath, activeLine, ajaxIndicatorUrl, symbolQuery) {
- var $codeContainer = $("#" + codeContainerId);
+ init: function(codeId, fileContent, filePath, activeLine, ajaxIndicatorUrl, symbolQuery) {
+ var $code = $("#" + codeId);
var options = {
value: fileContent,
readOnly: true,
@@ -18,33 +18,63 @@ gitplex.sourceview = {
var tooltip = document.createElement("div");
var $tooltip = $(tooltip);
$tooltip.html("<img src=" + ajaxIndicatorUrl + "></img>");
- $tooltip.attr("id", codeContainerId + "-symbolstooltip");
+ $tooltip.attr("id", codeId + "-symbolstooltip");
symbolQuery($(tokenEl).text());
return tooltip;
}
},
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
};
- var editor = CodeMirror($codeContainer[0], options);
+ var editor = CodeMirror($code[0], options);
var modeInfo = CodeMirror.findModeByFileName(filePath);
editor.setOption("mode", modeInfo.mime);
CodeMirror.autoLoadMode(editor, modeInfo.mode);
- if (activeLine) {
- editor.setCursor(activeLine);
- var h = editor.getScrollInfo().clientHeight;
- var coords = editor.charCoords({line: activeLine, ch: 0}, "local");
- editor.scrollTo(null, (coords.top + coords.bottom - h) / 2);
- }
+ var $sourceView = $code.closest(".source-view");
+ $sourceView.resize(function() {
+ var $head = $sourceView.find(">.head");
+ var $body = $sourceView.find(">.body");
+ var $outline = $body.find(">.outline");
+ if ($outline.is(":visible")) {
+ $code.width($body.width()/4.0*3);
+ $outline.width($body.width() - $code.width()-1);
+ } else {
+ $code.width($body.width());
+ }
+ $outline.height($sourceView.height()-$head.height());
+ $code.find(">.CodeMirror").height($outline.height());
+ });
+
+ $sourceView.resize();
+
+ gitplex.sourceview.gotoLine(editor, activeLine);
},
- symbolsQueried: function(codeContainerId, symbolsContainerId) {
- var $symbolsContainer = $("#" + symbolsContainerId);
- var $tooltipContainer = $("#" + codeContainerId + "-symbolstooltip");
- $tooltipContainer.children().remove();
- $symbolsContainer.children().appendTo($tooltipContainer);
- $tooltipContainer.align();
+ symbolsQueried: function(codeId, symbolsId) {
+ var $symbols = $("#" + symbolsId);
+ var $tooltip = $("#" + codeId + "-symbolstooltip");
+ $tooltip.children().remove();
+ $symbols.children().appendTo($tooltip);
+ $tooltip.align();
+ },
+
+ toggleOutline: function(outlineId) {
+ var $outline = $("#" + outlineId);
+ $outline.toggle();
+ $outline.closest(".source-view").resize();
+ },
+
+ gotoSymbol: function(outlineId, line) {
+ var cm = $('#'+ outlineId).closest(".source-view").find(".CodeMirror")[0].CodeMirror;
+ gitplex.sourceview.gotoLine(cm, line);
+ },
+
+ gotoLine: function(cm, line) {
+ cm.setCursor(line);
+ var h = cm.getScrollInfo().clientHeight;
+ var coords = cm.charCoords({line: line, ch: 0}, "local");
+ cm.scrollTo(null, (coords.top + coords.bottom - h) / 2);
}
}
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java
index c951c09048..3e424c964f 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java
@@ -128,11 +128,11 @@ public class TestPage extends BasePage {
});
*/
- add(newSourceView("sourceView", blobPath, null));
+ add(newSourceView("sourceView", blobPath, 0));
add(new WebMarkupContainer("searchResult").setOutputMarkupId(true));
}
- private SourceViewPanel newSourceView(final String id, String blobPath, Integer activeLine) {
+ private SourceViewPanel newSourceView(final String id, String blobPath, int activeLine) {
Source source = openBlob(blobPath, activeLine);
SourceViewPanel sourceView = new SourceViewPanel(id, repoModel, source) {
@@ -161,7 +161,7 @@ public class TestPage extends BasePage {
return sourceView;
}
- private Source openBlob(String blobPath, Integer activeLine) {
+ private Source openBlob(String blobPath, int activeLine) {
org.eclipse.jgit.lib.Repository jgitRepo = repoModel.getObject().openAsJGitRepo();
try {
RevTree revTree = new RevWalk(jgitRepo).parseCommit(repoModel.getObject().resolveRevision(revision)).getTree();