mirror of
https://github.com/textmate/textmate.git
synced 2026-01-22 13:17:55 -05:00
Provide TM_SCM_* variables for untitled document
When opening SCM manager folder TM opens untitled document in the editor area and the target folder in file browser. When one sets `windowTitle` to display SCM branch this is not displayed for untitled document. So one needs to open some existing file first. This change sets SCM variables also for untitled document as if it was saved in selected file browser folder, effectively showing current SCM branch.
This commit is contained in:
committed by
Allan Odgaard
parent
088bc09531
commit
4bc81053fe
@@ -372,7 +372,7 @@ OAK_DEBUG_VAR(DocumentController);
|
||||
{
|
||||
[controller->textView performSelector:@selector(applicationDidBecomeActiveNotification:) withObject:aNotification];
|
||||
|
||||
settings_t const& settings = [controller selectedDocument]->settings();
|
||||
settings_t const& settings = [controller selectedDocument]->settings(to_s([controller.untitledSavePath stringByAppendingPathComponent:DefaultSaveNameForDocument([controller selectedDocument])]));
|
||||
controller.windowTitle = [NSString stringWithCxxString:settings.get(kSettingsWindowTitleKey, [controller selectedDocument]->display_name())];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#import <OakAppKit/NSAlert Additions.h>
|
||||
#import <document/collection.h>
|
||||
#import <document/session.h>
|
||||
#import <ns/ns.h>
|
||||
|
||||
OAK_DEBUG_VAR(DocumentController_Tabs);
|
||||
|
||||
@@ -41,7 +42,7 @@ namespace
|
||||
document::schedule_session_backup();
|
||||
|
||||
// This is also set after open succeeds
|
||||
settings_t const& settings = [self selectedDocument]->settings();
|
||||
settings_t const& settings = [self selectedDocument]->settings(to_s([self.untitledSavePath stringByAppendingPathComponent:DefaultSaveNameForDocument([self selectedDocument])]));
|
||||
self.windowTitle = [NSString stringWithCxxString:settings.get(kSettingsWindowTitleKey, [self selectedDocument]->display_name())];
|
||||
self.representedFile = [NSString stringWithCxxString:[self selectedDocument]->path()];
|
||||
self.isDocumentEdited = [self selectedDocument]->is_modified();
|
||||
@@ -76,7 +77,7 @@ namespace
|
||||
D(DBF_DocumentController_Tabs, bug("\n"););
|
||||
if(*aDocument == *[self selectedDocument])
|
||||
{
|
||||
settings_t const& settings = [self selectedDocument]->settings();
|
||||
settings_t const& settings = [self selectedDocument]->settings(to_s([self.untitledSavePath stringByAppendingPathComponent:DefaultSaveNameForDocument([self selectedDocument])]));
|
||||
self.windowTitle = [NSString stringWithCxxString:settings.get(kSettingsWindowTitleKey, [self selectedDocument]->display_name())];
|
||||
self.representedFile = [NSString stringWithCxxString:[self selectedDocument]->path()];
|
||||
self.isDocumentEdited = [self selectedDocument]->is_modified();
|
||||
@@ -283,7 +284,7 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
settings_t const& settings = aDocument->settings();
|
||||
settings_t const& settings = aDocument->settings(to_s([self.untitledSavePath stringByAppendingPathComponent:DefaultSaveNameForDocument(aDocument)]));
|
||||
self.windowTitle = [NSString stringWithCxxString:settings.get(kSettingsWindowTitleKey, aDocument->display_name())];
|
||||
self.representedFile = [NSString stringWithCxxString:aDocument->path()];
|
||||
self.isDocumentEdited = aDocument->is_modified();
|
||||
|
||||
@@ -500,11 +500,13 @@ namespace document
|
||||
return _file_type;
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> document_t::variables (std::map<std::string, std::string> map, bool sourceFileSystem) const
|
||||
std::map<std::string, std::string> document_t::variables (std::map<std::string, std::string> map, bool sourceFileSystem, std::string const& untitledPath) const
|
||||
{
|
||||
map["TM_DISPLAYNAME"] = display_name();
|
||||
map["TM_DOCUMENT_UUID"] = to_s(identifier());
|
||||
|
||||
scm::info_ptr info;
|
||||
|
||||
if(path() != NULL_STR)
|
||||
{
|
||||
map["TM_FILEPATH"] = path();
|
||||
@@ -512,16 +514,20 @@ namespace document
|
||||
map["TM_DIRECTORY"] = path::parent(path());
|
||||
map["PWD"] = path::parent(path());
|
||||
|
||||
if(scm::info_ptr info = scm::info(path()))
|
||||
{
|
||||
std::string const& branch = info->branch();
|
||||
if(branch != NULL_STR)
|
||||
map["TM_SCM_BRANCH"] = branch;
|
||||
info = scm::info(path());
|
||||
}
|
||||
else if(untitledPath != NULL_STR)
|
||||
info = scm::info(untitledPath);
|
||||
|
||||
std::string const& name = info->scm_name();
|
||||
if(name != NULL_STR)
|
||||
map["TM_SCM_NAME"] = name;
|
||||
}
|
||||
if(info)
|
||||
{
|
||||
std::string const& branch = info->branch();
|
||||
if(branch != NULL_STR)
|
||||
map["TM_SCM_BRANCH"] = branch;
|
||||
|
||||
std::string const& name = info->scm_name();
|
||||
if(name != NULL_STR)
|
||||
map["TM_SCM_NAME"] = name;
|
||||
}
|
||||
|
||||
return sourceFileSystem ? variables_for_path(path(), scope(), map) : map;
|
||||
|
||||
@@ -248,9 +248,13 @@ namespace document
|
||||
std::string file_type () const;
|
||||
std::string path_attributes () const { return _path_attributes; }
|
||||
scope::scope_t scope () const { return file_type() + " " + path_attributes(); }
|
||||
settings_t const settings () const { return settings_for_path(virtual_path(), scope(), path::parent(_path), identifier(), variables(std::map<std::string, std::string>(), false)); }
|
||||
|
||||
std::map<std::string, std::string> variables (std::map<std::string, std::string> map, bool sourceFileSystem = true) const;
|
||||
settings_t const settings (std::string const& untitledPath = NULL_STR) const
|
||||
{
|
||||
return settings_for_path(virtual_path(), scope(), path::parent(_path), identifier(), variables(std::map<std::string, std::string>(), false, untitledPath));
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> variables (std::map<std::string, std::string> map, bool sourceFileSystem = true, std::string const& untitledPath = NULL_STR) const;
|
||||
|
||||
bool is_modified () const;
|
||||
bool is_on_disk () const { return is_open() ? _is_on_disk : path::exists(path()); }
|
||||
|
||||
Reference in New Issue
Block a user