/* Copyright (c) 2022 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #ifndef __DocumentFilesystemInterface_H__ #define __DocumentFilesystemInterface_H__ #ifdef __cplusplus extern "C" { #endif typedef struct DocumentFilesystemInterface DocumentFilesystemInterface; #define DocumentFilesystemInterface_superclass StemObject #include "stemobject/StemObject.h" #include #define DocumentFilesystemInterface_ivars \ StemObject_ivars \ \ char * openTypeDescriptionString; \ unsigned int openExtensionCount; \ char ** openExtensions; \ char * saveTypeDescriptionString; \ unsigned int saveExtensionCount; \ char ** saveExtensions; \ char * fileName; \ char * directory; \ bool fileExists; \ unsigned int preferredSaveExtensionIndex; #define DocumentFilesystemInterface_vtable(self_type) \ StemObject_vtable(self_type) stemobject_declare(DocumentFilesystemInterface) // typeDescription is a human-readable string describing the type of file being represented, such as // "Image files", "Audio files", etc. to be shown in file dialogs on some platforms. If applicable, // the provided list of extensions will automatically be appended. // preferredExtension is the primary file extension used for the represented file type. // Additional arguments are alternate extensions that can also be used to save or load the file. DocumentFilesystemInterface * DocumentFilesystemInterface_create(const char * typeDescription, const char * preferredExtension, ...) __attribute__((sentinel)); DocumentFilesystemInterface * DocumentFilesystemInterface_vcreate(const char * typeDescription, const char * preferredExtension, va_list args); DocumentFilesystemInterface * DocumentFilesystemInterface_createWithSeparateTypes(const char * openTypeDescription, unsigned int openExtensionCount, const char ** openExtensions, const char * saveTypeDescription, unsigned int saveExtensionCount, const char ** saveExtensions); bool DocumentFilesystemInterface_init(DocumentFilesystemInterface * self, const char * typeDescription, const char * preferredExtension, ...) __attribute__((sentinel)); bool DocumentFilesystemInterface_vinit(DocumentFilesystemInterface * self, const char * typeDescription, const char * preferredExtension, va_list args); bool DocumentFilesystemInterface_initWithSeparateTypes(DocumentFilesystemInterface * self, const char * openTypeDescription, unsigned int openExtensionCount, const char ** openExtensions, const char * saveTypeDescription, unsigned int saveExtensionCount, const char ** saveExtensions); void DocumentFilesystemInterface_dispose(DocumentFilesystemInterface * self); bool DocumentFilesystemInterface_showOpenFileDialog(DocumentFilesystemInterface * self, const char * title, const char ** outFilePath); bool DocumentFilesystemInterface_showOpenFileDialogMultiple(DocumentFilesystemInterface * self, const char * title, unsigned int * outFilePathCount, const char *** outFilePaths); bool DocumentFilesystemInterface_showSaveFileDialog(DocumentFilesystemInterface * self, const char * title, const char ** outFilePath); void DocumentFilesystemInterface_setFileName(DocumentFilesystemInterface * self, const char * fileName); void DocumentFilesystemInterface_setDirectory(DocumentFilesystemInterface * self, const char * directory); void DocumentFilesystemInterface_setFilePath(DocumentFilesystemInterface * self, const char * filePath); const char * DocumentFilesystemInterface_getFilePath(DocumentFilesystemInterface * self); // Call when document no longer has disk representation (after initializing a new document, etc.) void DocumentFilesystemInterface_resetFile(DocumentFilesystemInterface * self); // Call after document has been loaded or saved, and the in-memory representation matches the on-disk representation void DocumentFilesystemInterface_fileOnDisk(DocumentFilesystemInterface * self, const char * filePath); // Sets the default extension to assign when showing a save file dialog. extension must be one of the strings in // saveExtensions; otherwise, this function will have no effect. void DocumentFilesystemInterface_setPreferredExtension(DocumentFilesystemInterface * self, const char * extension); #ifdef __cplusplus } #endif #endif