mirror of
https://github.com/textmate/textmate.git
synced 2026-01-20 04:08:04 -05:00
Introduce editor_delegate_t
This is to avoid having editor_t hold a document_t.
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user