misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux
Rust bittorrent-clientdebriddownload-acceleratordownload-managerdownloadmanagereguifile-downloadergallery-dlidmidm-alternativeinternet-download-managerm3u8-downloadermagnetplaylist-downloaderreal-debridrusttorrent-clientvideo-downloaderyoutube-downloaderyt-dlp
Progress window: long names stay inside the Save to row (#62) (#90)
Ahmed Nefzaouiaa3e59066659
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c5d61093..b5ac70db 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -147,6 +147,11 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see### Fixed+- **A long file name ran out of the progress window** ([#62](https://github.com/anefzaoui/misterdownloadmanager/issues/62)):+ on the **Options on completion** tab, a longer translation of "Save To:" (Turkish, German…)+ ran into the path, and the path ran past the window's edge. The label now takes the room its+ language needs, and the path is shortened in the middle, keeping the file's name in sight,+ and shown whole on hover; right-to-left languages included.- **Download complete's Open with... stayed in English** in every other language([#80](https://github.com/anefzaoui/misterdownloadmanager/issues/80)). The tool that collectsMDM's texts for translation now also finds labels given through a window's own helpers, anddiff --git a/ROADMAP.md b/ROADMAP.mdindex d213065f..55aa8046 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -35,6 +35,8 @@ Everything below ships together, in one release.([#28](https://github.com/anefzaoui/misterdownloadmanager/issues/28))- ✅ No crash when a window opens while MDM is minimized([#22](https://github.com/anefzaoui/misterdownloadmanager/issues/22))+- ✅ Long file names stay inside the progress window: the Save to path is shortened in the+ middle, in every language ([#62](https://github.com/anefzaoui/misterdownloadmanager/issues/62))- ✅ Every button translated: Download complete's Open with... no longer stays in English([#80](https://github.com/anefzaoui/misterdownloadmanager/issues/80))- ✅ A smaller download ([#25](https://github.com/anefzaoui/misterdownloadmanager/issues/25)),@@ -60,7 +62,6 @@ Everything below ships together, in one release.- 🔍 A freeze of the window on start ([#57](https://github.com/anefzaoui/misterdownloadmanager/issues/57)):most likely a computer busy just after start; freeze reports now measure it, so the next one says-- 🔍 A long video title overflows the window ([#62](https://github.com/anefzaoui/misterdownloadmanager/issues/62))- 🔍 A crash on Linux as Download File Info opens([#48](https://github.com/anefzaoui/misterdownloadmanager/issues/48)), likely fixed with #22- 🔍 Linux display issues ([#29](https://github.com/anefzaoui/misterdownloadmanager/issues/29))diff --git a/crates/app/src/progress.rs b/crates/app/src/progress.rsindex 3ce3f1f7..ca285f40 100644--- a/crates/app/src/progress.rs+++ b/crates/app/src/progress.rs@@ -57,9 +57,20 @@ enum Tab {}impl Progress {- /// Open on a torrent's details tab by its English name in lower case ("peers"; /show- /// progress:peers); any other name leaves it as it is.+ /// Open on a tab by its English name in lower case: a top tab ("status", "limit", "done") or+ /// a torrent's details tab ("peers"; /show progress:peers, for the docs' screenshots and the+ /// fit audit); any other name leaves it as it is.pub fn show_tab(&mut self, name: &str) {+ let top = match name {+ "status" => Some(Tab::Status),+ "limit" => Some(Tab::Limiter),+ "done" => Some(Tab::Completion),+ _ => None,+ };+ if let Some(t) = top {+ self.tab = t;+ return;+ }let tab = match name {"files" => TTab::Files,"peers" => TTab::Peers,@@ -499,19 +510,29 @@ impl Progress {/// Returns true when "Hide tab" is pressed.fn completion_page(&mut self, ui: &mut Ui, o: Pos2, item: &Item) -> bool {let p = ui.painter().clone();- text(+ // The label as wide as its language makes it (half the row at most), then the path to+ // the row's end, shortened in the middle so the file's name stays in sight (#62).+ let (left, right) = (o.x + 33.0, o.x + 33.0 + 474.0);+ let label = winui::fit(+ ui,&p,- o.x + 33.0,+ left,o.y + 45.0,crate::i18n::t("Save To:"),winui::TEXT(),+ left + 237.0,+ "save-to-label",);- text(+ winui::fit_middle(+ ui,&p,- o.x + 90.0,+ // From the label's width: its rect is mirrored in a right-to-left interface.+ (left + label.width() + 6.0).max(o.x + 90.0),o.y + 45.0,&display_path(&item.dest),winui::TEXT(),+ right,+ "save-to-path",);winui::checkbox(ui,diff --git a/crates/app/src/winui.rs b/crates/app/src/winui.rsindex dda73696..3680349a 100644--- a/crates/app/src/winui.rs+++ b/crates/app/src/winui.rs@@ -482,6 +482,33 @@ pub fn ellipsize(p: &Painter, font: &FontId, s: &str, max: f32) -> String {cut(lo)}+/// `s` cut with "..." in the middle to fit `max` px (Windows' DT_PATH_ELLIPSIS): for a path or+/// an address, whose start (the folder) and end (the file's name) both matter. The end keeps+/// three parts in five of what fits.+pub fn ellipsize_middle(p: &Painter, font: &FontId, s: &str, max: f32) -> String {+ if text_width_font(p, font.clone(), s) <= max {+ return s.to_owned();+ }+ let chars: Vec<char> = s.chars().collect();+ let cut = |n: usize| {+ let head = n * 2 / 5;+ let tail = n - head;+ chars[..head].iter().collect::<String>()+ + "..."+ + &chars[chars.len() - tail..].iter().collect::<String>()+ };+ let (mut lo, mut hi) = (0, chars.len());+ while lo < hi {+ let mid = (lo + hi).div_ceil(2);+ if text_width_font(p, font.clone(), &cut(mid)) <= max {+ lo = mid;+ } else {+ hi = mid - 1;+ }+ }+ cut(lo)+}+/// [`text`] that never runs past `right`: cut with "..." when too long. Returns the drawn/// rect and whether the text was cut (then show it whole with [`full_on_hover`]).pub fn text_fit(@@ -1290,6 +1317,27 @@ pub fn fit(rect}+/// [`fit`] for a path or an address: shortened in the middle ([`ellipsize_middle`]) so the+/// file's name stays in sight, shown whole on hover when cut.+#[allow(clippy::too_many_arguments)]+pub fn fit_middle(+ ui: &Ui,+ p: &Painter,+ x: f32,+ baseline: f32,+ s: &str,+ color: Color32,+ right: f32,+ salt: impl std::hash::Hash + std::fmt::Debug,+) -> Rect {+ let shown = ellipsize_middle(p, &tahoma(), s, (right - x).max(0.0));+ let rect = text(p, x, baseline, &shown, color);+ if shown != s {+ full_on_hover(ui, rect, salt, s);+ }+ rect+}+/// Text already drawn in `rect` that the user may want to copy (an address, a hash, a path, a/// version): its right-click menu copies it whole ([`copy_menu`]), and it shows whole on hover/// when `cut`. Taken by the pointer only (labels are no Tab stops).@@ -4119,6 +4167,28 @@ pub fn icon_button_light(ui: &mut Ui, rc: Rect, id: &str, enabled: bool, tip: &smod tests {use super::*;+ #[test]+ fn a_path_is_shortened_in_the_middle_and_keeps_its_file_name() {+ let ctx = egui::Context::default();+ let font = FontId::proportional(11.0);+ let path = r"C:\Users\Someone\Downloads\Video\Ştirile PRO TV - 4 Noiembrie 2026 _ Cutremur politic după alegerile din Statele Unite.mp4";+ let mut out = ctx.run_ui(egui::RawInput::default(), |ui| {+ let p = ui.painter();+ let width = |s: &str| text_width_font(p, font.clone(), s);+ // Fits: as it is.+ assert_eq!(ellipsize_middle(p, &font, "C:\\a.mp4", 400.0), "C:\\a.mp4");+ for max in [120.0, 200.0, 300.0] {+ let s = ellipsize_middle(p, &font, path, max);+ assert!(width(&s) <= max, "{s} is wider than {max}");+ assert!(s.starts_with("C:\\") && s.ends_with(".mp4"), "{s}");+ assert!(s.contains("..."), "{s}");+ }+ // Nothing fits but the dots: no panic, the dots alone.+ assert_eq!(ellipsize_middle(p, &font, path, 1.0), "...");+ });+ out.textures_delta.clear();+ }+#[test]fn a_control_greyed_with_the_keys_hands_them_on() {let ctx = egui::Context::default();