From 82e6b7a035157dc9735eb3e8067220e2593cac34 Mon Sep 17 00:00:00 2001 From: crschnick Date: Mon, 18 Nov 2024 12:29:54 +0000 Subject: [PATCH] Add download action --- .../xpipe/app/util/HumanReadableFormat.java | 9 ++- .../ext/base/browser/DownloadAction.java | 64 +++++++++++++++++++ ext/base/src/main/java/module-info.java | 1 + 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 + 15 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 ext/base/src/main/java/io/xpipe/ext/base/browser/DownloadAction.java diff --git a/app/src/main/java/io/xpipe/app/util/HumanReadableFormat.java b/app/src/main/java/io/xpipe/app/util/HumanReadableFormat.java index c2be39371..85cdbd41c 100644 --- a/app/src/main/java/io/xpipe/app/util/HumanReadableFormat.java +++ b/app/src/main/java/io/xpipe/app/util/HumanReadableFormat.java @@ -48,8 +48,13 @@ public final class HumanReadableFormat { bytes /= b; ci.next(); } - var f = ci.getIndex() >= 2 ? "%.3f" : "%.0f"; - return String.format(f + " %cB", bytes / (double) b, ci.current()); + + var f = ci.getIndex() >= 2 ? "%.3f" : "%.1f"; + var r = String.format(f + " %cB", bytes / (double) b, ci.current()); + if (r.endsWith(".0")) { + r = r.substring(0, r.length() - 2); + } + return r; } public static String date(LocalDateTime x) { diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/DownloadAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/DownloadAction.java new file mode 100644 index 000000000..89273a9ec --- /dev/null +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/DownloadAction.java @@ -0,0 +1,64 @@ +package io.xpipe.ext.base.browser; + +import io.xpipe.app.browser.BrowserFullSessionModel; +import io.xpipe.app.browser.action.BrowserLeafAction; +import io.xpipe.app.browser.file.BrowserEntry; +import io.xpipe.app.browser.file.BrowserFileSystemTabModel; +import io.xpipe.app.core.AppI18n; +import io.xpipe.app.prefs.AppPrefs; +import io.xpipe.core.store.FileKind; +import javafx.beans.value.ObservableValue; +import javafx.scene.Node; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyCodeCombination; +import javafx.scene.input.KeyCombination; +import org.kordamp.ikonli.javafx.FontIcon; + +import java.util.Collections; +import java.util.List; + +public class DownloadAction implements BrowserLeafAction { + + @Override + public void execute(BrowserFileSystemTabModel model, List entries) { + var transfer = model.getBrowserModel(); + if (!(transfer instanceof BrowserFullSessionModel fullSessionModel)) { + return; + } + + fullSessionModel.getLocalTransfersStage().drop(model, entries); + } + + public String getId() { + return "download"; + } + + @Override + public Node getIcon(BrowserFileSystemTabModel model, List entries) { + return new FontIcon("mdi2d-download"); + } + + @Override + public Category getCategory() { + return Category.MUTATION; + } + + @Override + public KeyCombination getShortcut() { + return new KeyCodeCombination(KeyCode.D, KeyCombination.SHORTCUT_DOWN); + } + + @Override + public ObservableValue getName(BrowserFileSystemTabModel model, List entries) { + return AppI18n.observable("download"); + } + + @Override + public boolean isApplicable(BrowserFileSystemTabModel model, List entries) { + var transfer = model.getBrowserModel(); + if (!(transfer instanceof BrowserFullSessionModel)) { + return false; + } + return true; + } +} diff --git a/ext/base/src/main/java/module-info.java b/ext/base/src/main/java/module-info.java index 3fe581316..b569f4e81 100644 --- a/ext/base/src/main/java/module-info.java +++ b/ext/base/src/main/java/module-info.java @@ -36,6 +36,7 @@ open module io.xpipe.ext.base { requires atlantafx.base; provides BrowserAction with + DownloadAction, RunScriptAction, FollowLinkAction, BackAction, diff --git a/lang/base/strings/translations_da.properties b/lang/base/strings/translations_da.properties index 3350129b5..1e7570319 100644 --- a/lang/base/strings/translations_da.properties +++ b/lang/base/strings/translations_da.properties @@ -187,3 +187,4 @@ untarDirectory=Untar to $DIR$ unzipDirectory=Pak ud til $DIR$ unzipHere=Pak ud her requiresRestart=Kræver en genstart for at kunne anvendes. +download=Download diff --git a/lang/base/strings/translations_de.properties b/lang/base/strings/translations_de.properties index f6139f1d7..71c193252 100644 --- a/lang/base/strings/translations_de.properties +++ b/lang/base/strings/translations_de.properties @@ -178,3 +178,4 @@ untarDirectory=Untar zu $DIR$ unzipDirectory=Entpacken nach $DIR$ unzipHere=Hier entpacken requiresRestart=Erfordert einen Neustart zur Anwendung. +download=Herunterladen diff --git a/lang/base/strings/translations_en.properties b/lang/base/strings/translations_en.properties index 934247690..67ea7479a 100644 --- a/lang/base/strings/translations_en.properties +++ b/lang/base/strings/translations_en.properties @@ -177,4 +177,5 @@ untarDirectory=Untar to $DIR$ unzipDirectory=Unzip to $DIR$ unzipHere=Unzip here requiresRestart=Requires a restart to apply. +download=Download diff --git a/lang/base/strings/translations_es.properties b/lang/base/strings/translations_es.properties index f14a60d88..67bcb6dbb 100644 --- a/lang/base/strings/translations_es.properties +++ b/lang/base/strings/translations_es.properties @@ -176,3 +176,4 @@ untarDirectory=Untar a $DIR$ unzipDirectory=Descomprimir a $DIR$ unzipHere=Descomprimir aquí requiresRestart=Requiere un reinicio para aplicarse. +download=Descargar diff --git a/lang/base/strings/translations_fr.properties b/lang/base/strings/translations_fr.properties index 57d1eee38..9edd4703d 100644 --- a/lang/base/strings/translations_fr.properties +++ b/lang/base/strings/translations_fr.properties @@ -176,3 +176,4 @@ untarDirectory=Untar to $DIR$ unzipDirectory=Décompresser pour $DIR$ unzipHere=Décompresse ici requiresRestart=Nécessite un redémarrage pour s'appliquer. +download=Télécharger diff --git a/lang/base/strings/translations_it.properties b/lang/base/strings/translations_it.properties index 473cf3e28..baedc0ad7 100644 --- a/lang/base/strings/translations_it.properties +++ b/lang/base/strings/translations_it.properties @@ -176,3 +176,4 @@ untarDirectory=Untar a $DIR$ unzipDirectory=Decomprimere in $DIR$ unzipHere=Decomprimi qui requiresRestart=Richiede un riavvio per essere applicato. +download=Scarica diff --git a/lang/base/strings/translations_ja.properties b/lang/base/strings/translations_ja.properties index d7a0be9a5..90663980c 100644 --- a/lang/base/strings/translations_ja.properties +++ b/lang/base/strings/translations_ja.properties @@ -176,3 +176,4 @@ untarDirectory=未対応$DIR$ unzipDirectory=解凍先$DIR$ unzipHere=ここで解凍する requiresRestart=適用には再起動が必要である。 +download=ダウンロード diff --git a/lang/base/strings/translations_nl.properties b/lang/base/strings/translations_nl.properties index c131bc643..aa18bcbb6 100644 --- a/lang/base/strings/translations_nl.properties +++ b/lang/base/strings/translations_nl.properties @@ -176,3 +176,4 @@ untarDirectory=Naar $DIR$ unzipDirectory=Uitpakken naar $DIR$ unzipHere=Hier uitpakken requiresRestart=Vereist een herstart om toe te passen. +download=Downloaden diff --git a/lang/base/strings/translations_pt.properties b/lang/base/strings/translations_pt.properties index 69f3e4918..c7bc9f2da 100644 --- a/lang/base/strings/translations_pt.properties +++ b/lang/base/strings/translations_pt.properties @@ -176,3 +176,4 @@ untarDirectory=Untar para $DIR$ unzipDirectory=Descompacta para $DIR$ unzipHere=Descompacta aqui requiresRestart=Requer um reinício para ser aplicado. +download=Descarrega diff --git a/lang/base/strings/translations_ru.properties b/lang/base/strings/translations_ru.properties index a6b217c6f..3c354757e 100644 --- a/lang/base/strings/translations_ru.properties +++ b/lang/base/strings/translations_ru.properties @@ -176,3 +176,4 @@ untarDirectory=Унтар к $DIR$ unzipDirectory=Разархивировать в $DIR$ unzipHere=Распакуйте здесь requiresRestart=Требует перезапуска для применения. +download=Скачать diff --git a/lang/base/strings/translations_tr.properties b/lang/base/strings/translations_tr.properties index 1fbb46403..e39e2a39b 100644 --- a/lang/base/strings/translations_tr.properties +++ b/lang/base/strings/translations_tr.properties @@ -176,3 +176,4 @@ untarDirectory=Untar'a $DIR$ unzipDirectory=Açmak için $DIR$ unzipHere=Buradan açın requiresRestart=Uygulamak için yeniden başlatma gerekir. +download=İndir diff --git a/lang/base/strings/translations_zh.properties b/lang/base/strings/translations_zh.properties index 28909226a..a0a1bf01c 100644 --- a/lang/base/strings/translations_zh.properties +++ b/lang/base/strings/translations_zh.properties @@ -176,3 +176,4 @@ untarDirectory=到$DIR$ unzipDirectory=解压缩为$DIR$ unzipHere=在此解压缩 requiresRestart=需要重新启动才能应用。 +download=下载