This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/editors/interface/abstract_view.cc
Julian Eisel e86c2f7288 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.
2022-07-03 01:55:38 +02:00

103 lines
2.2 KiB
C++

/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup edinterface
*/
#include "interface_intern.h"
#include "UI_abstract_view.hh"
namespace blender::ui {
/* ---------------------------------------------------------------------- */
/** \name View Reconstruction
* \{ */
bool AbstractView::is_reconstructed() const
{
return is_reconstructed_;
}
void AbstractView::update_from_old(uiBlock &new_block)
{
uiBlock *old_block = new_block.oldblock;
if (!old_block) {
is_reconstructed_ = true;
return;
}
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. */
is_reconstructed_ = true;
return;
}
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;
}
/** \} */
/* ---------------------------------------------------------------------- */
/** \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