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);
|
||||
}
|
||||
|
||||
byte[] bytes = new byte[sync.content().size()];
|
||||
for(int i = 0; i < bytes.length; i++) {
|
||||
|
||||
}
|
||||
String content = sync.content().stream()
|
||||
.map(c -> String.valueOf(c.value()))
|
||||
.collect(Collectors.joining());
|
||||
|
@ -18,7 +18,9 @@ public class ShareClientPreferencePage extends FieldEditorPreferencePage impleme
|
||||
protected void createFieldEditors() {
|
||||
addField(new StringFieldEditor(ShareClientPreferences.SERVER_URI, "Server URI", 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
|
||||
|
@ -5,6 +5,8 @@ public class ShareClientPreferences {
|
||||
public static final String
|
||||
SERVER_URI = "serverUri",
|
||||
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 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.util.listeners.ShareClientDocumentListener;
|
||||
import me.mrletsplay.shareclientcore.connection.RemoteConnection;
|
||||
import me.mrletsplay.shareclientcore.document.DocumentListener;
|
||||
import me.mrletsplay.shareclientcore.document.SharedDocument;
|
||||
|
||||
public class ShareSession {
|
||||
@ -82,53 +77,53 @@ public class ShareSession {
|
||||
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 -> {
|
||||
SharedDocument doc = new SharedDocument(connection, path.toString(), initialContents.get());
|
||||
|
||||
doc.addListener(new DocumentListener() {
|
||||
|
||||
@Override
|
||||
public void onInsert(int index, char character) {
|
||||
// FIXME: potential desync. If changes arrive while waiting for asyncExec to execute, it will insert at the wrong position
|
||||
Display.getDefault().asyncExec(() -> {
|
||||
ShareClientDocumentListener documentListener = ShareClient.getDefault().getPartListener().getListener(path);
|
||||
if(documentListener != null) {
|
||||
IDocument document = documentListener.getDocument();
|
||||
|
||||
documentListener.setIgnoreChanges(true);
|
||||
try {
|
||||
document.replace(index, 0, String.valueOf(character));
|
||||
} catch (BadLocationException e) {
|
||||
e.printStackTrace();
|
||||
// TODO: treat as inconsistency
|
||||
// MessageDialog.openError(null, "Share Client", "Failed to update document: " + e.toString());
|
||||
}
|
||||
documentListener.setIgnoreChanges(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDelete(int index) {
|
||||
Display.getDefault().asyncExec(() -> {
|
||||
ShareClientDocumentListener documentListener = ShareClient.getDefault().getPartListener().getListener(path);
|
||||
if(documentListener != null) {
|
||||
IDocument document = documentListener.getDocument();
|
||||
|
||||
documentListener.setIgnoreChanges(true);
|
||||
try {
|
||||
document.replace(index, 1, "");
|
||||
} catch (BadLocationException e) {
|
||||
e.printStackTrace();
|
||||
// TODO: treat as inconsistency
|
||||
// MessageDialog.openError(null, "Share Client", "Failed to update document: " + e.toString());
|
||||
}
|
||||
documentListener.setIgnoreChanges(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// doc.addListener(new DocumentListener() {
|
||||
//
|
||||
// @Override
|
||||
// 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
|
||||
// Display.getDefault().asyncExec(() -> {
|
||||
// ShareClientDocumentListener documentListener = ShareClient.getDefault().getPartListener().getListener(path);
|
||||
// if(documentListener != null) {
|
||||
// IDocument document = documentListener.getDocument();
|
||||
//
|
||||
// documentListener.setIgnoreChanges(true);
|
||||
// try {
|
||||
// document.replace(index, 0, String.valueOf(character));
|
||||
// } catch (BadLocationException e) {
|
||||
// e.printStackTrace();
|
||||
// // TODO: treat as inconsistency
|
||||
//// MessageDialog.openError(null, "Share Client", "Failed to update document: " + e.toString());
|
||||
// }
|
||||
// documentListener.setIgnoreChanges(false);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onDelete(int index) {
|
||||
// Display.getDefault().asyncExec(() -> {
|
||||
// ShareClientDocumentListener documentListener = ShareClient.getDefault().getPartListener().getListener(path);
|
||||
// if(documentListener != null) {
|
||||
// IDocument document = documentListener.getDocument();
|
||||
//
|
||||
// documentListener.setIgnoreChanges(true);
|
||||
// try {
|
||||
// document.replace(index, 1, "");
|
||||
// } catch (BadLocationException e) {
|
||||
// e.printStackTrace();
|
||||
// // TODO: treat as inconsistency
|
||||
//// MessageDialog.openError(null, "Share Client", "Failed to update document: " + e.toString());
|
||||
// }
|
||||
// documentListener.setIgnoreChanges(false);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
|
||||
return doc;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user