From b2a988ac06fd993648f5eac0df0475891c97e5d5 Mon Sep 17 00:00:00 2001 From: crschnick Date: Sun, 28 Jul 2024 20:27:37 +0000 Subject: [PATCH] Script fixes --- .../app/comp/store/StoreCreationMenu.java | 3 +- .../ext/base/action/RunScriptActionMenu.java | 65 +++++++++++++++++-- lang/base/strings/translations_da.properties | 1 + lang/base/strings/translations_de.properties | 1 + lang/base/strings/translations_en.properties | 1 + lang/base/strings/translations_es.properties | 1 + lang/base/strings/translations_fr.properties | 1 + lang/base/strings/translations_it.properties | 1 + lang/base/strings/translations_ja.properties | 1 + lang/base/strings/translations_nl.properties | 1 + lang/base/strings/translations_pt.properties | 1 + lang/base/strings/translations_ru.properties | 1 + lang/base/strings/translations_tr.properties | 1 + lang/base/strings/translations_zh.properties | 1 + 14 files changed, 74 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreCreationMenu.java b/app/src/main/java/io/xpipe/app/comp/store/StoreCreationMenu.java index b30ec5bb..755c3b7b 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreCreationMenu.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreCreationMenu.java @@ -40,8 +40,7 @@ public class StoreCreationMenu { menu.getItems() .add(category("addTunnel", "mdi2v-vector-polyline-plus", DataStoreCreationCategory.TUNNEL, null)); - menu.getItems() - .add(category("addCommand", "mdi2c-code-greater-than", DataStoreCreationCategory.COMMAND, "cmd")); + // menu.getItems().add(category("addCommand", "mdi2c-code-greater-than", DataStoreCreationCategory.COMMAND, "cmd")); menu.getItems().add(category("addDatabase", "mdi2d-database-plus", DataStoreCreationCategory.DATABASE, null)); } diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/RunScriptActionMenu.java b/ext/base/src/main/java/io/xpipe/ext/base/action/RunScriptActionMenu.java index 5883c813..19f76857 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/action/RunScriptActionMenu.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/action/RunScriptActionMenu.java @@ -1,10 +1,12 @@ package io.xpipe.ext.base.action; +import io.xpipe.app.comp.store.StoreViewState; import io.xpipe.app.core.AppI18n; import io.xpipe.app.ext.ActionProvider; import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.app.util.TerminalLauncher; import io.xpipe.core.process.ShellStoreState; +import io.xpipe.core.store.LocalStore; import io.xpipe.core.store.ShellStore; import io.xpipe.ext.base.script.ScriptHierarchy; import javafx.beans.property.SimpleStringProperty; @@ -16,7 +18,7 @@ import java.util.List; public class RunScriptActionMenu implements ActionProvider { @Value - private static class ScriptAction implements ActionProvider { + private static class ScriptActionProvider implements ActionProvider { ScriptHierarchy hierarchy; @@ -96,7 +98,43 @@ public class RunScriptActionMenu implements ActionProvider { @Override public List getChildren(DataStoreEntryRef store) { - return hierarchy.getChildren().stream().map(c -> new ScriptAction(c)).toList(); + return hierarchy.getChildren().stream().map(c -> new ScriptActionProvider(c)).toList(); + } + }; + } + } + + private static class NoScriptsActionProvider implements ActionProvider { + + private static class Action implements ActionProvider.Action { + + @Override + public void execute() throws Exception { + StoreViewState.get().getAllScriptsCategory().select(); + } + } + + @Override + public LeafDataStoreCallSite getLeafDataStoreCallSite() { + return new LeafDataStoreCallSite() { + @Override + public Action createAction(DataStoreEntryRef store) { + return new Action(); + } + + @Override + public ObservableValue getName(DataStoreEntryRef store) { + return AppI18n.observable("noScriptsAvailable"); + } + + @Override + public String getIcon(DataStoreEntryRef store) { + return "mdi2i-image-filter-none"; + } + + @Override + public Class getApplicableClass() { + return ShellStore.class; } }; } @@ -131,11 +169,25 @@ public class RunScriptActionMenu implements ActionProvider { return "mdi2p-play-box-multiple-outline"; } + @Override + public boolean isApplicable(DataStoreEntryRef o) { + if (o.getStore() instanceof LocalStore) { + return true; + } + + var state = o.getEntry().getStorePersistentState(); + if (!(state instanceof ShellStoreState shellStoreState) || shellStoreState.getShellDialect() == null) { + return false; + } + + return true; + } + @Override public List getChildren(DataStoreEntryRef store) { var state = store.getEntry().getStorePersistentState(); if (!(state instanceof ShellStoreState shellStoreState) || shellStoreState.getShellDialect() == null) { - return List.of(); + return List.of(new NoScriptsActionProvider()); } var hierarchy = ScriptHierarchy.buildEnabledHierarchy(ref -> { @@ -149,7 +201,12 @@ public class RunScriptActionMenu implements ActionProvider { return true; }); - return hierarchy.getChildren().stream().map(c -> new ScriptAction(c)).toList(); + var list = hierarchy.getChildren().stream().map(c -> new ScriptActionProvider(c)).toList(); + if (list.isEmpty()) { + return List.of(new NoScriptsActionProvider()); + } else { + return list; + } } }; } diff --git a/lang/base/strings/translations_da.properties b/lang/base/strings/translations_da.properties index 4a118dfb..05bdd614 100644 --- a/lang/base/strings/translations_da.properties +++ b/lang/base/strings/translations_da.properties @@ -173,3 +173,4 @@ hasServices=$COUNT$ tilgængelige tjenester hasService=$COUNT$ tilgængelig tjeneste openHttp=Åben HTTP-tjeneste openHttps=Åben HTTPS-tjeneste +noScriptsAvailable=Ingen tilgængelige scripts diff --git a/lang/base/strings/translations_de.properties b/lang/base/strings/translations_de.properties index 7d0ef586..3c026935 100644 --- a/lang/base/strings/translations_de.properties +++ b/lang/base/strings/translations_de.properties @@ -164,3 +164,4 @@ hasServices=$COUNT$ verfügbare Dienste hasService=$COUNT$ verfügbarer Dienst openHttp=Offener HTTP-Dienst openHttps=HTTPS-Dienst öffnen +noScriptsAvailable=Keine Skripte verfügbar diff --git a/lang/base/strings/translations_en.properties b/lang/base/strings/translations_en.properties index 86fdfe88..c24bff2f 100644 --- a/lang/base/strings/translations_en.properties +++ b/lang/base/strings/translations_en.properties @@ -162,5 +162,6 @@ hasServices=$COUNT$ available services hasService=$COUNT$ available service openHttp=Open HTTP service openHttps=Open HTTPS service +noScriptsAvailable=No scripts available diff --git a/lang/base/strings/translations_es.properties b/lang/base/strings/translations_es.properties index 3862c0c0..790f34c6 100644 --- a/lang/base/strings/translations_es.properties +++ b/lang/base/strings/translations_es.properties @@ -162,3 +162,4 @@ hasServices=$COUNT$ servicios disponibles hasService=$COUNT$ servicio disponible openHttp=Servicio HTTP abierto openHttps=Abrir servicio HTTPS +noScriptsAvailable=No hay guiones disponibles diff --git a/lang/base/strings/translations_fr.properties b/lang/base/strings/translations_fr.properties index f10217cc..df537b87 100644 --- a/lang/base/strings/translations_fr.properties +++ b/lang/base/strings/translations_fr.properties @@ -162,3 +162,4 @@ hasServices=$COUNT$ services disponibles hasService=$COUNT$ service disponible openHttp=Service HTTP ouvert openHttps=Service HTTPS ouvert +noScriptsAvailable=Pas de scripts disponibles diff --git a/lang/base/strings/translations_it.properties b/lang/base/strings/translations_it.properties index 5de8faf0..955cd4c5 100644 --- a/lang/base/strings/translations_it.properties +++ b/lang/base/strings/translations_it.properties @@ -162,3 +162,4 @@ hasServices=$COUNT$ servizi disponibili hasService=$COUNT$ servizio disponibile openHttp=Servizio HTTP aperto openHttps=Servizio HTTPS aperto +noScriptsAvailable=Non sono disponibili script diff --git a/lang/base/strings/translations_ja.properties b/lang/base/strings/translations_ja.properties index 4903a3bc..0ab64ec5 100644 --- a/lang/base/strings/translations_ja.properties +++ b/lang/base/strings/translations_ja.properties @@ -162,3 +162,4 @@ hasServices=$COUNT$ 利用可能なサービス hasService=$COUNT$ 利用可能なサービス openHttp=オープンHTTPサービス openHttps=HTTPSサービスを開く +noScriptsAvailable=スクリプトはない diff --git a/lang/base/strings/translations_nl.properties b/lang/base/strings/translations_nl.properties index 2620d511..4fa31e6e 100644 --- a/lang/base/strings/translations_nl.properties +++ b/lang/base/strings/translations_nl.properties @@ -162,3 +162,4 @@ hasServices=$COUNT$ beschikbare diensten hasService=$COUNT$ beschikbare dienst openHttp=Open HTTP service openHttps=Open HTTPS service +noScriptsAvailable=Geen scripts beschikbaar diff --git a/lang/base/strings/translations_pt.properties b/lang/base/strings/translations_pt.properties index 7f79aea1..679cad41 100644 --- a/lang/base/strings/translations_pt.properties +++ b/lang/base/strings/translations_pt.properties @@ -162,3 +162,4 @@ hasServices=$COUNT$ serviços disponíveis hasService=$COUNT$ serviço disponível openHttp=Abre o serviço HTTP openHttps=Abre o serviço HTTPS +noScriptsAvailable=Não há scripts disponíveis diff --git a/lang/base/strings/translations_ru.properties b/lang/base/strings/translations_ru.properties index 0959e00a..4efa1dd7 100644 --- a/lang/base/strings/translations_ru.properties +++ b/lang/base/strings/translations_ru.properties @@ -162,3 +162,4 @@ hasServices=$COUNT$ доступные сервисы hasService=$COUNT$ доступный сервис openHttp=Открытый HTTP-сервис openHttps=Открытая служба HTTPS +noScriptsAvailable=Нет доступных скриптов diff --git a/lang/base/strings/translations_tr.properties b/lang/base/strings/translations_tr.properties index e6b579e0..ac72818c 100644 --- a/lang/base/strings/translations_tr.properties +++ b/lang/base/strings/translations_tr.properties @@ -162,3 +162,4 @@ hasServices=$COUNT$ mevcut hi̇zmetler hasService=$COUNT$ mevcut hizmet openHttp=Açık HTTP hizmeti openHttps=HTTPS hizmetini açın +noScriptsAvailable=Mevcut senaryo yok diff --git a/lang/base/strings/translations_zh.properties b/lang/base/strings/translations_zh.properties index 71aa1c16..1d8254d8 100644 --- a/lang/base/strings/translations_zh.properties +++ b/lang/base/strings/translations_zh.properties @@ -162,3 +162,4 @@ hasServices=$COUNT$ 可用服务 hasService=$COUNT$ 可用服务 openHttp=开放式 HTTP 服务 openHttps=打开 HTTPS 服务 +noScriptsAvailable=无脚本可用