Introduce ui_proxy_t::show_browser

This commit is contained in:
Allan Odgaard
2013-01-10 05:05:22 +01:00
parent db3c1a6f33
commit 759b7d1ae5
4 changed files with 79 additions and 82 deletions

View File

@@ -1769,106 +1769,101 @@ static NSUInteger DisableSessionSavingCount = 0;
SetFrontProcessWithOptions(&(ProcessSerialNumber){ 0, kCurrentProcess }, kSetFrontProcessFrontWindowOnly);
}
}
public:
void show_documents (std::vector<document::document_ptr> const& documents, std::string const& browserPath) const
void show_browser (std::string const& path) const
{
DocumentController* controller = nil;
if(browserPath != NULL_STR)
std::string const folder = path::resolve(path);
for(DocumentController* candidate in SortedControllers())
{
ASSERT(documents.empty());
std::string const folder = path::resolve(browserPath);
if(folder == to_s(candidate.projectPath))
return bring_to_front(candidate);
}
for(DocumentController* candidate in SortedControllers())
DocumentController* controller = nil;
for(DocumentController* candidate in SortedControllers())
{
if(!candidate.fileBrowserVisible && candidate.documents.size() == 1 && is_disposable(candidate.selectedDocument))
{
if(folder == to_s(candidate.projectPath))
return bring_to_front(candidate);
}
for(DocumentController* candidate in SortedControllers())
{
if(candidate.fileBrowserVisible || candidate.documents.size() != 1 || !is_disposable(candidate.selectedDocument))
continue;
controller = candidate;
break;
}
if(!controller)
{
controller = [DocumentController new];
}
else if(controller.selectedDocument)
{
[controller selectedDocument]->set_custom_name("not untitled"); // release potential untitled token used
}
controller.defaultProjectPath = [NSString stringWithCxxString:folder];
controller.fileBrowserVisible = YES;
controller.documents = make_vector(create_untitled_document_in_folder(folder));
[controller.fileBrowser showURL:[NSURL fileURLWithPath:[NSString stringWithCxxString:folder]]];
}
else if(!documents.empty())
if(!controller)
controller = [DocumentController new];
else if(controller.selectedDocument)
[controller selectedDocument]->set_custom_name("not untitled"); // release potential untitled token used
controller.defaultProjectPath = [NSString stringWithCxxString:folder];
controller.fileBrowserVisible = YES;
controller.documents = make_vector(create_untitled_document_in_folder(folder));
[controller.fileBrowser showURL:[NSURL fileURLWithPath:[NSString stringWithCxxString:folder]]];
[controller openAndSelectDocument:[controller documents][controller.selectedTabIndex]];
bring_to_front(controller);
}
void show_documents (std::vector<document::document_ptr> const& documents) const
{
ASSERT(!documents.empty());
DocumentController* controller = nil;
for(DocumentController* candidate in SortedControllers())
{
for(DocumentController* candidate in SortedControllers())
std::string const projectPath = to_s(candidate.projectPath);
std::string const fileBrowserPath = candidate.fileBrowserVisible ? to_s(candidate.fileBrowser.location) : NULL_STR;
iterate(document, documents)
{
std::string const projectPath = to_s(candidate.projectPath);
std::string const fileBrowserPath = candidate.fileBrowserVisible ? to_s(candidate.fileBrowser.location) : NULL_STR;
iterate(document, documents)
{
std::string const docPath = (*document)->path();
if(docPath.find(projectPath) == 0 || (fileBrowserPath != NULL_STR && docPath.find(fileBrowserPath) == 0))
controller = candidate;
citerate(projectDoc, candidate.documents)
{
if((*document)->identifier() == (*projectDoc)->identifier())
controller = candidate;
}
}
if(!controller && !candidate.fileBrowserVisible && candidate.documents.size() == 1 && is_disposable(candidate.selectedDocument))
std::string const docPath = (*document)->path();
if(docPath.find(projectPath) == 0 || (fileBrowserPath != NULL_STR && docPath.find(fileBrowserPath) == 0))
controller = candidate;
if(controller)
break;
citerate(projectDoc, candidate.documents)
{
if((*document)->identifier() == (*projectDoc)->identifier())
controller = candidate;
}
}
if(!controller && !candidate.fileBrowserVisible && candidate.documents.size() == 1 && is_disposable(candidate.selectedDocument))
controller = candidate;
if(controller)
{
std::vector<document::document_ptr> oldDocuments = controller.documents;
NSUInteger split = controller.selectedTabIndex;
break;
}
if(!oldDocuments.empty() && is_disposable(oldDocuments[split]))
oldDocuments.erase(oldDocuments.begin() + split);
else ++split;
if(controller)
{
std::vector<document::document_ptr> oldDocuments = controller.documents;
NSUInteger split = controller.selectedTabIndex;
std::vector<document::document_ptr> newDocuments;
split = merge_documents_splitting_at(oldDocuments, documents, split, newDocuments);
controller.documents = newDocuments;
controller.selectedTabIndex = split;
}
else
{
controller = [DocumentController new];
controller.documents = documents;
if(!oldDocuments.empty() && is_disposable(oldDocuments[split]))
oldDocuments.erase(oldDocuments.begin() + split);
else ++split;
std::string projectPath = NULL_STR;
iterate(document, documents)
{
std::string const path = path::parent((*document)->path());
if(path != NULL_STR && (projectPath == NULL_STR || path.size() < projectPath.size()))
projectPath = path;
}
if(projectPath != NULL_STR)
controller.defaultProjectPath = [NSString stringWithCxxString:projectPath];
}
std::vector<document::document_ptr> newDocuments;
split = merge_documents_splitting_at(oldDocuments, documents, split, newDocuments);
controller.documents = newDocuments;
controller.selectedTabIndex = split;
}
else
{
ASSERT(browserPath != NULL_STR || !documents.empty());
return;
controller = [DocumentController new];
controller.documents = documents;
std::string projectPath = NULL_STR;
iterate(document, documents)
{
std::string const path = path::parent((*document)->path());
if(path != NULL_STR && (projectPath == NULL_STR || path.size() < projectPath.size()))
projectPath = path;
}
if(projectPath != NULL_STR)
controller.defaultProjectPath = [NSString stringWithCxxString:projectPath];
}
[controller openAndSelectDocument:[controller documents][controller.selectedTabIndex]];

View File

@@ -22,12 +22,12 @@ namespace document
void show (std::vector<document_ptr> const& documents)
{
if(!documents.empty())
ui_proxy()->show_documents(documents, NULL_STR);
ui_proxy()->show_documents(documents);
}
void show_browser (std::string const& path)
{
ui_proxy()->show_documents(std::vector<document_ptr>(), path);
ui_proxy()->show_browser(path);
}
void run (bundle_command_t const& command, ng::buffer_t const& buffer, ng::ranges_t const& selection, document::document_ptr document, std::map<std::string, std::string> const& env, run_callback_ptr callback)

View File

@@ -29,7 +29,8 @@ namespace document
{
virtual ~ui_proxy_t () { }
virtual void show_document (oak::uuid_t const& collection, document_ptr document, text::range_t const& range, bool bringToFront) const = 0;
virtual void show_documents (std::vector<document_ptr> const& documents, std::string const& browserPath) const = 0;
virtual void show_documents (std::vector<document_ptr> const& documents) const = 0;
virtual void show_browser (std::string const& path) const = 0;
virtual void run (bundle_command_t const& command, ng::buffer_t const& buffer, ng::ranges_t const& selection, document::document_ptr document, std::map<std::string, std::string> const& env, run_callback_ptr callback) = 0;
};

View File

@@ -11,7 +11,8 @@ public:
{
static struct proxy_t : document::ui_proxy_t
{
void show_documents (std::vector<document::document_ptr> const& documents, std::string const& browserPath) const { }
void show_browser (std::string const& path) const { }
void show_documents (std::vector<document::document_ptr> const& documents) const { }
void show_document (oak::uuid_t const& collection, document::document_ptr document, text::range_t const& range, bool bringToFront) const { }
void run (bundle_command_t const& command, ng::buffer_t const& buffer, ng::ranges_t const& selection, document::document_ptr document, std::map<std::string, std::string> const& baseEnv, document::run_callback_ptr callback)