blob: 077c76a08f18c49fb6cc883c8dc9be9c327d8021 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup edinterface
*/
#include "interface_intern.h"
#include "UI_abstract_view.hh"
namespace blender::ui {
void AbstractView::register_item(AbstractViewItem &item)
{
/* Actually modifies the item, not the view. But for the public API it "feels" a bit nicer to
* have the view base class register the items, rather than setting the view on the item. */
item.view_ = this;
}
/* ---------------------------------------------------------------------- */
/** \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
|