Add download action

This commit is contained in:
crschnick 2024-11-18 12:29:54 +00:00
parent 3df5a1f697
commit 82e6b7a035
15 changed files with 84 additions and 2 deletions

View file

@ -48,8 +48,13 @@ public final class HumanReadableFormat {
bytes /= b; bytes /= b;
ci.next(); 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) { public static String date(LocalDateTime x) {

View file

@ -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<BrowserEntry> 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<BrowserEntry> 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<String> getName(BrowserFileSystemTabModel model, List<BrowserEntry> entries) {
return AppI18n.observable("download");
}
@Override
public boolean isApplicable(BrowserFileSystemTabModel model, List<BrowserEntry> entries) {
var transfer = model.getBrowserModel();
if (!(transfer instanceof BrowserFullSessionModel)) {
return false;
}
return true;
}
}

View file

@ -36,6 +36,7 @@ open module io.xpipe.ext.base {
requires atlantafx.base; requires atlantafx.base;
provides BrowserAction with provides BrowserAction with
DownloadAction,
RunScriptAction, RunScriptAction,
FollowLinkAction, FollowLinkAction,
BackAction, BackAction,

View file

@ -187,3 +187,4 @@ untarDirectory=Untar to $DIR$
unzipDirectory=Pak ud til $DIR$ unzipDirectory=Pak ud til $DIR$
unzipHere=Pak ud her unzipHere=Pak ud her
requiresRestart=Kræver en genstart for at kunne anvendes. requiresRestart=Kræver en genstart for at kunne anvendes.
download=Download

View file

@ -178,3 +178,4 @@ untarDirectory=Untar zu $DIR$
unzipDirectory=Entpacken nach $DIR$ unzipDirectory=Entpacken nach $DIR$
unzipHere=Hier entpacken unzipHere=Hier entpacken
requiresRestart=Erfordert einen Neustart zur Anwendung. requiresRestart=Erfordert einen Neustart zur Anwendung.
download=Herunterladen

View file

@ -177,4 +177,5 @@ untarDirectory=Untar to $DIR$
unzipDirectory=Unzip to $DIR$ unzipDirectory=Unzip to $DIR$
unzipHere=Unzip here unzipHere=Unzip here
requiresRestart=Requires a restart to apply. requiresRestart=Requires a restart to apply.
download=Download

View file

@ -176,3 +176,4 @@ untarDirectory=Untar a $DIR$
unzipDirectory=Descomprimir a $DIR$ unzipDirectory=Descomprimir a $DIR$
unzipHere=Descomprimir aquí unzipHere=Descomprimir aquí
requiresRestart=Requiere un reinicio para aplicarse. requiresRestart=Requiere un reinicio para aplicarse.
download=Descargar

View file

@ -176,3 +176,4 @@ untarDirectory=Untar to $DIR$
unzipDirectory=Décompresser pour $DIR$ unzipDirectory=Décompresser pour $DIR$
unzipHere=Décompresse ici unzipHere=Décompresse ici
requiresRestart=Nécessite un redémarrage pour s'appliquer. requiresRestart=Nécessite un redémarrage pour s'appliquer.
download=Télécharger

View file

@ -176,3 +176,4 @@ untarDirectory=Untar a $DIR$
unzipDirectory=Decomprimere in $DIR$ unzipDirectory=Decomprimere in $DIR$
unzipHere=Decomprimi qui unzipHere=Decomprimi qui
requiresRestart=Richiede un riavvio per essere applicato. requiresRestart=Richiede un riavvio per essere applicato.
download=Scarica

View file

@ -176,3 +176,4 @@ untarDirectory=未対応$DIR$
unzipDirectory=解凍先$DIR$ unzipDirectory=解凍先$DIR$
unzipHere=ここで解凍する unzipHere=ここで解凍する
requiresRestart=適用には再起動が必要である。 requiresRestart=適用には再起動が必要である。
download=ダウンロード

View file

@ -176,3 +176,4 @@ untarDirectory=Naar $DIR$
unzipDirectory=Uitpakken naar $DIR$ unzipDirectory=Uitpakken naar $DIR$
unzipHere=Hier uitpakken unzipHere=Hier uitpakken
requiresRestart=Vereist een herstart om toe te passen. requiresRestart=Vereist een herstart om toe te passen.
download=Downloaden

View file

@ -176,3 +176,4 @@ untarDirectory=Untar para $DIR$
unzipDirectory=Descompacta para $DIR$ unzipDirectory=Descompacta para $DIR$
unzipHere=Descompacta aqui unzipHere=Descompacta aqui
requiresRestart=Requer um reinício para ser aplicado. requiresRestart=Requer um reinício para ser aplicado.
download=Descarrega

View file

@ -176,3 +176,4 @@ untarDirectory=Унтар к $DIR$
unzipDirectory=Разархивировать в $DIR$ unzipDirectory=Разархивировать в $DIR$
unzipHere=Распакуйте здесь unzipHere=Распакуйте здесь
requiresRestart=Требует перезапуска для применения. requiresRestart=Требует перезапуска для применения.
download=Скачать

View file

@ -176,3 +176,4 @@ untarDirectory=Untar'a $DIR$
unzipDirectory=Açmak için $DIR$ unzipDirectory=Açmak için $DIR$
unzipHere=Buradan açın unzipHere=Buradan açın
requiresRestart=Uygulamak için yeniden başlatma gerekir. requiresRestart=Uygulamak için yeniden başlatma gerekir.
download=İndir

View file

@ -176,3 +176,4 @@ untarDirectory=到$DIR$
unzipDirectory=解压缩为$DIR$ unzipDirectory=解压缩为$DIR$
unzipHere=在此解压缩 unzipHere=在此解压缩
requiresRestart=需要重新启动才能应用。 requiresRestart=需要重新启动才能应用。
download=下载