filedialog: add open mode (no overwrite prompt) and use it for 'o'
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 <noreply@anthropic.com>
This commit is contained in:
@@ -54,11 +54,13 @@ void Tui::OpenFileDialog(std::string title,
|
||||
std::string persist_key,
|
||||
std::string default_filename,
|
||||
std::vector<FilenameFilter> filters,
|
||||
std::function<void(const std::string &)> on_confirm) {
|
||||
std::function<void(const std::string &)> 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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -149,6 +149,7 @@ private:
|
||||
std::vector<std::string> filter_labels; ///< parallel to `filters`
|
||||
int filter_idx = 0;
|
||||
std::function<void(const std::string &)> 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<FilenameFilter> filters,
|
||||
std::function<void(const std::string &)> on_confirm);
|
||||
std::function<void(const std::string &)> on_confirm,
|
||||
bool confirm_overwrite = true);
|
||||
void ConfirmFileDialog();
|
||||
ftxui::Component BuildSignalTypeModal();
|
||||
ftxui::Component BuildPaletteModal();
|
||||
|
||||
Reference in New Issue
Block a user