2010-02-07 14:26:50 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2010-02-06
|
|
|
|
# Copyright 2010 Hardcoded Software (http://www.hardcoded.net)
|
|
|
|
#
|
2010-09-30 10:17:41 +00:00
|
|
|
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
2010-02-07 14:26:50 +00:00
|
|
|
# which should be included with this package. The terms are also available at
|
2010-09-30 10:17:41 +00:00
|
|
|
# http://www.hardcoded.net/licenses/bsd_license
|
2010-02-07 14:26:50 +00:00
|
|
|
|
2010-11-24 15:12:10 +00:00
|
|
|
from hscommon.gui.tree import Tree, Node
|
2010-02-07 14:26:50 +00:00
|
|
|
|
|
|
|
from ..directories import STATE_NORMAL, STATE_REFERENCE, STATE_EXCLUDED
|
|
|
|
from .base import GUIObject
|
|
|
|
|
|
|
|
STATE_ORDER = [STATE_NORMAL, STATE_REFERENCE, STATE_EXCLUDED]
|
|
|
|
|
|
|
|
# Lazily loads children
|
|
|
|
class DirectoryNode(Node):
|
|
|
|
def __init__(self, app, path, name):
|
|
|
|
Node.__init__(self, name)
|
|
|
|
self._app = app
|
|
|
|
self._directory_path = path
|
|
|
|
self._loaded = False
|
|
|
|
self._state = STATE_ORDER.index(self._app.directories.get_state(path))
|
|
|
|
|
2010-02-07 15:00:58 +00:00
|
|
|
def __len__(self):
|
|
|
|
if not self._loaded:
|
|
|
|
self._load()
|
|
|
|
return Node.__len__(self)
|
|
|
|
|
2010-02-07 14:26:50 +00:00
|
|
|
def _load(self):
|
|
|
|
self.clear()
|
|
|
|
subpaths = self._app.directories.get_subfolders(self._directory_path)
|
|
|
|
for path in subpaths:
|
|
|
|
self.append(DirectoryNode(self._app, path, path[-1]))
|
|
|
|
self._loaded = True
|
|
|
|
|
|
|
|
# The state propery is an index to the combobox
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
return self._state
|
|
|
|
|
|
|
|
@state.setter
|
|
|
|
def state(self, value):
|
|
|
|
if value == self._state:
|
|
|
|
return
|
|
|
|
self._state = value
|
|
|
|
state = STATE_ORDER[value]
|
|
|
|
self._app.directories.set_state(self._directory_path, state)
|
|
|
|
|
|
|
|
|
|
|
|
class DirectoryTree(GUIObject, Tree):
|
|
|
|
def __init__(self, view, app):
|
|
|
|
GUIObject.__init__(self, view, app)
|
|
|
|
Tree.__init__(self)
|
2010-02-12 14:39:29 +00:00
|
|
|
|
|
|
|
def connect(self):
|
|
|
|
GUIObject.connect(self)
|
2010-02-07 14:26:50 +00:00
|
|
|
self._refresh()
|
|
|
|
self.view.refresh()
|
|
|
|
|
|
|
|
def _refresh(self):
|
|
|
|
self.clear()
|
|
|
|
for path in self.app.directories:
|
2010-08-11 14:39:06 +00:00
|
|
|
self.append(DirectoryNode(self.app, path, str(path)))
|
2010-02-07 14:26:50 +00:00
|
|
|
|
|
|
|
def add_directory(self, path):
|
|
|
|
self.app.add_directory(path)
|
|
|
|
|
|
|
|
#--- Event Handlers
|
|
|
|
def directories_changed(self):
|
|
|
|
self._refresh()
|
|
|
|
self.view.refresh()
|
|
|
|
|