2023-12-09 05:06:10 +01:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
|
2024-01-05 05:35:29 +01:00
|
|
|
#include "BLI_span.hh"
|
|
|
|
#include "BLI_string_ref.hh"
|
2023-12-09 05:06:10 +01:00
|
|
|
#include "BLI_vector.hh"
|
|
|
|
|
|
|
|
#include "DNA_windowmanager_types.h"
|
|
|
|
|
|
|
|
#include "RNA_types.hh"
|
|
|
|
|
2024-01-04 21:07:48 +01:00
|
|
|
struct bContext;
|
|
|
|
|
2024-01-05 05:35:29 +01:00
|
|
|
namespace blender::bke {
|
|
|
|
|
2023-12-09 05:06:10 +01:00
|
|
|
#define FH_MAX_FILE_EXTENSIONS_STR 512
|
|
|
|
|
|
|
|
struct FileHandlerType {
|
|
|
|
/** Unique name. */
|
|
|
|
char idname[OP_MAX_TYPENAME];
|
|
|
|
/** For UI text. */
|
|
|
|
char label[OP_MAX_TYPENAME];
|
|
|
|
/** Import operator name. */
|
|
|
|
char import_operator[OP_MAX_TYPENAME];
|
|
|
|
/** Formatted string of file extensions supported by the file handler, each extension should
|
|
|
|
* start with a `.` and be separated by `;`. For Example: `".blend;.ble"`. */
|
|
|
|
char file_extensions_str[FH_MAX_FILE_EXTENSIONS_STR];
|
|
|
|
|
|
|
|
/** Check if file handler can be used on file drop. */
|
2024-01-04 21:07:48 +01:00
|
|
|
bool (*poll_drop)(const bContext *C, FileHandlerType *file_handle_type);
|
2023-12-09 05:06:10 +01:00
|
|
|
|
|
|
|
/** List of file extensions supported by the file handler. */
|
2024-01-05 05:35:29 +01:00
|
|
|
Vector<std::string> file_extensions;
|
2023-12-09 05:06:10 +01:00
|
|
|
|
|
|
|
/** RNA integration. */
|
|
|
|
ExtensionRNA rna_ext;
|
2024-01-06 03:51:45 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a vector of indices in #paths of file paths supported by the file handler.
|
|
|
|
*/
|
|
|
|
blender::Vector<int64_t> filter_supported_paths(const blender::Span<std::string> paths) const;
|
2023-12-09 05:06:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a new `file_handler` to the `file_handlers` list, also loads all the file extensions from
|
|
|
|
* the formatted `FileHandlerType.file_extensions_str` string to `FileHandlerType.file_extensions`
|
|
|
|
* list.
|
|
|
|
*
|
|
|
|
* The new `file_handler` is expected to have a unique `FileHandlerType.idname`.
|
|
|
|
*/
|
2024-01-05 05:35:29 +01:00
|
|
|
void file_handler_add(std::unique_ptr<FileHandlerType> file_handler);
|
2023-12-09 05:06:10 +01:00
|
|
|
|
|
|
|
/** Returns a `file_handler` that have a specific `idname`, otherwise return `nullptr`. */
|
2024-01-05 05:35:29 +01:00
|
|
|
FileHandlerType *file_handler_find(StringRef idname);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes and frees a specific `file_handler` from the `file_handlers` list, the `file_handler`
|
|
|
|
* pointer will be not longer valid for use.
|
|
|
|
*/
|
|
|
|
void file_handler_remove(FileHandlerType *file_handler);
|
2023-12-09 05:06:10 +01:00
|
|
|
|
2024-01-05 05:35:29 +01:00
|
|
|
/** Return pointers to all registered file handlers. */
|
|
|
|
Span<std::unique_ptr<FileHandlerType>> file_handlers();
|
2023-12-09 05:06:10 +01:00
|
|
|
|
2024-01-06 03:51:45 +01:00
|
|
|
/**
|
|
|
|
* Return a vector of file handlers that support any file path in `paths` and the call to
|
|
|
|
* `poll_drop` returns #true. Caller must check if each file handler have a valid
|
|
|
|
* `import_operator`.
|
|
|
|
*/
|
|
|
|
blender::Vector<FileHandlerType *> file_handlers_poll_file_drop(
|
|
|
|
const bContext *C, const blender::Span<std::string> paths);
|
|
|
|
|
2024-01-05 05:35:29 +01:00
|
|
|
} // namespace blender::bke
|