def toggle_bullet_list(self, par_type=None): """Toggle the state of a bullet list""" self._buf.begin_user_action() # round selection to nearest paragraph start, end = get_paragraphs_selected(self._buf) start, end = self._ensure_par_newline(start, end) # toggle bullet presence if par_type is None: # are all paragraphs bulleted? all_bullets = True for pos in paragraph_iter(self._buf, start, end): if self.get_indent(pos)[1] != "bullet": all_bullets = False break if all_bullets: par_type = "none" else: par_type = "bullet" # set each paragraph's bullet status for pos in paragraph_iter(self._buf, start, end): par_end = pos.copy() par_end.forward_line() self._set_bullet_list_paragraph(pos, par_end, par_type) self._buf.end_user_action()
def change_indent(self, start, end, change): """Change indentation level""" # determine region if start is None or end is None: start, end = get_paragraphs_selected(self._buf) self._buf.begin_user_action() # loop through paragraphs for pos in paragraph_iter(self._buf, start, end): par_end = pos.copy() par_end.forward_line() indent, par_indent = self.get_indent(pos) if indent + change > 0: tag = self._buf.tag_table.lookup( RichTextIndentTag.tag_name(indent + change, par_indent)) self._buf.clear_tag_class(tag, pos, par_end) self._buf.apply_tag(tag, pos, par_end) elif indent > 0: # remove indent and possible bullets self._buf.clear_tag_class( self._buf.tag_table.lookup( RichTextIndentTag.tag_name(indent, par_indent)), pos, par_end) self._remove_bullet(pos) else: # do nothing pass self._buf.end_user_action()
def update_indentation(self): """Ensure the indentation tags between start and end are up to date""" # fixup indentation tags # The general rule is that the indentation at the start of # each paragraph should determines the indentation of the rest # of the paragraph # if no indentation requests are queued then do nothing if not self._indent_update: return self._indent_update = False self._buf.begin_user_action() self._buf.begin_noninteractive() # get range of updating pos = self._buf.get_iter_at_mark(self._indent_update_start) end = self._buf.get_iter_at_mark(self._indent_update_end) pos = move_to_start_of_line(pos) end.forward_line() # iterate through the paragraphs that need updating for pos in paragraph_iter(self._buf, pos, end): par_end = pos.copy() par_end.forward_line() indent_tag = self.get_indent_tag(pos) # remove bullets mid paragraph it = pos.copy() it.forward_char() while True: match = it.forward_search(BULLET_STR, 0, par_end) if not match: it.backward_char() pos, par_end = get_paragraph(it) break self._buf.move_mark(self._indent_update_start, match[0]) self._buf.delete(match[0], match[1]) it = self._buf.get_iter_at_mark(self._indent_update_start) par_end = it.copy() par_end.forward_line() # check indentation if indent_tag is None: # remove all indent tags # TODO: RichTextBaseBuffer function self._buf.clear_tag_class( self._buf.tag_table.lookup(RichTextIndentTag.tag_name(1)), pos, par_end) # remove bullets par_type = "none" else: self._buf.clear_tag_class(indent_tag, pos, par_end) self._buf.apply_tag(indent_tag, pos, par_end) # check for bullets par_type = indent_tag.get_par_indent() # check paragraph type if par_type == "bullet": # ensure proper bullet is in place pos = self._insert_bullet(pos, indent_tag) elif par_type == "none": # remove bullets pos = self._remove_bullet(pos) else: raise Exception("unknown par_type '%s'" % par_type) #self._updating = False self._buf.end_noninteractive() self._buf.end_user_action()
def update_indentation(self): """Ensure the indentation tags between start and end are up to date""" # fixup indentation tags # The general rule is that the indentation at the start of # each paragraph should determines the indentation of the rest # of the paragraph # if no indentation requests are queued then do nothing if not self._indent_update: return self._indent_update = False self._buf.begin_user_action() self._buf.begin_noninteractive() # get range of updating pos = self._buf.get_iter_at_mark(self._indent_update_start) end = self._buf.get_iter_at_mark(self._indent_update_end) pos = move_to_start_of_line(pos) end.forward_line() # iterate through the paragraphs that need updating for pos in paragraph_iter(self._buf, pos, end): par_end = pos.copy() par_end.forward_line() indent_tag = self.get_indent_tag(pos) # remove bullets mid paragraph it = pos.copy() it.forward_char() while True: match = it.forward_search(BULLET_STR, 0, par_end) if not match: it.backward_char() pos, par_end = get_paragraph(it) break self._buf.move_mark(self._indent_update_start, match[0]) self._buf.delete(match[0], match[1]) it = self._buf.get_iter_at_mark(self._indent_update_start) par_end = it.copy() par_end.forward_line() # check indentation if indent_tag is None: # remove all indent tags # TODO: RichTextBaseBuffer function self._buf.clear_tag_class( self._buf.tag_table.lookup( RichTextIndentTag.tag_name(1)), pos, par_end) # remove bullets par_type = "none" else: self._buf.clear_tag_class(indent_tag, pos, par_end) self._buf.apply_tag(indent_tag, pos, par_end) # check for bullets par_type = indent_tag.get_par_indent() # check paragraph type if par_type == "bullet": # ensure proper bullet is in place pos = self._insert_bullet(pos, indent_tag) elif par_type == "none": # remove bullets pos = self._remove_bullet(pos) else: raise Exception("unknown par_type '%s'" % par_type) #self._updating = False self._buf.end_noninteractive() self._buf.end_user_action()