diff options
author | Julian Eisel <julian@blender.org> | 2022-07-02 23:36:50 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2022-07-03 02:55:38 +0300 |
commit | e86c2f7288724bd6fec33ff43e89816d7520a2b3 (patch) | |
tree | d31a7f2089fa6c2de7a32bde859893d499f1f2f2 /source/blender/editors/interface/abstract_view.cc | |
parent | c355be6faeacef6a65afbce97f9776d2a2c7f54c (diff) |
UI: Move rename buffer management to new view base class
Renaming is a nice example of a feature that shouldn't need a specific
implementation for a specific view type (e.g. grid or tree view). So it's
something that can be supported in the general view code. Individual views can
use it "for free" then. This ports the view level part of the renaming code,
the view item level part of it can be ported once we have a common base class
for the view items.
Diffstat (limited to 'source/blender/editors/interface/abstract_view.cc')
-rw-r--r-- | source/blender/editors/interface/abstract_view.cc | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/source/blender/editors/interface/abstract_view.cc b/source/blender/editors/interface/abstract_view.cc index 542d82a56a3..dea9600fde4 100644 --- a/source/blender/editors/interface/abstract_view.cc +++ b/source/blender/editors/interface/abstract_view.cc @@ -27,7 +27,7 @@ void AbstractView::update_from_old(uiBlock &new_block) return; } - const uiViewHandle *old_view_handle = ui_block_view_find_matching_in_old_block( + uiViewHandle *old_view_handle = ui_block_view_find_matching_in_old_block( &new_block, reinterpret_cast<uiViewHandle *>(this)); if (old_view_handle == nullptr) { /* Initial construction, nothing to update. */ @@ -35,7 +35,15 @@ void AbstractView::update_from_old(uiBlock &new_block) return; } - update_children_from_old(reinterpret_cast<const AbstractView &>(*old_view_handle)); + AbstractView &old_view = reinterpret_cast<AbstractView &>(*old_view_handle); + + /* Update own persistent data. */ + /* Keep the rename buffer persistent while renaming! The rename button uses the buffer's + * pointer to identify itself over redraws. */ + rename_buffer_ = std::move(old_view.rename_buffer_); + old_view.rename_buffer_ = nullptr; + + update_children_from_old(old_view); /* Finished (re-)constructing the tree. */ is_reconstructed_ = true; @@ -43,10 +51,52 @@ void AbstractView::update_from_old(uiBlock &new_block) /** \} */ +/* ---------------------------------------------------------------------- */ +/** \name Default implementations of virtual functions + * \{ */ + bool AbstractView::listen(const wmNotifier & /*notifier*/) const { /* Nothing by default. */ return false; } +/** \} */ + +/* ---------------------------------------------------------------------- */ +/** \name Renaming + * \{ */ + +bool AbstractView::is_renaming() const +{ + return rename_buffer_ != nullptr; +} + +bool AbstractView::begin_renaming() +{ + if (is_renaming()) { + return false; + } + + rename_buffer_ = std::make_unique<decltype(rename_buffer_)::element_type>(); + return true; +} + +void AbstractView::end_renaming() +{ + BLI_assert(is_renaming()); + rename_buffer_ = nullptr; +} + +Span<char> AbstractView::get_rename_buffer() const +{ + return *rename_buffer_; +} +MutableSpan<char> AbstractView::get_rename_buffer() +{ + return *rename_buffer_; +} + +/** \} */ + } // namespace blender::ui |