Merge "Using a table to hold two side-by-side CodeMirrors."

This commit is contained in:
Shawn Pearce
2013-05-23 20:52:12 +00:00
committed by Gerrit Code Review
3 changed files with 90 additions and 12 deletions

View File

@@ -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.ResizeHandler;
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.ui.FlowPanel;
import net.codemirror.lib.CodeMirror;
import net.codemirror.lib.Configuration;
@@ -37,7 +35,7 @@ public class CodeMirrorDemo extends Screen {
private final PatchSet.Id revision;
private final String path;
private FlowPanel editorContainer;
private DiffTable diffTable;
private CodeMirror cmA;
private CodeMirror cmB;
private HandlerRegistration resizeHandler;
@@ -54,7 +52,7 @@ public class CodeMirrorDemo extends Screen {
@Override
protected void onInitUI() {
super.onInitUI();
add(editorContainer = new FlowPanel());
add(diffTable = new DiffTable());
}
@Override
@@ -90,8 +88,12 @@ public class CodeMirrorDemo extends Screen {
@Override
public void onShowView() {
super.onShowView();
cmA.refresh();
cmB.refresh();
if (cmA != null) {
cmA.refresh();
}
if (cmB != null) {
cmB.refresh();
}
}
@Override
@@ -112,8 +114,8 @@ public class CodeMirrorDemo extends Screen {
}
private void display(DiffInfo diff) {
cmA = displaySide(diff.meta_a(), diff.text_a());
cmB = displaySide(diff.meta_b(), diff.text_b());
cmA = displaySide(diff.meta_a(), diff.text_a(), diffTable.getCmA());
cmB = displaySide(diff.meta_b(), diff.text_b(), diffTable.getCmB());
resizeHandler = Window.addResizeHandler(new ResizeHandler() {
@Override
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) {
return null; // TODO: Handle empty contents
}
@@ -139,9 +142,7 @@ public class CodeMirrorDemo extends Screen {
.set("tabSize", 2)
.set("mode", getContentType(meta))
.set("value", contents);
Element child = DOM.createDiv();
editorContainer.getElement().appendChild(child);
final CodeMirror cm = CodeMirror.create(child, cfg);
final CodeMirror cm = CodeMirror.create(ele, cfg);
cm.setWidth("100%");
cm.setHeight(Window.getClientHeight() - HEADER_FOOTER);
return cm;

View File

@@ -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;
}
}

View File

@@ -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>