@@ -114,6 +114,57 @@ void ImageCompareWindow::button_output_browse()
114114 m_directory_browser_mode = directory_mode::output_mode;
115115};
116116
117+ void ImageCompareWindow::display_save_browser ()
118+ {
119+
120+ if (m_diff_results.empty ())
121+ {
122+ return ;
123+ }
124+ m_save_dialog.Display ();
125+
126+ if (!m_save_dialog.HasSelected ())
127+ {
128+ return ;
129+ }
130+ const auto save_path = m_save_dialog.GetSelected ();
131+ spdlog::info (" Saving compare diff toml to '{}'" , save_path.string ());
132+
133+ m_save_dialog.ClearSelected ();
134+ // Update save directory to the parent path of the saved file
135+ try
136+ {
137+ m_save_directory = save_path.parent_path ();
138+ }
139+ catch (const std::filesystem::filesystem_error &e)
140+ {
141+ spdlog::error (
142+ " {}:{} - Failed to get parent path of '{}', '{}'" , __FILE__,
143+ __LINE__, save_path, e.what ());
144+ }
145+ open_directory (m_save_directory);
146+
147+
148+ // Convert your diff results to TOML string/array
149+ toml::table entries{};
150+
151+ entries.insert_or_assign (" compare" , to_toml_array (m_diff_results));
152+
153+ // Choose a path — hardcoded or with a dialog
154+
155+ // Write the TOML to file
156+ std::ofstream ofs (save_path);
157+ if (!ofs)
158+ {
159+ spdlog::error (" Failed to open file for writing: {}" , save_path);
160+ }
161+ else
162+ {
163+ ofs << entries;
164+ spdlog::info (" Diff results written to {}" , save_path);
165+ }
166+ }
167+
117168void ImageCompareWindow::open_directory_browser ()
118169{
119170 m_directory_browser.Display ();
@@ -187,6 +238,7 @@ void ImageCompareWindow::render()
187238 return ;
188239 }
189240 open_directory_browser ();
241+ display_save_browser ();
190242
191243 const ImGuiStyle &style = ImGui::GetStyle ();
192244 const float spacing = style.ItemInnerSpacing .x ;
@@ -735,35 +787,11 @@ void ImageCompareWindow::export_button()
735787{
736788 if (ImGui::Button (" Export Diff Results" ))
737789 {
738- try
739- {
740- // Convert your diff results to TOML string/array
741- toml::table entries{};
742-
743- entries.insert_or_assign (
744- " compare" , to_toml_array (m_diff_results));
745-
746- // Choose a path — hardcoded or with a dialog
747- std::filesystem::path out_path = " diff_results.toml" ;
748-
749- // Write the TOML to file
750- std::ofstream ofs (out_path);
751- if (!ofs)
752- {
753- spdlog::error (
754- " Failed to open file for writing: {}" , out_path.string ());
755- }
756- else
757- {
758- ofs << entries;
759- spdlog::info (
760- " Diff results written to {}" , out_path.string ());
761- }
762- }
763- catch (const std::exception &e)
764- {
765- spdlog::error (" Error exporting diff results: {}" , e.what ());
766- }
790+ m_save_dialog.SetTitle (" Export Diff Results As..." );
791+ m_save_dialog.SetTypeFilters ({ " .toml" });
792+ m_save_dialog.SetDirectory (m_save_directory);
793+ m_save_dialog.SetInputName (" diff_results.toml" );
794+ m_save_dialog.Open ();
767795 }
768796}
769797
0 commit comments