A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.
Rust archive-managerdesktop-appdual-paneexplorer-alternativefile-browserfile-explorerfile-managerfluent-designgpu-acceleratedgpuimacosmicaproductivityquick-lookrustrust-guitabswindowswindows-11windows-explorer
Convert: Shift+click on a format asks for the quality and the longest side first
gelenmedya467ae9d43dab
diff --git a/crates/rf-app/src/ctx_menu.rs b/crates/rf-app/src/ctx_menu.rsindex a1320fbd..2ad96393 100644--- a/crates/rf-app/src/ctx_menu.rs+++ b/crates/rf-app/src/ctx_menu.rs@@ -1198,15 +1198,81 @@ fn convert_targets(items: &[PathBuf]) -> Vec<rf_convert::PictureFormat> {rf_convert::picture_targets(exts.iter().map(String::as_str))}-/// The "Dönüştür" submenu: one row a target format. A click converts every selected picture, next to its original.+/// The "Dönüştür" submenu: one row a target format. A click converts every selected picture, next to its original, as the+/// options last chosen say; a click with Shift held asks for the options first (quality, size). The last row says so.fn convert_menu(items: &[PathBuf], targets: &[rf_convert::PictureFormat]) -> Vec<Item> {- targets+ let mut rows: Vec<Item> = targets.iter().map(|&format| {let items = items.to_vec();- Item::action(format.label(), icon(L::FileImage), move |_, cx| crate::status_center::convert_pictures(cx, items.clone(), format))+ Item::action(format.label(), icon(L::FileImage), move |window, cx| {+ if shift_down() {+ convert_options_dialog(items.clone(), format, window, cx);+ } else {+ crate::status_center::convert_pictures(cx, items.clone(), format, rf_convert::PictureOptions::default());+ }+ })})- .collect()+ .collect();+ rows.push(Item::Separator);+ rows.push(Item::action(t!("Shift+tık: seçenekler"), MenuIcon::None, |_, _| {}).enabled(false));+ rows+}++/// The qualities and the longest sides the options dialog offers.+const CONVERT_QUALITIES: [u8; 6] = [60, 75, 85, 90, 95, 100];+const CONVERT_SIDES: [u32; 5] = [4000, 2560, 1920, 1280, 800];++/// What the options dialog's two rows stand for: the quality at `quality` (the usual 90 when out of range) and the longest side at+/// `side` (0: the picture's own size).+fn convert_options(quality: usize, side: usize) -> rf_convert::PictureOptions {+ rf_convert::PictureOptions {+ quality: CONVERT_QUALITIES.get(quality).copied().unwrap_or(90),+ max_side: side.checked_sub(1).and_then(|i| CONVERT_SIDES.get(i)).copied(),+ ..Default::default()+ }+}++#[cfg(test)]+mod convert_tests {+ use super::convert_options;++ #[test]+ fn the_options_rows_stand_for_a_quality_and_a_longest_side() {+ let plain = convert_options(3, 0);+ assert_eq!((plain.quality, plain.max_side), (90, None), "the rows as the dialog opens: what a plain click does");+ assert_eq!(plain, rf_convert::PictureOptions::default());+ let small = convert_options(0, 3);+ assert_eq!((small.quality, small.max_side), (60, Some(1920)));+ assert_eq!(convert_options(5, 5).max_side, Some(800));+ // (a row out of range: the usual quality, the picture's own size)+ let odd = convert_options(99, 99);+ assert_eq!((odd.quality, odd.max_side), (90, None));+ }+}++/// Shift+click on a target of "Dönüştür": the quality (for a format that has one) and the longest side, then the conversion.+fn convert_options_dialog(items: Vec<PathBuf>, format: rf_convert::PictureFormat, window: &mut Window, cx: &mut App) {+ use crate::prompt::{Button, Choice, Kind};+ let quality = std::rc::Rc::new(std::cell::Cell::new(3usize));+ let side = std::rc::Rc::new(std::cell::Cell::new(0usize));+ let mut choices = Vec::new();+ if format.lossy() {+ choices.push(Choice { label: t!("Kalite").into(), options: CONVERT_QUALITIES.iter().map(|q| SharedString::from(q.to_string())).collect(), selected: quality.clone() });+ }+ choices.push(Choice {+ label: t!("En uzun kenar").into(),+ options: std::iter::once(SharedString::from(t!("Asıl boyut"))).chain(CONVERT_SIDES.iter().map(|s| SharedString::from(format!("{s} px")))).collect(),+ selected: side.clone(),+ });+ let title = t!("{format} biçimine dönüştür").replace("{format}", format.label());+ let message = format!("{}: {}", t!("Seçili"), crate::i18n::items(items.len()));+ let go = Button::new(t!("Dönüştür"), Kind::Primary, move |_, _, cx| {+ crate::status_center::convert_pictures(cx, items.clone(), format, convert_options(quality.get(), side.get()));+ Ok(())+ });+ let cancel = Button::new(t!("İptal"), Kind::Normal, |_, _, _| Ok(()));+ crate::prompt::show_with(title, Some(message), None, choices, vec![go, cancel], window, cx);}/// The "Sıkıştır" submenu for `items`: the archive dialog, then ZIP, 7z and (with WinRAR) RAR at once. Also the toolbar's Compressdiff --git a/crates/rf-app/src/i18n_en.rs b/crates/rf-app/src/i18n_en.rsindex 504e3d35..f6471ff5 100644--- a/crates/rf-app/src/i18n_en.rs+++ b/crates/rf-app/src/i18n_en.rs@@ -421,6 +421,12 @@ pub const EN: &[(&str, &str)] = &[("Sıkıştır", "Compress"),("Dönüştür", "Convert"),("Dönüştürülüyor:", "Converting:"),+ ("Shift+tık: seçenekler", "Shift+click: options"),+ ("{format} biçimine dönüştür", "Convert to {format}"),+ ("En uzun kenar", "Longest side"),+ ("Asıl boyut", "Original size"),+ ("Kalite", "Quality"),+ ("Seçili", "Selected"),("{n} dosya dönüştürülemedi. İlki: {name}: {why}", "{n} file(s) could not be converted. The first: {name}: {why}"),("Sırala", "Sort"),("Ada göre sırala, A'dan Z'ye", "Sort by name, A to Z"),diff --git a/crates/rf-app/src/status_center.rs b/crates/rf-app/src/status_center.rsindex 0f898a21..5d73acb6 100644--- a/crates/rf-app/src/status_center.rs+++ b/crates/rf-app/src/status_center.rs@@ -1469,11 +1469,11 @@ pub fn compress_level(cx: &mut App, sources: Vec<std::path::PathBuf>, dest: std:/// Pictures written in another format next to their originals (the converter). Nothing is replaced: a name that is taken gets a/// number. The files run a few at a time; one that cannot be read is named when the work ends, and the others are still made.-pub fn convert_pictures(cx: &mut App, sources: Vec<std::path::PathBuf>, format: rf_convert::PictureFormat) {+pub fn convert_pictures(cx: &mut App, sources: Vec<std::path::PathBuf>, format: rf_convert::PictureFormat, options: rf_convert::PictureOptions) {let title = format!("{} {} → {}", t!("Dönüştürülüyor:"), named(&sources), format.label());start(cx, title, move |t| {let progress = |done: u32, total: u32, name: &str| (t.on_progress)(total, done, Some(name.to_string()));- let outcomes = rf_win::convert::pictures(&sources, format, &rf_convert::PictureOptions::default(), &t.cancel, &progress);+ let outcomes = rf_win::convert::pictures(&sources, format, &options, &t.cancel, &progress);let failed: Vec<(String, String)> = outcomes.iter().filter_map(|o| o.result.as_ref().err().map(|e| (rf_core::history::display_name(&o.source), format!("{e:#}"))))