From 1c6a1c1b11bee3e607945d7796a3be5d924e1a8f Mon Sep 17 00:00:00 2001 From: Darby Johnston Date: Fri, 29 Nov 2024 16:43:34 -0800 Subject: [PATCH 1/2] Add settings Signed-off-by: Darby Johnston --- cmake/SuperBuild/Builddtk-deps.cmake | 2 +- cmake/SuperBuild/Builddtk.cmake | 2 +- lib/toucan/FFmpegRead.cpp | 2 +- lib/toucanView/App.cpp | 22 ++++--- lib/toucanView/App.h | 1 + lib/toucanView/DocumentsModel.cpp | 10 +++- lib/toucanView/DocumentsModel.h | 30 ++++++++++ lib/toucanView/ExportTool.cpp | 10 +++- lib/toucanView/MenuBar.cpp | 30 +++++++++- lib/toucanView/MenuBar.h | 4 ++ lib/toucanView/TimeUnitsModel.cpp | 87 +++++++++++++++++++++------- lib/toucanView/TimeUnitsModel.h | 26 +++++++-- lib/toucanView/TimeWidgets.cpp | 6 +- lib/toucanView/TimelineItem.cpp | 6 +- 14 files changed, 191 insertions(+), 47 deletions(-) diff --git a/cmake/SuperBuild/Builddtk-deps.cmake b/cmake/SuperBuild/Builddtk-deps.cmake index 865df89..a9d454f 100644 --- a/cmake/SuperBuild/Builddtk-deps.cmake +++ b/cmake/SuperBuild/Builddtk-deps.cmake @@ -1,7 +1,7 @@ include(ExternalProject) set(dtk_GIT_REPOSITORY "https://github.com/darbyjohnston/dtk.git") -set(dtk_GIT_TAG "fe317ed208c6befeeb832fd9e8c6cce18575f9cb") +set(dtk_GIT_TAG "3f569280b3ea1c9cf37241f80be7847b6105d12c") set(dtk-deps_ARGS ${toucan_EXTERNAL_PROJECT_ARGS} diff --git a/cmake/SuperBuild/Builddtk.cmake b/cmake/SuperBuild/Builddtk.cmake index 556a538..ae2a82c 100644 --- a/cmake/SuperBuild/Builddtk.cmake +++ b/cmake/SuperBuild/Builddtk.cmake @@ -1,7 +1,7 @@ include(ExternalProject) set(dtk_GIT_REPOSITORY "https://github.com/darbyjohnston/dtk.git") -set(dtk_GIT_TAG "fe317ed208c6befeeb832fd9e8c6cce18575f9cb") +set(dtk_GIT_TAG "3f569280b3ea1c9cf37241f80be7847b6105d12c") set(dtk_DEPS dtk-deps) set(dtk_ARGS diff --git a/lib/toucan/FFmpegRead.cpp b/lib/toucan/FFmpegRead.cpp index e9dae4b..b368bd2 100644 --- a/lib/toucan/FFmpegRead.cpp +++ b/lib/toucan/FFmpegRead.cpp @@ -116,7 +116,7 @@ namespace toucan !_avFormatContext ? fileName.c_str() : nullptr, nullptr, nullptr); - if (r < 0) + if (r < 0 || !_avFormatContext) { throw std::runtime_error("Cannot open file"); } diff --git a/lib/toucanView/App.cpp b/lib/toucanView/App.cpp index 8ba79b4..330d01b 100644 --- a/lib/toucanView/App.cpp +++ b/lib/toucanView/App.cpp @@ -11,15 +11,22 @@ #include #include #include +#include #include +#include + namespace toucan { void App::_init( const std::shared_ptr& context, std::vector& argv) { + _messageLog = std::make_shared(); + + _settings = dtk::Settings::create(dtk::getSettingsPath("toucan", "toucan-view.settings")); + dtk::App::_init( context, argv, @@ -31,13 +38,11 @@ namespace toucan "input", "Input timeline.", true) - }); - - context->getSystem()->setNativeFileDialog(false); - - _messageLog = std::make_shared(); + }, + {}, + _settings); - _timeUnitsModel = std::make_shared(); + _timeUnitsModel = std::make_shared(_settings); std::vector searchPath; const std::filesystem::path parentPath = std::filesystem::path(argv[0]).parent_path(); @@ -51,7 +56,10 @@ namespace toucan //hostOptions.log = _messageLog; _host = std::make_shared(searchPath, hostOptions); - _documentsModel = std::make_shared(context, _host); + auto fileBrowserSystem = context->getSystem(); + fileBrowserSystem->setNativeFileDialog(false); + + _documentsModel = std::make_shared(context, _settings, _host); _windowModel = std::make_shared(); diff --git a/lib/toucanView/App.h b/lib/toucanView/App.h index 3899e1b..ddb3707 100644 --- a/lib/toucanView/App.h +++ b/lib/toucanView/App.h @@ -35,6 +35,7 @@ namespace toucan private: std::shared_ptr _messageLog; + std::shared_ptr _settings; std::string _path; std::shared_ptr _timeUnitsModel; std::shared_ptr _host; diff --git a/lib/toucanView/DocumentsModel.cpp b/lib/toucanView/DocumentsModel.cpp index 0dae5d2..28cf5cb 100644 --- a/lib/toucanView/DocumentsModel.cpp +++ b/lib/toucanView/DocumentsModel.cpp @@ -3,8 +3,6 @@ #include "DocumentsModel.h" -#include "PlaybackModel.h" - #include #include @@ -13,6 +11,7 @@ namespace toucan { DocumentsModel::DocumentsModel( const std::shared_ptr& context, + const std::shared_ptr& settings, const std::shared_ptr& host) : _context(context), _host(host) @@ -22,6 +21,7 @@ namespace toucan _remove = dtk::ObservableValue::create(-1); _current = dtk::ObservableValue< std::shared_ptr >::create(nullptr); _currentIndex = dtk::ObservableValue::create(-1); + _recentFilesModel = dtk::RecentFilesModel::create(context, settings); } DocumentsModel::~DocumentsModel() @@ -39,6 +39,7 @@ namespace toucan _add->setAlways(index); _current->setIfChanged(documents[index]); _currentIndex->setIfChanged(index); + _recentFilesModel->addRecent(path); } } @@ -137,4 +138,9 @@ namespace toucan setCurrentIndex(index); } } + + const std::shared_ptr& DocumentsModel::getRecentFilesModel() const + { + return _recentFilesModel; + } } diff --git a/lib/toucanView/DocumentsModel.h b/lib/toucanView/DocumentsModel.h index f072042..d694baf 100644 --- a/lib/toucanView/DocumentsModel.h +++ b/lib/toucanView/DocumentsModel.h @@ -5,6 +5,8 @@ #include "Document.h" +#include +#include #include #include #include @@ -14,29 +16,56 @@ namespace toucan class Document; class ImageEffectHost; + //! Documents model. class DocumentsModel : public std::enable_shared_from_this { public: DocumentsModel( const std::shared_ptr&, + const std::shared_ptr&, const std::shared_ptr&); virtual ~DocumentsModel(); + //! Open a document. void open(const std::filesystem::path&); + + //! Close the current document. void close(); + + //! Close a document. void close(int); + + //! Close all documents. void closeAll(); + //! Observe the documents. std::shared_ptr > > observeDocuments() const; + + //! Observe when a document is added. std::shared_ptr > observeAdd() const; + + //! Observe when a document is removed. std::shared_ptr > observeRemove() const; + + //! Observe the current document. std::shared_ptr > > observeCurrent() const; + + //! Observe the current document index. std::shared_ptr > observeCurrentIndex() const; + + //! Set the current document index. void setCurrentIndex(int); + + //! Go to the next document. void next(); + + //! Go to the previous document. void prev(); + //! Get the recent files model. + const std::shared_ptr& getRecentFilesModel() const; + private: std::weak_ptr _context; std::shared_ptr _host; @@ -45,6 +74,7 @@ namespace toucan std::shared_ptr > _remove; std::shared_ptr > > _current; std::shared_ptr > _currentIndex; + std::shared_ptr _recentFilesModel; }; } diff --git a/lib/toucanView/ExportTool.cpp b/lib/toucanView/ExportTool.cpp index eca44bb..ad70f0b 100644 --- a/lib/toucanView/ExportTool.cpp +++ b/lib/toucanView/ExportTool.cpp @@ -60,7 +60,10 @@ namespace toucan auto divider = dtk::Divider::create(context, dtk::Orientation::Vertical, _layout); - auto exportSequenceButton = dtk::PushButton::create(context, "Export Sequence", _layout); + auto exportSequenceButton = dtk::PushButton::create( + context, + "Export Sequence", + _layout); exportSequenceButton->setClickedCallback( [this] { @@ -68,7 +71,10 @@ namespace toucan _export(); }); - auto exportCurrentButton = dtk::PushButton::create(context, "Export Current Frame", _layout); + auto exportCurrentButton = dtk::PushButton::create( + context, + "Export Current Frame", + _layout); exportCurrentButton->setClickedCallback( [this] { diff --git a/lib/toucanView/MenuBar.cpp b/lib/toucanView/MenuBar.cpp index a83853d..e7103c1 100644 --- a/lib/toucanView/MenuBar.cpp +++ b/lib/toucanView/MenuBar.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include namespace toucan @@ -50,6 +51,7 @@ namespace toucan [this, i] { _documentsModel->setCurrentIndex(i); + _menus["File"]->close(); }); _menus["Files"]->addItem(item); _filesActions.push_back(item); @@ -78,6 +80,27 @@ namespace toucan _menus["Files"]->setItemChecked(_filesActions[i], i == index); } }); + + _recentFilesObserver = dtk::ListObserver::create( + _documentsModel->getRecentFilesModel()->observeRecent(), + [this](const std::vector& files) + { + _menus["RecentFiles"]->clear(); + _recentFilesActions.clear(); + for (auto i = files.rbegin(); i != files.rend(); ++i) + { + auto file = *i; + auto item = std::make_shared( + file.string(), + [this, file] + { + _documentsModel->open(file); + _menus["File"]->close(); + }); + _menus["RecentFiles"]->addItem(item); + _recentFilesActions.push_back(item); + } + }); } MenuBar::~MenuBar() @@ -140,7 +163,8 @@ namespace toucan context->getSystem()->message("ERROR", e.what(), getWindow()); } } - }); + }, + _documentsModel->getRecentFilesModel()); } } }); @@ -167,6 +191,10 @@ namespace toucan _menus["File"]->addDivider(); + _menus["RecentFiles"] = _menus["File"]->addSubMenu("RecentFiles"); + + _menus["File"]->addDivider(); + _menus["Files"] = _menus["File"]->addSubMenu("Files"); _actions["File/Next"] = std::make_shared( diff --git a/lib/toucanView/MenuBar.h b/lib/toucanView/MenuBar.h index 643322c..5d83277 100644 --- a/lib/toucanView/MenuBar.h +++ b/lib/toucanView/MenuBar.h @@ -10,6 +10,8 @@ #include #include +#include + namespace toucan { class App; @@ -72,10 +74,12 @@ namespace toucan std::map > _menus; std::map > _actions; std::vector > _filesActions; + std::vector > _recentFilesActions; std::shared_ptr > > _documentsObserver; std::shared_ptr > > _documentObserver; std::shared_ptr > _documentIndexObserver; + std::shared_ptr > _recentFilesObserver; std::shared_ptr > _playbackObserver; std::shared_ptr > _fullScreenObserver; std::shared_ptr > _controlsObserver; diff --git a/lib/toucanView/TimeUnitsModel.cpp b/lib/toucanView/TimeUnitsModel.cpp index db8a871..2b3f37e 100644 --- a/lib/toucanView/TimeUnitsModel.cpp +++ b/lib/toucanView/TimeUnitsModel.cpp @@ -3,17 +3,60 @@ #include "TimeUnitsModel.h" +#include + +#include #include namespace toucan { - TimeUnitsModel::TimeUnitsModel() + namespace { - _timeUnits = dtk::ObservableValue::create(TimeUnits::Timecode); + const std::array timeUnits = + { + "Timecode", + "Frames", + "Seconds" + }; + } + + std::string toString(TimeUnits value) + { + return timeUnits[static_cast(value)]; + } + + TimeUnits fromString(const std::string& value) + { + const auto i = std::find(timeUnits.begin(), timeUnits.end(), value); + return i != timeUnits.end() ? + static_cast(i - timeUnits.begin()) : + TimeUnits::Timecode; + } + + TimeUnitsModel::TimeUnitsModel(const std::shared_ptr& settings) + { + _settings = settings; + TimeUnits value = TimeUnits::Timecode; + try + { + const auto json = std::any_cast(_settings->get("TimeUnits")); + if (json.is_object()) + { + value = toucan::fromString(json["Units"]); + } + } + catch (const std::exception&) + {} + + _timeUnits = dtk::ObservableValue::create(value); } TimeUnitsModel::~TimeUnitsModel() - {} + { + nlohmann::json json; + json["Units"] = toucan::toString(_timeUnits->get()); + _settings->set("TimeUnits", json); + } TimeUnits TimeUnitsModel::getTimeUnits() const { @@ -30,48 +73,48 @@ namespace toucan _timeUnits->setIfChanged(value); } - OTIO_NS::RationalTime TimeUnitsModel::getTime(const std::string& text, double rate) const + std::string TimeUnitsModel::toString(const OTIO_NS::RationalTime& time) const { - OTIO_NS::RationalTime out; + std::string out; switch (_timeUnits->get()) { case TimeUnits::Timecode: - out = OTIO_NS::RationalTime::from_timecode(text, rate); + out = time.to_timecode(); break; case TimeUnits::Frames: - out = OTIO_NS::RationalTime::from_frames(std::atof(text.c_str()), rate); + { + std::stringstream ss; + ss << time.to_frames(); + out = ss.str(); break; + } case TimeUnits::Seconds: - out = OTIO_NS::RationalTime::from_seconds(std::atof(text.c_str()), rate); + { + std::stringstream ss; + ss.precision(2); + ss << std::fixed << time.to_seconds(); + out = ss.str(); break; + } default: break; } return out; } - std::string TimeUnitsModel::getLabel(const OTIO_NS::RationalTime& time) const + OTIO_NS::RationalTime TimeUnitsModel::fromString(const std::string& text, double rate) const { - std::string out; + OTIO_NS::RationalTime out; switch (_timeUnits->get()) { case TimeUnits::Timecode: - out = time.to_timecode(); + out = OTIO_NS::RationalTime::from_timecode(text, rate); break; case TimeUnits::Frames: - { - std::stringstream ss; - ss << time.to_frames(); - out = ss.str(); + out = OTIO_NS::RationalTime::from_frames(std::atof(text.c_str()), rate); break; - } case TimeUnits::Seconds: - { - std::stringstream ss; - ss.precision(2); - ss << std::fixed << time.to_seconds(); - out = ss.str(); + out = OTIO_NS::RationalTime::from_seconds(std::atof(text.c_str()), rate); break; - } default: break; } return out; diff --git a/lib/toucanView/TimeUnitsModel.h b/lib/toucanView/TimeUnitsModel.h index c472b22..4b82558 100644 --- a/lib/toucanView/TimeUnitsModel.h +++ b/lib/toucanView/TimeUnitsModel.h @@ -3,12 +3,14 @@ #pragma once +#include #include -#include +#include namespace toucan { + //! Time units. enum class TimeUnits { Timecode, @@ -16,21 +18,37 @@ namespace toucan Seconds }; + //! Convert to a string. + std::string toString(TimeUnits); + + //! Convert from a string. + TimeUnits fromString(const std::string&); + + //! Time units model. class TimeUnitsModel : public std::enable_shared_from_this { public: - TimeUnitsModel(); + TimeUnitsModel(const std::shared_ptr&); virtual ~TimeUnitsModel(); + //! Get the time units. TimeUnits getTimeUnits() const; + + //! Observe the time units. std::shared_ptr > observeTimeUnits() const; + + //! Set the time units. void setTimeUnits(TimeUnits); - OTIO_NS::RationalTime getTime(const std::string&, double rate) const; - std::string getLabel(const OTIO_NS::RationalTime&) const; + //! Convert a time to a string. + std::string toString(const OTIO_NS::RationalTime&) const; + + //! Convert a string to a time. + OTIO_NS::RationalTime fromString(const std::string&, double rate) const; private: + std::shared_ptr _settings; std::shared_ptr > _timeUnits; }; } diff --git a/lib/toucanView/TimeWidgets.cpp b/lib/toucanView/TimeWidgets.cpp index 98b1a39..10800b8 100644 --- a/lib/toucanView/TimeWidgets.cpp +++ b/lib/toucanView/TimeWidgets.cpp @@ -188,7 +188,7 @@ namespace toucan { if (_callback) { - _callback(_timeUnitsModel->getTime(text, _time.rate())); + _callback(_timeUnitsModel->fromString(text, _time.rate())); } }); @@ -302,7 +302,7 @@ namespace toucan void TimeEdit::_timeUpdate() { - _lineEdit->setText(_timeUnitsModel->getLabel(_time)); + _lineEdit->setText(_timeUnitsModel->toString(_time)); } void TimeEdit::_timeInc(int value) @@ -385,6 +385,6 @@ namespace toucan void TimeLabel::_timeUpdate() { - _label->setText(_timeUnitsModel->getLabel(_time)); + _label->setText(_timeUnitsModel->toString(_time)); } } diff --git a/lib/toucanView/TimelineItem.cpp b/lib/toucanView/TimelineItem.cpp index 34deac7..a7d411a 100644 --- a/lib/toucanView/TimelineItem.cpp +++ b/lib/toucanView/TimelineItem.cpp @@ -272,7 +272,7 @@ namespace toucan dtk::Box2I(pos, g.min.y + _size.scrollPos.y, _size.border * 2, g.h()), event.style->getColorRole(dtk::ColorRole::Red)); - std::string s = _timeUnitsModel->getLabel(_currentTime); + std::string s = _timeUnitsModel->toString(_currentTime); dtk::Size2I size = event.fontSystem->getSize(s, _size.fontInfo); dtk::Box2I g3( pos + _size.border * 2 + _size.margin, @@ -374,7 +374,7 @@ namespace toucan dtk::Size2I TimelineItem::_getLabelMaxSize( const std::shared_ptr& fontSystem) const { - const std::string labelMax = _timeUnitsModel->getLabel(_timeRange.duration()); + const std::string labelMax = _timeUnitsModel->toString(_timeRange.duration()); const dtk::Size2I labelMaxSize = fontSystem->getSize(labelMax, _size.fontInfo); return labelMaxSize; } @@ -537,7 +537,7 @@ namespace toucan _size.fontMetrics.lineHeight); if (time != _currentTime && intersects(box, drawRect)) { - const std::string label = _timeUnitsModel->getLabel(time); + const std::string label = _timeUnitsModel->toString(time); event.render->drawText( event.fontSystem->getGlyphs(label, _size.fontInfo), _size.fontMetrics, From 7d8dc45cb065c95bb5c6bf3450547c490d321aeb Mon Sep 17 00:00:00 2001 From: Darby Johnston Date: Fri, 29 Nov 2024 17:46:30 -0800 Subject: [PATCH 2/2] Refactoring Signed-off-by: Darby Johnston --- lib/toucanView/App.cpp | 10 +- lib/toucanView/App.h | 6 +- lib/toucanView/CMakeLists.txt | 12 +- lib/toucanView/DocumentsModel.cpp | 146 ----------- lib/toucanView/ExportTool.cpp | 24 +- lib/toucanView/ExportTool.h | 6 +- lib/toucanView/{Document.cpp => File.cpp} | 36 +-- lib/toucanView/{Document.h => File.h} | 6 +- .../{DocumentTab.cpp => FileTab.cpp} | 24 +- lib/toucanView/{DocumentTab.h => FileTab.h} | 14 +- lib/toucanView/FilesModel.cpp | 146 +++++++++++ .../{DocumentsModel.h => FilesModel.h} | 44 ++-- lib/toucanView/GraphTool.cpp | 20 +- lib/toucanView/GraphTool.h | 6 +- lib/toucanView/InfoBar.cpp | 30 +-- lib/toucanView/InfoBar.h | 4 +- lib/toucanView/JSONTool.cpp | 12 +- lib/toucanView/JSONTool.h | 6 +- lib/toucanView/MainWindow.cpp | 48 ++-- lib/toucanView/MainWindow.h | 12 +- lib/toucanView/MenuBar.cpp | 236 +++++++++--------- lib/toucanView/MenuBar.h | 14 +- lib/toucanView/PlaybackBar.cpp | 40 +-- lib/toucanView/PlaybackBar.h | 6 +- lib/toucanView/TimelineItem.cpp | 18 +- lib/toucanView/TimelineItem.h | 6 +- lib/toucanView/TimelineWidget.cpp | 24 +- lib/toucanView/TimelineWidget.h | 6 +- lib/toucanView/ToolBar.cpp | 36 +-- lib/toucanView/ToolBar.h | 10 +- lib/toucanView/Viewport.cpp | 12 +- lib/toucanView/Viewport.h | 6 +- 32 files changed, 514 insertions(+), 512 deletions(-) delete mode 100644 lib/toucanView/DocumentsModel.cpp rename lib/toucanView/{Document.cpp => File.cpp} (85%) rename lib/toucanView/{Document.h => File.h} (96%) rename lib/toucanView/{DocumentTab.cpp => FileTab.cpp} (54%) rename lib/toucanView/{DocumentTab.h => FileTab.h} (73%) create mode 100644 lib/toucanView/FilesModel.cpp rename lib/toucanView/{DocumentsModel.h => FilesModel.h} (57%) diff --git a/lib/toucanView/App.cpp b/lib/toucanView/App.cpp index 330d01b..dbfe84b 100644 --- a/lib/toucanView/App.cpp +++ b/lib/toucanView/App.cpp @@ -3,7 +3,7 @@ #include "App.h" -#include "DocumentsModel.h" +#include "FilesModel.h" #include "MainWindow.h" #include "TimeUnitsModel.h" #include "WindowModel.h" @@ -59,7 +59,7 @@ namespace toucan auto fileBrowserSystem = context->getSystem(); fileBrowserSystem->setNativeFileDialog(false); - _documentsModel = std::make_shared(context, _settings, _host); + _filesModel = std::make_shared(context, _settings, _host); _windowModel = std::make_shared(); @@ -74,7 +74,7 @@ namespace toucan { try { - _documentsModel->open(_path); + _filesModel->open(_path); } catch (const std::exception& e) { @@ -107,9 +107,9 @@ namespace toucan return _host; } - const std::shared_ptr& App::getDocumentsModel() const + const std::shared_ptr& App::getFilesModel() const { - return _documentsModel; + return _filesModel; } const std::shared_ptr& App::getWindowModel() const diff --git a/lib/toucanView/App.h b/lib/toucanView/App.h index ddb3707..a253ad9 100644 --- a/lib/toucanView/App.h +++ b/lib/toucanView/App.h @@ -7,7 +7,7 @@ namespace toucan { - class DocumentsModel; + class FilesModel; class ImageEffectHost; class MainWindow; class MessageLog; @@ -30,7 +30,7 @@ namespace toucan const std::shared_ptr& getTimeUnitsModel() const; const std::shared_ptr& getHost() const; - const std::shared_ptr& getDocumentsModel() const; + const std::shared_ptr& getFilesModel() const; const std::shared_ptr& getWindowModel() const; private: @@ -39,7 +39,7 @@ namespace toucan std::string _path; std::shared_ptr _timeUnitsModel; std::shared_ptr _host; - std::shared_ptr _documentsModel; + std::shared_ptr _filesModel; std::shared_ptr _windowModel; std::shared_ptr _window; }; diff --git a/lib/toucanView/CMakeLists.txt b/lib/toucanView/CMakeLists.txt index e8f49f8..df3a0fd 100644 --- a/lib/toucanView/CMakeLists.txt +++ b/lib/toucanView/CMakeLists.txt @@ -1,10 +1,10 @@ set(HEADERS App.h ClipItem.h - DocumentTab.h - Document.h - DocumentsModel.h ExportTool.h + FileTab.h + File.h + FilesModel.h GapItem.h GraphTool.h IItem.h @@ -31,10 +31,10 @@ set(HEADERS set(SOURCE App.cpp ClipItem.cpp - DocumentTab.cpp - Document.cpp - DocumentsModel.cpp ExportTool.cpp + FileTab.cpp + File.cpp + FilesModel.cpp GapItem.cpp GraphTool.cpp IItem.cpp diff --git a/lib/toucanView/DocumentsModel.cpp b/lib/toucanView/DocumentsModel.cpp deleted file mode 100644 index 28cf5cb..0000000 --- a/lib/toucanView/DocumentsModel.cpp +++ /dev/null @@ -1,146 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// Copyright Contributors to the toucan project. - -#include "DocumentsModel.h" - -#include - -#include - -namespace toucan -{ - DocumentsModel::DocumentsModel( - const std::shared_ptr& context, - const std::shared_ptr& settings, - const std::shared_ptr& host) : - _context(context), - _host(host) - { - _documents = dtk::ObservableList< std::shared_ptr >::create(); - _add = dtk::ObservableValue::create(-1); - _remove = dtk::ObservableValue::create(-1); - _current = dtk::ObservableValue< std::shared_ptr >::create(nullptr); - _currentIndex = dtk::ObservableValue::create(-1); - _recentFilesModel = dtk::RecentFilesModel::create(context, settings); - } - - DocumentsModel::~DocumentsModel() - {} - - void DocumentsModel::open(const std::filesystem::path& path) - { - if (auto context = _context.lock()) - { - auto documents = _documents->get(); - auto document = std::make_shared(context, _host, path); - documents.push_back(document); - _documents->setIfChanged(documents); - const int index = documents.size() - 1; - _add->setAlways(index); - _current->setIfChanged(documents[index]); - _currentIndex->setIfChanged(index); - _recentFilesModel->addRecent(path); - } - } - - void DocumentsModel::close() - { - close(_currentIndex->get()); - } - - void DocumentsModel::close(int index) - { - auto documents = _documents->get(); - if (index >= 0 && index < documents.size()) - { - auto document = *(documents.begin() + index); - documents.erase(documents.begin() + index); - _remove->setAlways(index); - _documents->setIfChanged(documents); - int current = std::min(_currentIndex->get(), static_cast(documents.size()) - 1); - _current->setAlways( - (current >= 0 && current < documents.size()) ? - documents[current] : - nullptr); - _currentIndex->setAlways(current); - } - } - - void DocumentsModel::closeAll() - { - auto documents = _documents->get(); - for (size_t i = 0; i < documents.size(); ++i) - { - _remove->setAlways(i); - } - _documents->setIfChanged({}); - _current->setIfChanged(nullptr); - _currentIndex->setIfChanged(-1); - } - - std::shared_ptr > > DocumentsModel::observeDocuments() const - { - return _documents; - } - - std::shared_ptr > DocumentsModel::observeAdd() const - { - return _add; - } - - std::shared_ptr > DocumentsModel::observeRemove() const - { - return _remove; - } - - std::shared_ptr > > DocumentsModel::observeCurrent() const - { - return _current; - } - - std::shared_ptr > DocumentsModel::observeCurrentIndex() const - { - return _currentIndex; - } - - void DocumentsModel::setCurrentIndex(int value) - { - const auto& documents = _documents->get(); - const int index = dtk::clamp(value, 0, static_cast(documents.size()) - 1); - _current->setIfChanged(documents[index]); - _currentIndex->setIfChanged(index); - } - - void DocumentsModel::next() - { - const auto& documents = _documents->get(); - if (!documents.empty()) - { - int index = _currentIndex->get() + 1; - if (index >= documents.size()) - { - index = 0; - } - setCurrentIndex(index); - } - } - - void DocumentsModel::prev() - { - const auto& documents = _documents->get(); - if (!documents.empty()) - { - int index = _currentIndex->get() - 1; - if (index < 0) - { - index = static_cast(documents.size()) - 1; - } - setCurrentIndex(index); - } - } - - const std::shared_ptr& DocumentsModel::getRecentFilesModel() const - { - return _recentFilesModel; - } -} diff --git a/lib/toucanView/ExportTool.cpp b/lib/toucanView/ExportTool.cpp index ad70f0b..18f39b2 100644 --- a/lib/toucanView/ExportTool.cpp +++ b/lib/toucanView/ExportTool.cpp @@ -4,7 +4,7 @@ #include "ExportTool.h" #include "App.h" -#include "DocumentsModel.h" +#include "FilesModel.h" #include "PlaybackModel.h" #include @@ -67,7 +67,7 @@ namespace toucan exportSequenceButton->setClickedCallback( [this] { - _timeRange = _document->getPlaybackModel()->getInOutRange(); + _timeRange = _file->getPlaybackModel()->getInOutRange(); _export(); }); @@ -79,24 +79,24 @@ namespace toucan [this] { _timeRange = OTIO_NS::TimeRange( - _document->getPlaybackModel()->getCurrentTime(), - OTIO_NS::RationalTime(1.0, _document->getPlaybackModel()->getTimeRange().duration().rate())); + _file->getPlaybackModel()->getCurrentTime(), + OTIO_NS::RationalTime(1.0, _file->getPlaybackModel()->getTimeRange().duration().rate())); _export(); }); _timer = dtk::Timer::create(context); _timer->setRepeating(true); - _documentObserver = dtk::ValueObserver >::create( - app->getDocumentsModel()->observeCurrent(), - [this](const std::shared_ptr& document) + _fileObserver = dtk::ValueObserver >::create( + app->getFilesModel()->observeCurrent(), + [this](const std::shared_ptr& file) { - _document = document; - if (_document) + _file = file; + if (_file) { _graph = std::make_shared( - _document->getPath(), - _document->getTimelineWrapper()); + _file->getPath(), + _file->getTimelineWrapper()); } else { @@ -104,7 +104,7 @@ namespace toucan _time = OTIO_NS::RationalTime(); _graph.reset(); } - setEnabled(_document.get()); + setEnabled(_file.get()); }); } diff --git a/lib/toucanView/ExportTool.h b/lib/toucanView/ExportTool.h index 4aabf5e..3049b87 100644 --- a/lib/toucanView/ExportTool.h +++ b/lib/toucanView/ExportTool.h @@ -20,7 +20,7 @@ namespace toucan { - class Document; + class File; class ExportWidget : public dtk::IWidget { @@ -45,7 +45,7 @@ namespace toucan void _export(); std::shared_ptr _host; - std::shared_ptr _document; + std::shared_ptr _file; OTIO_NS::TimeRange _timeRange; OTIO_NS::RationalTime _time; std::shared_ptr _graph; @@ -59,7 +59,7 @@ namespace toucan std::shared_ptr _dialog; std::shared_ptr _timer; - std::shared_ptr > > _documentObserver; + std::shared_ptr > > _fileObserver; }; class ExportTool : public IToolWidget diff --git a/lib/toucanView/Document.cpp b/lib/toucanView/File.cpp similarity index 85% rename from lib/toucanView/Document.cpp rename to lib/toucanView/File.cpp index c007079..9e73eab 100644 --- a/lib/toucanView/Document.cpp +++ b/lib/toucanView/File.cpp @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright Contributors to the toucan project. -#include "Document.h" +#include "File.h" #include "PlaybackModel.h" #include "SelectionModel.h" @@ -14,7 +14,7 @@ namespace toucan { - Document::Document( + File::File( const std::shared_ptr& context, const std::shared_ptr& host, const std::filesystem::path& path) : @@ -60,75 +60,75 @@ namespace toucan }); } - Document::~Document() + File::~File() {} - const std::filesystem::path& Document::getPath() const + const std::filesystem::path& File::getPath() const { return _path; } - const std::shared_ptr& Document::getTimelineWrapper() const + const std::shared_ptr& File::getTimelineWrapper() const { return _timelineWrapper; } - const OTIO_NS::SerializableObject::Retainer& Document::getTimeline() const + const OTIO_NS::SerializableObject::Retainer& File::getTimeline() const { return _timelineWrapper->getTimeline(); } - const std::shared_ptr& Document::getPlaybackModel() const + const std::shared_ptr& File::getPlaybackModel() const { return _playbackModel; } - const std::shared_ptr& Document::getViewModel() const + const std::shared_ptr& File::getViewModel() const { return _viewModel; } - const std::shared_ptr& Document::getSelectionModel() const + const std::shared_ptr& File::getSelectionModel() const { return _selectionModel; } - const std::shared_ptr& Document::getThumbnailGenerator() const + const std::shared_ptr& File::getThumbnailGenerator() const { return _thumbnailGenerator; } - const IMATH_NAMESPACE::V2i& Document::getImageSize() const + const IMATH_NAMESPACE::V2i& File::getImageSize() const { return _graph->getImageSize(); } - int Document::getImageChannels() const + int File::getImageChannels() const { return _graph->getImageChannels(); } - const std::string& Document::getImageDataType() const + const std::string& File::getImageDataType() const { return _graph->getImageDataType(); } - std::shared_ptr > > Document::observeCurrentImage() const + std::shared_ptr > > File::observeCurrentImage() const { return _currentImage; } - std::shared_ptr > > Document::observeRootNode() const + std::shared_ptr > > File::observeRootNode() const { return _rootNode; } - std::shared_ptr > > Document::observeCurrentNode() const + std::shared_ptr > > File::observeCurrentNode() const { return _currentNode; } - void Document::setCurrentNode(const std::shared_ptr& value) + void File::setCurrentNode(const std::shared_ptr& value) { if (_currentNode->setIfChanged(value)) { @@ -136,7 +136,7 @@ namespace toucan } } - void Document::_render() + void File::_render() { std::shared_ptr image; if (_currentNode->get()) diff --git a/lib/toucanView/Document.h b/lib/toucanView/File.h similarity index 96% rename from lib/toucanView/Document.h rename to lib/toucanView/File.h index a0fe59c..6d84360 100644 --- a/lib/toucanView/Document.h +++ b/lib/toucanView/File.h @@ -20,15 +20,15 @@ namespace toucan class ThumbnailGenerator; class ViewModel; - class Document : std::enable_shared_from_this + class File : std::enable_shared_from_this { public: - Document( + File( const std::shared_ptr&, const std::shared_ptr&, const std::filesystem::path&); - ~Document(); + ~File(); const std::filesystem::path& getPath() const; diff --git a/lib/toucanView/DocumentTab.cpp b/lib/toucanView/FileTab.cpp similarity index 54% rename from lib/toucanView/DocumentTab.cpp rename to lib/toucanView/FileTab.cpp index 880ff09..054351d 100644 --- a/lib/toucanView/DocumentTab.cpp +++ b/lib/toucanView/FileTab.cpp @@ -1,45 +1,45 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright Contributors to the toucan project. -#include "DocumentTab.h" +#include "FileTab.h" #include "App.h" #include "Viewport.h" namespace toucan { - void DocumentTab::_init( + void FileTab::_init( const std::shared_ptr& context, const std::shared_ptr& app, - const std::shared_ptr& document, + const std::shared_ptr& file, const std::shared_ptr& parent) { - dtk::IWidget::_init(context, "toucan::DocumentTab", parent); - _viewport = Viewport::create(context, document, shared_from_this()); + dtk::IWidget::_init(context, "toucan::FileTab", parent); + _viewport = Viewport::create(context, file, shared_from_this()); _viewport->setStretch(dtk::Stretch::Expanding); } - DocumentTab::~DocumentTab() + FileTab::~FileTab() {} - std::shared_ptr DocumentTab::create( + std::shared_ptr FileTab::create( const std::shared_ptr& context, const std::shared_ptr& app, - const std::shared_ptr& document, + const std::shared_ptr& file, const std::shared_ptr& parent) { - auto out = std::shared_ptr(new DocumentTab); - out->_init(context, app, document, parent); + auto out = std::shared_ptr(new FileTab); + out->_init(context, app, file, parent); return out; } - void DocumentTab::setGeometry(const dtk::Box2I& value) + void FileTab::setGeometry(const dtk::Box2I& value) { dtk::IWidget::setGeometry(value); _viewport->setGeometry(value); } - void DocumentTab::sizeHintEvent(const dtk::SizeHintEvent& event) + void FileTab::sizeHintEvent(const dtk::SizeHintEvent& event) { dtk::IWidget::sizeHintEvent(event); _setSizeHint(_viewport->getSizeHint()); diff --git a/lib/toucanView/DocumentTab.h b/lib/toucanView/FileTab.h similarity index 73% rename from lib/toucanView/DocumentTab.h rename to lib/toucanView/FileTab.h index 7dd96ee..ae83518 100644 --- a/lib/toucanView/DocumentTab.h +++ b/lib/toucanView/FileTab.h @@ -8,25 +8,27 @@ namespace toucan { class App; - class Document; + class File; class Viewport; - class DocumentTab : public dtk::IWidget + //! File tab. + class FileTab : public dtk::IWidget { protected: void _init( const std::shared_ptr&, const std::shared_ptr&, - const std::shared_ptr&, + const std::shared_ptr&, const std::shared_ptr& parent); public: - virtual ~DocumentTab(); + virtual ~FileTab(); - static std::shared_ptr create( + //! Create a new file tab. + static std::shared_ptr create( const std::shared_ptr&, const std::shared_ptr&, - const std::shared_ptr&, + const std::shared_ptr&, const std::shared_ptr& parent = nullptr); void setGeometry(const dtk::Box2I&) override; diff --git a/lib/toucanView/FilesModel.cpp b/lib/toucanView/FilesModel.cpp new file mode 100644 index 0000000..0cee7a9 --- /dev/null +++ b/lib/toucanView/FilesModel.cpp @@ -0,0 +1,146 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Contributors to the toucan project. + +#include "FilesModel.h" + +#include + +#include + +namespace toucan +{ + FilesModel::FilesModel( + const std::shared_ptr& context, + const std::shared_ptr& settings, + const std::shared_ptr& host) : + _context(context), + _host(host) + { + _files = dtk::ObservableList< std::shared_ptr >::create(); + _add = dtk::ObservableValue::create(-1); + _remove = dtk::ObservableValue::create(-1); + _current = dtk::ObservableValue< std::shared_ptr >::create(nullptr); + _currentIndex = dtk::ObservableValue::create(-1); + _recentFilesModel = dtk::RecentFilesModel::create(context, settings); + } + + FilesModel::~FilesModel() + {} + + void FilesModel::open(const std::filesystem::path& path) + { + if (auto context = _context.lock()) + { + auto files = _files->get(); + auto file = std::make_shared(context, _host, path); + files.push_back(file); + _files->setIfChanged(files); + const int index = files.size() - 1; + _add->setAlways(index); + _current->setIfChanged(files[index]); + _currentIndex->setIfChanged(index); + _recentFilesModel->addRecent(path); + } + } + + void FilesModel::close() + { + close(_currentIndex->get()); + } + + void FilesModel::close(int index) + { + auto files = _files->get(); + if (index >= 0 && index < files.size()) + { + auto file = *(files.begin() + index); + files.erase(files.begin() + index); + _remove->setAlways(index); + _files->setIfChanged(files); + int current = std::min(_currentIndex->get(), static_cast(files.size()) - 1); + _current->setAlways( + (current >= 0 && current < files.size()) ? + files[current] : + nullptr); + _currentIndex->setAlways(current); + } + } + + void FilesModel::closeAll() + { + auto files = _files->get(); + for (size_t i = 0; i < files.size(); ++i) + { + _remove->setAlways(i); + } + _files->setIfChanged({}); + _current->setIfChanged(nullptr); + _currentIndex->setIfChanged(-1); + } + + std::shared_ptr > > FilesModel::observeFiles() const + { + return _files; + } + + std::shared_ptr > FilesModel::observeAdd() const + { + return _add; + } + + std::shared_ptr > FilesModel::observeRemove() const + { + return _remove; + } + + std::shared_ptr > > FilesModel::observeCurrent() const + { + return _current; + } + + std::shared_ptr > FilesModel::observeCurrentIndex() const + { + return _currentIndex; + } + + void FilesModel::setCurrentIndex(int value) + { + const auto& files = _files->get(); + const int index = dtk::clamp(value, 0, static_cast(files.size()) - 1); + _current->setIfChanged(files[index]); + _currentIndex->setIfChanged(index); + } + + void FilesModel::next() + { + const auto& files = _files->get(); + if (!files.empty()) + { + int index = _currentIndex->get() + 1; + if (index >= files.size()) + { + index = 0; + } + setCurrentIndex(index); + } + } + + void FilesModel::prev() + { + const auto& files = _files->get(); + if (!files.empty()) + { + int index = _currentIndex->get() - 1; + if (index < 0) + { + index = static_cast(files.size()) - 1; + } + setCurrentIndex(index); + } + } + + const std::shared_ptr& FilesModel::getRecentFilesModel() const + { + return _recentFilesModel; + } +} diff --git a/lib/toucanView/DocumentsModel.h b/lib/toucanView/FilesModel.h similarity index 57% rename from lib/toucanView/DocumentsModel.h rename to lib/toucanView/FilesModel.h index d694baf..0df3baf 100644 --- a/lib/toucanView/DocumentsModel.h +++ b/lib/toucanView/FilesModel.h @@ -3,7 +3,7 @@ #pragma once -#include "Document.h" +#include "File.h" #include #include @@ -13,54 +13,54 @@ namespace toucan { - class Document; + class File; class ImageEffectHost; - //! Documents model. - class DocumentsModel : public std::enable_shared_from_this + //! Files model. + class FilesModel : public std::enable_shared_from_this { public: - DocumentsModel( + FilesModel( const std::shared_ptr&, const std::shared_ptr&, const std::shared_ptr&); - virtual ~DocumentsModel(); + virtual ~FilesModel(); - //! Open a document. + //! Open a file. void open(const std::filesystem::path&); - //! Close the current document. + //! Close the current file. void close(); - //! Close a document. + //! Close a file. void close(int); - //! Close all documents. + //! Close all files. void closeAll(); - //! Observe the documents. - std::shared_ptr > > observeDocuments() const; + //! Observe the files. + std::shared_ptr > > observeFiles() const; - //! Observe when a document is added. + //! Observe when a file is added. std::shared_ptr > observeAdd() const; - //! Observe when a document is removed. + //! Observe when a file is removed. std::shared_ptr > observeRemove() const; - //! Observe the current document. - std::shared_ptr > > observeCurrent() const; + //! Observe the current file. + std::shared_ptr > > observeCurrent() const; - //! Observe the current document index. + //! Observe the current file index. std::shared_ptr > observeCurrentIndex() const; - //! Set the current document index. + //! Set the current file index. void setCurrentIndex(int); - //! Go to the next document. + //! Go to the next file. void next(); - //! Go to the previous document. + //! Go to the previous file. void prev(); //! Get the recent files model. @@ -69,10 +69,10 @@ namespace toucan private: std::weak_ptr _context; std::shared_ptr _host; - std::shared_ptr > > _documents; + std::shared_ptr > > _files; std::shared_ptr > _add; std::shared_ptr > _remove; - std::shared_ptr > > _current; + std::shared_ptr > > _current; std::shared_ptr > _currentIndex; std::shared_ptr _recentFilesModel; }; diff --git a/lib/toucanView/GraphTool.cpp b/lib/toucanView/GraphTool.cpp index d25ee45..c900561 100644 --- a/lib/toucanView/GraphTool.cpp +++ b/lib/toucanView/GraphTool.cpp @@ -4,7 +4,7 @@ #include "GraphTool.h" #include "App.h" -#include "DocumentsModel.h" +#include "FilesModel.h" #include @@ -26,25 +26,25 @@ namespace toucan _buttonGroup->setCheckedCallback( [this](int index, bool value) { - if (_document && index >= 0 && index < _buttons.size()) + if (_file && index >= 0 && index < _buttons.size()) { auto i = _buttonToNode.find(_buttons[index]); if (i != _buttonToNode.end()) { - _document->setCurrentNode(i->second); + _file->setCurrentNode(i->second); } } }); - _documentObserver = dtk::ValueObserver >::create( - app->getDocumentsModel()->observeCurrent(), - [this](const std::shared_ptr& document) + _fileObserver = dtk::ValueObserver >::create( + app->getFilesModel()->observeCurrent(), + [this](const std::shared_ptr& file) { - _document = document; - if (document) + _file = file; + if (file) { _rootNodeObserver = dtk::ValueObserver >::create( - document->observeRootNode(), + file->observeRootNode(), [this](const std::shared_ptr& node) { _rootNode = node; @@ -53,7 +53,7 @@ namespace toucan }); _currentNodeObserver = dtk::ValueObserver >::create( - document->observeCurrentNode(), + file->observeCurrentNode(), [this](const std::shared_ptr& node) { _currentNode = node; diff --git a/lib/toucanView/GraphTool.h b/lib/toucanView/GraphTool.h index a720792..780aa6f 100644 --- a/lib/toucanView/GraphTool.h +++ b/lib/toucanView/GraphTool.h @@ -14,7 +14,7 @@ namespace toucan { - class Document; + class File; class GraphWidget : public dtk::IWidget { @@ -52,7 +52,7 @@ namespace toucan void _graphUpdate(); - std::shared_ptr _document; + std::shared_ptr _file; std::shared_ptr _rootNode; int _depth = 0; std::shared_ptr _currentNode; @@ -72,7 +72,7 @@ namespace toucan }; SizeData _size; - std::shared_ptr > > _documentObserver; + std::shared_ptr > > _fileObserver; std::shared_ptr > > _rootNodeObserver; std::shared_ptr > > _currentNodeObserver; }; diff --git a/lib/toucanView/InfoBar.cpp b/lib/toucanView/InfoBar.cpp index d29f41d..cd687fa 100644 --- a/lib/toucanView/InfoBar.cpp +++ b/lib/toucanView/InfoBar.cpp @@ -4,7 +4,7 @@ #include "InfoBar.h" #include "App.h" -#include "DocumentsModel.h" +#include "FilesModel.h" #include #include @@ -24,33 +24,33 @@ namespace toucan _label = dtk::Label::create(context, _layout); _label->setMarginRole(dtk::SizeRole::MarginInside); - _documentObserver = dtk::ValueObserver >::create( - app->getDocumentsModel()->observeCurrent(), - [this](const std::shared_ptr& document) + _fileObserver = dtk::ValueObserver >::create( + app->getFilesModel()->observeCurrent(), + [this](const std::shared_ptr& file) { std::string text; std::string tooltip; - if (document) + if (file) { - const IMATH_NAMESPACE::V2i& imageSize = document->getImageSize(); - const size_t trackCount = document->getTimeline()->find_children().size(); + const IMATH_NAMESPACE::V2i& imageSize = file->getImageSize(); + const size_t trackCount = file->getTimeline()->find_children().size(); - text = dtk::Format("{0}: {1}x{2}, {3} channels, {4} data, {5} tracks"). - arg(dtk::elide(document->getPath().filename().string())). + text = dtk::Format("{0}: {1}x{2}, {3} image channels, {4} pixel data, {5} tracks"). + arg(dtk::elide(file->getPath().filename().string())). arg(imageSize.x). arg(imageSize.y). - arg(document->getImageChannels()). - arg(document->getImageDataType()). + arg(file->getImageChannels()). + arg(file->getImageDataType()). arg(trackCount); tooltip = dtk::Format( "Path: {0}\n" - "Render: {1}x{2}, {3} channels, {4} data\n" + "Render: {1}x{2}, {3} image channels, {4} pixel data\n" "Tracks: {5}"). - arg(document->getPath().string()). + arg(file->getPath().string()). arg(imageSize.x). arg(imageSize.y). - arg(document->getImageChannels()). - arg(document->getImageDataType()). + arg(file->getImageChannels()). + arg(file->getImageDataType()). arg(trackCount); } _label->setText(text); diff --git a/lib/toucanView/InfoBar.h b/lib/toucanView/InfoBar.h index a43e1a2..f2a8ed2 100644 --- a/lib/toucanView/InfoBar.h +++ b/lib/toucanView/InfoBar.h @@ -12,7 +12,7 @@ namespace toucan { class App; - class Document; + class File; class InfoBar : public dtk::IWidget { @@ -37,7 +37,7 @@ namespace toucan std::shared_ptr _layout; std::shared_ptr _label; - std::shared_ptr > > _documentObserver; + std::shared_ptr > > _fileObserver; }; } diff --git a/lib/toucanView/JSONTool.cpp b/lib/toucanView/JSONTool.cpp index 5bb9cde..bddcd9b 100644 --- a/lib/toucanView/JSONTool.cpp +++ b/lib/toucanView/JSONTool.cpp @@ -4,7 +4,7 @@ #include "JSONTool.h" #include "App.h" -#include "DocumentsModel.h" +#include "FilesModel.h" #include "SelectionModel.h" #include @@ -162,14 +162,14 @@ namespace toucan } }); - _documentObserver = dtk::ValueObserver >::create( - app->getDocumentsModel()->observeCurrent(), - [this](const std::shared_ptr& document) + _fileObserver = dtk::ValueObserver >::create( + app->getFilesModel()->observeCurrent(), + [this](const std::shared_ptr& file) { - if (document) + if (file) { _selectionObserver = dtk::ListObserver >::create( - document->getSelectionModel()->observeSelection(), + file->getSelectionModel()->observeSelection(), [this](const std::vector >& selection) { for (const auto& widget : _widgets) diff --git a/lib/toucanView/JSONTool.h b/lib/toucanView/JSONTool.h index e6a8b5f..18ef45d 100644 --- a/lib/toucanView/JSONTool.h +++ b/lib/toucanView/JSONTool.h @@ -16,7 +16,7 @@ namespace toucan { - class Document; + class File; class JSONWidget : public dtk::IWidget { @@ -70,7 +70,7 @@ namespace toucan void sizeHintEvent(const dtk::SizeHintEvent&) override; private: - std::shared_ptr _document; + std::shared_ptr _file; std::shared_ptr _layout; std::shared_ptr _searchBox; @@ -80,7 +80,7 @@ namespace toucan std::shared_ptr _nothingSelectedLabel; std::shared_ptr _bottomLayout; - std::shared_ptr > > _documentObserver; + std::shared_ptr > > _fileObserver; std::shared_ptr > > _selectionObserver; }; } diff --git a/lib/toucanView/MainWindow.cpp b/lib/toucanView/MainWindow.cpp index efa4d65..3587ab2 100644 --- a/lib/toucanView/MainWindow.cpp +++ b/lib/toucanView/MainWindow.cpp @@ -4,9 +4,9 @@ #include "MainWindow.h" #include "App.h" -#include "DocumentTab.h" -#include "DocumentsModel.h" #include "ExportTool.h" +#include "FileTab.h" +#include "FilesModel.h" #include "GraphTool.h" #include "InfoBar.h" #include "JSONTool.h" @@ -88,7 +88,7 @@ namespace toucan { if (auto app = appWeak.lock()) { - app->getDocumentsModel()->setCurrentIndex(index); + app->getFilesModel()->setCurrentIndex(index); } }); _tabWidget->setTabCloseCallback( @@ -96,53 +96,53 @@ namespace toucan { if (auto app = appWeak.lock()) { - app->getDocumentsModel()->close(index); + app->getFilesModel()->close(index); } }); - _documentsObserver = dtk::ListObserver >::create( - app->getDocumentsModel()->observeDocuments(), - [this](const std::vector >& documents) + _filesObserver = dtk::ListObserver >::create( + app->getFilesModel()->observeFiles(), + [this](const std::vector >& files) { - _documents = documents; + _files = files; }); _addObserver = dtk::ValueObserver::create( - app->getDocumentsModel()->observeAdd(), + app->getFilesModel()->observeAdd(), [this, appWeak](int index) { - if (index >= 0 && index < _documents.size()) + if (index >= 0 && index < _files.size()) { auto context = getContext(); auto app = appWeak.lock(); - auto document = _documents[index]; - auto tab = DocumentTab::create(context, app, document); + auto file = _files[index]; + auto tab = FileTab::create(context, app, file); _tabWidget->addTab( - dtk::elide(document->getPath().filename().string()), + dtk::elide(file->getPath().filename().string()), tab, - document->getPath().string()); - _documentTabs[document] = tab; + file->getPath().string()); + _fileTabs[file] = tab; } }); _removeObserver = dtk::ValueObserver::create( - app->getDocumentsModel()->observeRemove(), + app->getFilesModel()->observeRemove(), [this, appWeak](int index) { - if (index >= 0 && index < _documents.size()) + if (index >= 0 && index < _files.size()) { - auto document = _documents[index]; - const auto i = _documentTabs.find(document); - if (i != _documentTabs.end()) + auto file = _files[index]; + const auto i = _fileTabs.find(file); + if (i != _fileTabs.end()) { _tabWidget->removeTab(i->second); - _documentTabs.erase(i); + _fileTabs.erase(i); } } }); - _documentObserver = dtk::ValueObserver::create( - app->getDocumentsModel()->observeCurrentIndex(), + _fileObserver = dtk::ValueObserver::create( + app->getFilesModel()->observeCurrentIndex(), [this](int index) { _tabWidget->setCurrentTab(index); @@ -225,7 +225,7 @@ namespace toucan { try { - app->getDocumentsModel()->open(i); + app->getFilesModel()->open(i); } catch (const std::exception& e) { diff --git a/lib/toucanView/MainWindow.h b/lib/toucanView/MainWindow.h index adb704f..1771925 100644 --- a/lib/toucanView/MainWindow.h +++ b/lib/toucanView/MainWindow.h @@ -15,8 +15,8 @@ namespace toucan { class App; - class Document; - class DocumentTab; + class File; + class FileTab; class IToolWidget; class InfoBar; class MenuBar; @@ -52,7 +52,7 @@ namespace toucan private: std::weak_ptr _app; - std::vector > _documents; + std::vector > _files; std::shared_ptr _layout; std::shared_ptr _menuBar; @@ -61,7 +61,7 @@ namespace toucan std::shared_ptr _vSplitter; std::shared_ptr _hSplitter; std::shared_ptr _tabWidget; - std::map, std::shared_ptr > _documentTabs; + std::map, std::shared_ptr > _fileTabs; std::shared_ptr _toolWidget; std::vector > _toolWidgets; std::shared_ptr _bottomLayout; @@ -71,10 +71,10 @@ namespace toucan std::shared_ptr _infoBar; std::shared_ptr _infoDivider; - std::shared_ptr > > _documentsObserver; + std::shared_ptr > > _filesObserver; std::shared_ptr > _addObserver; std::shared_ptr > _removeObserver; - std::shared_ptr > _documentObserver; + std::shared_ptr > _fileObserver; std::shared_ptr > _controlsObserver; std::shared_ptr > _tooltipsObserver; }; diff --git a/lib/toucanView/MenuBar.cpp b/lib/toucanView/MenuBar.cpp index e7103c1..fb03294 100644 --- a/lib/toucanView/MenuBar.cpp +++ b/lib/toucanView/MenuBar.cpp @@ -4,7 +4,7 @@ #include "MenuBar.h" #include "App.h" -#include "DocumentsModel.h" +#include "FilesModel.h" #include "MainWindow.h" #include "SelectionModel.h" #include "ViewModel.h" @@ -29,7 +29,7 @@ namespace toucan dtk::MenuBar::_init(context, parent); _app = app; - _documentsModel = app->getDocumentsModel(); + _filesModel = app->getFilesModel(); _fileMenuInit(context, app); _selectMenuInit(context, app); @@ -38,19 +38,19 @@ namespace toucan _windowMenuInit(context, app, window); _viewMenuInit(context, app); - _documentsObserver = dtk::ListObserver >::create( - _documentsModel->observeDocuments(), - [this](const std::vector >& documents) + _filesObserver = dtk::ListObserver >::create( + _filesModel->observeFiles(), + [this](const std::vector >& files) { _menus["Files"]->clear(); _filesActions.clear(); - for (int i = 0; i < documents.size(); ++i) + for (int i = 0; i < files.size(); ++i) { auto item = std::make_shared( - documents[i]->getPath().filename().string(), + files[i]->getPath().filename().string(), [this, i] { - _documentsModel->setCurrentIndex(i); + _filesModel->setCurrentIndex(i); _menus["File"]->close(); }); _menus["Files"]->addItem(item); @@ -58,11 +58,11 @@ namespace toucan } }); - _documentObserver = dtk::ValueObserver >::create( - _documentsModel->observeCurrent(), - [this](const std::shared_ptr& document) + _fileObserver = dtk::ValueObserver >::create( + _filesModel->observeCurrent(), + [this](const std::shared_ptr& file) { - _document = document; + _file = file; _fileMenuUpdate(); _selectMenuUpdate(); _timeMenuUpdate(); @@ -71,8 +71,8 @@ namespace toucan _viewMenuUpdate(); }); - _documentIndexObserver = dtk::ValueObserver::create( - _documentsModel->observeCurrentIndex(), + _fileIndexObserver = dtk::ValueObserver::create( + _filesModel->observeCurrentIndex(), [this](int index) { for (int i = 0; i < _filesActions.size(); ++i) @@ -82,7 +82,7 @@ namespace toucan }); _recentFilesObserver = dtk::ListObserver::create( - _documentsModel->getRecentFilesModel()->observeRecent(), + _filesModel->getRecentFilesModel()->observeRecent(), [this](const std::vector& files) { _menus["RecentFiles"]->clear(); @@ -94,7 +94,7 @@ namespace toucan file.string(), [this, file] { - _documentsModel->open(file); + _filesModel->open(file); _menus["File"]->close(); }); _menus["RecentFiles"]->addItem(item); @@ -141,9 +141,9 @@ namespace toucan { if (auto fileBrowserSystem = context->getSystem()) { - if (_document) + if (_file) { - fileBrowserSystem->setPath(_document->getPath().parent_path()); + fileBrowserSystem->setPath(_file->getPath().parent_path()); } dtk::FileBrowserOptions options; options.extensions.push_back(".otio"); @@ -156,7 +156,7 @@ namespace toucan { try { - _documentsModel->open(path); + _filesModel->open(path); } catch (const std::exception& e) { @@ -164,7 +164,7 @@ namespace toucan } } }, - _documentsModel->getRecentFilesModel()); + _filesModel->getRecentFilesModel()); } } }); @@ -176,7 +176,7 @@ namespace toucan "FileClose", dtk::Key::E, static_cast(dtk::KeyModifier::Control), - [this] { _documentsModel->close(); }); + [this] { _filesModel->close(); }); _actions["File/Close"]->toolTip = "Close the current file"; _menus["File"]->addItem(_actions["File/Close"]); @@ -185,7 +185,7 @@ namespace toucan "FileCloseAll", dtk::Key::E, static_cast(dtk::KeyModifier::Shift) | static_cast(dtk::KeyModifier::Control), - [this] { _documentsModel->closeAll(); }); + [this] { _filesModel->closeAll(); }); _actions["File/CloseAll"]->toolTip = "Close all files"; _menus["File"]->addItem(_actions["File/CloseAll"]); @@ -201,7 +201,7 @@ namespace toucan "Next", dtk::Key::PageUp, 0, - [this] { _documentsModel->next(); }); + [this] { _filesModel->next(); }); _actions["File/Next"]->toolTip = "Switch to the next file"; _menus["File"]->addItem(_actions["File/Next"]); @@ -209,7 +209,7 @@ namespace toucan "Previous", dtk::Key::PageDown, 0, - [this] { _documentsModel->prev(); }); + [this] { _filesModel->prev(); }); _actions["File/Prev"]->toolTip = "Switch to the previous file"; _menus["File"]->addItem(_actions["File/Prev"]); @@ -242,9 +242,9 @@ namespace toucan static_cast(dtk::KeyModifier::Control), [this] { - if (_document) + if (_file) { - _document->getSelectionModel()->selectAll(_document->getTimeline()); + _file->getSelectionModel()->selectAll(_file->getTimeline()); } }); _menus["Select"]->addItem(_actions["Select/All"]); @@ -253,10 +253,10 @@ namespace toucan "All Tracks", [this] { - if (_document) + if (_file) { - _document->getSelectionModel()->selectAll( - _document->getTimeline(), + _file->getSelectionModel()->selectAll( + _file->getTimeline(), SelectionType::Tracks); } }); @@ -266,10 +266,10 @@ namespace toucan "All Clips", [this] { - if (_document) + if (_file) { - _document->getSelectionModel()->selectAll( - _document->getTimeline(), + _file->getSelectionModel()->selectAll( + _file->getTimeline(), SelectionType::Clips); } }); @@ -282,9 +282,9 @@ namespace toucan static_cast(dtk::KeyModifier::Control), [this] { - if (_document) + if (_file) { - _document->getSelectionModel()->clearSelection(); + _file->getSelectionModel()->clearSelection(); } }); _menus["Select"]->addItem(_actions["Select/None"]); @@ -295,9 +295,9 @@ namespace toucan static_cast(dtk::KeyModifier::Control), [this] { - if (_document) + if (_file) { - _document->getSelectionModel()->invertSelection(_document->getTimeline()); + _file->getSelectionModel()->invertSelection(_file->getTimeline()); } }); _menus["Select"]->addItem(_actions["Select/Invert"]); @@ -317,11 +317,11 @@ namespace toucan 0, [this] { - if (_document) + if (_file) { - _document->getPlaybackModel()->timeAction( + _file->getPlaybackModel()->timeAction( TimeAction::FrameStart, - _document->getTimeline()); + _file->getTimeline()); } }); _menus["Time"]->addItem(_actions["Time/FrameStart"]); @@ -333,11 +333,11 @@ namespace toucan 0, [this] { - if (_document) + if (_file) { - _document->getPlaybackModel()->timeAction( + _file->getPlaybackModel()->timeAction( TimeAction::FramePrev, - _document->getTimeline()); + _file->getTimeline()); } }); _menus["Time"]->addItem(_actions["Time/FramePrev"]); @@ -349,11 +349,11 @@ namespace toucan 0, [this] { - if (_document) + if (_file) { - _document->getPlaybackModel()->timeAction( + _file->getPlaybackModel()->timeAction( TimeAction::FrameNext, - _document->getTimeline()); + _file->getTimeline()); } }); _menus["Time"]->addItem(_actions["Time/FrameNext"]); @@ -365,11 +365,11 @@ namespace toucan 0, [this] { - if (_document) + if (_file) { - _document->getPlaybackModel()->timeAction( + _file->getPlaybackModel()->timeAction( TimeAction::FrameEnd, - _document->getTimeline()); + _file->getTimeline()); } }); _menus["Time"]->addItem(_actions["Time/FrameEnd"]); @@ -382,11 +382,11 @@ namespace toucan static_cast(dtk::KeyModifier::Control), [this] { - if (_document) + if (_file) { - _document->getPlaybackModel()->timeAction( + _file->getPlaybackModel()->timeAction( TimeAction::ClipNext, - _document->getTimeline()); + _file->getTimeline()); } }); _menus["Time"]->addItem(_actions["Time/ClipNext"]); @@ -397,11 +397,11 @@ namespace toucan static_cast(dtk::KeyModifier::Control), [this] { - if (_document) + if (_file) { - _document->getPlaybackModel()->timeAction( + _file->getPlaybackModel()->timeAction( TimeAction::ClipPrev, - _document->getTimeline()); + _file->getTimeline()); } }); _menus["Time"]->addItem(_actions["Time/ClipPrev"]); @@ -414,10 +414,10 @@ namespace toucan 0, [this] { - if (_document) + if (_file) { - _document->getPlaybackModel()->setInPoint( - _document->getPlaybackModel()->getCurrentTime()); + _file->getPlaybackModel()->setInPoint( + _file->getPlaybackModel()->getCurrentTime()); } }); _menus["Time"]->addItem(_actions["Time/InPointSet"]); @@ -428,9 +428,9 @@ namespace toucan static_cast(dtk::KeyModifier::Shift), [this] { - if (_document) + if (_file) { - _document->getPlaybackModel()->resetInPoint(); + _file->getPlaybackModel()->resetInPoint(); } }); _menus["Time"]->addItem(_actions["Time/InPointReset"]); @@ -441,10 +441,10 @@ namespace toucan 0, [this] { - if (_document) + if (_file) { - _document->getPlaybackModel()->setOutPoint( - _document->getPlaybackModel()->getCurrentTime()); + _file->getPlaybackModel()->setOutPoint( + _file->getPlaybackModel()->getCurrentTime()); } }); _menus["Time"]->addItem(_actions["Time/OutPointSet"]); @@ -455,9 +455,9 @@ namespace toucan static_cast(dtk::KeyModifier::Shift), [this] { - if (_document) + if (_file) { - _document->getPlaybackModel()->resetOutPoint(); + _file->getPlaybackModel()->resetOutPoint(); } }); _menus["Time"]->addItem(_actions["Time/OutPointReset"]); @@ -468,9 +468,9 @@ namespace toucan static_cast(dtk::KeyModifier::Shift), [this] { - if (_document) + if (_file) { - _document->getPlaybackModel()->resetInOutPoints(); + _file->getPlaybackModel()->resetInOutPoints(); } }); _menus["Time"]->addItem(_actions["Time/InOutPointReset"]); @@ -481,21 +481,21 @@ namespace toucan static_cast(dtk::KeyModifier::Shift) | static_cast(dtk::KeyModifier::Control), [this] { - if (_document) + if (_file) { - const auto selection = _document->getSelectionModel()->getSelection(); - const OTIO_NS::TimeRange& timeRange = _document->getTimelineWrapper()->getTimeRange(); + const auto selection = _file->getSelectionModel()->getSelection(); + const OTIO_NS::TimeRange& timeRange = _file->getTimelineWrapper()->getTimeRange(); const auto timeRangeOpt = getTimeRange( selection, timeRange.start_time(), timeRange.duration().rate()); if (timeRangeOpt.has_value()) { - _document->getPlaybackModel()->setInOutRange(timeRangeOpt.value()); + _file->getPlaybackModel()->setInOutRange(timeRangeOpt.value()); } else { - _document->getPlaybackModel()->resetInOutPoints(); + _file->getPlaybackModel()->resetInOutPoints(); } } }); @@ -516,9 +516,9 @@ namespace toucan 0, [this] { - if (_document) + if (_file) { - _document->getPlaybackModel()->setPlayback(Playback::Stop); + _file->getPlaybackModel()->setPlayback(Playback::Stop); } }); _menus["Playback"]->addItem(_actions["Playback/Stop"]); @@ -530,9 +530,9 @@ namespace toucan 0, [this] { - if (_document) + if (_file) { - _document->getPlaybackModel()->setPlayback(Playback::Forward); + _file->getPlaybackModel()->setPlayback(Playback::Forward); } }); _menus["Playback"]->addItem(_actions["Playback/Forward"]); @@ -544,9 +544,9 @@ namespace toucan 0, [this] { - if (_document) + if (_file) { - _document->getPlaybackModel()->setPlayback(Playback::Reverse); + _file->getPlaybackModel()->setPlayback(Playback::Reverse); } }); _menus["Playback"]->addItem(_actions["Playback/Reverse"]); @@ -559,9 +559,9 @@ namespace toucan 0, [this] { - if (_document) + if (_file) { - _document->getPlaybackModel()->togglePlayback(); + _file->getPlaybackModel()->togglePlayback(); } }); _menus["Playback"]->addItem(_actions["Playback/Toggle"]); @@ -772,9 +772,9 @@ namespace toucan 0, [this] { - if (_document) + if (_file) { - _document->getViewModel()->zoomIn(); + _file->getViewModel()->zoomIn(); } }); _actions["View/ZoomIn"]->toolTip = "View zoom in"; @@ -787,9 +787,9 @@ namespace toucan 0, [this] { - if (_document) + if (_file) { - _document->getViewModel()->zoomOut(); + _file->getViewModel()->zoomOut(); } }); _actions["View/ZoomOut"]->toolTip = "View zoom out"; @@ -802,9 +802,9 @@ namespace toucan 0, [this] { - if (_document) + if (_file) { - _document->getViewModel()->zoomReset(); + _file->getViewModel()->zoomReset(); } }); _actions["View/ZoomReset"]->toolTip = "Reset the view zoom"; @@ -819,9 +819,9 @@ namespace toucan 0, [this](bool value) { - if (_document) + if (_file) { - _document->getViewModel()->setFrame(value); + _file->getViewModel()->setFrame(value); } }); _actions["View/Frame"]->toolTip = "Frame the view"; @@ -830,42 +830,42 @@ namespace toucan void MenuBar::_fileMenuUpdate() { - const bool document = _document.get(); - _menus["File"]->setItemEnabled(_actions["File/Close"], document); - _menus["File"]->setItemEnabled(_actions["File/CloseAll"], document); - _menus["File"]->setSubMenuEnabled(_menus["Files"], document); + const bool file = _file.get(); + _menus["File"]->setItemEnabled(_actions["File/Close"], file); + _menus["File"]->setItemEnabled(_actions["File/CloseAll"], file); + _menus["File"]->setSubMenuEnabled(_menus["Files"], file); _menus["File"]->setItemEnabled(_actions["File/Next"], _filesActions.size() > 1); _menus["File"]->setItemEnabled(_actions["File/Prev"], _filesActions.size() > 1); } void MenuBar::_selectMenuUpdate() { - const bool document = _document.get(); - _menus["Select"]->setItemEnabled(_actions["Select/All"], document); - _menus["Select"]->setItemEnabled(_actions["Select/AllTracks"], document); - _menus["Select"]->setItemEnabled(_actions["Select/AllClips"], document); - _menus["Select"]->setItemEnabled(_actions["Select/None"], document); - _menus["Select"]->setItemEnabled(_actions["Select/Invert"], document); + const bool file = _file.get(); + _menus["Select"]->setItemEnabled(_actions["Select/All"], file); + _menus["Select"]->setItemEnabled(_actions["Select/AllTracks"], file); + _menus["Select"]->setItemEnabled(_actions["Select/AllClips"], file); + _menus["Select"]->setItemEnabled(_actions["Select/None"], file); + _menus["Select"]->setItemEnabled(_actions["Select/Invert"], file); } void MenuBar::_timeMenuUpdate() { - const bool document = _document.get(); - _menus["Time"]->setItemEnabled(_actions["Time/FrameStart"], document); - _menus["Time"]->setItemEnabled(_actions["Time/FramePrev"], document); - _menus["Time"]->setItemEnabled(_actions["Time/FrameNext"], document); - _menus["Time"]->setItemEnabled(_actions["Time/FrameEnd"], document); - _menus["Time"]->setItemEnabled(_actions["Time/ClipPrev"], document); - _menus["Time"]->setItemEnabled(_actions["Time/ClipNext"], document); + const bool file = _file.get(); + _menus["Time"]->setItemEnabled(_actions["Time/FrameStart"], file); + _menus["Time"]->setItemEnabled(_actions["Time/FramePrev"], file); + _menus["Time"]->setItemEnabled(_actions["Time/FrameNext"], file); + _menus["Time"]->setItemEnabled(_actions["Time/FrameEnd"], file); + _menus["Time"]->setItemEnabled(_actions["Time/ClipPrev"], file); + _menus["Time"]->setItemEnabled(_actions["Time/ClipNext"], file); } void MenuBar::_playbackMenuUpdate() { - const bool document = _document.get(); - if (document) + const bool file = _file.get(); + if (file) { _playbackObserver = dtk::ValueObserver::create( - _document->getPlaybackModel()->observePlayback(), + _file->getPlaybackModel()->observePlayback(), [this](Playback value) { _menus["Playback"]->setItemChecked(_actions["Playback/Stop"], Playback::Stop == value); @@ -878,10 +878,10 @@ namespace toucan _playbackObserver.reset(); } - _menus["Playback"]->setItemEnabled(_actions["Playback/Stop"], document); - _menus["Playback"]->setItemEnabled(_actions["Playback/Forward"], document); - _menus["Playback"]->setItemEnabled(_actions["Playback/Reverse"], document); - _menus["Playback"]->setItemEnabled(_actions["Playback/Toggle"], document); + _menus["Playback"]->setItemEnabled(_actions["Playback/Stop"], file); + _menus["Playback"]->setItemEnabled(_actions["Playback/Forward"], file); + _menus["Playback"]->setItemEnabled(_actions["Playback/Reverse"], file); + _menus["Playback"]->setItemEnabled(_actions["Playback/Toggle"], file); } void MenuBar::_windowMenuUpdate() @@ -890,11 +890,11 @@ namespace toucan void MenuBar::_viewMenuUpdate() { - const bool document = _document.get(); - if (document) + const bool file = _file.get(); + if (file) { _frameViewObserver = dtk::ValueObserver::create( - _document->getViewModel()->observeFrame(), + _file->getViewModel()->observeFrame(), [this](bool value) { _menus["View"]->setItemChecked(_actions["View/Frame"], value); @@ -905,9 +905,9 @@ namespace toucan _frameViewObserver.reset(); } - _menus["View"]->setItemEnabled(_actions["View/ZoomIn"], document); - _menus["View"]->setItemEnabled(_actions["View/ZoomOut"], document); - _menus["View"]->setItemEnabled(_actions["View/ZoomReset"], document); - _menus["View"]->setItemEnabled(_actions["View/Frame"], document); + _menus["View"]->setItemEnabled(_actions["View/ZoomIn"], file); + _menus["View"]->setItemEnabled(_actions["View/ZoomOut"], file); + _menus["View"]->setItemEnabled(_actions["View/ZoomReset"], file); + _menus["View"]->setItemEnabled(_actions["View/Frame"], file); } } diff --git a/lib/toucanView/MenuBar.h b/lib/toucanView/MenuBar.h index 5d83277..b71b5a5 100644 --- a/lib/toucanView/MenuBar.h +++ b/lib/toucanView/MenuBar.h @@ -15,8 +15,8 @@ namespace toucan { class App; - class Document; - class DocumentsModel; + class File; + class FilesModel; class MainWindow; class MenuBar : public dtk::MenuBar @@ -68,17 +68,17 @@ namespace toucan void _viewMenuUpdate(); std::weak_ptr _app; - std::shared_ptr _documentsModel; - std::shared_ptr _document; + std::shared_ptr _filesModel; + std::shared_ptr _file; std::map > _menus; std::map > _actions; std::vector > _filesActions; std::vector > _recentFilesActions; - std::shared_ptr > > _documentsObserver; - std::shared_ptr > > _documentObserver; - std::shared_ptr > _documentIndexObserver; + std::shared_ptr > > _filesObserver; + std::shared_ptr > > _fileObserver; + std::shared_ptr > _fileIndexObserver; std::shared_ptr > _recentFilesObserver; std::shared_ptr > _playbackObserver; std::shared_ptr > _fullScreenObserver; diff --git a/lib/toucanView/PlaybackBar.cpp b/lib/toucanView/PlaybackBar.cpp index 3daedcb..34d9701 100644 --- a/lib/toucanView/PlaybackBar.cpp +++ b/lib/toucanView/PlaybackBar.cpp @@ -4,7 +4,7 @@ #include "PlaybackBar.h" #include "App.h" -#include "DocumentsModel.h" +#include "FilesModel.h" namespace toucan { @@ -37,29 +37,29 @@ namespace toucan _frameButtons->setCallback( [this](TimeAction value) { - if (_document) + if (_file) { - _document->getPlaybackModel()->timeAction( + _file->getPlaybackModel()->timeAction( value, - _document->getTimeline()); + _file->getTimeline()); } }); _playbackButtons->setCallback( [this](Playback value) { - if (_document) + if (_file) { - _document->getPlaybackModel()->setPlayback(value); + _file->getPlaybackModel()->setPlayback(value); } }); _timeEdit->setCallback( [this](const OTIO_NS::RationalTime& value) { - if (_document) + if (_file) { - _document->getPlaybackModel()->setCurrentTime(value); + _file->getPlaybackModel()->setCurrentTime(value); } }); @@ -73,15 +73,15 @@ namespace toucan } }); - _documentObserver = dtk::ValueObserver >::create( - app->getDocumentsModel()->observeCurrent(), - [this](const std::shared_ptr& document) + _fileObserver = dtk::ValueObserver >::create( + app->getFilesModel()->observeCurrent(), + [this](const std::shared_ptr& file) { - _document = document; - if (document) + _file = file; + if (file) { _timeRangeObserver = dtk::ValueObserver::create( - document->getPlaybackModel()->observeTimeRange(), + file->getPlaybackModel()->observeTimeRange(), [this](const OTIO_NS::TimeRange& value) { _timeRange = value; @@ -89,7 +89,7 @@ namespace toucan }); _currentTimeObserver = dtk::ValueObserver::create( - document->getPlaybackModel()->observeCurrentTime(), + file->getPlaybackModel()->observeCurrentTime(), [this](const OTIO_NS::RationalTime& value) { _currentTime = value; @@ -97,7 +97,7 @@ namespace toucan }); _playbackObserver = dtk::ValueObserver::create( - document->getPlaybackModel()->observePlayback(), + file->getPlaybackModel()->observePlayback(), [this](Playback value) { _playback = value; @@ -119,10 +119,10 @@ namespace toucan _playbackObserver.reset(); } - _frameButtons->setEnabled(document.get()); - _playbackButtons->setEnabled(document.get()); - _timeEdit->setEnabled(document.get()); - _durationLabel->setEnabled(document.get()); + _frameButtons->setEnabled(file.get()); + _playbackButtons->setEnabled(file.get()); + _timeEdit->setEnabled(file.get()); + _durationLabel->setEnabled(file.get()); }); _timeUnitsObserver = dtk::ValueObserver::create( diff --git a/lib/toucanView/PlaybackBar.h b/lib/toucanView/PlaybackBar.h index 9f05d64..25694a5 100644 --- a/lib/toucanView/PlaybackBar.h +++ b/lib/toucanView/PlaybackBar.h @@ -13,7 +13,7 @@ namespace toucan { class App; - class Document; + class File; class PlaybackBar : public dtk::IWidget { @@ -40,7 +40,7 @@ namespace toucan void _currentTimeUpdate(); void _playbackUpdate(); - std::shared_ptr _document; + std::shared_ptr _file; OTIO_NS::TimeRange _timeRange; OTIO_NS::RationalTime _currentTime; Playback _playback = Playback::Stop; @@ -52,7 +52,7 @@ namespace toucan std::shared_ptr _durationLabel; std::shared_ptr _timeUnitsComboBox; - std::shared_ptr > > _documentObserver; + std::shared_ptr > > _fileObserver; std::shared_ptr > _timeRangeObserver; std::shared_ptr > _currentTimeObserver; std::shared_ptr > _playbackObserver; diff --git a/lib/toucanView/TimelineItem.cpp b/lib/toucanView/TimelineItem.cpp index a7d411a..1a367b9 100644 --- a/lib/toucanView/TimelineItem.cpp +++ b/lib/toucanView/TimelineItem.cpp @@ -4,7 +4,7 @@ #include "TimelineItem.h" #include "App.h" -#include "DocumentsModel.h" +#include "FilesModel.h" #include "SelectionModel.h" #include "StackItem.h" @@ -15,14 +15,14 @@ namespace toucan void TimelineItem::_init( const std::shared_ptr& context, const std::shared_ptr& app, - const std::shared_ptr& document, + const std::shared_ptr& file, const std::shared_ptr& parent) { IItem::_init( context, app, nullptr, - document->getTimelineWrapper()->getTimeRange(), + file->getTimelineWrapper()->getTimeRange(), "toucan::TimelineItem", parent); @@ -32,12 +32,12 @@ namespace toucan 0, 0 | static_cast(dtk::KeyModifier::Shift) | static_cast(dtk::KeyModifier::Control)); - _timeline = document->getTimeline(); - _timeRange = document->getTimelineWrapper()->getTimeRange(); + _timeline = file->getTimeline(); + _timeRange = file->getTimelineWrapper()->getTimeRange(); _timeUnitsModel = app->getTimeUnitsModel(); - _selectionModel = document->getSelectionModel(); + _selectionModel = file->getSelectionModel(); _thumbnails.setMax(100); - _thumbnailGenerator = document->getThumbnailGenerator(); + _thumbnailGenerator = file->getThumbnailGenerator(); StackItem::create(context, app, _timeline->tracks(), shared_from_this()); @@ -63,11 +63,11 @@ namespace toucan std::shared_ptr TimelineItem::create( const std::shared_ptr& context, const std::shared_ptr& app, - const std::shared_ptr& document, + const std::shared_ptr& file, const std::shared_ptr& parent) { auto out = std::make_shared(); - out->_init(context, app, document, parent); + out->_init(context, app, file, parent); return out; } diff --git a/lib/toucanView/TimelineItem.h b/lib/toucanView/TimelineItem.h index 9553a9e..186a136 100644 --- a/lib/toucanView/TimelineItem.h +++ b/lib/toucanView/TimelineItem.h @@ -12,7 +12,7 @@ namespace toucan { - class Document; + class File; class SelectionModel; class TimelineItem : public IItem @@ -21,7 +21,7 @@ namespace toucan void _init( const std::shared_ptr&, const std::shared_ptr&, - const std::shared_ptr&, + const std::shared_ptr&, const std::shared_ptr& parent); public: @@ -30,7 +30,7 @@ namespace toucan static std::shared_ptr create( const std::shared_ptr&, const std::shared_ptr&, - const std::shared_ptr&, + const std::shared_ptr&, const std::shared_ptr& parent = nullptr); const OTIO_NS::RationalTime& getCurrentTime() const; diff --git a/lib/toucanView/TimelineWidget.cpp b/lib/toucanView/TimelineWidget.cpp index 2331b34..25e71da 100644 --- a/lib/toucanView/TimelineWidget.cpp +++ b/lib/toucanView/TimelineWidget.cpp @@ -4,7 +4,7 @@ #include "TimelineWidget.h" #include "App.h" -#include "DocumentsModel.h" +#include "FilesModel.h" #include "PlaybackModel.h" #include "TimelineItem.h" @@ -35,32 +35,32 @@ namespace toucan _scrollWidget->setBorder(false); auto appWeak = std::weak_ptr(app); - _documentObserver = dtk::ValueObserver >::create( - app->getDocumentsModel()->observeCurrent(), - [this, appWeak](const std::shared_ptr& document) + _fileObserver = dtk::ValueObserver >::create( + app->getFilesModel()->observeCurrent(), + [this, appWeak](const std::shared_ptr& file) { - _document = document; - if (document) + _file = file; + if (file) { - _timeRange = document->getPlaybackModel()->getTimeRange(); + _timeRange = file->getPlaybackModel()->getTimeRange(); _sizeInit = true; _timelineItem = TimelineItem::create( getContext(), appWeak.lock(), - document); + file); _timelineItem->setCurrentTimeCallback( [this](const OTIO_NS::RationalTime& value) { - if (_document) + if (_file) { - _document->getPlaybackModel()->setCurrentTime(value, CurrentTime::Free); + _file->getPlaybackModel()->setCurrentTime(value, CurrentTime::Free); } }); _scrollWidget->setWidget(_timelineItem); _currentTimeObserver = dtk::ValueObserver::create( - document->getPlaybackModel()->observeCurrentTime(), + file->getPlaybackModel()->observeCurrentTime(), [this](const OTIO_NS::RationalTime& value) { _currentTime = value; @@ -72,7 +72,7 @@ namespace toucan }); _inOutRangeObserver = dtk::ValueObserver::create( - document->getPlaybackModel()->observeInOutRange(), + file->getPlaybackModel()->observeInOutRange(), [this](const OTIO_NS::TimeRange& value) { _inOutRange = value; diff --git a/lib/toucanView/TimelineWidget.h b/lib/toucanView/TimelineWidget.h index dcee4f4..7a977b0 100644 --- a/lib/toucanView/TimelineWidget.h +++ b/lib/toucanView/TimelineWidget.h @@ -13,7 +13,7 @@ namespace toucan { class App; - class Document; + class File; class TimelineItem; class TimelineWidget : public dtk::IWidget @@ -61,7 +61,7 @@ namespace toucan void _scrollUpdate(); - std::shared_ptr _document; + std::shared_ptr _file; OTIO_NS::TimeRange _timeRange; OTIO_NS::RationalTime _currentTime; OTIO_NS::TimeRange _inOutRange; @@ -85,7 +85,7 @@ namespace toucan }; MouseData _mouse; - std::shared_ptr > > _documentObserver; + std::shared_ptr > > _fileObserver; std::shared_ptr > _currentTimeObserver; std::shared_ptr > _inOutRangeObserver; }; diff --git a/lib/toucanView/ToolBar.cpp b/lib/toucanView/ToolBar.cpp index 9aee0f2..be597b4 100644 --- a/lib/toucanView/ToolBar.cpp +++ b/lib/toucanView/ToolBar.cpp @@ -4,7 +4,7 @@ #include "ToolBar.h" #include "App.h" -#include "DocumentsModel.h" +#include "FilesModel.h" #include "MainWindow.h" #include "ViewModel.h" @@ -108,19 +108,19 @@ namespace toucan _widgetUpdate(); - _documentsObserver = dtk::ListObserver >::create( - app->getDocumentsModel()->observeDocuments(), - [this](const std::vector >& documents) + _filesObserver = dtk::ListObserver >::create( + app->getFilesModel()->observeFiles(), + [this](const std::vector >& files) { - _documentsSize = documents.size(); + _filesSize = files.size(); _widgetUpdate(); }); - _documentObserver = dtk::ValueObserver >::create( - app->getDocumentsModel()->observeCurrent(), - [this](const std::shared_ptr& document) + _fileObserver = dtk::ValueObserver >::create( + app->getFilesModel()->observeCurrent(), + [this](const std::shared_ptr& file) { - _document = document; + _file = file; _widgetUpdate(); }); @@ -161,17 +161,17 @@ namespace toucan void ToolBar::_widgetUpdate() { - _buttons["File/Close"]->setEnabled(_documentsSize > 0); - _buttons["File/CloseAll"]->setEnabled(_documentsSize > 0); - _buttons["View/ZoomIn"]->setEnabled(_documentsSize > 0); - _buttons["View/ZoomOut"]->setEnabled(_documentsSize > 0); - _buttons["View/ZoomReset"]->setEnabled(_documentsSize > 0); - _buttons["View/Frame"]->setEnabled(_documentsSize > 0); - - if (_document) + _buttons["File/Close"]->setEnabled(_filesSize > 0); + _buttons["File/CloseAll"]->setEnabled(_filesSize > 0); + _buttons["View/ZoomIn"]->setEnabled(_filesSize > 0); + _buttons["View/ZoomOut"]->setEnabled(_filesSize > 0); + _buttons["View/ZoomReset"]->setEnabled(_filesSize > 0); + _buttons["View/Frame"]->setEnabled(_filesSize > 0); + + if (_file) { _frameViewObserver = dtk::ValueObserver::create( - _document->getViewModel()->observeFrame(), + _file->getViewModel()->observeFrame(), [this](bool value) { _buttons["View/Frame"]->setChecked(value); diff --git a/lib/toucanView/ToolBar.h b/lib/toucanView/ToolBar.h index 4bc15bc..d88cdd4 100644 --- a/lib/toucanView/ToolBar.h +++ b/lib/toucanView/ToolBar.h @@ -12,7 +12,7 @@ namespace toucan { class App; - class Document; + class File; class MainWindow; class ToolBar : public dtk::IWidget @@ -41,14 +41,14 @@ namespace toucan private: void _widgetUpdate(); - size_t _documentsSize = 0; - std::shared_ptr _document; + size_t _filesSize = 0; + std::shared_ptr _file; std::shared_ptr _layout; std::map > _buttons; - std::shared_ptr > > _documentsObserver; - std::shared_ptr > > _documentObserver; + std::shared_ptr > > _filesObserver; + std::shared_ptr > > _fileObserver; std::shared_ptr > _fullScreenObserver; std::shared_ptr > _frameViewObserver; }; diff --git a/lib/toucanView/Viewport.cpp b/lib/toucanView/Viewport.cpp index 497c777..d8a85a4 100644 --- a/lib/toucanView/Viewport.cpp +++ b/lib/toucanView/Viewport.cpp @@ -4,14 +4,14 @@ #include "Viewport.h" #include "App.h" -#include "Document.h" +#include "File.h" #include "ViewModel.h" namespace toucan { void Viewport::_init( const std::shared_ptr& context, - const std::shared_ptr& document, + const std::shared_ptr& file, const std::shared_ptr& parent) { IWidget::_init(context, "toucan::Viewport", parent); @@ -19,13 +19,13 @@ namespace toucan _setMouseHoverEnabled(true); _setMousePressEnabled(true); - _viewModel = document->getViewModel(); + _viewModel = file->getViewModel(); _pos = dtk::ObservableValue::create(); _zoom = dtk::ObservableValue::create(1.F); _frame = dtk::ObservableValue::create(true); _imageObserver = dtk::ValueObserver >::create( - document->observeCurrentImage(), + file->observeCurrentImage(), [this](const std::shared_ptr& value) { _image = value; @@ -75,11 +75,11 @@ namespace toucan std::shared_ptr Viewport::create( const std::shared_ptr& context, - const std::shared_ptr& document, + const std::shared_ptr& file, const std::shared_ptr& parent) { auto out = std::shared_ptr(new Viewport); - out->_init(context, document, parent); + out->_init(context, file, parent); return out; } diff --git a/lib/toucanView/Viewport.h b/lib/toucanView/Viewport.h index aa9846a..6994559 100644 --- a/lib/toucanView/Viewport.h +++ b/lib/toucanView/Viewport.h @@ -9,7 +9,7 @@ namespace toucan { - class Document; + class File; class ViewModel; class Viewport : public dtk::IWidget @@ -17,7 +17,7 @@ namespace toucan protected: void _init( const std::shared_ptr&, - const std::shared_ptr&, + const std::shared_ptr&, const std::shared_ptr& parent); public: @@ -25,7 +25,7 @@ namespace toucan static std::shared_ptr create( const std::shared_ptr&, - const std::shared_ptr&, + const std::shared_ptr&, const std::shared_ptr& parent = nullptr); const dtk::V2I& getPos() const;