feat(transactions): export dialog — disabled-with-reason, no silent overwrite, folder link (F034/F073/F085)

UX audit, Export transactions dialog:

- F034: the Export button is disabled when the scope is stale/invalid or no rows
  match, with the reason spelled out inline next to the count (was: always enabled,
  reason only shown as a toast after clicking).
- F073: a persistent "Open folder" link (not only on the success screen), and an
  existing file is auto-suffixed (-2, -3, …) instead of being silently overwritten.
- F085: the error line uses the themed ErrorVec4() instead of a raw literal.

F096 (export shield legs as one merged row) deferred — needs a shared shield-merge
helper with the History list. Build + tests green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 15:04:00 -06:00
co-authored by Claude Opus 4.8
parent 6956710639
commit 12284d91b1
+24 -5
View File
@@ -22,6 +22,7 @@
#include <ctime>
#include <algorithm>
#include <cctype>
#include <filesystem>
namespace dragonx {
namespace ui {
@@ -158,6 +159,15 @@ void ExportTransactionsDialog::render(App* app)
ImGui::Spacing();
ImGui::Text(TR("export_tx_count"), scopeOk ? subsetIdx.size() : (size_t)0);
// Spell out why Export is unavailable, inline, instead of only reacting on click. (F034)
const bool canExport = scopeOk && !subsetIdx.empty();
if (!canExport) {
const char* why = !scopeOk ? (s_scope == 1 ? TR("export_tx_scope_stale") : TR("export_tx_range_invalid"))
: TR("export_tx_none");
ImGui::PushTextWrapPos(0.0f);
ImGui::TextColored(m::WarningVec4(), "%s", why);
ImGui::PopTextWrapPos();
}
ImGui::Spacing();
// Filename + save-location hint.
@@ -166,6 +176,9 @@ void ExportTransactionsDialog::render(App* app)
// Show the real, resolved config directory (the old hardcoded ~/.config path was wrong on Windows/macOS).
ImGui::TextColored(ImGui::ColorConvertU32ToFloat4(m::OnSurfaceDisabled()), "%s %s",
TR("file_save_location"), util::Platform::getConfigDir().c_str());
// Persistent "Open folder" — reachable before an export too, not only on the success screen. (F073)
if (m::TactileButton(TR("export_tx_open_folder"), ImVec2(0, 0)))
util::Platform::openFolder(util::Platform::getConfigDir());
// Result — success shows the saved path as a copy field; failure shows a red line.
if (!s_saved_path.empty()) {
@@ -176,19 +189,17 @@ void ExportTransactionsDialog::render(App* app)
ImGui::SameLine(0, 4.0f * Layout::dpiScale());
ImGui::TextColored(m::SuccessVec4(), "%s", TR("export_tx_success"));
widgets::AddressCopyField("##exportedpath", s_saved_path);
if (m::TactileButton(TR("export_tx_open_folder"), ImVec2(0, 0)))
util::Platform::openFolder(util::Platform::getConfigDir());
} else if (!s_error.empty()) {
ImGui::Spacing();
ImGui::PushTextWrapPos(0.0f);
ImGui::TextColored(ImVec4(0.8f, 0.3f, 0.3f, 1.0f), "%s", s_error.c_str());
ImGui::TextColored(m::ErrorVec4(), "%s", s_error.c_str()); // follow the active skin (F085)
ImGui::PopTextWrapPos();
}
ImGui::Spacing();
bool doExport = false, doClose = false;
m::DialogActionFooter(TR("export"), true, TR("close"), doExport, doClose);
m::DialogActionFooter(TR("export"), canExport, TR("close"), doExport, doClose);
if (doClose) s_open = false;
if (doExport) {
s_saved_path.clear();
@@ -203,8 +214,16 @@ void ExportTransactionsDialog::render(App* app)
// Sanitize in-buffer so the user sees exactly what was written (and we can't be pointed outside
// the config dir by a pasted path).
std::string safeName = util::sanitizeExportFilename(s_filename, ".csv", "dragonx_transactions.csv");
snprintf(s_filename, sizeof(s_filename), "%s", safeName.c_str());
std::string filepath = configDir + "/" + safeName;
// Don't silently overwrite an existing export — suffix the name (-2, -3, …). (F073)
if (std::filesystem::exists(filepath)) {
const std::string stem = safeName.substr(0, safeName.size() - 4); // strip ".csv"
for (int k = 2; k < 1000; ++k) {
std::string cand = stem + "-" + std::to_string(k) + ".csv";
if (!std::filesystem::exists(configDir + "/" + cand)) { safeName = cand; filepath = configDir + "/" + cand; break; }
}
}
snprintf(s_filename, sizeof(s_filename), "%s", safeName.c_str());
// Build the chosen subset (scope 0 exports the whole list with no copy), then write atomically
// (temp + fsync + rename) so a disk-full failure is reported instead of a truncated CSV.
std::string csv;