diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-01-15 21:58:18 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-01-15 21:58:18 +0100 |
| commit | 511d1b7325f2f0a027ca72b5bc1fc3798abb8bbc (patch) | |
| tree | b45d4edafa42297dc691abe1a725e18bf53f359c /src | |
| parent | 023e5ad3d9e704fb63e43bb45a0f279c1fdc3a0f (diff) | |
Allow paste of 8-digit numbers as timecodes.
Diffstat (limited to 'src')
| -rw-r--r-- | src/wx/timecode.cc | 32 | ||||
| -rw-r--r-- | src/wx/timecode.h | 1 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/wx/timecode.cc b/src/wx/timecode.cc index 63c119a18..d4a8a5074 100644 --- a/src/wx/timecode.cc +++ b/src/wx/timecode.cc @@ -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 () { diff --git a/src/wx/timecode.h b/src/wx/timecode.h index ed78f9428..53cd93694 100644 --- a/src/wx/timecode.h +++ b/src/wx/timecode.h @@ -50,6 +50,7 @@ public: protected: void changed(wxCommandEvent& ev); + void paste(wxClipboardTextEvent& ev); void set_clicked (); virtual bool valid() const = 0; |
