Extract common code out into kdm_for_screen()
[dcpomatic.git] / src / wx / i18n_hook.cc
index bb185526e8c0e99db25f12e73870de35842e0e77..b2cd6df8e7f5e1af60ff0179cb2673bac43422b1 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2018-2019 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 #include "lib/cross.h"
 #include <wx/wx.h>
 #include <boost/bind.hpp>
-#include <boost/filesystem.hpp>
 
-I18NHook::I18NHook (wxWindow* window)
+using std::map;
+using std::string;
+
+map<string, string> I18NHook::_translations;
+
+I18NHook::I18NHook (wxWindow* window, wxString original)
        : _window (window)
+       , _original (original)
 {
        _window->Bind (wxEVT_MIDDLE_DOWN, bind(&I18NHook::handle, this, _1));
 }
@@ -35,22 +40,20 @@ I18NHook::I18NHook (wxWindow* window)
 void
 I18NHook::handle (wxMouseEvent& ev)
 {
-       wxString const original = get_text ();
-
        InstantI18NDialog* d = new InstantI18NDialog (_window, get_text());
        d->ShowModal();
        set_text (d->get());
-       _window->GetContainingSizer()->Layout();
-       ev.Skip ();
+       d->Destroy ();
+
+       wxWindow* w = _window;
+       while (w) {
+               if (w->GetContainingSizer()) {
+                       w->GetContainingSizer()->Layout();
+               }
+               w = w->GetParent();
+       }
 
-       boost::filesystem::path file = "instant_i18n";
+       ev.Skip ();
 
-       FILE* f = fopen_boost (file, "a");
-       if (!f) {
-               error_dialog (_window, wxString::Format(_("Could not open translation file %s"), std_to_wx(file.string()).data()));
-               return;
-       }
-       fprintf (f, "%s\n", wx_to_std(original).c_str());
-       fprintf (f, "%s\n", wx_to_std(get_text()).c_str());
-       fclose (f);
+       _translations[wx_to_std(_original)] = wx_to_std(get_text());
 }