Skip to content

Commit

Permalink
Provide TM_SCM_* variables for untitled document
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nanoant authored and sorbits committed Sep 9, 2012
1 parent 088bc09 commit 4bc8105
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Frameworks/DocumentWindow/src/DocumentController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ + (void)applicationDidBecomeActiveNotification:(NSNotification*)aNotification
{
[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())];
}
}
Expand Down
7 changes: 4 additions & 3 deletions Frameworks/DocumentWindow/src/DocumentTabs.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -41,7 +42,7 @@ - (void)setSelectedTabIndex:(NSInteger)newSelectedTabIndex
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();
Expand Down Expand Up @@ -76,7 +77,7 @@ - (void)documentDidChange:(document::document_ptr const&)aDocument
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();
Expand Down Expand Up @@ -283,7 +284,7 @@ - (void)documentOpenHelper:(DocumentOpenHelper*)documentOpenHelper didOpenDocume
}
}

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();
Expand Down
26 changes: 16 additions & 10 deletions Frameworks/document/src/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -500,28 +500,34 @@ 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();
map["TM_FILENAME"] = path::name(path());
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;
Expand Down
8 changes: 6 additions & 2 deletions Frameworks/document/src/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()); }
Expand Down

0 comments on commit 4bc8105

Please sign in to comment.