Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2022-07-02 23:36:50 +0300
committerJulian Eisel <julian@blender.org>2022-07-03 02:55:38 +0300
commite86c2f7288724bd6fec33ff43e89816d7520a2b3 (patch)
treed31a7f2089fa6c2de7a32bde859893d499f1f2f2 /source/blender/editors/include/UI_abstract_view.hh
parentc355be6faeacef6a65afbce97f9776d2a2c7f54c (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/include/UI_abstract_view.hh')
-rw-r--r--source/blender/editors/include/UI_abstract_view.hh24
1 files changed, 23 insertions, 1 deletions
diff --git a/source/blender/editors/include/UI_abstract_view.hh b/source/blender/editors/include/UI_abstract_view.hh
index 477f68ca03f..82f81f1702b 100644
--- a/source/blender/editors/include/UI_abstract_view.hh
+++ b/source/blender/editors/include/UI_abstract_view.hh
@@ -6,17 +6,31 @@
* Base for all views (UIs to display data sets), supporting common features.
* https://wiki.blender.org/wiki/Source/Interface/Views
*
- * The base class manages reconstruction, most importantly keeping state over reconstructions.
+ * One of the most important responsibilities of the base class is managing reconstruction,
+ * enabling state that is persistent over reconstructions/redraws.
*/
#pragma once
+#include <array>
+#include <memory>
+
+#include "BLI_span.hh"
+
struct wmNotifier;
namespace blender::ui {
class AbstractView {
bool is_reconstructed_ = false;
+ /**
+ * Only one item can be renamed at a time. So rather than giving each item an own rename buffer
+ * (which just adds unused memory in most cases), have one here that is managed by the view.
+ *
+ * This fixed-size buffer is needed because that's what the rename button requires. In future we
+ * may be able to bind the button to a `std::string` or similar.
+ */
+ std::unique_ptr<std::array<char, MAX_NAME>> rename_buffer_;
public:
virtual ~AbstractView() = default;
@@ -24,6 +38,14 @@ class AbstractView {
/** Listen to a notifier, returning true if a redraw is needed. */
virtual bool listen(const wmNotifier &) const;
+ /** Only one item can be renamed at a time. */
+ bool is_renaming() const;
+ /** \return If renaming was started successfully. */
+ bool begin_renaming();
+ void end_renaming();
+ Span<char> get_rename_buffer() const;
+ MutableSpan<char> get_rename_buffer();
+
protected:
AbstractView() = default;