From ff52a386213ed06e73c87acdb627bd4833f8deda Mon Sep 17 00:00:00 2001 From: Adam Strzelecki Date: Tue, 28 Aug 2012 22:14:18 +0200 Subject: [PATCH] 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. --- .../DocumentWindow/src/DocumentController.mm | 2 +- Frameworks/DocumentWindow/src/DocumentTabs.mm | 7 ++--- Frameworks/document/src/document.cc | 26 ++++++++++++------- Frameworks/document/src/document.h | 8 ++++-- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/Frameworks/DocumentWindow/src/DocumentController.mm b/Frameworks/DocumentWindow/src/DocumentController.mm index e6859e30..5be509c4 100644 --- a/Frameworks/DocumentWindow/src/DocumentController.mm +++ b/Frameworks/DocumentWindow/src/DocumentController.mm @@ -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())]; } } diff --git a/Frameworks/DocumentWindow/src/DocumentTabs.mm b/Frameworks/DocumentWindow/src/DocumentTabs.mm index 3229736e..a5187953 100644 --- a/Frameworks/DocumentWindow/src/DocumentTabs.mm +++ b/Frameworks/DocumentWindow/src/DocumentTabs.mm @@ -7,6 +7,7 @@ #import #import #import +#import 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(); diff --git a/Frameworks/document/src/document.cc b/Frameworks/document/src/document.cc index 49d9413b..2356f487 100644 --- a/Frameworks/document/src/document.cc +++ b/Frameworks/document/src/document.cc @@ -500,11 +500,13 @@ namespace document return _file_type; } - std::map document_t::variables (std::map map, bool sourceFileSystem) const + std::map document_t::variables (std::map 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; diff --git a/Frameworks/document/src/document.h b/Frameworks/document/src/document.h index 3378f982..012a0768 100644 --- a/Frameworks/document/src/document.h +++ b/Frameworks/document/src/document.h @@ -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(), false)); } - std::map variables (std::map 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(), false, untitledPath)); + } + + std::map variables (std::map 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()); }