Update document handling (WIP)
This commit is contained in:
parent
1a8a559697
commit
d47edc9e1a
@ -228,6 +228,10 @@ public class ShareClient extends AbstractUIPlugin implements MessageListener, Di
|
|||||||
Files.createFile(filePath);
|
Files.createFile(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
byte[] bytes = new byte[sync.content().size()];
|
||||||
|
for(int i = 0; i < bytes.length; i++) {
|
||||||
|
|
||||||
|
}
|
||||||
String content = sync.content().stream()
|
String content = sync.content().stream()
|
||||||
.map(c -> String.valueOf(c.value()))
|
.map(c -> String.valueOf(c.value()))
|
||||||
.collect(Collectors.joining());
|
.collect(Collectors.joining());
|
||||||
|
@ -18,7 +18,9 @@ public class ShareClientPreferencePage extends FieldEditorPreferencePage impleme
|
|||||||
protected void createFieldEditors() {
|
protected void createFieldEditors() {
|
||||||
addField(new StringFieldEditor(ShareClientPreferences.SERVER_URI, "Server URI", getFieldEditorParent()));
|
addField(new StringFieldEditor(ShareClientPreferences.SERVER_URI, "Server URI", getFieldEditorParent()));
|
||||||
addField(new StringFieldEditor(ShareClientPreferences.USERNAME, "Display Name", getFieldEditorParent()));
|
addField(new StringFieldEditor(ShareClientPreferences.USERNAME, "Display Name", getFieldEditorParent()));
|
||||||
addField(new BooleanFieldEditor(ShareClientPreferences.SHOW_CURSORS, "Show other users' cursors", getFieldEditorParent()));
|
addField(new BooleanFieldEditor(ShareClientPreferences.SHOW_CURSORS, "Show other users' cursors (TODO)", getFieldEditorParent()));
|
||||||
|
addField(new BooleanFieldEditor(ShareClientPreferences.ONLY_SHARE_SOURCE_FOLDERS, "Only share files in source folders (TODO)", getFieldEditorParent()));
|
||||||
|
addField(new BooleanFieldEditor(ShareClientPreferences.USE_SHARECLIENT_PROJECT_CONFIG, "Use configuration from .shareclient file in the project (TODO)", getFieldEditorParent()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,6 +5,8 @@ public class ShareClientPreferences {
|
|||||||
public static final String
|
public static final String
|
||||||
SERVER_URI = "serverUri",
|
SERVER_URI = "serverUri",
|
||||||
USERNAME = "username",
|
USERNAME = "username",
|
||||||
SHOW_CURSORS = "showCursors";
|
SHOW_CURSORS = "showCursors",
|
||||||
|
ONLY_SHARE_SOURCE_FOLDERS = "onlyShareSourceFolders", // TODO: option to only share source folders of projects?
|
||||||
|
USE_SHARECLIENT_PROJECT_CONFIG = "useShareClientConfig"; // TODO: option to enable a .shareclient project-specific config file
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,9 @@ import java.util.Map;
|
|||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.jface.text.BadLocationException;
|
|
||||||
import org.eclipse.jface.text.IDocument;
|
|
||||||
import org.eclipse.swt.widgets.Display;
|
|
||||||
|
|
||||||
import me.mrletsplay.shareclient.ShareClient;
|
import me.mrletsplay.shareclient.ShareClient;
|
||||||
import me.mrletsplay.shareclient.util.listeners.ShareClientDocumentListener;
|
|
||||||
import me.mrletsplay.shareclientcore.connection.RemoteConnection;
|
import me.mrletsplay.shareclientcore.connection.RemoteConnection;
|
||||||
import me.mrletsplay.shareclientcore.document.DocumentListener;
|
|
||||||
import me.mrletsplay.shareclientcore.document.SharedDocument;
|
import me.mrletsplay.shareclientcore.document.SharedDocument;
|
||||||
|
|
||||||
public class ShareSession {
|
public class ShareSession {
|
||||||
@ -82,53 +77,53 @@ public class ShareSession {
|
|||||||
return sharedDocuments.get(path);
|
return sharedDocuments.get(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SharedDocument getOrCreateSharedDocument(ProjectRelativePath path, Supplier<String> initialContents) {
|
public SharedDocument getOrCreateSharedDocument(ProjectRelativePath path, Supplier<byte[]> initialContents) {
|
||||||
return sharedDocuments.computeIfAbsent(path, p -> {
|
return sharedDocuments.computeIfAbsent(path, p -> {
|
||||||
SharedDocument doc = new SharedDocument(connection, path.toString(), initialContents.get());
|
SharedDocument doc = new SharedDocument(connection, path.toString(), initialContents.get());
|
||||||
|
|
||||||
doc.addListener(new DocumentListener() {
|
// doc.addListener(new DocumentListener() {
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void onInsert(int index, char character) {
|
// public void onInsert(int index, byte character) {
|
||||||
// FIXME: potential desync. If changes arrive while waiting for asyncExec to execute, it will insert at the wrong position
|
// // FIXME: potential desync. If changes arrive while waiting for asyncExec to execute, it will insert at the wrong position
|
||||||
Display.getDefault().asyncExec(() -> {
|
// Display.getDefault().asyncExec(() -> {
|
||||||
ShareClientDocumentListener documentListener = ShareClient.getDefault().getPartListener().getListener(path);
|
// ShareClientDocumentListener documentListener = ShareClient.getDefault().getPartListener().getListener(path);
|
||||||
if(documentListener != null) {
|
// if(documentListener != null) {
|
||||||
IDocument document = documentListener.getDocument();
|
// IDocument document = documentListener.getDocument();
|
||||||
|
//
|
||||||
documentListener.setIgnoreChanges(true);
|
// documentListener.setIgnoreChanges(true);
|
||||||
try {
|
// try {
|
||||||
document.replace(index, 0, String.valueOf(character));
|
// document.replace(index, 0, String.valueOf(character));
|
||||||
} catch (BadLocationException e) {
|
// } catch (BadLocationException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
// TODO: treat as inconsistency
|
// // TODO: treat as inconsistency
|
||||||
// MessageDialog.openError(null, "Share Client", "Failed to update document: " + e.toString());
|
//// MessageDialog.openError(null, "Share Client", "Failed to update document: " + e.toString());
|
||||||
}
|
// }
|
||||||
documentListener.setIgnoreChanges(false);
|
// documentListener.setIgnoreChanges(false);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void onDelete(int index) {
|
// public void onDelete(int index) {
|
||||||
Display.getDefault().asyncExec(() -> {
|
// Display.getDefault().asyncExec(() -> {
|
||||||
ShareClientDocumentListener documentListener = ShareClient.getDefault().getPartListener().getListener(path);
|
// ShareClientDocumentListener documentListener = ShareClient.getDefault().getPartListener().getListener(path);
|
||||||
if(documentListener != null) {
|
// if(documentListener != null) {
|
||||||
IDocument document = documentListener.getDocument();
|
// IDocument document = documentListener.getDocument();
|
||||||
|
//
|
||||||
documentListener.setIgnoreChanges(true);
|
// documentListener.setIgnoreChanges(true);
|
||||||
try {
|
// try {
|
||||||
document.replace(index, 1, "");
|
// document.replace(index, 1, "");
|
||||||
} catch (BadLocationException e) {
|
// } catch (BadLocationException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
// TODO: treat as inconsistency
|
// // TODO: treat as inconsistency
|
||||||
// MessageDialog.openError(null, "Share Client", "Failed to update document: " + e.toString());
|
//// MessageDialog.openError(null, "Share Client", "Failed to update document: " + e.toString());
|
||||||
}
|
// }
|
||||||
documentListener.setIgnoreChanges(false);
|
// documentListener.setIgnoreChanges(false);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
return doc;
|
return doc;
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user