Clean up code, Add minimal target

This commit is contained in:
MrLetsplay 2024-06-15 20:23:06 +02:00
parent a309eb0838
commit 08bcf39865
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
5 changed files with 75 additions and 14 deletions

40
eclipse2.target Normal file
View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?>
<target includeMode="feature" name="Minimal">
<content>
<plugins>
</plugins>
<features>
<feature id="org.eclipse.rcp"/>
<feature id="org.eclipse.platform"/>
<feature id="org.eclipse.e4.rcp"/>
</features>
</content>
<locations>
<location path="${eclipse_home}" type="Directory"/>
<location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" missingManifest="generate" type="Maven">
<dependencies>
<dependency>
<groupId>me.mrletsplay</groupId>
<artifactId>ShareLib</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>1.5.6</version>
<type>jar</type>
</dependency>
</dependencies>
</location>
</locations>
<includeBundles>
<plugin id="wrapped.me.mrletsplay.ShareLib"/>
<plugin id="Java-WebSocket"/>
<feature id="org.eclipse.e4.rcp"/>
<feature id="org.eclipse.rcp"/>
<feature id="org.eclipse.platform"/>
<plugin id="javax.inject"/>
</includeBundles>
</target>

View File

@ -173,7 +173,6 @@ public class ShareClient extends AbstractUIPlugin implements MessageListener, Di
@Override
public void onMessage(Message message) {
Display.getDefault().asyncExec(() -> {
System.out.println("Got: " + message);
if (message instanceof PeerJoinMessage join) {
activeSession.getPeers().add(new Peer(join.peerName(), join.peerSiteID()));
updateView();

View File

@ -39,10 +39,6 @@ public class ShareClientDocumentListener implements IDocumentListener {
if(ignoreChanges) return;
System.out.println("UPDATE ON THREAD " + Thread.currentThread());
// FIXME: bug somewhere here, can cause discrepancies in local editor when editing while changes are coming in
ShareSession session = ShareClient.getDefault().getActiveSession();
if(session == null) return;

View File

@ -8,7 +8,6 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IPartListener2;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartReference;
@ -34,11 +33,9 @@ public class ShareClientPartListener implements IPartListener2 {
public void addDocumentListener(IWorkbenchPartReference partRef) {
IWorkbenchPart part = partRef.getPart(false);
if(!(part instanceof IEditorPart)) return;
IEditorPart editor = (IEditorPart) part;
if(!(editor instanceof ITextEditor)) return;
ITextEditor textEditor = (ITextEditor) editor;
IEditorInput editorInput = editor.getEditorInput();
if(!(part instanceof ITextEditor)) return;
ITextEditor textEditor = (ITextEditor) part;
IEditorInput editorInput = textEditor.getEditorInput();
if(!(editorInput instanceof FileEditorInput)) return;
FileEditorInput fileEditorInput = (FileEditorInput) editorInput;
IDocument document = textEditor.getDocumentProvider().getDocument(editorInput);
@ -47,10 +44,31 @@ public class ShareClientPartListener implements IPartListener2 {
IProject project = file.getProject();
Path filePath = project.getLocation().toPath().relativize(file.getLocation().toPath());
// FIXME: this should probably just store an IProject with a relative path
ProjectAndPath relPath = new ProjectAndPath(project, filePath.toString());
System.out.println("Opened editor: " + relPath);
document.addDocumentListener(createListener(relPath, document));
System.out.println("Opened editor: " + relPath);
}
private void removeDocumentListener(IWorkbenchPartReference partRef) {
IWorkbenchPart part = partRef.getPart(false);
if(!(part instanceof ITextEditor)) return;
ITextEditor textEditor = (ITextEditor) part;
IEditorInput editorInput = textEditor.getEditorInput();
if(!(editorInput instanceof FileEditorInput)) return;
FileEditorInput fileEditorInput = (FileEditorInput) editorInput;
IDocument document = textEditor.getDocumentProvider().getDocument(editorInput);
IFile file = fileEditorInput.getFile();
IProject project = file.getProject();
Path filePath = project.getLocation().toPath().relativize(file.getLocation().toPath());
ProjectAndPath relPath = new ProjectAndPath(project, filePath.toString());
ShareClientDocumentListener listener = getListener(relPath);
if(listener == null) return;
document.removeDocumentListener(listener);
listeners.remove(relPath);
System.out.println("Closed editor: " + relPath);
}
@Override
@ -63,10 +81,19 @@ public class ShareClientPartListener implements IPartListener2 {
addDocumentListener(partRef);
}
@Override
public void partClosed(IWorkbenchPartReference partRef) {
removeDocumentListener(partRef);
}
public Map<ProjectAndPath, ShareClientDocumentListener> getListeners() {
return listeners;
}
public ShareClientDocumentListener getListener(ProjectAndPath path) {
return listeners.get(path);
}
public ShareClientDocumentListener getListener(ProjectRelativePath path) {
ShareSession session = ShareClient.getDefault().getActiveSession();
if(session == null) return null;

View File

@ -66,7 +66,6 @@ public class ShareView extends ViewPart {
@Override
public void init(IViewSite site) throws PartInitException {
super.init(site);
System.out.println(ShareClient.getDefault());
ShareClient.getDefault().setView(this);
}