# HG changeset patch # User Shinji KONO # Date 1283474325 -32400 # Node ID 61db2f70ceda3b00499814d2e8445f427c2580d5 # Parent 1f63cec3755cf6890954a5bcde3ee951db834495# Parent ca9f72b8b4ab93f3054e5ce22789acdd22bf54ee merge diff -r 1f63cec3755c -r 61db2f70ceda src/remoteeditor/editors/REPEditor.java --- a/src/remoteeditor/editors/REPEditor.java Fri Sep 03 09:38:17 2010 +0900 +++ b/src/remoteeditor/editors/REPEditor.java Fri Sep 03 09:38:45 2010 +0900 @@ -27,7 +27,7 @@ private int eid; private int sid; private REPText repText; - private boolean hasInputLock; + private boolean hasInputLock = true; private boolean master; private boolean syncEnable = true; @@ -99,7 +99,7 @@ /* * Editor main loop with input lock */ - private void mainloop() throws IOException { + void mainloop() throws IOException { channel.configureBlocking(false); selector = REPSelector.create(); @@ -113,7 +113,8 @@ runners.clear(); } - if (inputLock) { +// if(inputLock){ + if (repText.isMerging()) { // No user input during merge mode (optional) if (selector.select(0)>0) { handle(channel.read()); @@ -133,7 +134,7 @@ } } - private void handle(REPCommand command) { + public void handle(REPCommand command) { Logger.print(command); if(command == null) return; switch(command.cmd){ @@ -170,11 +171,13 @@ case SMCMD_START_MERGE : // lock user input during merge (optional) inputLock = hasInputLock; + repText.startMerge(this); command.cmd = REP.SMCMD_START_MERGE_ACK; send(command); break; case SMCMD_END_MERGE : inputLock = false; + repText.endMerge(); break; case SMCMD_SYNC: // start contents sync with newly joined editor diff -r 1f63cec3755c -r 61db2f70ceda src/remoteeditor/editors/REPText.java --- a/src/remoteeditor/editors/REPText.java Fri Sep 03 09:38:17 2010 +0900 +++ b/src/remoteeditor/editors/REPText.java Fri Sep 03 09:38:45 2010 +0900 @@ -2,6 +2,8 @@ import java.util.List; +import org.eclipse.swt.widgets.Display; + public interface REPText { public void insert(int lineno, String text); @@ -16,4 +18,12 @@ public String get(int i); + public void startMerge(REPEditor editor); + + public void endMerge(); + + public boolean isMerging(); + + public Display getDisplay(); + } diff -r 1f63cec3755c -r 61db2f70ceda src/remoteeditor/editors/REPTextImpl2.java --- a/src/remoteeditor/editors/REPTextImpl2.java Fri Sep 03 09:38:17 2010 +0900 +++ b/src/remoteeditor/editors/REPTextImpl2.java Fri Sep 03 09:38:45 2010 +0900 @@ -1,5 +1,6 @@ package remoteeditor.editors; +import java.io.IOException; import java.util.LinkedList; import java.util.List; @@ -16,6 +17,7 @@ private String BR = System.getProperty("line.separator"); private List textListenerList; private boolean myInput = false; + private boolean inMerging = false; public REPTextImpl2(IDocument document, Display display){ this.document = document; @@ -61,6 +63,24 @@ } private void edit(final int offset, final int length, final String text) { + if(inMerging){ + edit2(offset, length, text); + }else{ + edit1(offset, length, text); + } + } + + private void edit2(int offset, int length, String text) { + try { + myInput = true; + document.replace(offset, length, text); + myInput = false; + } catch (BadLocationException e) { + e.printStackTrace(); + } + } + + private void edit1(final int offset, final int length, final String text) { display.syncExec(new Runnable(){ public void run(){ try { @@ -136,7 +156,6 @@ } catch (BadLocationException e) { e.printStackTrace(); } - } public synchronized void addTextListener(REPTextListener listener) { @@ -152,4 +171,35 @@ return document.getNumberOfLines(); } + public void doMerge(REPEditor editor) { + while(inMerging){ + try { + editor.mainloop(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + public void endMerge() { + inMerging = false; + } + + public void startMerge(final REPEditor editor) { + inMerging = true; + display.syncExec(new Runnable(){ + public void run(){ + doMerge(editor); + } + }); + } + + public boolean isMerging() { + return inMerging; + } + + public Display getDisplay() { + return display; + } + }