Skip to content

Commit 8d1c6d2

Browse files
committed
small improvements.
1 parent 1e0096c commit 8d1c6d2

12 files changed

Lines changed: 179 additions & 19 deletions

File tree

src/main/java/com/ss/editor/ui/Icons.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ public interface Icons {
126126
* The constant EXPORT_16.
127127
*/
128128
Image EXPORT_16 = ICON_MANAGER.getImage("/ui/icons/svg/scale-symbol.svg", 16);
129+
/**
130+
* The constant EXPORT_16.
131+
*/
132+
Image EXPLORER_16 = ICON_MANAGER.getImage("/ui/icons/svg/inbox.svg", 16);
133+
/**
134+
* The constant EXPORT_16.
135+
*/
136+
Image EDIT_2_16 = ICON_MANAGER.getImage("/ui/icons/svg/font-selection-editor.svg", 16);
129137
/**
130138
* The constant BONE_16.
131139
*/

src/main/java/com/ss/editor/ui/component/asset/tree/context/menu/action/OpenFileByEditorAction.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.ss.editor.ui.component.asset.tree.context.menu.action;
22

3+
import com.ss.editor.ui.Icons;
34
import com.ss.editor.ui.component.asset.tree.resource.ResourceElement;
45
import com.ss.editor.ui.component.editor.EditorDescription;
56
import com.ss.editor.ui.event.impl.RequestedOpenFileEvent;
@@ -36,6 +37,11 @@ public OpenFileByEditorAction(@NotNull final ResourceElement element,
3637
}
3738
}
3839

40+
@Override
41+
protected @Nullable Image getIcon() {
42+
return Icons.EDIT_16;
43+
}
44+
3945
@Override
4046
protected void execute(@Nullable final ActionEvent event) {
4147
super.execute(event);

src/main/java/com/ss/editor/ui/component/asset/tree/context/menu/action/OpenFileByExternalEditorAction.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.ss.editor.ui.component.asset.tree.context.menu.action;
22

33
import com.ss.editor.Messages;
4+
import com.ss.editor.ui.Icons;
45
import com.ss.editor.ui.component.asset.tree.resource.ResourceElement;
56
import com.ss.editor.util.EditorUtil;
67
import javafx.event.ActionEvent;
8+
import javafx.scene.image.Image;
79
import org.jetbrains.annotations.NotNull;
810
import org.jetbrains.annotations.Nullable;
911

@@ -23,6 +25,10 @@ public OpenFileByExternalEditorAction(@NotNull final ResourceElement element) {
2325
return Messages.ASSET_COMPONENT_RESOURCE_TREE_CONTEXT_MENU_OPEN_FILE_BY_EXTERNAL_EDITOR;
2426
}
2527

28+
@Override
29+
protected @Nullable Image getIcon() {
30+
return Icons.EDIT_2_16;
31+
}
2632

2733
@Override
2834
protected void execute(@Nullable final ActionEvent event) {
Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package com.ss.editor.ui.component.asset.tree.context.menu.action;
22

33
import com.ss.editor.Messages;
4+
import com.ss.editor.ui.Icons;
45
import com.ss.editor.ui.component.asset.tree.resource.ResourceElement;
56
import com.ss.editor.util.EditorUtil;
67
import javafx.event.ActionEvent;
78
import javafx.scene.image.Image;
89
import org.jetbrains.annotations.NotNull;
910
import org.jetbrains.annotations.Nullable;
1011

11-
import java.nio.file.Files;
12-
import java.nio.file.Path;
13-
1412
/**
1513
* The action to open a file in an system explorer.
1614
*
@@ -24,7 +22,7 @@ public OpenFileInExplorerAction(@NotNull final ResourceElement element) {
2422

2523
@Override
2624
protected @Nullable Image getIcon() {
27-
return super.getIcon();
25+
return Icons.EXPLORER_16;
2826
}
2927

3028
@Override
@@ -35,13 +33,6 @@ public OpenFileInExplorerAction(@NotNull final ResourceElement element) {
3533
@Override
3634
protected void execute(@Nullable final ActionEvent event) {
3735
super.execute(event);
38-
39-
final Path file = getElement().getFile();
40-
41-
if (Files.isDirectory(file)) {
42-
EditorUtil.openFileInExternalEditor(file);
43-
} else {
44-
EditorUtil.openFileInExternalEditor(file.getParent());
45-
}
36+
EditorUtil.openFileInSystemExplorer(getElement().getFile());
4637
}
4738
}

src/main/java/com/ss/editor/ui/component/asset/tree/context/menu/filler/impl/ResourceAssetTreeSingleContextMenuFiller.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ public class ResourceAssetTreeSingleContextMenuFiller implements AssetTreeSingle
2929
public void fill(@NotNull final ResourceElement element, @NotNull final List<MenuItem> items,
3030
@NotNull final Predicate<Class<?>> actionTester) {
3131

32+
if (element instanceof FolderResourceElement && actionTester.test(NewFileAction.class)) {
33+
items.add(new NewFileAction(element));
34+
}
35+
3236
if(actionTester.test(OpenFileInExplorerAction.class)) {
3337
items.add(new OpenFileInExplorerAction(element));
3438
}
3539

36-
if (actionTester.test(NewFileAction.class)) {
40+
if (element instanceof FileResourceElement && actionTester.test(NewFileAction.class)) {
3741
items.add(new NewFileAction(element));
3842
}
3943

src/main/java/com/ss/editor/util/EditorUtil.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,63 @@ public static void openFileInExternalEditor(@NotNull final Path path) {
479479
}
480480
}
481481

482+
/**
483+
* Open the file in a system explorer.
484+
*
485+
* @param path the path
486+
*/
487+
public static void openFileInSystemExplorer(@NotNull final Path path) {
488+
489+
final Platform platform = JmeSystem.getPlatform();
490+
final List<String> commands = new ArrayList<>();
491+
492+
if (platform == Platform.MacOSX64 || platform == Platform.MacOSX_PPC64) {
493+
commands.add("/System/Library/CoreServices/Finder.app");
494+
} else if (platform == Platform.Windows32 || platform == Platform.Windows64) {
495+
commands.add("explorer");
496+
} else if (platform == Platform.Linux32 || platform == Platform.Linux64) {
497+
if (isAppExists("nautilus -v")) {
498+
commands.add("nautilus");
499+
} else if (isAppExists("dolphin -v")) {
500+
commands.add("dolphin");
501+
}
502+
}
503+
504+
if (commands.isEmpty()) return;
505+
506+
final String url;
507+
try {
508+
url = path.toUri().toURL().toString();
509+
} catch (final MalformedURLException e) {
510+
handleException(LOGGER, null, e);
511+
return;
512+
}
513+
514+
commands.add(url);
515+
516+
final ProcessBuilder processBuilder = new ProcessBuilder();
517+
processBuilder.command(commands);
518+
try {
519+
processBuilder.start();
520+
} catch (final IOException e) {
521+
handleException(LOGGER, null, e);
522+
}
523+
}
524+
525+
private static boolean isAppExists(@NotNull final String command) {
526+
527+
final Runtime runtime = Runtime.getRuntime();
528+
final int result;
529+
try {
530+
final Process exec = runtime.exec(command);
531+
result = exec.waitFor();
532+
} catch (final InterruptedException | IOException e) {
533+
return false;
534+
}
535+
536+
return result >= 0;
537+
}
538+
482539
/**
483540
* Convert the object to byte array.
484541
*

src/main/resources/credits/icons.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,6 @@ ui/icons/svg/plug-silhouette.svg icon made by http://www.flaticon.com/authors/fr
7676
ui/icons/filetypes/cube.svg icon made by https://www.flaticon.com/authors/madebyoliver from www.flaticon.com
7777
ui/icons/filetypes/parquet.svg icon made by https://www.flaticon.com/authors/madebyoliver from www.flaticon.com
7878
ui/icons/svg/draws.svg icon made by http://www.flaticon.com/authors/freepik from www.flaticon.com
79-
ui/icons/svg/scale-symbol.svg icon made by https://www.flaticon.com/authors/popcic from www.flaticon.com
79+
ui/icons/svg/scale-symbol.svg icon made by https://www.flaticon.com/authors/popcic from www.flaticon.com
80+
ui/icons/svg/font-selection-editor.svg made by https://www.flaticon.com/authors/dave-gandy from www.flaticon.com
81+
ui/icons/svg/inbox.svg icon made by http://www.flaticon.com/authors/freepik from www.flaticon.com

src/main/resources/messages/messages.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ AssetComponentResourceTreeContextMenuDeleteFile=Delete
2525
AssetComponentResourceTreeContextMenuDeleteFileQuestion=Do you want to remove the file "%file_name%"?
2626
AssetComponentResourceTreeContextMenuDeleteFilesQuestion=Do you want to remove the %file_count% files?
2727
AssetComponentResourceTreeContextMenuConvertFile=Convert
28-
AssetComponentResourceTreeContextMenuOpenFileByExternalEditor=Open file in external editor
29-
AssetComponentResourceTreeContextMenuOpenFileBySystemExplorer=Open file in system explorer
28+
AssetComponentResourceTreeContextMenuOpenFileByExternalEditor=Open in external editor
29+
AssetComponentResourceTreeContextMenuOpenFileBySystemExplorer=Open in Explorer
3030
AssetComponentResourceTreeContextMenuRenameFile=Rename
3131

3232
FileEditorActionSave=Save

src/main/resources/messages/messages_de.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ AssetComponentResourceTreeContextMenuDeleteFileQuestion=Wollen Sie die Datei "%f
2626
AssetComponentResourceTreeContextMenuDeleteFilesQuestion=Do you want to remove the %file_count% files?
2727
AssetComponentResourceTreeContextMenuConvertFile=Konvertieren
2828
AssetComponentResourceTreeContextMenuOpenFileByExternalEditor=Datei mit externen Programm öffnen
29-
AssetComponentResourceTreeContextMenuOpenFileBySystemExplorer=Open file in system explorer
29+
AssetComponentResourceTreeContextMenuOpenFileBySystemExplorer=Open in Explorer
3030
AssetComponentResourceTreeContextMenuRenameFile=Umbenennen
3131

3232
FileEditorActionSave=Speichern

src/main/resources/messages/messages_ru.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ AssetComponentResourceTreeContextMenuDeleteFile=Удалить
2626
AssetComponentResourceTreeContextMenuDeleteFileQuestion=Вы уверены что хотите удалить файл "%file_name%"?
2727
AssetComponentResourceTreeContextMenuDeleteFilesQuestion=Вы уверены что хотите удалить "%file_count% файла(ов)"?
2828
AssetComponentResourceTreeContextMenuConvertFile=Конвертировать
29-
AssetComponentResourceTreeContextMenuOpenFileByExternalEditor=Открыть файл во внешнем редакторе
30-
AssetComponentResourceTreeContextMenuOpenFileBySystemExplorer=Открыть файл в системном проводнике
29+
AssetComponentResourceTreeContextMenuOpenFileByExternalEditor=Открыть во внешнем редакторе
30+
AssetComponentResourceTreeContextMenuOpenFileBySystemExplorer=Открыть в проводнике
3131
AssetComponentResourceTreeContextMenuRenameFile=Переименовать
3232

3333
FileEditorActionSave=Сохранить

0 commit comments

Comments
 (0)