diff --git a/Frameworks/document/src/document.cc b/Frameworks/document/src/document.cc index b67c3d32..61aea1a7 100644 --- a/Frameworks/document/src/document.cc +++ b/Frameworks/document/src/document.cc @@ -338,12 +338,19 @@ namespace document document_ptr create (std::string const& path, path::identifier_t const& key) { return documents.create(path, key); } document_ptr find (oak::uuid_t const& uuid, bool searchBackups) { return documents.find(uuid, searchBackups); } - document_ptr from_content (std::string const& content, std::string const& fileType) + document_ptr from_content (std::string const& content, std::string fileType) { D(DBF_Document, bug("%s\n", fileType.c_str());); + if(fileType == NULL_STR) + fileType = file::type(NULL_STR, io::bytes_ptr(new io::bytes_t(content.data(), content.size(), false))); + document_ptr doc = create(); if(fileType != NULL_STR) doc->set_file_type(fileType); + + auto const settings = settings_for_path(NULL_STR, doc->file_type()); + doc->set_indent(text::indent_t(std::max(1, settings.get(kSettingsTabSizeKey, 4)), SIZE_T_MAX, settings.get(kSettingsSoftTabsKey, false))); + doc->set_content(content); return doc; } diff --git a/Frameworks/document/src/document.h b/Frameworks/document/src/document.h index 12630dbf..695170ba 100644 --- a/Frameworks/document/src/document.h +++ b/Frameworks/document/src/document.h @@ -284,7 +284,7 @@ namespace document // ============== friend document_ptr create (std::string const& path); - friend document_ptr from_content (std::string const& content, std::string const& fileType); + friend document_ptr from_content (std::string const& content, std::string fileType); friend document_ptr find (oak::uuid_t const& uuid, bool searchBackups); oak::uuid_t _identifier; // to identify this document when there is no path @@ -336,7 +336,7 @@ namespace document PUBLIC document_ptr create (std::string const& path = NULL_STR); PUBLIC document_ptr find (oak::uuid_t const& uuid, bool searchBackups = false); - PUBLIC document_ptr from_content (std::string const& content, std::string const& fileType = NULL_STR); + PUBLIC document_ptr from_content (std::string const& content, std::string fileType = NULL_STR); // ==================== // = Document scanner =