1
# -*- coding: utf-8 -*-
3
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
4
#Copyright (c) 2005 Ali Afshar aafshar@gmail.com
6
#Permission is hereby granted, free of charge, to any person obtaining a copy
7
#of this software and associated documentation files (the "Software"), to deal
8
#in the Software without restriction, including without limitation the rights
9
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
#copies of the Software, and to permit persons to whom the Software is
11
#furnished to do so, subject to the following conditions:
13
#The above copyright notice and this permission notice shall be included in
14
#all copies or substantial portions of the Software.
16
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
import pida.core.base as base
29
class BufferItem(tree.IconTreeItem):
31
def __get_markup(self):
32
return self.value.markup
33
markup = property(__get_markup)
36
class BufferTree(tree.Tree):
39
SORT_AVAILABLE = [('Time Opened','creation_time'),
40
('File path','filename'),
41
('File name','basename'),
42
('Mime Type','mimetype'),
43
('File Length','length'),
44
('Project', 'project_name')]
47
tree.Tree.__init__(self)
48
self.view.set_expander_column(self.view.get_column(1))
49
self.set_property('markup-format-string', '%(filename)s')
50
self.__bufferdetails = BufferDetails()
51
self.view.set_enable_search(False)
52
def _se(model, column, key, iter):
53
val = model.get_value(iter, 1).value
54
isnt = not val.basename.startswith(key)
56
self.view.set_search_equal_func(_se)
57
#self.pack_start(self.__bufferdetails, expand=False)
59
def set_bufferlist(self, bufferlist):
61
self.set_items(self.__adapt_bufferlist(bufferlist))
63
def set_currentbuffer(self, filename):
64
self.set_selected(filename)
66
def display_buffer(self, buf):
67
self.__bufferdetails.display_buffer(buf)
69
def __adapt_bufferlist(self, bufferlist):
70
for buf in bufferlist:
71
yield self.__adapt_buffer(bufferlist[buf])
73
def __adapt_buffer(self, buf):
74
return BufferItem(buf.filename, buf, buf.icon)
76
def get_details_box(self):
77
return self.__bufferdetails
78
details_box = property(get_details_box)
80
class BufferDetails(gtk.VBox):
83
gtk.VBox.__init__(self)
85
self.__contextbars = []
86
self.__toolbarholder = gtk.HBox()
87
self.pack_start(self.__toolbarholder, expand=False)
88
self.__title = gtk.Label()
89
self.pack_start(self.__title)
91
def display_buffer(self, buf):
92
self.__currentbuffer = buf
93
if self.__toolbar is not None:
94
self.__toolbarholder.remove(self.__toolbar)
95
for bar in self.__contextbars:
96
self.__toolbarholder.remove(bar)
97
self.__create_toolbar(buf)
99
def __create_toolbar(self, buf):
100
globaldict={'filename':buf.filename}
101
self.__contextbars = []
103
self.__toolbarholder.remove(toolbar)
104
self.__toolbarholder.foreach(remove)
105
for context in buf.contexts:
106
contextbar = buf.boss.command('contexts', 'get-toolbar',
108
globaldict=globaldict)
109
self.__contextbars.append(contextbar)
110
self.__toolbarholder.pack_start(contextbar, expand=False)
112
self.__title.set_markup(buf.markup)