mirror of
https://github.com/textmate/textmate.git
synced 2026-01-20 04:08:04 -05:00
Document from content now sets file type and tab settings
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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user