Introduce editor_delegate_t

This is to avoid having editor_t hold a document_t.
This commit is contained in:
Allan Odgaard
2013-05-15 22:38:02 +07:00
parent e80e9c5172
commit e3bc6e982b
3 changed files with 38 additions and 6 deletions

View File

@@ -452,6 +452,9 @@ static std::string shell_quote (std::vector<std::string> 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<std::string> 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<std::string, std::string> 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));

View File

@@ -76,12 +76,17 @@ namespace ng
cmd.output = output::replace_selection;
cmd.output_format = output_format::completion_list;
std::map<std::string, std::string> 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<std::string, std::string> 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));

View File

@@ -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<std::string, std::string> 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;
};