Commit Graph

324 Commits

Author SHA1 Message Date
Hans Goudey d5a61a8f55 Fix: Missing early return when asset isn't found
This didn't cause a crash since `resolve_asset_weak_reference_to_full_path`
doesn't actually use the `this` pointer, but it's still quite unsafe.
2024-03-28 13:43:20 -04:00
Hans Goudey a7cdb9e94d Cleanup: Use "this" keyword to access class methods 2024-03-28 13:43:20 -04:00
Campbell Barton 115f8b0c59 Cleanup: clarify variable being iterated over, avoid shadowing 2024-03-28 13:45:20 +11:00
Hans Goudey aae9446599 Cleanup: Remove unnecessary "using namespace"
This file is in the blender namespace already
2024-03-27 20:19:23 -04:00
Hans Goudey fc06dc31d8 Cleanup: Sort forward declaration lists, remove duplicate 2024-03-27 20:19:23 -04:00
Hans Goudey acd1b0b7f9 Refactor: Use C++ Vector for RNA/context collection retrieval
Previously retrieving a collection from the context like "selected_ids"
would give a linked list of allocated items. Now it returns a vector of
RNA pointers. Though the number of items is typically fairly small,
using contiguous memory and avoiding many small allocations are
typical performance improvements that could still be beneficial
when there are many items. Iteration also becomes much simpler.

Pull Request: https://projects.blender.org/blender/blender/pulls/119939
2024-03-27 00:47:39 +01:00
Hans Goudey efee753e8f Cleanup: Move BKE_idprop.h to C++ 2024-03-26 13:07:04 -04:00
Hans Goudey f41ab9abc1 Cleanup: Combine BKE_idprop C and C++ headers
In preparation for moving the whole BKE_idprop.h to C++.
To keep the git history intact we remove the newer smaller file.
2024-03-26 13:07:04 -04:00
Campbell Barton 155dae94d7 Cleanup: code-comments, use doxygen formatting & spelling corrections
Also move some function doc-strings from the implementation
to their declarations.
2024-03-26 17:55:20 +11:00
Pratik Borhade 209db414e0 Fix #119860: Undo crash in asset browser poll function
`asset_lib` is null when calling undo in active file browser space.
This causes crash in `asset undo poll`. So exit out of the poll function
when active file space is filebrowser.

Pull Request: https://projects.blender.org/blender/blender/pulls/119870
2024-03-25 14:00:38 +01:00
Julian Eisel 0d7ac2542e Merge branch 'blender-v4.1-release' 2024-03-18 19:37:56 +01:00
Julian Eisel 745fd2a2cb Fix: Tree-view items always collapsed by default
Since 660867fa00, having tree-view items uncollapsed by default using
the `set_collapsed()` functions wouldn't work anymore. An attempt to do
this would assert even, so eb71d9f7bc disabled the assert.

I think a function designed to handle exactly this is the best solution,
it makes the intent & behavior more clear than before, and highlights
that this is a special case.

Mitigates #117957, in that it solves the regression, but tree-views still
don't remember their state on screen-layout changes. This is a known
limitation and not supported.

Pull Request: https://projects.blender.org/blender/blender/pulls/119166
2024-03-18 19:32:53 +01:00
Brecht Van Lommel 7a395e2e7f Revert changes from main commits that were merged into blender-v4.1-release
The last good commit was f57e4c5b98.

After this one more fix was committed, this one is preserved as well:
67bd678887.
2024-03-18 15:04:12 +01:00
Hans Goudey b5082f6640 Refactor: Simplify BLI_serialize.hh for asset indexer
- Remove the unnecessary `ContainerValue` from the class hierarchy
- Construct `StringValue` with a `std::string` by value to avoid copies
- Remove some indirection by using type names directly instead of aliases
- Use utility methods to lookup/append specific data types for arrays/dicts
- Simplify conversion from unique_ptr to shared_ptr
- Avoid use of `new` and `delete`
- Avoid creating maps of all elements in vector for a single lookup
2024-03-13 14:52:57 -04:00
Hans Goudey ae12c1bd92 Refactor: Remove unnecessary indirection from classes in asset indexer
The `AssetEntryReader` and `AssetEntryWriter` classes were only used
once and just added indirection hiding the actual logic of reading and writing
asset metadata from the index. It also hid double map lookups and extra
string copies/allocations.
2024-03-13 14:52:57 -04:00
Hans Goudey 24c9f736ff Cleanup: Follow style guide for use of "this" in classes
Also simplify iteration over map keys and slightly simplify string hash.
2024-03-13 14:52:57 -04:00
Hans Goudey 6b671c4b54 Cleanup: Use simpler lambda capture
It's typically only worth specifying specific captures when the lambda
is stored as a function object for use later. Since this is just passed
as a FunctionRef as an iteration callback, we can use a less complex
capture here. That also helps clarify that this isn't a callback.
2024-03-13 10:42:00 -04:00
Hans Goudey 4e196f916c Cleanup: Remove unnecessary AssetListStorage class
This class was just used to hold some functions which can just as well
be declared static outside of any class. It was never even instantiated.
Removing the class removes some indirection in this file that made
the code less readability, and avoids misleading readers.

Pull Request: https://projects.blender.org/blender/blender/pulls/119137
2024-03-07 18:56:24 +01:00
Hans Goudey ddc9dcce86 Cleanup: Remove unnecessary AssetLibraryReferenceWrapper class
This class was used to make `AssetLibraryReference` work as a key
in `Map`. But defining a class for that is unnecessary. Instead it's
simpler to just declare the equals and hash operators separately.
Reducing the number of wrappers and indirections should make
this code slightly easier to understand.
2024-03-07 09:30:22 -05:00
Hans Goudey eb8557f8a7 Cleanup: Use snake case for function names in file list 2024-03-06 14:31:51 -05:00
Campbell Barton 76867ad4c2 Cleanup: redundant "void" in function declarations for C++ 2024-03-05 11:25:35 +11:00
Hans Goudey d29ce3d531 UI: Remove uiBut a1 and a2 values
Over the last couple years (!) UI buttons have moved to derived classes,
meaning we don't need to use the same "a1" and "a2" variables to store
different information. At this point, that information is set specifically
by internal UI code, or functions like `UI_but_*_set`.

These values are only set to their default 0 values now (or -1 in some
non-meaningful cases). This commit removes the values from buttons
and removes the remaining a1 and a2 arguments from the UI API.
2024-03-01 14:27:57 -05:00
Julian Eisel 4cc1c65272 Refactor: Make asset catalog service non-public, access through API
Making the member private (or at least protected) makes threat safety
more tangible, and we don't need to expose locking in the API. Generally
we need to make data more encapsulated, so we can make edits more
controlled and threat safe.

Asset libraries also always have a catalog-service, so it can accessed
by reference, rather than pointer that would have to be null-checked.
2024-02-29 17:12:08 +01:00
Julian Eisel 30ef07867e UI: Remove excessive padding in asset shelf catalog selector tree
Affects the catalog tree found in the catalog selector popup in the
asset shelf.

Looks like this added the padding for indented items without children
twice, which was misleading (because it would look like items were
nested deeper than siblings with children). I think it was added twice
since 2e02c0c515, which changed how tree view indentation is done.
2024-02-29 12:24:55 +01:00
Julian Eisel 2bfaf94fa7 Refactor: Lazy create & update asset catalog trees
Rebuilding the tree immediately after changes could cause the tree to be
rebuilt multiple times. More importantly, it made it harder to reason
about thread safety, since we would touch the tree within a whole bunch
of API functions. Now tree building is simplified and managed in a
single place, so making the tree building thread safe can be made
trivially in a follow-up.

Note, this means the initial catalog tree building doesn't happen in a
background thread together with loading the asset library and catalogs
anymore. But we would already do all further rebuilds on the main thread
anyway, this shouldn't have any notable impact.
2024-02-26 10:35:15 +01:00
Julian Eisel 57dfc2a885 Cleanup: Make catalog tree const-correct
Basic motivation is that `AssetCatalogService::get_catalog_tree()`
should return a const tree, since this tree is internal state and
shouldn't be modified from outside. This exposed a whole bunch of const
incorrectnesses and just generally allows to make much more of the API
const (as it should be).

Also use references instead of pointers in testing functions, where null
is not an expected value.
2024-02-23 18:13:10 +01:00
Julian Eisel b07506c87b Fix unintentional copies of asset catalog tree items in asset shelf
The asset catalog selector tree-view would store a copy of each of the
items in the catalog tree, including all of its sub-hierarchy. This can
be avoided, it can just use a reference.
2024-02-23 18:13:10 +01:00
Hans Goudey eb484188dd Cleanup: Move asset filter settings out of DNA
There's no reason for this struct to be declared in DNA when it isn't
saved to files.

Pull Request: https://projects.blender.org/blender/blender/pulls/118285
2024-02-21 14:23:17 +01:00
Julian Eisel 99673edd85 Cleanup: Add method to get UUID as std::string
Avoids having to use the C-style `BLI_uuid_format()` function with
manual buffer management, and makes it easy to get a `std::string` from
a UUID.
2024-02-20 15:20:11 +01:00
Hans Goudey 8ab23f0a6e Assets: Return weak reference by value from asset representation
This is generally more flexible and less error prone. The struct
implements a proper descructorfor this anyway. That also makes the
separate free function unnecessary-- it's redundant with the destructor.
2024-02-16 12:02:08 -05:00
Hans Goudey 61e61ce0e1 Cleanup: Use Span instead of Vector const reference
Span is preferrable since it's agnostic of the source container,
makes it clearer that there is no ownership, is 8 bytes smaller,
and can be passed by value.
2024-02-14 17:23:01 -05:00
Hans Goudey 57586df687 Cleanup: Remove unnecessary asset system functions
These functions appear to be thin wrappers around the C++ classes
that previously weren't accessible in C code.
2024-02-14 17:23:01 -05:00
Campbell Barton b372ebae68 Cleanup: unused headers for source/blender/editors
Remove 1317 includes from editors.
2024-02-13 10:02:53 +11:00
Campbell Barton 39f0dbf47a Cleanup: use FILE_MAX instead of PATH_MAX for operators
FILE_MAX is used by operators, avoid an MSVC specific include.
2024-02-13 09:19:47 +11:00
Julian Eisel 4f68fa453f Fix compiling after previous fix in release branch 2024-02-12 19:51:56 +01:00
Julian Eisel 0ffe2d4848 Merge branch 'blender-v4.1-release' 2024-02-12 19:51:40 +01:00
Julian Eisel d54a1b0364 Fix asset indexer string shortening breaking UTF-8 strings
Would shorten the string without ensuring the string isn't shortened in
the middle of a multi-byte UTF-8 character.
2024-02-12 19:25:20 +01:00
Bastien Montagne 29fe777445 Cleanup: Make `BKE_report.h` a full Cpp header. 2024-02-10 18:34:29 +01:00
Bastien Montagne 54618dbae3 Cleanup: Make `BKE_global.h` a Cpp header. 2024-02-10 18:25:14 +01:00
Bastien Montagne a9b2cf8ce6 Cleanup: Move `BKE_path.h` to CPP header. 2024-02-09 19:23:03 +01:00
Bastien Montagne 45e7827898 Clenup: Move BLT headers to Cpp.
Noisy but fairly straight forward.
2024-02-09 18:59:42 +01:00
Hans Goudey 91e54fdd83 Cleanup: Move BLO_readfile.h to C++
I added a new BLO_userdef_default.h header to contain declarations of
two global variables that are still defined in C files. Use of designated
initializers for large structs make those files harder to change.
Arguably this is a better header for them anyway.

Pull Request: https://projects.blender.org/blender/blender/pulls/118015
2024-02-09 13:41:30 +01:00
Hans Goudey 7f5f37ea65 Cleanup: Simplify asset metadata copying
Use `BLI_strdupn` instead of repeating the same logic a bunch of times.
Use StringRef where StringRefNull isn't necessary, and use StringRefNull
instead of a std::string reference in one case.
2024-02-08 14:51:01 -05:00
Hans Goudey df8c85d3f9 Cleanup: UI Remove more unnecessary a1 and a2 parameters
Similar to 5155feeeb8. These had values without any meeting,
almost completely just 0 or -1 (which meant "find good values if possible"
anyway).
2024-02-05 14:38:11 -05:00
Hans Goudey cfb4e5a25d Cleanup: Store asset shelf types in vector of unique_ptr
This avoids the need for manual memory management/raw pointers,
improves const correctness, improves type safety, simplifies iteration,
and simplifies the process of registering a new asset shelf type.

Pull Request: https://projects.blender.org/blender/blender/pulls/117770
2024-02-05 16:23:57 +01:00
Hans Goudey 1a0214471b Fix: Missing translation for asset catalog tooltip
Also remove an unnecessary c_str() call.
2024-02-01 13:09:04 -05:00
Hans Goudey 809499a3d0 Refactor: UI: Use derived struct for number slider buttons
Similar to d204830107. This is the last real use of
the a1 and a2 arguments for many button definition functions.
2024-02-01 13:08:50 -05:00
Hans Goudey ed500d93b4 Cleanup: Pass const context to asset function 2024-01-31 21:18:09 -05:00
Hans Goudey 02895d342c Cleanup: Small changes to asset shelf code
- Remove unnecessary use of "shelf" namespace inside that namespace
- Remove unused function declaration
- Don't bother passing a pointer to a pointer to the region data,
  that didn't accomplish anything and added unnecessary complexity
2024-01-31 14:25:21 -05:00
Hans Goudey fb0d6198c0 Cleanup: Move remaining asset editors code to C++ namespace 2024-01-26 18:43:13 -05:00