From c70e767cf164028e072b5906ab173cee4a7c57a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Wed, 3 Jun 2026 18:52:53 +0200 Subject: [PATCH] filedialog: add open mode (no overwrite prompt) and use it for 'o' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The picker is built for saving, so it asks 'file exists — overwrite?' on confirm. That's wrong when opening a script (you want an existing file). Add a confirm_overwrite flag (default true; FileDialogState + OpenFileDialog param); ConfirmFileDialog only prompts when it's set. The dashboard 'o' shortcut now opens the dialog with confirm_overwrite=false. save/export keep the guard. Co-Authored-By: Claude Opus 4.8 --- src/tui/screen_filedialog.cpp | 6 ++++-- src/tui/tui.cpp | 3 ++- src/tui/tui.hpp | 6 +++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/tui/screen_filedialog.cpp b/src/tui/screen_filedialog.cpp index 8885f2e..57d91f7 100644 --- a/src/tui/screen_filedialog.cpp +++ b/src/tui/screen_filedialog.cpp @@ -54,11 +54,13 @@ void Tui::OpenFileDialog(std::string title, std::string persist_key, std::string default_filename, std::vector filters, - std::function on_confirm) { + std::function on_confirm, + bool confirm_overwrite) { file_dialog.title = std::move(title); file_dialog.persist_key = std::move(persist_key); file_dialog.on_confirm = std::move(on_confirm); file_dialog.filters = std::move(filters); + file_dialog.confirm_overwrite = confirm_overwrite; file_dialog.filter_labels.clear(); for (const auto &f : file_dialog.filters) file_dialog.filter_labels.push_back(f.label); @@ -122,7 +124,7 @@ void Tui::ConfirmFileDialog() { // Overwrite guard: if the file already exists, ask before letting // the action proceed. Esc / No cancels; Yes runs the action. std::error_code ec; - if (fs::exists(full, ec) && !ec) { + if (file_dialog.confirm_overwrite && fs::exists(full, ec) && !ec) { ShowConfirm("File '" + full.string() + "' already exists.\n" "Overwrite?", invoke); diff --git a/src/tui/tui.cpp b/src/tui/tui.cpp index 4fabcec..3de1a5b 100644 --- a/src/tui/tui.cpp +++ b/src/tui/tui.cpp @@ -106,7 +106,8 @@ void Tui::Run() { "dashboard.source", "", {}, [this](const std::string &path) { Dispatch("source " + path); - }); + }, + /*confirm_overwrite=*/false); // opening, not saving return true; } if (e == Event::Character("s")) { // save the system snapshot diff --git a/src/tui/tui.hpp b/src/tui/tui.hpp index 53abd45..63861a8 100644 --- a/src/tui/tui.hpp +++ b/src/tui/tui.hpp @@ -149,6 +149,7 @@ private: std::vector filter_labels; ///< parallel to `filters` int filter_idx = 0; std::function on_confirm; + bool confirm_overwrite = true; ///< false in "open" mode — skip the overwrite prompt. }; FileDialogState file_dialog; @@ -272,11 +273,14 @@ private: // dir + filename are stored (one tiny file per key under the user // data directory). `on_confirm` runs when the user presses Enter on // the action button — it receives the absolute path the user picked. + // `confirm_overwrite = false` puts the dialog in "open" mode: it skips the + // "file exists — overwrite?" prompt (you *want* an existing file to open). void OpenFileDialog(std::string title, std::string persist_key, std::string default_filename, std::vector filters, - std::function on_confirm); + std::function on_confirm, + bool confirm_overwrite = true); void ConfirmFileDialog(); ftxui::Component BuildSignalTypeModal(); ftxui::Component BuildPaletteModal();