From 0c0d91b67d7c17c64ed707e989c7bb53cb7abb28 Mon Sep 17 00:00:00 2001 From: crschnick Date: Fri, 21 Mar 2025 14:28:33 +0000 Subject: [PATCH] Add ability to launch custom terminal editors --- app/src/main/java/io/xpipe/app/prefs/AppPrefs.java | 6 ++++++ .../main/java/io/xpipe/app/prefs/EditorCategory.java | 10 +++++++--- .../java/io/xpipe/app/prefs/ExternalEditorType.java | 12 ++++++++---- lang/strings/translations_da.properties | 2 ++ lang/strings/translations_de.properties | 2 ++ lang/strings/translations_en.properties | 2 ++ lang/strings/translations_es.properties | 2 ++ lang/strings/translations_fr.properties | 2 ++ lang/strings/translations_id.properties | 2 ++ lang/strings/translations_it.properties | 2 ++ lang/strings/translations_ja.properties | 2 ++ lang/strings/translations_nl.properties | 2 ++ lang/strings/translations_pl.properties | 2 ++ lang/strings/translations_pt.properties | 2 ++ lang/strings/translations_ru.properties | 2 ++ lang/strings/translations_sv.properties | 2 ++ lang/strings/translations_tr.properties | 2 ++ lang/strings/translations_zh.properties | 4 ++-- 18 files changed, 51 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/prefs/AppPrefs.java b/app/src/main/java/io/xpipe/app/prefs/AppPrefs.java index 86b33991e..b26715e76 100644 --- a/app/src/main/java/io/xpipe/app/prefs/AppPrefs.java +++ b/app/src/main/java/io/xpipe/app/prefs/AppPrefs.java @@ -117,6 +117,8 @@ public class AppPrefs { mapLocal(new SimpleObjectProperty<>(), "externalEditor", ExternalEditorType.class, false); final StringProperty customEditorCommand = mapLocal(new SimpleStringProperty(""), "customEditorCommand", String.class, false); + final BooleanProperty customEditorCommandInTerminal = + mapLocal(new SimpleBooleanProperty(false), "customEditorCommandInTerminal", Boolean.class, false); final BooleanProperty automaticallyCheckForUpdates = mapLocal(new SimpleBooleanProperty(true), "automaticallyCheckForUpdates", Boolean.class, false); final BooleanProperty encryptAllVaultData = @@ -405,6 +407,10 @@ public class AppPrefs { return customEditorCommand; } + public ObservableBooleanValue customEditorCommandInTerminal() { + return customEditorCommandInTerminal; + } + public final ReadOnlyIntegerProperty editorReloadTimeout() { return editorReloadTimeout; } diff --git a/app/src/main/java/io/xpipe/app/prefs/EditorCategory.java b/app/src/main/java/io/xpipe/app/prefs/EditorCategory.java index 0fd9c7075..ddafaf8eb 100644 --- a/app/src/main/java/io/xpipe/app/prefs/EditorCategory.java +++ b/app/src/main/java/io/xpipe/app/prefs/EditorCategory.java @@ -47,9 +47,13 @@ public class EditorCategory extends AppPrefsCategory { prefs.externalEditor, PrefsChoiceValue.getSupported(ExternalEditorType.class), false)) .nameAndDescription("customEditorCommand") .addComp(new TextFieldComp(prefs.customEditorCommand, true) - .apply(struc -> struc.get().setPromptText("myeditor $FILE")) - .hide(prefs.externalEditor.isNotEqualTo(ExternalEditorType.CUSTOM))) - .addComp(terminalTest)) + .apply(struc -> struc.get().setPromptText("myeditor $FILE"))) + .hide(prefs.externalEditor.isNotEqualTo(ExternalEditorType.CUSTOM)) + .addComp(terminalTest) + .nameAndDescription("customEditorCommandInTerminal") + .addToggle(prefs.customEditorCommandInTerminal) + .hide(prefs.externalEditor.isNotEqualTo(ExternalEditorType.CUSTOM)) + ) .buildComp(); } } diff --git a/app/src/main/java/io/xpipe/app/prefs/ExternalEditorType.java b/app/src/main/java/io/xpipe/app/prefs/ExternalEditorType.java index 02927e675..a40f2e92a 100644 --- a/app/src/main/java/io/xpipe/app/prefs/ExternalEditorType.java +++ b/app/src/main/java/io/xpipe/app/prefs/ExternalEditorType.java @@ -2,6 +2,7 @@ package io.xpipe.app.prefs; import io.xpipe.app.ext.PrefsChoiceValue; import io.xpipe.app.issue.ErrorEvent; +import io.xpipe.app.terminal.TerminalLauncher; import io.xpipe.app.util.LocalShell; import io.xpipe.app.util.WindowsRegistry; import io.xpipe.core.process.CommandBuilder; @@ -171,10 +172,13 @@ public interface ExternalEditorType extends PrefsChoiceValue { throw ErrorEvent.expected(new IllegalStateException("No custom editor command specified")); } - var format = - customCommand.toLowerCase(Locale.ROOT).contains("$file") ? customCommand : customCommand + " $FILE"; - ExternalApplicationHelper.startAsync(CommandBuilder.of() - .add(ExternalApplicationHelper.replaceFileArgument(format, "FILE", file.toString()))); + var format = customCommand.toLowerCase(Locale.ROOT).contains("$file") ? customCommand : customCommand + " $FILE"; + var command = CommandBuilder.of().add(ExternalApplicationHelper.replaceFileArgument(format, "FILE", file.toString())); + if (AppPrefs.get().customEditorCommandInTerminal().get()) { + TerminalLauncher.openDirect(file.toString(), sc -> command.buildFull(sc), AppPrefs.get().terminalType.get()); + } else { + ExternalApplicationHelper.startAsync(command); + } } @Override diff --git a/lang/strings/translations_da.properties b/lang/strings/translations_da.properties index a5f0878b1..a4ff6c0b2 100644 --- a/lang/strings/translations_da.properties +++ b/lang/strings/translations_da.properties @@ -1335,3 +1335,5 @@ externalLaunchTitle=Anmodning om ekstern lancering externalLaunchContent=En ekstern terminal har anmodet om at starte en shell-forbindelse. Vil du tillade, at der oprettes shell-forbindelser uden for XPipe? noScriptStateAvailable=Opdater for at bestemme scriptkompatibilitet ... documentationDescription=Tjek dokumentationen ud +customEditorCommandInTerminal=Kør en brugerdefineret kommando i en terminal +customEditorCommandInTerminalDescription=Hvis din editor er terminalbaseret, kan du aktivere denne mulighed for automatisk at åbne en terminal og køre kommandoen i terminalsessionen i stedet.\n\nDu kan bruge denne indstilling til editorer som vi, vim, nvim og andre. diff --git a/lang/strings/translations_de.properties b/lang/strings/translations_de.properties index f2e0ed157..25dc1cdea 100644 --- a/lang/strings/translations_de.properties +++ b/lang/strings/translations_de.properties @@ -1319,3 +1319,5 @@ externalLaunchTitle=Externe Startanforderung externalLaunchContent=Ein externes Terminal hat angefragt, eine Shell-Verbindung zu starten. Willst du das Starten von Shell-Verbindungen von außerhalb von XPipe erlauben? noScriptStateAvailable=Aktualisieren, um die Skriptkompatibilität zu bestimmen ... documentationDescription=Schau dir die Dokumentation an +customEditorCommandInTerminal=Benutzerdefinierten Befehl in einem Terminal ausführen +customEditorCommandInTerminalDescription=Wenn dein Editor terminalbasiert ist, kannst du diese Option aktivieren, um automatisch ein Terminal zu öffnen und den Befehl stattdessen in der Terminalsitzung auszuführen.\n\nDu kannst diese Option für Editoren wie vi, vim, nvim und andere verwenden. diff --git a/lang/strings/translations_en.properties b/lang/strings/translations_en.properties index 05bfb2d8b..4331bcf08 100644 --- a/lang/strings/translations_en.properties +++ b/lang/strings/translations_en.properties @@ -1347,3 +1347,5 @@ externalLaunchTitle=External launch request externalLaunchContent=An external terminal has requested to launch a shell connection. Do you want to allow launching shell connections from outside XPipe? noScriptStateAvailable=Refresh to determine script compatibility ... documentationDescription=Check out the documentation +customEditorCommandInTerminal=Run custom command in a terminal +customEditorCommandInTerminalDescription=If your editor is terminal-based, you can enable this option to automatically open a terminal and run the command in the terminal session instead.\n\nYou can use this option for editors like vi, vim, nvim, and others. diff --git a/lang/strings/translations_es.properties b/lang/strings/translations_es.properties index ff066bae8..6d673a06b 100644 --- a/lang/strings/translations_es.properties +++ b/lang/strings/translations_es.properties @@ -1288,3 +1288,5 @@ externalLaunchTitle=Solicitud de lanzamiento externo externalLaunchContent=Un terminal externo ha solicitado lanzar una conexión shell. ¿Quieres permitir el lanzamiento de conexiones shell desde fuera de XPipe? noScriptStateAvailable=Actualizar para determinar la compatibilidad del script ... documentationDescription=Consulta la documentación +customEditorCommandInTerminal=Ejecutar un comando personalizado en un terminal +customEditorCommandInTerminalDescription=Si tu editor está basado en un terminal, puedes activar esta opción para abrir automáticamente un terminal y ejecutar el comando en la sesión del terminal en su lugar.\n\nPuedes utilizar esta opción para editores como vi, vim, nvim y otros. diff --git a/lang/strings/translations_fr.properties b/lang/strings/translations_fr.properties index 4ed3c67ac..c61bc37b6 100644 --- a/lang/strings/translations_fr.properties +++ b/lang/strings/translations_fr.properties @@ -1323,3 +1323,5 @@ externalLaunchTitle=Demande de lancement externe externalLaunchContent=Un terminal externe a demandé à lancer une connexion shell. Veux-tu autoriser le lancement de connexions shell depuis l'extérieur de XPipe ? noScriptStateAvailable=Actualise pour déterminer la compatibilité des scripts... documentationDescription=Vérifie la documentation +customEditorCommandInTerminal=Exécuter une commande personnalisée dans un terminal +customEditorCommandInTerminalDescription=Si ton éditeur est basé sur un terminal, tu peux activer cette option pour ouvrir automatiquement un terminal et exécuter la commande dans la session du terminal à la place.\n\nTu peux utiliser cette option pour des éditeurs comme vi, vim, nvim et d'autres. diff --git a/lang/strings/translations_id.properties b/lang/strings/translations_id.properties index af78c042d..e158038f8 100644 --- a/lang/strings/translations_id.properties +++ b/lang/strings/translations_id.properties @@ -1288,3 +1288,5 @@ externalLaunchTitle=Permintaan peluncuran eksternal externalLaunchContent=Terminal eksternal telah meminta untuk meluncurkan koneksi shell. Apakah Anda ingin mengizinkan peluncuran koneksi shell dari luar XPipe? noScriptStateAvailable=Menyegarkan untuk menentukan kompatibilitas skrip ... documentationDescription=Lihat dokumentasi +customEditorCommandInTerminal=Menjalankan perintah khusus di terminal +customEditorCommandInTerminalDescription=Jika editor Anda berbasis terminal, Anda dapat mengaktifkan opsi ini untuk secara otomatis membuka terminal dan menjalankan perintah dalam sesi terminal.\n\nAnda dapat menggunakan opsi ini untuk editor seperti vi, vim, nvim, dan lainnya. diff --git a/lang/strings/translations_it.properties b/lang/strings/translations_it.properties index 453c8b9c0..5add37f8d 100644 --- a/lang/strings/translations_it.properties +++ b/lang/strings/translations_it.properties @@ -1288,3 +1288,5 @@ externalLaunchTitle=Richiesta di lancio esterno externalLaunchContent=Un terminale esterno ha chiesto di lanciare una connessione shell. Vuoi consentire l'avvio di connessioni shell dall'esterno di XPipe? noScriptStateAvailable=Aggiorna per determinare la compatibilità dello script ... documentationDescription=Controlla la documentazione +customEditorCommandInTerminal=Eseguire un comando personalizzato in un terminale +customEditorCommandInTerminalDescription=Se il tuo editor è basato su un terminale, puoi attivare questa opzione per aprire automaticamente un terminale ed eseguire il comando nella sessione del terminale.\n\nPuoi utilizzare questa opzione per editor come vi, vim, nvim e altri. diff --git a/lang/strings/translations_ja.properties b/lang/strings/translations_ja.properties index a7a117f2a..5f7ae1046 100644 --- a/lang/strings/translations_ja.properties +++ b/lang/strings/translations_ja.properties @@ -1288,3 +1288,5 @@ externalLaunchTitle=外部起動要求 externalLaunchContent=外部端末がシェル接続の起動を要求してきた。XPipeの外部からのシェル接続の起動を許可するか。 noScriptStateAvailable=スクリプトの互換性を判断するためにリフレッシュする... documentationDescription=ドキュメントをチェックする +customEditorCommandInTerminal=ターミナルでカスタムコマンドを実行する +customEditorCommandInTerminalDescription=エディターがターミナルベースの場合、このオプションを有効にすると、自動的にターミナルが開き、代わりにターミナルセッションでコマンドが実行される。\n\nこのオプションは、vi、vim、nvimなどのエディタに使用できる。 diff --git a/lang/strings/translations_nl.properties b/lang/strings/translations_nl.properties index cba907a2d..f5ee505ae 100644 --- a/lang/strings/translations_nl.properties +++ b/lang/strings/translations_nl.properties @@ -1288,3 +1288,5 @@ externalLaunchTitle=Extern lanceringsverzoek externalLaunchContent=Een externe terminal heeft gevraagd om een shellverbinding te starten. Wil je het starten van shellverbindingen van buiten XPipe toestaan? noScriptStateAvailable=Vernieuwen om scriptcompatibiliteit te bepalen ... documentationDescription=Bekijk de documentatie +customEditorCommandInTerminal=Een aangepast commando uitvoeren in een terminal +customEditorCommandInTerminalDescription=Als je editor terminalgebaseerd is, kun je deze optie inschakelen om automatisch een terminal te openen en in plaats daarvan het commando in de terminalsessie uit te voeren.\n\nJe kunt deze optie gebruiken voor editors zoals vi, vim, nvim en andere. diff --git a/lang/strings/translations_pl.properties b/lang/strings/translations_pl.properties index f353a63b1..741f5a9e0 100644 --- a/lang/strings/translations_pl.properties +++ b/lang/strings/translations_pl.properties @@ -1288,3 +1288,5 @@ externalLaunchTitle=Żądanie uruchomienia zewnętrznego externalLaunchContent=Zewnętrzny terminal zażądał uruchomienia połączenia powłoki. Czy chcesz zezwolić na uruchamianie połączeń powłoki spoza XPipe? noScriptStateAvailable=Odśwież, aby określić zgodność skryptu ... documentationDescription=Sprawdź dokumentację +customEditorCommandInTerminal=Uruchom niestandardowe polecenie w terminalu +customEditorCommandInTerminalDescription=Jeśli twój edytor jest oparty na terminalu, możesz włączyć tę opcję, aby automatycznie otworzyć terminal i zamiast tego uruchomić polecenie w sesji terminala.\n\nMożesz użyć tej opcji dla edytorów takich jak vi, vim, nvim i innych. diff --git a/lang/strings/translations_pt.properties b/lang/strings/translations_pt.properties index 92fffb462..0b38825c4 100644 --- a/lang/strings/translations_pt.properties +++ b/lang/strings/translations_pt.properties @@ -1288,3 +1288,5 @@ externalLaunchTitle=Pedido de lançamento externo externalLaunchContent=Um terminal externo solicitou o lançamento de uma ligação shell. Pretendes permitir o lançamento de ligações shell a partir do exterior do XPipe? noScriptStateAvailable=Actualiza para determinar a compatibilidade do script ... documentationDescription=Verifica a documentação +customEditorCommandInTerminal=Executa um comando personalizado num terminal +customEditorCommandInTerminalDescription=Se o teu editor for baseado em terminal, podes ativar esta opção para abrir automaticamente um terminal e executar o comando na sessão do terminal.\n\nPodes utilizar esta opção para editores como o vi, vim, nvim e outros. diff --git a/lang/strings/translations_ru.properties b/lang/strings/translations_ru.properties index c1a8e6af3..7ed4d6f79 100644 --- a/lang/strings/translations_ru.properties +++ b/lang/strings/translations_ru.properties @@ -1288,3 +1288,5 @@ externalLaunchTitle=Запрос на внешний запуск externalLaunchContent=Внешний терминал запросил запуск shell-соединения. Хочешь ли ты разрешить запуск shell-соединений извне XPipe? noScriptStateAvailable=Обновите, чтобы определить совместимость скриптов ... documentationDescription=Ознакомьтесь с документацией +customEditorCommandInTerminal=Запуск пользовательской команды в терминале +customEditorCommandInTerminalDescription=Если твой редактор работает через терминал, ты можешь включить эту опцию, чтобы автоматически открыть терминал и вместо этого выполнить команду в терминальной сессии.\n\nЭту опцию можно использовать для таких редакторов, как vi, vim, nvim и других. diff --git a/lang/strings/translations_sv.properties b/lang/strings/translations_sv.properties index 34c96d35e..4e6d1f639 100644 --- a/lang/strings/translations_sv.properties +++ b/lang/strings/translations_sv.properties @@ -1288,3 +1288,5 @@ externalLaunchTitle=Begäran om extern lansering externalLaunchContent=En extern terminal har begärt att få starta en shell-anslutning. Vill du tillåta att shell-anslutningar startas från utanför XPipe? noScriptStateAvailable=Uppdatera för att fastställa skriptkompatibilitet ... documentationDescription=Kolla in dokumentationen +customEditorCommandInTerminal=Kör ett anpassat kommando i en terminal +customEditorCommandInTerminalDescription=Om din editor är terminalbaserad kan du aktivera det här alternativet för att automatiskt öppna en terminal och köra kommandot i terminalsessionen istället.\n\nDu kan använda det här alternativet för editorer som vi, vim, nvim och andra. diff --git a/lang/strings/translations_tr.properties b/lang/strings/translations_tr.properties index 4a2e370ed..6a652548a 100644 --- a/lang/strings/translations_tr.properties +++ b/lang/strings/translations_tr.properties @@ -1288,3 +1288,5 @@ externalLaunchTitle=Harici fırlatma talebi externalLaunchContent=Harici bir terminal bir kabuk bağlantısı başlatmak istedi. XPipe dışından kabuk bağlantılarının başlatılmasına izin vermek istiyor musunuz? noScriptStateAvailable=Komut dosyası uyumluluğunu belirlemek için yenileyin ... documentationDescription=Belgelere göz atın +customEditorCommandInTerminal=Terminalde özel komut çalıştırma +customEditorCommandInTerminalDescription=Düzenleyiciniz terminal tabanlı ise, otomatik olarak bir terminal açmak ve bunun yerine komutu terminal oturumunda çalıştırmak için bu seçeneği etkinleştirebilirsiniz.\n\nBu seçeneği vi, vim, nvim ve diğerleri gibi editörler için kullanabilirsiniz. diff --git a/lang/strings/translations_zh.properties b/lang/strings/translations_zh.properties index 09f4b7f83..2559359ca 100644 --- a/lang/strings/translations_zh.properties +++ b/lang/strings/translations_zh.properties @@ -150,7 +150,6 @@ errorDetails=显示详细信息 updateReadyAlertTitle=更新就绪 updateReadyAlertHeader=$VERSION$ 版本的更新已准备就绪,可以安装 #custom -#custom updateReadyAlertContent=此操作将安装新版本,并在安装完成后重启 XPipe。 #custom errorNoDetail=没有错误详细信息 @@ -1470,7 +1469,6 @@ tailscaleId=设备 ID tailscaleIdDescription=内部 Tailscale 设备 ID tailscaleHostName=主机名 #custom -#custom tailscaleHostNameDescription=Tailnet 设备的主机名 tailscaleUsername=用户名 tailscaleUsernameDescription=登录用户 @@ -1516,3 +1514,5 @@ externalLaunchContent=外部终端尝试启动 Shell 连接。是否允许 XPipe #custom noScriptStateAvailable=请刷新以检查脚本兼容性... documentationDescription=查看文档 +customEditorCommandInTerminal=在终端中运行自定义命令 +customEditorCommandInTerminalDescription=如果编辑器是基于终端的,可以启用此选项自动打开终端,并在终端会话中运行命令。\n\nvi、vim、nvim 等编辑器都可以使用该选项。