rendered paste body def __escape_placeholders(self):
"""
Tag placeholders in templates.
@param self: Reference to the TemplateManager instance.
@type self: A TemplateManager object.
@param result: A list of placeholders in the template.
@type result: A List object.
@param begin_mark: The beginning position of a template.
@type begin_mark: A gtk.TextMark object.
@param end_mark: The end position of a template.
@type end_mark: A gtk.TextMark object.
"""
begin_position = self.editor.textbuffer.get_iter_at_mark(self.begin_mark)
from gtk import TEXT_SEARCH_VISIBLE_ONLY
from cursor import get_cursor_iterator
count = 0
for placeholder in self.result:
end_position = self.editor.textbuffer.get_iter_at_mark(self.end_mark)
begin, end = begin_position.forward_search(placeholder, TEXT_SEARCH_VISIBLE_ONLY, end_position)
self.editor.textbuffer.place_cursor(begin)
self.editor.textbuffer.begin_user_action()
self.editor.textbuffer.delete(begin, end)
self.editor.textbuffer.end_user_action()
cursor_position = get_cursor_iterator(self.editor.textbuffer)
#variables
escaped_variable = self.__replace_variable(placeholder)
if placeholder == "${cursor}":
emark = self.editor.textbuffer.create_mark(None, cursor_position, False)
emark.set_visible(True)
self.placeholder_dictionary["cursor"] = (emark,)
elif escaped_variable != "":
bmark = self.editor.textbuffer.create_mark(None, cursor_position, True)
emark = self.editor.textbuffer.create_mark(None, cursor_position, False)
self.editor.textbuffer.begin_user_action()
self.editor.textbuffer.insert_at_cursor(escaped_variable)
self.editor.textbuffer.end_user_action()
else:
bmark = self.editor.textbuffer.create_mark(None, cursor_position, True)
emark = self.editor.textbuffer.create_mark(None, cursor_position, False)
self.placeholder_dictionary[count] = (bmark, emark)
count += 1
escaped_placeholder = self.__escape_placeholder(placeholder)
if escaped_placeholder in self.mirror_list:
self.mirror_dictionary[(bmark, emark)] = escaped_placeholder
self.editor.textbuffer.begin_user_action()
if escaped_placeholder == "":
escaped_placeholder = " "
self.editor.textbuffer.insert_at_cursor(escaped_placeholder)
self.editor.textbuffer.end_user_action()
begin_position = self.editor.textbuffer.get_iter_at_mark(emark)
return