Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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.
  • Loading branch information...
commit 4bc81053fe301c15d84a5c062ff5b954346ac657 1 parent 088bc09
@nanoant nanoant authored sorbits committed
View
2  Frameworks/DocumentWindow/src/DocumentController.mm
@@ -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())];
}
}
View
7 Frameworks/DocumentWindow/src/DocumentTabs.mm
@@ -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 @@ - (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();
@@ -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();
@@ -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();
View
26 Frameworks/document/src/document.cc
@@ -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;
View
8 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<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()); }
Please sign in to comment.
Something went wrong with that request. Please try again.