示例#1
0
class StagerUnstager(Panel):

    def __init__(self, parent, *args, **kwargs):
        super(StagerUnstager, self).__init__(*args, **kwargs)
        self.parent = parent
        self.default_title = self.title
        self.postponer = Postponer(timeout_in_seconds=0.3)

    def filename_from_linenum(self, linenum):
        if len(self.content) <= linenum:
            # TODO: log error and raise exception
            return 'error: l.%s>%s' % (linenum, str(len(self.content)+1))
        return self.content[linenum].split()[1]

    def move_cursor(self):
        super(StagerUnstager, self).move_cursor()
        self.request_diff_in_diff_view()

    def request_diff_in_diff_view(self):
        if self.content:
            self.postponer.set(
                action=self.parent['diff'].handle_event,
                args=[self.filename_from_linenum(self.hovered_line)])

    def select(self):
        if self.selected_line == self.hovered_line:
            self.selected_line = -1
        else:
            self.selected_line = self.hovered_line
        if self.selected_line != -1:
            self.selected_file = self.filename_from_linenum(self.selected_line)
            self.cursor_y = max(self.cursor_y - 1, self.CT)
            self.action(self.selected_file)
            self.unselect()
        self.display()
示例#2
0
文件: gui.py 项目: timlegrand/giterm
class StagerUnstager(Panel):

    def __init__(self, parent, *args, **kwargs):
        super(StagerUnstager, self).__init__(*args, **kwargs)
        self.parent = parent
        self.default_title = self.title
        self.postponer = Postponer(timeout_in_seconds=0.3)

    def filename_from_linenum(self, linenum):
        if linenum < 0 or linenum >= len(self.content):
            return ''
        line = None
        try:
            line = self.content[linenum]
        except:
            return ''
        return line.split()[1]

    def move_cursor(self):
        super(StagerUnstager, self).move_cursor()
        if self.active:
            self.request_diff_in_diff_view()

    def handle_event(self, event=None):
        super(StagerUnstager, self).handle_event()
        self.request_diff_in_diff_view()

    def activate(self):
        this = super(StagerUnstager, self).activate()
        self.request_diff_in_diff_view()
        return this

    def request_diff_in_diff_view(self, even_not_active=False):
        if not self.active and not even_not_active:
            return
        self.hovered_line = self.cursor_y + self.topLineNum - self.CT
        if self.hovered_line < 0 or self.hovered_line >= len(self.content):
            return
        filepath = self.filename_from_linenum(self.hovered_line)
        if self.content and filepath:
            self.postponer.set(
                action=self.parent['diff'].handle_event,
                args=[filepath, (self.title == 'Staging Area')])

    def select(self):
        if self.selected_line == self.hovered_line:
            self.selected_line = -1
        else:
            self.selected_line = self.hovered_line
        if self.selected_line != -1:
            self.selected_file = self.filename_from_linenum(self.selected_line)
            self.cursor_y = max(self.cursor_y - 1, self.CT)
            self.action(self.selected_file)
            self.unselect()
        self.display()
示例#3
0
 def __init__(self, parent, *args, **kwargs):
     super(StagerUnstager, self).__init__(*args, **kwargs)
     self.parent = parent
     self.default_title = self.title
     self.postponer = Postponer(timeout_in_seconds=0.3)