From d8f5a9379dc13dafdcc638482abedb2771454388 Mon Sep 17 00:00:00 2001 From: Oliver Hagmann <268387159+ohagmann@users.noreply.github.com> Date: Tue, 24 Nov 2026 20:04:13 +0100 Subject: [PATCH 1/2] Blocks palette: open a library drawing, and come back on the tab and folder left The Libraries tab lists a folder's drawings, but a drawing could only be inserted: someone who keeps template drawings in a library still needed a file manager beside it to open one. Now: - Right-click a library drawing, or a whole drawing on the Recent or Favorites tab, and choose Open Drawing: it opens in its own tab the way a drawing dropped on the window opens (a tab already showing it comes to the front). - The palette remembers the tab it was left on and the library folder the Libraries tab showed, across sessions (block_palette_tab, block_library_folder in the settings). The folder is used when it still exists; BLOCKNAVIGATE, when it names a folder, still comes first. The new menu text is in every language. Wiki page BLOCKPALETTE updated. Tests (app::update::block_palette_library_tests): the menu opens the drawing; only drawings offer Open Drawing; tab and sub-folder come back in the next session, a folder that is gone falls back to the library root; tab indices round-trip. --- docs/wiki/commands/BLOCKPALETTE.md | 8 +- locales/ar-SA/opencadstudio.ftl | 1 + locales/bg-BG/opencadstudio.ftl | 1 + locales/cs-CZ/opencadstudio.ftl | 1 + locales/de-DE/opencadstudio.ftl | 1 + locales/el-GR/opencadstudio.ftl | 1 + locales/en-US/opencadstudio.ftl | 1 + locales/es-ES/opencadstudio.ftl | 1 + locales/fi-FI/opencadstudio.ftl | 1 + locales/fr-FR/opencadstudio.ftl | 1 + locales/hi-IN/opencadstudio.ftl | 1 + locales/hu-HU/opencadstudio.ftl | 1 + locales/it-IT/opencadstudio.ftl | 1 + locales/ja-JP/opencadstudio.ftl | 1 + locales/ko-KR/opencadstudio.ftl | 1 + locales/lo-LA/opencadstudio.ftl | 1 + locales/nl-NL/opencadstudio.ftl | 1 + locales/pl-PL/opencadstudio.ftl | 1 + locales/pt-BR/opencadstudio.ftl | 1 + locales/ru-RU/opencadstudio.ftl | 1 + locales/tr-TR/opencadstudio.ftl | 1 + locales/uz-UZ/opencadstudio.ftl | 1 + locales/vi-VN/opencadstudio.ftl | 1 + locales/zh-CN/opencadstudio.ftl | 1 + locales/zh-TW/opencadstudio.ftl | 1 + src/app/settings.rs | 10 ++ src/app/update/block_palette_library_tests.rs | 120 ++++++++++++++++++ src/app/update/blocks_palette.rs | 15 ++- src/app/update/file/settings.rs | 13 ++ src/app/update/mod.rs | 2 + src/locale_catalog.rs | 1 + src/ui/window/block_palette.rs | 33 +++++ 32 files changed, 222 insertions(+), 4 deletions(-) create mode 100644 src/app/update/block_palette_library_tests.rs diff --git a/docs/wiki/commands/BLOCKPALETTE.md b/docs/wiki/commands/BLOCKPALETTE.md index 8abb16c9eb..1e2979df8b 100644 --- a/docs/wiki/commands/BLOCKPALETTE.md +++ b/docs/wiki/commands/BLOCKPALETTE.md @@ -6,12 +6,13 @@ web: The Libraries tab cannot browse for a folder in the web app. --- ## Usage -1. Run the command. The Blocks palette opens on the tab you used last. +1. Run the command. The Blocks palette opens on the tab you used last, also after a restart. 2. Choose a tab: - **Current Drawing**: the blocks defined in this drawing. - **Recent**: blocks you inserted recently. - **Favorites**: blocks you added to your favorites. - - **Libraries**: drawings and blocks from a library folder you choose. + - **Libraries**: drawings and blocks from a library folder you choose. Click a sub-folder to open it, **Up** to go + back. The tab opens again in the folder it showed last, unless `BLOCKNAVIGATE` names a folder. 3. Type in the filter box to narrow the list. The wildcards `*` and `?` work. 4. Set the insertion options, then click a block to insert it. @@ -25,7 +26,8 @@ web: The Libraries tab cannot browse for a folder in the web app. | **Explode** | Inserts the block as separate objects instead of a block reference. | ## Notes -- Right-click a block for more actions: **Insert**, **Redefine**, **Add to Favorites** or **Remove from Favorites**, **Edit Block** and **Remove Block** (or **Remove from List** on the Recent and Favorites tabs). +- Right-click a block for more actions: **Insert**, **Open Drawing** (a library drawing, or a whole drawing on the + Recent or Favorites tab, opens in its own tab for editing), **Show Blocks** (a library drawing), **Redefine**, **Add to Favorites** or **Remove from Favorites**, **Edit Block** and **Remove Block** (or **Remove from List** on the Recent and Favorites tabs). - The view can show the blocks as icons in several sizes, as a list or with details. - You can also drag a block into the drawing. It is placed where you drop it, with the typed scale and rotation. - The palette can also insert a whole DWG or DXF file as a block. diff --git a/locales/ar-SA/opencadstudio.ftl b/locales/ar-SA/opencadstudio.ftl index ae55940b4b..16cf82303f 100644 --- a/locales/ar-SA/opencadstudio.ftl +++ b/locales/ar-SA/opencadstudio.ftl @@ -4911,6 +4911,7 @@ insert = .bp-select-library-drawing = Select a Drawing to List Its Blocks .bp-open-library-drawing = Open a drawing's blocks... .bp-show-blocks = Show Blocks + .bp-open-drawing = فتح الرسم .bp-view-small = Small Icons .bp-on-screen = specified on screen .bp-block-not-found = Block "__ocs_fmt_0__" not found. diff --git a/locales/bg-BG/opencadstudio.ftl b/locales/bg-BG/opencadstudio.ftl index 63c6fcb367..670c1eb8c1 100644 --- a/locales/bg-BG/opencadstudio.ftl +++ b/locales/bg-BG/opencadstudio.ftl @@ -4898,6 +4898,7 @@ insert = .bp-select-library-drawing = Select a Drawing to List Its Blocks .bp-open-library-drawing = Open a drawing's blocks... .bp-show-blocks = Show Blocks + .bp-open-drawing = Отваряне на чертежа .bp-view-small = Small Icons .bp-on-screen = specified on screen .bp-block-not-found = Block "__ocs_fmt_0__" not found. diff --git a/locales/cs-CZ/opencadstudio.ftl b/locales/cs-CZ/opencadstudio.ftl index 7d02523a54..726174214c 100644 --- a/locales/cs-CZ/opencadstudio.ftl +++ b/locales/cs-CZ/opencadstudio.ftl @@ -4901,6 +4901,7 @@ insert = .bp-select-library-drawing = Select a Drawing to List Its Blocks .bp-open-library-drawing = Open a drawing's blocks... .bp-show-blocks = Show Blocks + .bp-open-drawing = Otevřít výkres .bp-view-small = Malé ikony .bp-on-screen = určeno na obrazovce .bp-block-not-found = Blok „__ocs_fmt_0__“ nebyl nalezen. diff --git a/locales/de-DE/opencadstudio.ftl b/locales/de-DE/opencadstudio.ftl index fe8946bcc1..8ff20d20f8 100644 --- a/locales/de-DE/opencadstudio.ftl +++ b/locales/de-DE/opencadstudio.ftl @@ -4897,6 +4897,7 @@ insert = .bp-select-library-drawing = Select a Drawing to List Its Blocks .bp-open-library-drawing = Open a drawing's blocks... .bp-show-blocks = Show Blocks + .bp-open-drawing = Zeichnung öffnen .bp-view-small = Small Icons .bp-on-screen = specified on screen .bp-block-not-found = Block "__ocs_fmt_0__" not found. diff --git a/locales/el-GR/opencadstudio.ftl b/locales/el-GR/opencadstudio.ftl index f034a2e1f3..74768562b2 100644 --- a/locales/el-GR/opencadstudio.ftl +++ b/locales/el-GR/opencadstudio.ftl @@ -4899,6 +4899,7 @@ insert = .bp-select-library-drawing = Select a Drawing to List Its Blocks .bp-open-library-drawing = Open a drawing's blocks... .bp-show-blocks = Show Blocks + .bp-open-drawing = Άνοιγμα σχεδίου .bp-view-small = Small Icons .bp-on-screen = specified on screen .bp-block-not-found = Block "__ocs_fmt_0__" not found. diff --git a/locales/en-US/opencadstudio.ftl b/locales/en-US/opencadstudio.ftl index 578956fb61..b3a553a333 100644 --- a/locales/en-US/opencadstudio.ftl +++ b/locales/en-US/opencadstudio.ftl @@ -4900,6 +4900,7 @@ insert = .bp-select-library-drawing = Select a Drawing to List Its Blocks .bp-open-library-drawing = Open a drawing's blocks... .bp-show-blocks = Show Blocks + .bp-open-drawing = Open Drawing .bp-view-small = Small Icons .bp-on-screen = specified on screen .bp-block-not-found = Block "__ocs_fmt_0__" not found. diff --git a/locales/es-ES/opencadstudio.ftl b/locales/es-ES/opencadstudio.ftl index 8df2ed994f..ffd348c7b4 100644 --- a/locales/es-ES/opencadstudio.ftl +++ b/locales/es-ES/opencadstudio.ftl @@ -4899,6 +4899,7 @@ insert = .bp-select-library-drawing = Select a Drawing to List Its Blocks .bp-open-library-drawing = Open a drawing's blocks... .bp-show-blocks = Show Blocks + .bp-open-drawing = Abrir dibujo .bp-view-small = Small Icons .bp-on-screen = specified on screen .bp-block-not-found = Block "__ocs_fmt_0__" not found. diff --git a/locales/fi-FI/opencadstudio.ftl b/locales/fi-FI/opencadstudio.ftl index 34ce7128e2..1985319cfa 100644 --- a/locales/fi-FI/opencadstudio.ftl +++ b/locales/fi-FI/opencadstudio.ftl @@ -4898,6 +4898,7 @@ insert = .bp-select-library-drawing = Select a Drawing to List Its Blocks .bp-open-library-drawing = Open a drawing's blocks... .bp-show-blocks = Show Blocks + .bp-open-drawing = Avaa piirustus .bp-view-small = Small Icons .bp-on-screen = specified on screen .bp-block-not-found = Block "__ocs_fmt_0__" not found. diff --git a/locales/fr-FR/opencadstudio.ftl b/locales/fr-FR/opencadstudio.ftl index e2c3ad09d0..4190fb6d4d 100644 --- a/locales/fr-FR/opencadstudio.ftl +++ b/locales/fr-FR/opencadstudio.ftl @@ -4899,6 +4899,7 @@ insert = .bp-select-library-drawing = Sélectionner un dessin pour lister ses blocs .bp-open-library-drawing = Ouvrir les blocs d'un dessin... .bp-show-blocks = Afficher les blocs + .bp-open-drawing = Ouvrir le dessin .bp-view-small = Petites icônes .bp-on-screen = spécifier à l'écran .bp-block-not-found = Bloc "__ocs_fmt_0__" introuvable. diff --git a/locales/hi-IN/opencadstudio.ftl b/locales/hi-IN/opencadstudio.ftl index db0ad7a065..70ee2e2c00 100644 --- a/locales/hi-IN/opencadstudio.ftl +++ b/locales/hi-IN/opencadstudio.ftl @@ -4887,6 +4887,7 @@ insert = .bp-select-library-drawing = Select a Drawing to List Its Blocks .bp-open-library-drawing = Open a drawing's blocks... .bp-show-blocks = Show Blocks + .bp-open-drawing = ड्रॉइंग खोलें .bp-view-small = Small Icons .bp-on-screen = specified on screen .bp-block-not-found = Block "__ocs_fmt_0__" not found. diff --git a/locales/hu-HU/opencadstudio.ftl b/locales/hu-HU/opencadstudio.ftl index c954142dc5..018ebdf478 100644 --- a/locales/hu-HU/opencadstudio.ftl +++ b/locales/hu-HU/opencadstudio.ftl @@ -4889,6 +4889,7 @@ insert = .bp-select-library-drawing = Select a Drawing to List Its Blocks .bp-open-library-drawing = Open a drawing's blocks... .bp-show-blocks = Show Blocks + .bp-open-drawing = Rajz megnyitása .bp-view-small = Kis ikonok .bp-on-screen = képernyőn megadva .bp-block-not-found = A(z) „__ocs_fmt_0__” blokk nem található. diff --git a/locales/it-IT/opencadstudio.ftl b/locales/it-IT/opencadstudio.ftl index ce225c1531..8a0d68eb96 100644 --- a/locales/it-IT/opencadstudio.ftl +++ b/locales/it-IT/opencadstudio.ftl @@ -4898,6 +4898,7 @@ insert = .bp-select-library-drawing = Select a Drawing to List Its Blocks .bp-open-library-drawing = Open a drawing's blocks... .bp-show-blocks = Show Blocks + .bp-open-drawing = Apri disegno .bp-view-small = Small Icons .bp-on-screen = specified on screen .bp-block-not-found = Block "__ocs_fmt_0__" not found. diff --git a/locales/ja-JP/opencadstudio.ftl b/locales/ja-JP/opencadstudio.ftl index 0ea9bfce3d..5fed099471 100644 --- a/locales/ja-JP/opencadstudio.ftl +++ b/locales/ja-JP/opencadstudio.ftl @@ -4887,6 +4887,7 @@ insert = .bp-select-library-drawing = Select a Drawing to List Its Blocks .bp-open-library-drawing = Open a drawing's blocks... .bp-show-blocks = Show Blocks + .bp-open-drawing = 図面を開く .bp-view-small = Small Icons .bp-on-screen = specified on screen .bp-block-not-found = Block "__ocs_fmt_0__" not found. diff --git a/locales/ko-KR/opencadstudio.ftl b/locales/ko-KR/opencadstudio.ftl index 48e39ef6a4..6dab785145 100644 --- a/locales/ko-KR/opencadstudio.ftl +++ b/locales/ko-KR/opencadstudio.ftl @@ -4898,6 +4898,7 @@ insert = .bp-select-library-drawing = Select a Drawing to List Its Blocks .bp-open-library-drawing = Open a drawing's blocks... .bp-show-blocks = Show Blocks + .bp-open-drawing = 도면 열기 .bp-view-small = Small Icons .bp-on-screen = specified on screen .bp-block-not-found = Block "__ocs_fmt_0__" not found. diff --git a/locales/lo-LA/opencadstudio.ftl b/locales/lo-LA/opencadstudio.ftl index 4dd1ed49c3..a447521879 100644 --- a/locales/lo-LA/opencadstudio.ftl +++ b/locales/lo-LA/opencadstudio.ftl @@ -4900,6 +4900,7 @@ insert = .bp-select-library-drawing = Select a Drawing to List Its Blocks .bp-open-library-drawing = Open a drawing's blocks... .bp-show-blocks = Show Blocks + .bp-open-drawing = ເປີດແບບແຕ້ມ .bp-view-small = ໄອຄອນນ້ອຍ .bp-on-screen = ກໍານົດເທິງໜ້າຈໍ .bp-block-not-found = ບໍ່ພົບຊື່ບລັອກ "__ocs_fmt_0__". diff --git a/locales/nl-NL/opencadstudio.ftl b/locales/nl-NL/opencadstudio.ftl index d5e2d0de50..968955c666 100644 --- a/locales/nl-NL/opencadstudio.ftl +++ b/locales/nl-NL/opencadstudio.ftl @@ -4897,6 +4897,7 @@ insert = .bp-select-library-drawing = Select a Drawing to List Its Blocks .bp-open-library-drawing = Open a drawing's blocks... .bp-show-blocks = Show Blocks + .bp-open-drawing = Tekening openen .bp-view-small = Small Icons .bp-on-screen = specified on screen .bp-block-not-found = Block "__ocs_fmt_0__" not found. diff --git a/locales/pl-PL/opencadstudio.ftl b/locales/pl-PL/opencadstudio.ftl index 57c8ebdb8c..534f118ba1 100644 --- a/locales/pl-PL/opencadstudio.ftl +++ b/locales/pl-PL/opencadstudio.ftl @@ -4898,6 +4898,7 @@ insert = .bp-select-library-drawing = Select a Drawing to List Its Blocks .bp-open-library-drawing = Open a drawing's blocks... .bp-show-blocks = Show Blocks + .bp-open-drawing = Otwórz rysunek .bp-view-small = Small Icons .bp-on-screen = specified on screen .bp-block-not-found = Block "__ocs_fmt_0__" not found. diff --git a/locales/pt-BR/opencadstudio.ftl b/locales/pt-BR/opencadstudio.ftl index e22a7b471d..4545d723ae 100644 --- a/locales/pt-BR/opencadstudio.ftl +++ b/locales/pt-BR/opencadstudio.ftl @@ -4899,6 +4899,7 @@ insert = .bp-select-library-drawing = Select a Drawing to List Its Blocks .bp-open-library-drawing = Open a drawing's blocks... .bp-show-blocks = Show Blocks + .bp-open-drawing = Abrir desenho .bp-view-small = Small Icons .bp-on-screen = specified on screen .bp-block-not-found = Block "__ocs_fmt_0__" not found. diff --git a/locales/ru-RU/opencadstudio.ftl b/locales/ru-RU/opencadstudio.ftl index 15826bb97b..9497299179 100644 --- a/locales/ru-RU/opencadstudio.ftl +++ b/locales/ru-RU/opencadstudio.ftl @@ -4900,6 +4900,7 @@ insert = .bp-select-library-drawing = Select a Drawing to List Its Blocks .bp-open-library-drawing = Open a drawing's blocks... .bp-show-blocks = Show Blocks + .bp-open-drawing = Открыть чертёж .bp-view-small = Small Icons .bp-on-screen = specified on screen .bp-block-not-found = Block "__ocs_fmt_0__" not found. diff --git a/locales/tr-TR/opencadstudio.ftl b/locales/tr-TR/opencadstudio.ftl index c641afb589..32edd4bfde 100644 --- a/locales/tr-TR/opencadstudio.ftl +++ b/locales/tr-TR/opencadstudio.ftl @@ -4859,6 +4859,7 @@ insert = .bp-select-library-drawing = Bloklarını listelemek için bir çizim seçin .bp-open-library-drawing = Bir çizimin bloklarını aç... .bp-show-blocks = Blokları göster + .bp-open-drawing = Çizimi aç .bp-view-small = Küçük simgeler .bp-on-screen = ekranda belirtilir .bp-block-not-found = "__ocs_fmt_0__" bloğu bulunamadı. diff --git a/locales/uz-UZ/opencadstudio.ftl b/locales/uz-UZ/opencadstudio.ftl index e28eb33300..142f2a987c 100644 --- a/locales/uz-UZ/opencadstudio.ftl +++ b/locales/uz-UZ/opencadstudio.ftl @@ -4900,6 +4900,7 @@ insert = .bp-select-library-drawing = Bloklarini körsatiş uçun çizmani tanlang .bp-open-library-drawing = Çizma bloklarini oçiş... .bp-show-blocks = Bloklarni körsatiş + .bp-open-drawing = Chizmani ochish .bp-view-small = Kiçik belgilar .bp-on-screen = ekranda belgilangan .bp-block-not-found = "__ocs_fmt_0__" bloki topilmadi. diff --git a/locales/vi-VN/opencadstudio.ftl b/locales/vi-VN/opencadstudio.ftl index df483ff9af..e7087d6df0 100644 --- a/locales/vi-VN/opencadstudio.ftl +++ b/locales/vi-VN/opencadstudio.ftl @@ -4906,6 +4906,7 @@ insert = .bp-select-library-drawing = Select a Drawing to List Its Blocks .bp-open-library-drawing = Open a drawing's blocks... .bp-show-blocks = Show Blocks + .bp-open-drawing = Mở bản vẽ .bp-view-small = Biểu tượng nhỏ .bp-on-screen = được chỉ định trên màn hình .bp-block-not-found = Không tìm thấy khối "__ocs_fmt_0__". diff --git a/locales/zh-CN/opencadstudio.ftl b/locales/zh-CN/opencadstudio.ftl index 153a2d3cf8..d5bb78d495 100644 --- a/locales/zh-CN/opencadstudio.ftl +++ b/locales/zh-CN/opencadstudio.ftl @@ -4882,6 +4882,7 @@ insert = .bp-select-library-drawing = Select a Drawing to List Its Blocks .bp-open-library-drawing = Open a drawing's blocks... .bp-show-blocks = Show Blocks + .bp-open-drawing = 打开图形 .bp-view-small = Small Icons .bp-on-screen = specified on screen .bp-block-not-found = Block "__ocs_fmt_0__" not found. diff --git a/locales/zh-TW/opencadstudio.ftl b/locales/zh-TW/opencadstudio.ftl index b688b83780..12f61f8733 100644 --- a/locales/zh-TW/opencadstudio.ftl +++ b/locales/zh-TW/opencadstudio.ftl @@ -4894,6 +4894,7 @@ insert = .bp-select-library-drawing = 選取要列出其圖塊的圖面 .bp-open-library-drawing = 開啟圖面的圖塊... .bp-show-blocks = 顯示圖塊 + .bp-open-drawing = 開啟圖面 .bp-view-small = 小型圖示 .bp-on-screen = 在畫面上指定 .bp-block-not-found = 找不到圖塊 “__ocs_fmt_0__”。 diff --git a/src/app/settings.rs b/src/app/settings.rs index 29c1b3b45f..a4e1a558fe 100644 --- a/src/app/settings.rs +++ b/src/app/settings.rs @@ -1273,6 +1273,14 @@ pub struct UserSettings { /// 4 details, 5 list. #[serde(default = "default_block_view")] pub block_palette_view: u8, + /// Blocks palette: the tab it was left on (0 Current Drawing, 1 Recent, + /// 2 Favorites, 3 Libraries). + #[serde(default)] + pub block_palette_tab: u8, + /// Blocks palette: the library folder the Libraries tab showed last; it + /// opens there again unless BLOCKNAVIGATE names a folder. + #[serde(default)] + pub block_library_folder: String, /// Blocks palette insertion options. #[serde(default)] pub block_insert: BlockInsertOptions, @@ -1681,6 +1689,8 @@ impl Default for UserSettings { block_favorites: Vec::new(), block_libraries: Vec::new(), block_palette_view: 1, + block_palette_tab: 0, + block_library_folder: String::new(), block_insert: BlockInsertOptions::default(), block_mru_list: 50, block_redefine_mode: 1, diff --git a/src/app/update/block_palette_library_tests.rs b/src/app/update/block_palette_library_tests.rs new file mode 100644 index 0000000000..0f4a8eb1bb --- /dev/null +++ b/src/app/update/block_palette_library_tests.rs @@ -0,0 +1,120 @@ +//! The Blocks palette's Libraries tab as a drawing browser: a library drawing +//! opens from the context menu, and the palette comes back on the tab and in +//! the folder it was left on. + +use std::path::PathBuf; + +use crate::app::settings::PaletteBlockRef; +use crate::app::{Message, OpenCADStudio}; +use crate::ui::window::block_palette::{BlockPaletteMsg, Item, MenuAction, Tab}; + +fn library(name: &str) -> PathBuf { + let root = std::env::temp_dir().join(format!("ocs-bp-library-{name}-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&root); + std::fs::create_dir_all(root.join("Pfeile")).unwrap(); + std::fs::write(root.join("Pfeile/Pfeil.dwg"), b"x").unwrap(); + root +} + +fn send(app: &mut OpenCADStudio, msg: BlockPaletteMsg) { + let _ = app.update_root(Message::BlockPalette(msg)); +} + +#[test] +fn a_library_drawing_opens_from_the_context_menu() { + let root = library("open"); + let drawing = root.join("Pfeile/Pfeil.dwg"); + let mut app = OpenCADStudio::new_for_test(); + send( + &mut app, + BlockPaletteMsg::Menu(Item::File(drawing.clone()), MenuAction::OpenDrawing), + ); + assert_eq!( + app.opening.as_ref().and_then(|o| o.source_path.clone()), + Some(drawing.clone()), + "the drawing is being opened" + ); + let _ = std::fs::remove_dir_all(&root); +} + +#[test] +fn only_drawings_offer_open_drawing() { + let whole = PaletteBlockRef { + name: "Pfeil".into(), + source: "/lib/Pfeil.dwg".into(), + time: 0, + drawing: true, + }; + let block = PaletteBlockRef { + drawing: false, + ..whole.clone() + }; + assert_eq!( + Item::File("/lib/Pfeil.dwg".into()).drawing(), + Some(PathBuf::from("/lib/Pfeil.dwg")) + ); + assert_eq!( + Item::Ref(whole).drawing(), + Some(PathBuf::from("/lib/Pfeil.dwg")) + ); + assert_eq!(Item::Ref(block).drawing(), None, "a block of a drawing"); + assert_eq!(Item::Current("Pfeil".into()).drawing(), None); + assert_eq!(Item::Folder("/lib".into()).drawing(), None); +} + +#[test] +fn the_palette_comes_back_on_its_tab_and_library_folder() { + let root = library("resume"); + let mut app = OpenCADStudio::new_for_test(); + send( + &mut app, + BlockPaletteMsg::LibrarySelect(root.display().to_string()), + ); + send(&mut app, BlockPaletteMsg::Tab(Tab::Libraries)); + let sub = Item::Folder(root.join("Pfeile")); + send(&mut app, BlockPaletteMsg::Press(sub.clone())); + send(&mut app, BlockPaletteMsg::Release(sub)); + assert_eq!(app.block_palette.library_dir, Some(root.join("Pfeile"))); + + let settings = app.current_settings(); + assert_eq!(settings.block_palette_tab, Tab::Libraries.index()); + assert_eq!( + settings.block_library_folder, + root.join("Pfeile").display().to_string() + ); + + // The next session opens on the Libraries tab, in that folder. + let mut next = OpenCADStudio::new_for_test(); + next.apply_settings(&settings); + assert_eq!(next.block_palette.tab, Tab::Libraries); + next.open_blocks_palette(None); + assert_eq!(next.block_palette.library_dir, Some(root.join("Pfeile"))); + assert!( + next.block_palette + .library_entries + .iter() + .any(|e| e.path == root.join("Pfeile/Pfeil.dwg")), + "the folder's drawings are listed" + ); + + // A folder that is gone falls back to the library root. + let mut gone = settings.clone(); + gone.block_library_folder = root.join("weg").display().to_string(); + let mut fallback = OpenCADStudio::new_for_test(); + fallback.apply_settings(&gone); + fallback.open_blocks_palette(None); + assert_eq!(fallback.block_palette.library_dir, Some(root.clone())); + let _ = std::fs::remove_dir_all(&root); +} + +#[test] +fn tabs_round_trip_through_their_settings_index() { + for tab in [Tab::Current, Tab::Recent, Tab::Favorites, Tab::Libraries] { + assert_eq!(Tab::from_u8(tab.index()), tab); + } + assert_eq!( + Tab::from_u8(9), + Tab::Current, + "an unknown index opens the first tab" + ); +} diff --git a/src/app/update/blocks_palette.rs b/src/app/update/blocks_palette.rs index dbbffbe972..6c85bfd786 100644 --- a/src/app/update/blocks_palette.rs +++ b/src/app/update/blocks_palette.rs @@ -93,7 +93,10 @@ impl OpenCADStudio { pub(super) fn on_block_palette(&mut self, m: BlockPaletteMsg) -> Task { match m { BlockPaletteMsg::Search(s) => self.block_palette.search = s, - BlockPaletteMsg::Tab(tab) => self.show_block_palette_tab(tab), + BlockPaletteMsg::Tab(tab) => { + self.show_block_palette_tab(tab); + self.persist_settings_if_changed(); + } BlockPaletteMsg::View(v) => { self.block_palette.view = v; self.persist_settings_if_changed(); @@ -218,6 +221,7 @@ impl OpenCADStudio { { let parent = parent.to_path_buf(); self.list_block_library(parent); + self.persist_settings_if_changed(); } } BlockPaletteMsg::Press(item) => self.block_palette.pressed = Some(item), @@ -226,6 +230,7 @@ impl OpenCADStudio { return match item { Item::Folder(dir) => { self.list_block_library(dir); + self.persist_settings_if_changed(); Task::none() } item => self.palette_insert(item, None), @@ -257,6 +262,7 @@ impl OpenCADStudio { let start = Some(self.block_navigate.trim()) .filter(|p| !p.is_empty() && *p != "." && Path::new(p).is_dir()) .map(PathBuf::from) + .or_else(|| self.block_palette.library_resume.take()) .or_else(|| self.block_palette.libraries.first().map(PathBuf::from)); if let Some(dir) = start { self.list_block_library(dir); @@ -611,6 +617,13 @@ impl OpenCADStudio { }; match action { MenuAction::Insert => return self.palette_insert(item, None), + // Opened as a drawing dropped on the window opens: a tab already + // showing it comes to the front. + MenuAction::OpenDrawing => { + if let Some(path) = item.drawing() { + return self.update(Message::FileDropped(path)); + } + } MenuAction::ShowBlocks => { if let Item::File(path) = item { self.list_block_library(path); diff --git a/src/app/update/file/settings.rs b/src/app/update/file/settings.rs index e06df5ef30..ac0f8bae9c 100644 --- a/src/app/update/file/settings.rs +++ b/src/app/update/file/settings.rs @@ -290,6 +290,15 @@ impl OpenCADStudio { block_favorites: self.block_palette.favorites.clone(), block_libraries: self.block_palette.libraries.clone(), block_palette_view: self.block_palette.view as u8, + block_palette_tab: self.block_palette.tab.index(), + block_library_folder: self + .block_palette + .library_dir + .as_ref() + .filter(|dir| dir.is_dir()) + .or(self.block_palette.library_resume.as_ref()) + .map(|dir| dir.display().to_string()) + .unwrap_or_default(), block_insert: self.block_palette.options.clone(), block_mru_list: self.block_mru_list, block_redefine_mode: self.block_redefine_mode, @@ -596,6 +605,10 @@ impl OpenCADStudio { self.block_palette.libraries = s.block_libraries.clone(); self.block_palette.view = crate::ui::window::block_palette::ViewMode::from_u8(s.block_palette_view); + self.block_palette.tab = + crate::ui::window::block_palette::Tab::from_u8(s.block_palette_tab); + self.block_palette.library_resume = Some(std::path::PathBuf::from(&s.block_library_folder)) + .filter(|dir| !s.block_library_folder.is_empty() && dir.is_dir()); self.block_palette.set_options(s.block_insert.clone()); self.trim_recent_blocks(); // Push restored display defaults onto every drawing tab that exists now. diff --git a/src/app/update/mod.rs b/src/app/update/mod.rs index aeef9603fd..d07e7dfa08 100644 --- a/src/app/update/mod.rs +++ b/src/app/update/mod.rs @@ -154,6 +154,8 @@ fn reorder_insertion_index(from: usize, to: usize, after: bool, len: usize) -> O #[cfg(test)] mod block_ops_tests; +#[cfg(test)] +mod block_palette_library_tests; pub(super) mod blocks_palette; pub(in crate::app) mod command; pub(crate) mod context_menu; diff --git a/src/locale_catalog.rs b/src/locale_catalog.rs index 2304c60ade..8206f6c508 100644 --- a/src/locale_catalog.rs +++ b/src/locale_catalog.rs @@ -1374,6 +1374,7 @@ pub(super) fn message_attribute(source: &str) -> Option<(&'static str, &'static "Select a Drawing to List Its Blocks" => Some(("insert", "bp-select-library-drawing")), "Open a drawing's blocks..." => Some(("insert", "bp-open-library-drawing")), "Show Blocks" => Some(("insert", "bp-show-blocks")), + "Open Drawing" => Some(("insert", "bp-open-drawing")), "Small Icons" => Some(("insert", "bp-view-small")), "specified on screen" => Some(("insert", "bp-on-screen")), "Block \"{}\" not found." => Some(("insert", "bp-block-not-found")), diff --git a/src/ui/window/block_palette.rs b/src/ui/window/block_palette.rs index 7960cb6d06..615e7409b3 100644 --- a/src/ui/window/block_palette.rs +++ b/src/ui/window/block_palette.rs @@ -69,6 +69,17 @@ pub enum Tab { } impl Tab { + const ALL: [Tab; 4] = [Tab::Current, Tab::Recent, Tab::Favorites, Tab::Libraries]; + + /// The tab's place in the settings (0 Current Drawing … 3 Libraries). + pub fn index(self) -> u8 { + Self::ALL.iter().position(|t| *t == self).unwrap_or(0) as u8 + } + + pub fn from_u8(v: u8) -> Self { + Self::ALL.get(v as usize).copied().unwrap_or_default() + } + fn label(self) -> String { match self { Tab::Current => crate::t!("Current Drawing"), @@ -166,6 +177,16 @@ pub enum Item { } impl Item { + /// The drawing file the item stands for: a library drawing, or a recent + /// or favorite drawing inserted whole. + pub fn drawing(&self) -> Option { + match self { + Item::File(path) => Some(path.clone()), + Item::Ref(r) if r.drawing && !r.source.is_empty() => Some(PathBuf::from(&r.source)), + _ => None, + } + } + pub fn name(&self) -> String { match self { Item::Current(name) => name.clone(), @@ -206,6 +227,8 @@ pub enum MenuAction { Remove, /// List the blocks of a library drawing. ShowBlocks, + /// Open a library or recent drawing for editing. + OpenDrawing, } /// Every message the block palette emits. Wrapped in `Message::BlockPalette`. @@ -374,6 +397,9 @@ pub struct BlockPalette { pub libraries: Vec, /// The folder shown (a library root or one of its sub-folders). pub library_dir: Option, + /// The folder the Libraries tab showed in the last session, shown again + /// when the tab first opens. + pub library_resume: Option, pub library_entries: Vec, /// Thumbnails of drawings recent / favorite entries point at. pub file_thumbs: std::collections::HashMap>, @@ -850,6 +876,13 @@ fn item_menu(tab: Tab, item: Item, in_drawing: bool, external: bool) -> Element< MenuAction::Insert, !matches!(item, Item::Folder(_)), )]; + if item.drawing().is_some() { + rows.push(entry( + crate::t!("Open Drawing").into_owned(), + MenuAction::OpenDrawing, + true, + )); + } if show_blocks { rows.push(entry( crate::t!("Show Blocks").into_owned(), From 2030930797634af1d0d73e20f4b012a7a4521cdb Mon Sep 17 00:00:00 2001 From: Oliver Hagmann <268387159+ohagmann@users.noreply.github.com> Date: Tue, 24 Nov 2026 20:04:13 +0100 Subject: [PATCH 2/2] German: the Blocks palette's texts The palette's tabs, headings, options and messages were still in English in the German catalog. --- locales/de-DE/opencadstudio.ftl | 74 ++++++++++++++++----------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/locales/de-DE/opencadstudio.ftl b/locales/de-DE/opencadstudio.ftl index 8ff20d20f8..81d5a8f97d 100644 --- a/locales/de-DE/opencadstudio.ftl +++ b/locales/de-DE/opencadstudio.ftl @@ -4867,44 +4867,44 @@ insert = .pcs-positive = Requires a positive number. .pcs-positive-int = Requires a positive integer. .pcs-help = Traces the points on the kept side of a live section as lines. - .bp-add-favorite = Add to Favorites - .bp-annotative-dynamic = Annotative / Dynamic - .bp-auto-placement = Auto-Placement - .bp-gallery-libraries = Blocks from Libraries... - .bp-choose-library = Choose a library folder with … - .bp-tab-current = Current Drawing - .bp-heading-current = Current Drawing Blocks - .bp-view-xl = Extra Large Icons - .bp-heading-favorites = Favorite Blocks - .bp-gallery-favorites = Favorite Blocks... - .bp-tab-favorites = Favorites - .bp-filter = Filter... (* ? wildcards) - .bp-icon = Icon - .bp-insertion-point = Insertion Point - .bp-view-large = Large Icons - .bp-tab-libraries = Libraries - .bp-heading-libraries = Library Blocks - .bp-view-medium = Medium Icons - .bp-tab-recent = Recent - .bp-heading-recent = Recent Blocks - .bp-gallery-recent = Recent Blocks... - .bp-redefine = Redefine - .bp-remove-block = Remove Block - .bp-remove-favorite = Remove from Favorites - .bp-remove-list = Remove from List - .bp-repeat-placement = Repeat Placement - .bp-select-library = Select a Block Library Folder - .bp-select-library-drawing = Select a Drawing to List Its Blocks - .bp-open-library-drawing = Open a drawing's blocks... - .bp-show-blocks = Show Blocks + .bp-add-favorite = Zu Favoriten hinzufügen + .bp-annotative-dynamic = Beschriftung / Dynamisch + .bp-auto-placement = Automatisch platzieren + .bp-gallery-libraries = Blöcke aus Bibliotheken... + .bp-choose-library = Einen Bibliotheksordner wählen mit … + .bp-tab-current = Zeichnung + .bp-heading-current = Blöcke der aktuellen Zeichnung + .bp-view-xl = Extra große Symbole + .bp-heading-favorites = Favorisierte Blöcke + .bp-gallery-favorites = Favorisierte Blöcke... + .bp-tab-favorites = Favoriten + .bp-filter = Filter... (* ? Platzhalter) + .bp-icon = Symbol + .bp-insertion-point = Einfügepunkt + .bp-view-large = Große Symbole + .bp-tab-libraries = Bibliotheken + .bp-heading-libraries = Bibliotheksblöcke + .bp-view-medium = Mittelgroße Symbole + .bp-tab-recent = Zuletzt + .bp-heading-recent = Zuletzt verwendete Blöcke + .bp-gallery-recent = Zuletzt verwendete Blöcke... + .bp-redefine = Neu definieren + .bp-remove-block = Block entfernen + .bp-remove-favorite = Aus Favoriten entfernen + .bp-remove-list = Aus der Liste entfernen + .bp-repeat-placement = Platzierung wiederholen + .bp-select-library = Bibliotheksordner für Blöcke wählen + .bp-select-library-drawing = Zeichnung wählen, deren Blöcke angezeigt werden + .bp-open-library-drawing = Blöcke einer Zeichnung öffnen... + .bp-show-blocks = Blöcke anzeigen .bp-open-drawing = Zeichnung öffnen - .bp-view-small = Small Icons - .bp-on-screen = specified on screen - .bp-block-not-found = Block "__ocs_fmt_0__" not found. - .bp-block-redefined = Block "__ocs_fmt_0__" redefined. - .bp-block-no-reference = Block "__ocs_fmt_0__" has no reference in the drawing to edit. - .bp-block-referenced = Block "__ocs_fmt_0__" is referenced in the drawing and cannot be removed. - .bp-block-removed = Block "__ocs_fmt_0__" removed. + .bp-view-small = Kleine Symbole + .bp-on-screen = am Bildschirm bestimmen + .bp-block-not-found = Block "__ocs_fmt_0__" nicht gefunden. + .bp-block-redefined = Block "__ocs_fmt_0__" neu definiert. + .bp-block-no-reference = Block "__ocs_fmt_0__" hat in der Zeichnung keine Referenz zum Bearbeiten. + .bp-block-referenced = Block "__ocs_fmt_0__" wird in der Zeichnung verwendet und kann nicht entfernt werden. + .bp-block-removed = Block "__ocs_fmt_0__" entfernt. .attdef-on-screen = Specify on-screen .attdef-insertion-point = Insertion Point .attdef-insert-field = Insert field