From e3bc6e982beee221febd666ff1917a2260b36f9e Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Wed, 15 May 2013 22:38:02 +0700 Subject: [PATCH] Introduce editor_delegate_t This is to avoid having editor_t hold a document_t. --- Frameworks/OakTextView/src/OakTextView.mm | 17 +++++++++++++++++ Frameworks/editor/src/completion.cc | 17 +++++++++++------ Frameworks/editor/src/editor.h | 10 ++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/Frameworks/OakTextView/src/OakTextView.mm b/Frameworks/OakTextView/src/OakTextView.mm index 97044f0b..524d37b5 100644 --- a/Frameworks/OakTextView/src/OakTextView.mm +++ b/Frameworks/OakTextView/src/OakTextView.mm @@ -452,6 +452,9 @@ static std::string shell_quote (std::vector paths) delete callback; callback = NULL; + delete editor->delegate(); + editor->set_delegate(NULL); + editor.reset(); layout.reset(); @@ -474,6 +477,20 @@ static std::string shell_quote (std::vector paths) callback = new buffer_refresh_callback_t(self); + struct textview_delegate_t : ng::editor_delegate_t + { + textview_delegate_t (OakTextView* textView) : _self(textView) { } + + std::map variables_for_bundle_item (bundles::item_ptr item) + { + return [_self variablesForBundleItem:item]; + } + + OakTextView* _self; + }; + + editor->set_delegate(new textview_delegate_t(self)); + editor->set_clipboard(get_clipboard(NSGeneralPboard)); editor->set_find_clipboard(get_clipboard(NSFindPboard)); editor->set_replace_clipboard(get_clipboard(NSReplacePboard)); diff --git a/Frameworks/editor/src/completion.cc b/Frameworks/editor/src/completion.cc index b1282763..231ec888 100644 --- a/Frameworks/editor/src/completion.cc +++ b/Frameworks/editor/src/completion.cc @@ -76,12 +76,17 @@ namespace ng cmd.output = output::replace_selection; cmd.output_format = output_format::completion_list; - std::map env = oak::basic_environment(); - env << editor_variables(scopeAttributes) << item->bundle_variables(); - if(_document) - env << _document->document_variables(); - env = bundles::scope_variables(env, this->scope(scopeAttributes)); - env = variables_for_path(env, _document ? _document->virtual_path() : NULL_STR, this->scope(scopeAttributes).right, _document ? path::parent(_document->path()) : NULL_STR); + std::map env; + if(_delegate) + { + env = _delegate->variables_for_bundle_item(item); + } + else + { + env << oak::basic_environment() << editor_variables(scopeAttributes) << item->bundle_variables(); + env = bundles::scope_variables(env, this->scope(scopeAttributes)); + env = variables_for_path(env, NULL_STR, this->scope(scopeAttributes).right); + } env["TM_CURRENT_WORD"] = prefix; completion_command_delegate_ptr delegate(new completion_command_delegate_t(_buffer, _selections)); diff --git a/Frameworks/editor/src/editor.h b/Frameworks/editor/src/editor.h index b84f922a..6960c3b2 100644 --- a/Frameworks/editor/src/editor.h +++ b/Frameworks/editor/src/editor.h @@ -152,12 +152,21 @@ namespace ng PUBLIC action_t to_action (std::string const& sel); + struct editor_delegate_t + { + virtual ~editor_delegate_t () { } + virtual std::map variables_for_bundle_item (bundles::item_ptr item) = 0; + }; + struct PUBLIC editor_t { editor_t (); editor_t (buffer_t& buffer); editor_t (document::document_ptr document); + editor_delegate_t* delegate () const { return _delegate; } + void set_delegate (editor_delegate_t* delegate) { _delegate = delegate; } + void perform (action_t action, layout_t const* layout = NULL, bool indentCorrections = false, std::string const& scopeAttributes = NULL_STR); bool disallow_tab_expansion () const; @@ -282,6 +291,7 @@ namespace ng clipboard_ptr _yank_clipboard; bool _extend_yank_clipboard = false; + editor_delegate_t* _delegate = NULL; document::document_ptr _document; };