class documentation

class TextBufferList(list): (source)

View In Hierarchy

This class represents a bullet or checkbox list in a TextBuffer. It is used to perform recursive actions on the list.

While the TextBuffer just treats list items as lines that start with a bullet, the TextBufferList maps to a number of lines that together form a list. It uses "row ids" to refer to specific items within this range.

TextBufferList objects will become invalid after any modification to the buffer that changes the line count within the list. Using them after such modification will result in errors.

Class Method new_from_line Constructor for a new TextBufferList mapping the list at a specific line in the buffer
Method __init__ Constructor
Method can_indent Check whether a specific item in the list can be indented
Method can_unindent Check if a specific item in the list has indenting which can be reduced
Method get_row_at_line Get the row in the list for a specific line
Method indent Indent a list item and all it's children
Method set_bullet Set the bullet type for a specific item and update parents and children accordingly
Method unindent Un-indent a list item and it's children
Constant BULLET_COL Undocumented
Constant INDENT_COL Undocumented
Constant LINE_COL Undocumented
Instance Variable buffer Undocumented
Instance Variable firstline Undocumented
Instance Variable lastline Undocumented
Method _change_bullet_type Undocumented
Method _checkbox_checked Undocumented
Method _checkbox_unchecked Undocumented
Method _indent Undocumented
Method _indent_row Undocumented
Method _parents Undocumented
@classmethod
def new_from_line(self, textbuffer, line): (source)
Constructor for a new TextBufferList mapping the list at a specific line in the buffer
Parameters
textbuffera TextBuffer object
line

a line number

This line should be part of a list, the TextBufferList object that is returned maps the full list, so it possibly extends above and below line.

Returns
a 2-tuple of a row id and a the new TextBufferList object, or (None, None) if line is not part of a list. The row id points to line in the list.
def __init__(self, textbuffer, firstline, lastline): (source)
Constructor
Parameters
textbuffera TextBuffer object
firstlinethe line number for the first line of the list
lastlinethe line number for the last line of the list
def can_indent(self, row): (source)

Check whether a specific item in the list can be indented

List items can only be indented if they are on top of the list or when there is some node above them to serve as new parent node. This avoids indenting two levels below the parent.

So e.g. in the case of:

  * item a
  * item b

then "item b" can indent and become a child of "item a". However after indenting once:

  * item a
      * item b

now "item b" can not be indented further because it is already one level below "item a".

Parameters
rowthe row id
Returns
True when indenting is possible
def can_unindent(self, row): (source)
Check if a specific item in the list has indenting which can be reduced
Parameters
rowthe row id
Returns
True when the item has indenting
def get_row_at_line(self, line): (source)
Get the row in the list for a specific line
Parameters
linethe line number for a line in the TextBuffer
Returns
the row id for a row in the list or None when the line was outside of the list
def indent(self, row): (source)

Indent a list item and all it's children

For example, when indenting "item b" in this list:

  * item a
  * item b
      * item C

it will result in:

  * item a
      * item b
          * item C
Parameters
rowthe row id
Returns
True if successfulll
def set_bullet(self, row, bullet): (source)

Set the bullet type for a specific item and update parents and children accordingly

Used to (un-)check the checkboxes and synchronize child nodes and parent nodes. When a box is checked, any open child nodes are checked. Also when this is the last checkbox on the given level to be checked, the parent box can be checked as well. When a box is un-checked, also the parent checkbox is un-checked. Both updating of children and parents is recursive.

Parameters
rowthe row id
bullet

the bullet type, which can be one of:

        BULLET
        CHECKED_BOX
        UNCHECKED_BOX
        XCHECKED_BOX
        MIGRATED_BOX
        TRANSMIGRATED_BOX
def unindent(self, row): (source)
Un-indent a list item and it's children
Parameters
rowthe row id
Returns
True if successfulll
BULLET_COL: int = (source)

Undocumented

Value
2
INDENT_COL: int = (source)

Undocumented

Value
1
LINE_COL: int = (source)

Undocumented

Value
0
buffer = (source)

Undocumented

firstline = (source)

Undocumented

lastline = (source)

Undocumented

def _change_bullet_type(self, row, bullet): (source)

Undocumented

def _checkbox_checked(self, row, state): (source)

Undocumented

def _checkbox_unchecked(self, row): (source)

Undocumented

def _indent(self, row, step): (source)

Undocumented

def _indent_row(self, row, step): (source)

Undocumented

def _parents(self, row): (source)

Undocumented