Allow paste of 8-digit numbers as timecodes.
authorCarl Hetherington <cth@carlh.net>
Wed, 15 Jan 2025 20:58:18 +0000 (21:58 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 15 Jan 2025 20:58:18 +0000 (21:58 +0100)
src/wx/timecode.cc
src/wx/timecode.h

index 63c119a18c6625345aa0e81b1559495adda3ac0f..d4a8a507454fe85218e990e30c3111c4a83caf41 100644 (file)
@@ -23,6 +23,8 @@
 #include "timecode.h"
 #include "wx_util.h"
 #include "lib/util.h"
+#include <dcp/scope_guard.h>
+#include <wx/clipbrd.h>
 
 
 using std::string;
@@ -79,6 +81,7 @@ TimecodeBase::TimecodeBase (wxWindow* parent, bool set_button)
 
        for (auto control: _controls) {
                control->Bind(wxEVT_TEXT, boost::bind(&TimecodeBase::changed, this, _1));
+               control->Bind(wxEVT_TEXT_PASTE, boost::bind(&TimecodeBase::paste, this, _1));
        }
        if (_set_button) {
                _set_button->Bind (wxEVT_BUTTON, boost::bind (&TimecodeBase::set_clicked, this));
@@ -127,6 +130,35 @@ TimecodeBase::changed(wxCommandEvent& ev)
        }
 }
 
+
+void
+TimecodeBase::paste(wxClipboardTextEvent& ev)
+{
+       if (!wxTheClipboard->Open()) {
+               return;
+       }
+
+       dcp::ScopeGuard sg = []() {
+               wxTheClipboard->Close();
+       };
+
+       if (wxTheClipboard->IsSupported(wxDF_TEXT) || wxTheClipboard->IsSupported(wxDF_UNICODETEXT)) {
+               wxTextDataObject clipboard;
+               wxTheClipboard->GetData(clipboard);
+               auto contents = clipboard.GetText();
+               if (contents.Length() == 8 && contents.IsNumber()) {
+                       _hours->SetValue(contents.Mid(0, 2));
+                       _minutes->SetValue(contents.Mid(2, 2));
+                       _seconds->SetValue(contents.Mid(4, 2));
+                       _frames->SetValue(contents.Mid(6, 2));
+                       return;
+               }
+       }
+
+       ev.Skip();
+}
+
+
 void
 TimecodeBase::set_clicked ()
 {
index ed78f942833388d1032ed5bdbc11b20f39e6d076..53cd936942403e82bf1603e7a81f8dec3013d956 100644 (file)
@@ -50,6 +50,7 @@ public:
 
 protected:
        void changed(wxCommandEvent& ev);
+       void paste(wxClipboardTextEvent& ev);
        void set_clicked ();
        virtual bool valid() const = 0;