Merge "Using a table to hold two side-by-side CodeMirrors."
This commit is contained in:
@@ -23,9 +23,7 @@ import com.google.gwt.dom.client.Element;
|
|||||||
import com.google.gwt.event.logical.shared.ResizeEvent;
|
import com.google.gwt.event.logical.shared.ResizeEvent;
|
||||||
import com.google.gwt.event.logical.shared.ResizeHandler;
|
import com.google.gwt.event.logical.shared.ResizeHandler;
|
||||||
import com.google.gwt.event.shared.HandlerRegistration;
|
import com.google.gwt.event.shared.HandlerRegistration;
|
||||||
import com.google.gwt.user.client.DOM;
|
|
||||||
import com.google.gwt.user.client.Window;
|
import com.google.gwt.user.client.Window;
|
||||||
import com.google.gwt.user.client.ui.FlowPanel;
|
|
||||||
|
|
||||||
import net.codemirror.lib.CodeMirror;
|
import net.codemirror.lib.CodeMirror;
|
||||||
import net.codemirror.lib.Configuration;
|
import net.codemirror.lib.Configuration;
|
||||||
@@ -37,7 +35,7 @@ public class CodeMirrorDemo extends Screen {
|
|||||||
private final PatchSet.Id revision;
|
private final PatchSet.Id revision;
|
||||||
private final String path;
|
private final String path;
|
||||||
|
|
||||||
private FlowPanel editorContainer;
|
private DiffTable diffTable;
|
||||||
private CodeMirror cmA;
|
private CodeMirror cmA;
|
||||||
private CodeMirror cmB;
|
private CodeMirror cmB;
|
||||||
private HandlerRegistration resizeHandler;
|
private HandlerRegistration resizeHandler;
|
||||||
@@ -54,7 +52,7 @@ public class CodeMirrorDemo extends Screen {
|
|||||||
@Override
|
@Override
|
||||||
protected void onInitUI() {
|
protected void onInitUI() {
|
||||||
super.onInitUI();
|
super.onInitUI();
|
||||||
add(editorContainer = new FlowPanel());
|
add(diffTable = new DiffTable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -90,9 +88,13 @@ public class CodeMirrorDemo extends Screen {
|
|||||||
@Override
|
@Override
|
||||||
public void onShowView() {
|
public void onShowView() {
|
||||||
super.onShowView();
|
super.onShowView();
|
||||||
|
if (cmA != null) {
|
||||||
cmA.refresh();
|
cmA.refresh();
|
||||||
|
}
|
||||||
|
if (cmB != null) {
|
||||||
cmB.refresh();
|
cmB.refresh();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onUnload() {
|
protected void onUnload() {
|
||||||
@@ -112,8 +114,8 @@ public class CodeMirrorDemo extends Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void display(DiffInfo diff) {
|
private void display(DiffInfo diff) {
|
||||||
cmA = displaySide(diff.meta_a(), diff.text_a());
|
cmA = displaySide(diff.meta_a(), diff.text_a(), diffTable.getCmA());
|
||||||
cmB = displaySide(diff.meta_b(), diff.text_b());
|
cmB = displaySide(diff.meta_b(), diff.text_b(), diffTable.getCmB());
|
||||||
resizeHandler = Window.addResizeHandler(new ResizeHandler() {
|
resizeHandler = Window.addResizeHandler(new ResizeHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onResize(ResizeEvent event) {
|
public void onResize(ResizeEvent event) {
|
||||||
@@ -129,7 +131,8 @@ public class CodeMirrorDemo extends Screen {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private CodeMirror displaySide(DiffInfo.FileMeta meta, String contents) {
|
private CodeMirror displaySide(DiffInfo.FileMeta meta, String contents,
|
||||||
|
Element ele) {
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
return null; // TODO: Handle empty contents
|
return null; // TODO: Handle empty contents
|
||||||
}
|
}
|
||||||
@@ -139,9 +142,7 @@ public class CodeMirrorDemo extends Screen {
|
|||||||
.set("tabSize", 2)
|
.set("tabSize", 2)
|
||||||
.set("mode", getContentType(meta))
|
.set("mode", getContentType(meta))
|
||||||
.set("value", contents);
|
.set("value", contents);
|
||||||
Element child = DOM.createDiv();
|
final CodeMirror cm = CodeMirror.create(ele, cfg);
|
||||||
editorContainer.getElement().appendChild(child);
|
|
||||||
final CodeMirror cm = CodeMirror.create(child, cfg);
|
|
||||||
cm.setWidth("100%");
|
cm.setWidth("100%");
|
||||||
cm.setHeight(Window.getClientHeight() - HEADER_FOOTER);
|
cm.setHeight(Window.getClientHeight() - HEADER_FOOTER);
|
||||||
return cm;
|
return cm;
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
//Copyright (C) 2013 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package com.google.gerrit.client.diff;
|
||||||
|
|
||||||
|
import com.google.gwt.core.client.GWT;
|
||||||
|
import com.google.gwt.dom.client.DivElement;
|
||||||
|
import com.google.gwt.uibinder.client.UiBinder;
|
||||||
|
import com.google.gwt.uibinder.client.UiField;
|
||||||
|
import com.google.gwt.user.client.ui.Composite;
|
||||||
|
import com.google.gwt.user.client.ui.HTMLPanel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A table with one row and two columns to hold the two CodeMirrors displaying
|
||||||
|
* the files to be diffed.
|
||||||
|
*/
|
||||||
|
class DiffTable extends Composite {
|
||||||
|
interface Binder extends UiBinder<HTMLPanel, DiffTable> {}
|
||||||
|
private static Binder uiBinder = GWT.create(Binder.class);
|
||||||
|
|
||||||
|
@UiField
|
||||||
|
DivElement cmA;
|
||||||
|
|
||||||
|
@UiField
|
||||||
|
DivElement cmB;
|
||||||
|
|
||||||
|
DiffTable() {
|
||||||
|
initWidget(uiBinder.createAndBindUi(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
DivElement getCmA() {
|
||||||
|
return cmA;
|
||||||
|
}
|
||||||
|
|
||||||
|
DivElement getCmB() {
|
||||||
|
return cmB;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2013 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
|
||||||
|
xmlns:g='urn:import:com.google.gwt.user.client.ui'>
|
||||||
|
<g:HTMLPanel>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td><div ui:field='cmA'></div></td>
|
||||||
|
<td><div ui:field='cmB'></div></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</g:HTMLPanel>
|
||||||
|
</ui:UiBinder>
|
||||||
Reference in New Issue
Block a user