boa-constructor / Browse.py

#-----------------------------------------------------------------------------
# Name:        Browse.py
# Purpose:
#
# Author:      Riaan Booysen
#
# Created:     2000/09/24
# RCS-ID:      $Id$
# Copyright:   (c) 2000 Riaan Booysen
# Licence:     GPL
#-----------------------------------------------------------------------------

class BrowsePage:
    def __init__(self, modulepage, view, marker):
        self.modulePage = modulepage
        self.view = view
        self.marker = marker

    def goto(self):
        # XXX What if page has been closed, notification
        self.modulePage.focus()
        self.modulePage.model.views[self.view].goto(self.marker)
        self.modulePage.model.views[self.view].focus()

    def __repr__(self):
        return 'BrowsePage(%s, %s, %s)' % (`self.modulePage`, `self.view`,
               `self.marker`)

class Browser:
    def __init__(self):
        self.pages = []
        self.idx = -1

    def add(self, page):
        if self.idx == len(self.pages)-1:
            self.pages.append(page)
        else:
            self.pages[self.idx:] = [page]
        self.idx = len(self.pages)-1
#        print 'add idx', self.idx, self.pages

    def checkRemoval(self, modPage):
        for page in self.pages[:]:
            if page.modulePage == modPage:
                idx = self.pages.index(page)
                if idx < self.idx:
                    self.idx = self.idx - 1
                del self.pages[idx]

    def step(self, dir):
        self.pages[self.idx].goto()
        self.idx = self.idx + dir

    def canForward(self):
        return self.idx < len(self.pages)-1

    def forward(self):
#        print 'forward', self.idx, self.canForward()
        if self.canForward():
            self.step(1)

    def canBack(self):
        return self.idx >= 0

    def back(self):
#        print 'back', self.idx, self.canBack()
        if self.canBack():
            self.step(-1)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.