From a05088f9be98718dca533d369db3dfaea97e51f3 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Mon, 29 Jul 2013 13:56:15 +0200 Subject: [PATCH] Document from content now sets file type and tab settings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Presently we also set file type (and thus indirectly indent settings) when “opening” a document, but I wish to remove that code, so that one can create a document, set all desired settings, and not worry about later code overwriting these settings. --- Frameworks/document/src/document.cc | 9 ++++++++- Frameworks/document/src/document.h | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) 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 =