Document settings would not be read using document’s path

A document has both a virtual and an actual path. The virtual path is relevant e.g. when opening files via rmate, where we want to lookup file-type specific settings based on the remote path (filename) rather than the local temporary file. However, if there is no virtual path, we should fallback on the actual path, which broke when we made document_t a wrapper for OakDocument.

There is now a new logical_path getter which return the virtual path and fallback on the actual path.

Closes textmate/bugs#21
This commit is contained in:
Allan Odgaard
2016-07-06 16:46:07 +02:00
parent 4843ca3e1a
commit 665ad94892
3 changed files with 9 additions and 7 deletions

View File

@@ -469,7 +469,7 @@ namespace
{
if(doc->is_modified() && doc->path() != NULL_STR)
{
settings_t const settings = settings_for_path(doc->virtual_path(), doc->file_type(), path::parent(doc->path()));
settings_t const settings = settings_for_path(doc->logical_path(), doc->file_type(), path::parent(doc->path()));
if(settings.get(kSettingsSaveOnBlurKey, false))
{
if(doc == _selectedDocument)
@@ -866,7 +866,7 @@ namespace
{
document::document_ptr doc = document::create(to_s([url path]));
doc->set_file_type(fileType);
auto const settings = settings_for_path(doc->virtual_path(), doc->file_type(), path::parent(doc->path()));
auto const settings = settings_for_path(doc->logical_path(), doc->file_type(), path::parent(doc->path()));
doc->set_indent(text::indent_t(std::max(1, settings.get(kSettingsTabSizeKey, 4)), SIZE_T_MAX, settings.get(kSettingsSoftTabsKey, false)));
[self insertDocuments:{ doc } atIndex:_selectedTabIndex + 1 selecting:doc andClosing:[self disposableDocument]];
@@ -1322,7 +1322,7 @@ namespace
map["projectDirectory"] = to_s(self.projectPath);
std::string docDirectory = _selectedDocument->path() != NULL_STR ? path::parent(_selectedDocument->path()) : to_s(self.untitledSavePath);
settings_t const settings = settings_for_path(_selectedDocument->virtual_path(), _selectedDocument->file_type() + " " + to_s(self.scopeAttributes), docDirectory, map);
settings_t const settings = settings_for_path(_selectedDocument->logical_path(), _selectedDocument->file_type() + " " + to_s(self.scopeAttributes), docDirectory, map);
self.window.title = [NSString stringWithCxxString:settings.get(kSettingsWindowTitleKey, to_s(self.documentDisplayName))];
}
else
@@ -2233,7 +2233,7 @@ namespace
if(self.projectPath)
map["projectDirectory"] = to_s(self.projectPath);
settings_t const settings = settings_for_path(_selectedDocument->virtual_path(), _selectedDocument->file_type() + " " + to_s(self.scopeAttributes), path::parent(documentPath), map);
settings_t const settings = settings_for_path(_selectedDocument->logical_path(), _selectedDocument->file_type() + " " + to_s(self.scopeAttributes), path::parent(documentPath), map);
std::string const customCandidate = settings.get(kSettingsRelatedFilePathKey, NULL_STR);
if(customCandidate != NULL_STR && customCandidate != documentPath && (std::find_if(_documents.begin(), _documents.end(), [&customCandidate](document::document_ptr const& doc){ return customCandidate == doc->path(); }) != _documents.end() || path::exists(customCandidate)))

View File

@@ -247,7 +247,7 @@ struct document_view_t : ng::buffer_api_t
_editor->set_find_clipboard(get_clipboard(NSFindPboard));
_editor->set_replace_clipboard(get_clipboard(OakReplacePboard));
settings_t const settings = settings_for_path(_document->virtual_path(), _document->file_type() + " " + scopeAttributes, path::parent(_document->path()));
settings_t const settings = settings_for_path(_document->logical_path(), _document->file_type() + " " + scopeAttributes, path::parent(_document->path()));
invisibles_map = settings.get(kSettingsInvisiblesMapKey, "");
bool softWrap = settings.get(kSettingsSoftWrapKey, false);
@@ -289,6 +289,7 @@ struct document_view_t : ng::buffer_api_t
oak::uuid_t identifier () const { return _document->identifier(); }
std::string path () const { return _document->path(); }
std::string virtual_path () const { return _document->virtual_path(); }
std::string logical_path () const { return _document->logical_path(); }
std::string file_type () const { return _document->file_type(); }
void set_file_type (std::string const& newType) { _document->set_file_type(newType); }
@@ -1748,7 +1749,7 @@ doScroll:
res << [self.delegate variables];
res = bundles::scope_variables(res, [self scopeContext]);
res = variables_for_path(res, documentView->virtual_path(), [self scopeContext].right, path::parent(documentView->path()));
res = variables_for_path(res, documentView->logical_path(), [self scopeContext].right, path::parent(documentView->path()));
return res;
}
@@ -1805,7 +1806,7 @@ doScroll:
case bundles::kItemTypeGrammar:
{
documentView->set_file_type(item->value_for_field(bundles::kFieldGrammarScope));
file::set_type(documentView->virtual_path(), item->value_for_field(bundles::kFieldGrammarScope));
file::set_type(documentView->logical_path(), item->value_for_field(bundles::kFieldGrammarScope));
}
break;
}

View File

@@ -87,6 +87,7 @@ namespace document
oak::uuid_t identifier () const;
std::string path () const;
std::string virtual_path () const;
std::string logical_path () const { return virtual_path() == NULL_STR ? path() : virtual_path(); }
std::string custom_name () const;
std::string backup_path () const;
std::string display_name () const;