8
8
from zim.plugins import PluginClass
9
9
from zim.config import data_file, config_file
10
from zim.notebook import get_notebook_list
10
from zim.notebook import get_notebook_list, NotebookInfo, NotebookInfoList
11
11
from zim.gui.widgets import gtk_window_set_default_icon
153
def list_configured_notebooks(self):
154
# returns (name, uri) pairs
155
list = get_notebook_list()
156
return [(info.name, info.uri) for info in list]
158
153
def list_open_notebooks(self):
154
'''Returns a list of open notebook.
156
This method is to be implemented in child classes.
158
@returns: a list of L{NotebookInfo} objects
159
160
# should return (name, uri) pairs
160
161
raise NotImplementedError
162
163
def list_all_notebooks(self):
164
'''Returns a list of all notebooks known in the current context
166
This method mixes notebooks from L{list_open_notebooks()} with
167
input from L{get_notebook_list()}. Open notebooks will have
168
the C{active} attribute set.
170
@returns: a list of L{NotebookInfo} objects
166
self.list_configured_notebooks(),
167
self.list_open_notebooks()
169
for name, uri in nlist:
172
notebooks.append((name, uri))
173
notebooks = [info for info in get_notebook_list()]
174
for info in self.list_open_notebooks():
175
if info in notebooks:
176
# info from notebook list is updated already
177
i = notebooks.index(info)
178
notebooks[i].active = True
182
notebooks.append(info)
184
for info in notebooks:
186
info.active = False # None -> False
176
190
def populate_menu_with_notebooks(self, menu, notebooks):
180
194
item.set_sensitive(False)
181
195
menu.append(item)
183
for name, uri in notebooks:
184
#~ print '>>>', name, uri
185
item = gtk.MenuItem(' ' + name) # Hack - using ' ' to indent visually
186
item.connect('activate', lambda o, u: self.do_activate_notebook(u), uri)
197
if isinstance(notebooks, NotebookInfoList):
198
notebooks = [info for info in notebooks] # copy
200
notebooks.sort(key=lambda info: info.name)
202
for info in notebooks:
204
item = gtk.MenuItem(' ' + info.name)
205
# Hack - using ' ' to indent visually
207
child = item.get_child()
208
if isinstance(child, gtk.Label):
209
# FIXME this doesn't seem to work in Ubuntu menu :(
210
child.set_markup(' <b>' + info.name + '</b>')
211
# Hack - using ' ' to indent visually
212
item.connect('activate', lambda o, u: self.do_activate_notebook(u), info.uri)
187
213
menu.append(item)
189
215
def do_activate_notebook(self, uri):
225
251
# No open notebooks, open default or prompt full list
226
252
notebooks = get_notebook_list()
227
253
if notebooks.default:
228
self.do_activate_notebook(notebooks.uri)
254
self.do_activate_notebook(notebooks.default)
230
self.do_popup_menu_notebooks([info.uri for info in notebooks])
256
self.do_popup_menu_notebooks(notebooks)
231
257
elif len(open_notebooks) == 1:
232
258
# Only one open notebook - present it
233
self.do_activate_notebook(open_notebooks[0][1])
259
self.do_activate_notebook(open_notebooks[0].uri)
235
261
# Let the user choose from the open notebooks
236
262
self.do_popup_menu_notebooks(open_notebooks)
270
296
def list_open_notebooks(self):
271
297
# No daemon, so we only know one open notebook
272
298
notebook = self.ui.notebook
273
return [(notebook.name, notebook.uri)]
299
info = NotebookInfo(notebook.uri, name=notebook.name)
275
303
def do_activate_notebook(self, uri):
276
304
# Open a notebook using the ui object
304
332
def list_open_notebooks(self):
305
list = get_notebook_list()
306
names = dict((info.uri, info.name) for info in list)
307
333
for uri in self.daemon.list_notebooks():
308
name = names[uri] or uri
334
info = NotebookInfo(uri)
311
338
def do_activate_notebook(self, uri):
312
339
self.daemon.get_notebook(uri).toggle_present()