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:
authorSybren A. Stüvel <sybren@blender.org>2021-10-19 19:07:22 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-10-19 19:07:22 +0300
commit823996b0342b7352fc5b2e24eceb6204612438cd (patch)
tree08dca1ce5386c2b06ab01fad1f2f1ac5c236047a /source/blender/editors/asset
parentb6c3b41d413813d8059476f2c0357b7a4e51ad22 (diff)
Asset Browser: Improved workflow for asset catalog saving
No longer save asset catalogs on blendfile save. Instead: - extend the confirmation prompt for unsaved changes to show unsaved catalogs. - In the confirmation prompt, make catalog saving explicit & optional, just like we do it for external images. {F10881736} - In the Asset Browser catalog tree, show an operator icon to save the catalogs to disk. It's grayed out if there are no changes to save, or if the .blend wasn't saved yet (required to know where to save the catalog definitions to). {F10881743} Much of the work was done by @Severin and reviewed by me, then we swapped roles. Reviewed By: Severin Differential Revision: https://developer.blender.org/D12796
Diffstat (limited to 'source/blender/editors/asset')
-rw-r--r--source/blender/editors/asset/CMakeLists.txt1
-rw-r--r--source/blender/editors/asset/ED_asset_catalog.h39
-rw-r--r--source/blender/editors/asset/ED_asset_catalog.hh4
-rw-r--r--source/blender/editors/asset/intern/asset_catalog.cc54
-rw-r--r--source/blender/editors/asset/intern/asset_ops.cc57
5 files changed, 152 insertions, 3 deletions
diff --git a/source/blender/editors/asset/CMakeLists.txt b/source/blender/editors/asset/CMakeLists.txt
index b6657bfca63..9017f136319 100644
--- a/source/blender/editors/asset/CMakeLists.txt
+++ b/source/blender/editors/asset/CMakeLists.txt
@@ -41,6 +41,7 @@ set(SRC
intern/asset_ops.cc
intern/asset_temp_id_consumer.cc
+ ED_asset_catalog.h
ED_asset_catalog.hh
ED_asset_filter.h
ED_asset_handle.h
diff --git a/source/blender/editors/asset/ED_asset_catalog.h b/source/blender/editors/asset/ED_asset_catalog.h
new file mode 100644
index 00000000000..451ec0d5984
--- /dev/null
+++ b/source/blender/editors/asset/ED_asset_catalog.h
@@ -0,0 +1,39 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup edasset
+ */
+
+#pragma once
+
+#include "BLI_utildefines.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct Main;
+struct AssetLibrary;
+
+void ED_asset_catalogs_save_from_main_path(struct AssetLibrary *library, const struct Main *bmain);
+
+void ED_asset_catalogs_set_save_catalogs_when_file_is_saved(bool should_save);
+bool ED_asset_catalogs_get_save_catalogs_when_file_is_saved(void);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/editors/asset/ED_asset_catalog.hh b/source/blender/editors/asset/ED_asset_catalog.hh
index cffd7728a60..8b8fc4d3574 100644
--- a/source/blender/editors/asset/ED_asset_catalog.hh
+++ b/source/blender/editors/asset/ED_asset_catalog.hh
@@ -33,3 +33,7 @@ blender::bke::AssetCatalog *ED_asset_catalog_add(AssetLibrary *library,
blender::StringRefNull name,
blender::StringRef parent_path = nullptr);
void ED_asset_catalog_remove(AssetLibrary *library, const blender::bke::CatalogID &catalog_id);
+
+void ED_asset_catalog_rename(AssetLibrary *library,
+ blender::bke::CatalogID catalog_id,
+ blender::StringRefNull new_name);
diff --git a/source/blender/editors/asset/intern/asset_catalog.cc b/source/blender/editors/asset/intern/asset_catalog.cc
index 056fda63bd7..f8b33e76447 100644
--- a/source/blender/editors/asset/intern/asset_catalog.cc
+++ b/source/blender/editors/asset/intern/asset_catalog.cc
@@ -21,11 +21,15 @@
#include "BKE_asset_catalog.hh"
#include "BKE_asset_catalog_path.hh"
#include "BKE_asset_library.hh"
+#include "BKE_main.h"
#include "BLI_string_utils.h"
+#include "ED_asset_catalog.h"
#include "ED_asset_catalog.hh"
+#include "WM_api.h"
+
using namespace blender;
using namespace blender::bke;
@@ -67,7 +71,13 @@ AssetCatalog *ED_asset_catalog_add(::AssetLibrary *library,
AssetCatalogPath fullpath = AssetCatalogPath(parent_path) / unique_name;
catalog_service->undo_push();
- return catalog_service->create_catalog(fullpath);
+ catalog_service->tag_has_unsaved_changes();
+ bke::AssetCatalog *new_catalog = catalog_service->create_catalog(fullpath);
+ if (!new_catalog) {
+ return nullptr;
+ }
+
+ return new_catalog;
}
void ED_asset_catalog_remove(::AssetLibrary *library, const CatalogID &catalog_id)
@@ -79,5 +89,47 @@ void ED_asset_catalog_remove(::AssetLibrary *library, const CatalogID &catalog_i
}
catalog_service->undo_push();
+ catalog_service->tag_has_unsaved_changes();
catalog_service->prune_catalogs_by_id(catalog_id);
}
+
+void ED_asset_catalog_rename(::AssetLibrary *library,
+ const CatalogID catalog_id,
+ const StringRefNull new_name)
+{
+ bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service(library);
+ if (!catalog_service) {
+ BLI_assert_unreachable();
+ return;
+ }
+
+ const AssetCatalog *catalog = catalog_service->find_catalog(catalog_id);
+
+ AssetCatalogPath new_path = catalog->path.parent();
+ new_path = new_path / StringRef(new_name);
+
+ catalog_service->undo_push();
+ catalog_service->tag_has_unsaved_changes();
+ catalog_service->update_catalog_path(catalog_id, new_path);
+}
+
+void ED_asset_catalogs_save_from_main_path(::AssetLibrary *library, const Main *bmain)
+{
+ bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service(library);
+ if (!catalog_service) {
+ BLI_assert_unreachable();
+ return;
+ }
+
+ catalog_service->write_to_disk(bmain->name);
+}
+
+void ED_asset_catalogs_set_save_catalogs_when_file_is_saved(const bool should_save)
+{
+ bke::AssetLibrary::save_catalogs_when_file_is_saved = should_save;
+}
+
+bool ED_asset_catalogs_get_save_catalogs_when_file_is_saved()
+{
+ return bke::AssetLibrary::save_catalogs_when_file_is_saved;
+}
diff --git a/source/blender/editors/asset/intern/asset_ops.cc b/source/blender/editors/asset/intern/asset_ops.cc
index 33a22775280..834874abc19 100644
--- a/source/blender/editors/asset/intern/asset_ops.cc
+++ b/source/blender/editors/asset/intern/asset_ops.cc
@@ -22,6 +22,7 @@
#include "BKE_asset_library.hh"
#include "BKE_context.h"
#include "BKE_lib_id.h"
+#include "BKE_main.h"
#include "BKE_report.h"
#include "BLI_string_ref.hh"
@@ -398,7 +399,8 @@ static int asset_catalog_new_exec(bContext *C, wmOperator *op)
MEM_freeN(parent_path);
- WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr);
+ WM_event_add_notifier_ex(
+ CTX_wm_manager(C), CTX_wm_window(C), NC_ASSET | ND_ASSET_CATALOGS, nullptr);
return OPERATOR_FINISHED;
}
@@ -436,7 +438,8 @@ static int asset_catalog_delete_exec(bContext *C, wmOperator *op)
MEM_freeN(catalog_id_str);
- WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr);
+ WM_event_add_notifier_ex(
+ CTX_wm_manager(C), CTX_wm_window(C), NC_ASSET | ND_ASSET_CATALOGS, nullptr);
return OPERATOR_FINISHED;
}
@@ -561,6 +564,55 @@ static void ASSET_OT_catalog_undo_push(struct wmOperatorType *ot)
/* -------------------------------------------------------------------- */
+static bool asset_catalogs_save_poll(bContext *C)
+{
+ if (!asset_catalog_operator_poll(C)) {
+ return false;
+ }
+
+ const Main *bmain = CTX_data_main(C);
+ if (!bmain->name[0]) {
+ CTX_wm_operator_poll_msg_set(C, "Cannot save asset catalogs before the Blender file is saved");
+ return false;
+ }
+
+ if (!BKE_asset_library_has_any_unsaved_catalogs()) {
+ CTX_wm_operator_poll_msg_set(C, "No changes to be saved");
+ return false;
+ }
+
+ return true;
+}
+
+static int asset_catalogs_save_exec(bContext *C, wmOperator * /*op*/)
+{
+ const SpaceFile *sfile = CTX_wm_space_file(C);
+ ::AssetLibrary *asset_library = ED_fileselect_active_asset_library_get(sfile);
+
+ ED_asset_catalogs_save_from_main_path(asset_library, CTX_data_main(C));
+
+ WM_event_add_notifier_ex(
+ CTX_wm_manager(C), CTX_wm_window(C), NC_ASSET | ND_ASSET_CATALOGS, nullptr);
+
+ return OPERATOR_FINISHED;
+}
+
+static void ASSET_OT_catalogs_save(struct wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Save Asset Catalogs";
+ ot->description =
+ "Make any edits to any catalogs permanent by writing the current set up to the asset "
+ "library";
+ ot->idname = "ASSET_OT_catalogs_save";
+
+ /* api callbacks */
+ ot->exec = asset_catalogs_save_exec;
+ ot->poll = asset_catalogs_save_poll;
+}
+
+/* -------------------------------------------------------------------- */
+
void ED_operatortypes_asset(void)
{
WM_operatortype_append(ASSET_OT_mark);
@@ -568,6 +620,7 @@ void ED_operatortypes_asset(void)
WM_operatortype_append(ASSET_OT_catalog_new);
WM_operatortype_append(ASSET_OT_catalog_delete);
+ WM_operatortype_append(ASSET_OT_catalogs_save);
WM_operatortype_append(ASSET_OT_catalog_undo);
WM_operatortype_append(ASSET_OT_catalog_redo);
WM_operatortype_append(ASSET_OT_catalog_undo_push);