Skip to content

Commit c2d7b2c

Browse files
committed
implemented opening files from IDEA.
1 parent 24cd17c commit c2d7b2c

File tree

6 files changed

+96
-19
lines changed

6 files changed

+96
-19
lines changed

build-native.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180

181181
<fx:platform>
182182
<fx:jvmarg value="-XX:+UseParallelGC"/>
183-
<fx:jvmarg value="-agentlib:jdwp=transport=dt_socket,server=n,address=javasabr-NB:6005,suspend=y"/>
183+
<!--<fx:jvmarg value="-agentlib:jdwp=transport=dt_socket,server=n,address=javasabr-NB:6005,suspend=y"/>-->
184184
</fx:platform>
185185

186186
<preferences shortcut="true" menu="true" install="false"/>

src/main/java/com/ss/editor/JFXApplication.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import com.ss.editor.ui.scene.EditorFXScene;
3535
import com.ss.editor.util.OpenGLVersion;
3636
import com.ss.editor.util.svg.SvgImageLoaderFactory;
37-
import com.ss.rlib.concurrent.util.ThreadUtils;
3837
import com.ss.rlib.logging.Logger;
3938
import com.ss.rlib.logging.LoggerManager;
4039
import com.ss.rlib.manager.InitializeManager;
@@ -101,7 +100,7 @@ public class JFXApplication extends Application {
101100
* @throws IOException the io exception
102101
*/
103102
public static void main(final String[] args) {
104-
103+
105104
// need to disable to work on macos
106105
Configuration.GLFW_CHECK_THREAD0.set(false);
107106
// use jemalloc
@@ -265,6 +264,13 @@ public JFXApplication() {
265264
this.openedWindows = ArrayFactory.newConcurrentStampedLockArray(Window.class);
266265
}
267266

267+
/**
268+
* Request focus of this window.
269+
*/
270+
public void requestFocus() {
271+
notNull(stage).requestFocus();
272+
}
273+
268274
/**
269275
* Add the new opened window.
270276
*

src/main/java/com/ss/editor/manager/ClasspathManager.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ public static ClasspathManager getInstance() {
9595
@Nullable
9696
private volatile URLClassLoader classesLoader;
9797

98+
/**
99+
* The local libraries class loader.
100+
*/
101+
@Nullable
102+
private volatile URLClassLoader localLibrariesLoader;
103+
104+
/**
105+
* The local classes class loader.
106+
*/
107+
@Nullable
108+
private volatile URLClassLoader localClassesLoader;
109+
98110
private ClasspathManager() {
99111
InitializeManager.valid(getClass());
100112

@@ -276,6 +288,43 @@ private void setClassesLoader(@Nullable final URLClassLoader classesLoader) {
276288
public @Nullable URLClassLoader getClassesLoader() {
277289
return classesLoader;
278290
}
291+
292+
/**
293+
* Get the local libraries class loader.
294+
*
295+
* @return the local libraries class loader.
296+
*/
297+
private @Nullable URLClassLoader getLocalLibrariesLoader() {
298+
return localLibrariesLoader;
299+
}
300+
301+
/**
302+
* Set the local libraries class loader.
303+
*
304+
* @param localLibrariesLoader the local libraries class loader.
305+
*/
306+
private void setLocalLibrariesLoader(@Nullable final URLClassLoader localLibrariesLoader) {
307+
this.localLibrariesLoader = localLibrariesLoader;
308+
}
309+
310+
/**
311+
* Get the local classes class loader.
312+
*
313+
* @return the local classes class loader.
314+
*/
315+
private @Nullable URLClassLoader getLocalClassesLoader() {
316+
return localClassesLoader;
317+
}
318+
319+
/**
320+
* Set the local classes class loader.
321+
*
322+
* @param localClassesLoader the local classes class loader.
323+
*/
324+
private void setLocalClassesLoader(@Nullable final URLClassLoader localClassesLoader) {
325+
this.localClassesLoader = localClassesLoader;
326+
}
327+
279328
/**
280329
* Find all implementations of the interface class.
281330
*
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.ss.editor.remote.control.client;
2+
3+
import com.ss.editor.annotation.BackgroundThread;
4+
import com.ss.rlib.network.ConnectionOwner;
5+
import com.ss.rlib.network.packet.impl.AbstractReadablePacket;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
import java.nio.ByteBuffer;
9+
10+
/**
11+
* The base implementation of a client packet.
12+
*
13+
* @author JavaSaBr
14+
*/
15+
public abstract class ClientCommand extends AbstractReadablePacket {
16+
17+
@Override
18+
@BackgroundThread
19+
protected abstract void readImpl(@NotNull final ConnectionOwner owner, @NotNull final ByteBuffer buffer);
20+
}

src/main/java/com/ss/editor/remote/control/client/ClientPacket.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/main/java/com/ss/editor/remote/control/client/OpenFileClientPacket.java renamed to src/main/java/com/ss/editor/remote/control/client/OpenFileClientCommand.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.ss.editor.remote.control.client;
22

3+
import com.ss.editor.JFXApplication;
4+
import com.ss.editor.annotation.BackgroundThread;
35
import com.ss.editor.config.EditorConfig;
46
import com.ss.editor.manager.ExecutorManager;
57
import com.ss.editor.ui.component.bar.action.OpenAssetAction;
@@ -22,7 +24,7 @@
2224
* @author JavaSaBr
2325
*/
2426
@PacketDescription(id = 1)
25-
public class OpenFileClientPacket extends ClientPacket {
27+
public class OpenFileClientCommand extends ClientCommand {
2628

2729
@NotNull
2830
private static final FXEventManager FX_EVENT_MANAGER = FXEventManager.getInstance();
@@ -31,6 +33,7 @@ public class OpenFileClientPacket extends ClientPacket {
3133
private static final ExecutorManager EXECUTOR_MANAGER = ExecutorManager.getInstance();
3234

3335
@Override
36+
@BackgroundThread
3437
protected void readImpl(@NotNull final ConnectionOwner owner, @NotNull final ByteBuffer buffer) {
3538

3639
final Path assetPath = Paths.get(readString(buffer));
@@ -39,7 +42,9 @@ protected void readImpl(@NotNull final ConnectionOwner owner, @NotNull final Byt
3942
final EditorConfig editorConfig = EditorConfig.getInstance();
4043
final Path currentAsset = editorConfig.getCurrentAsset();
4144

42-
if (currentAsset == null || !assetPath.equals(currentAsset)) {
45+
if (currentAsset != null && assetPath.equals(currentAsset)) {
46+
EXECUTOR_MANAGER.addFXTask(() -> openFile(fileToOpen));
47+
} else {
4348
EXECUTOR_MANAGER.addFXTask(() -> {
4449

4550
final OpenAssetAction action = new OpenAssetAction();
@@ -50,15 +55,23 @@ protected void readImpl(@NotNull final ConnectionOwner owner, @NotNull final Byt
5055
@Override
5156
public void handle(final Event event) {
5257
FX_EVENT_MANAGER.removeEventHandler(AssetComponentLoadedEvent.EVENT_TYPE, this);
53-
FX_EVENT_MANAGER.notify(new RequestedOpenFileEvent(fileToOpen));
58+
openFile(fileToOpen);
5459
}
5560
};
5661

5762
FX_EVENT_MANAGER.addEventHandler(AssetComponentLoadedEvent.EVENT_TYPE, eventHandler);
5863
});
5964

60-
} else {
61-
FX_EVENT_MANAGER.notify(new RequestedOpenFileEvent(fileToOpen));
6265
}
6366
}
67+
68+
/**
69+
* Open the file.
70+
*
71+
* @param fileToOpen the file.
72+
*/
73+
private void openFile(@NotNull final Path fileToOpen) {
74+
FX_EVENT_MANAGER.notify(new RequestedOpenFileEvent(fileToOpen));
75+
JFXApplication.getInstance().requestFocus();
76+
}
6477
}

0 commit comments

Comments
 (0)