Skip to content

Commit

Permalink
Rough implementation of page name completion
Browse files Browse the repository at this point in the history
  • Loading branch information
jaap-karssenberg committed Aug 13, 2009
1 parent 67be15f commit 450a291
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 13 deletions.
6 changes: 3 additions & 3 deletions HACKING/Tasks.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Content-Type: text/x-zim-wiki
Wiki-Format: zim 0.26
Creation-Date: Sat, 04 Apr 2009 10:54:39 +0200
Modification-Date: Thu, 13 Aug 2009 16:48:53 +0200
Modification-Date: Thu, 13 Aug 2009 18:10:59 +0200

====== Tasks ======

Expand Down Expand Up @@ -42,8 +42,7 @@ Modification-Date: Thu, 13 Aug 2009 16:48:53 +0200
[ ] Exporter: Check if linker for exporter is OK
[ ] Notebook: When moving / renaming links need to be updated
* Allow non-exisitng pag as placeholder in the index for resolving
[ ] Dialog: Autocompletion for pages and namespaces in dialogs
* Use a sub-class of the treemodel from the index ?
[*] Dialog: Autocompletion for pages and namespaces in dialogs
[*] Commandline: Allow opening files mapping to pages from the commandline
[ ] WWW: check resolving of files and icons for web server
* Add extra check that no files outside allowed directories are served
Expand All @@ -58,6 +57,7 @@ Modification-Date: Thu, 13 Aug 2009 16:48:53 +0200
* Check emission of indent-changed signal to set state of buttons
* Also think about keybindings for moving a line up / down or top / bottom
[ ] Pageview: support numbered lists
[ ] Dialog: improved widgets for page and namespace inputs
[ ] Implement "Open with custom command"dialog
[*] Implement Calendar plugin
[ ] Implement TaskList plugin
Expand Down
59 changes: 49 additions & 10 deletions zim/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from zim.fs import *
import zim.errors
import zim.config
from zim.notebook import Path


logger = logging.getLogger('zim.gui')
Expand Down Expand Up @@ -126,8 +127,6 @@ def do_button_release_event(self, event):
# expander in front of a path should not select the path.
# This logic is based on particulars of the C implementation
# and might not be future proof.
elif event.button == 3:
print 'TODO: context menu for page'

return gtk.TreeView.do_button_release_event(self, event)

Expand Down Expand Up @@ -432,14 +431,15 @@ def add_fields(self, fields, table=None, trigger_response=True):
label.set_alignment(0.0, 0.5)
table.attach(label, 0,1, i,i+1, xoptions=gtk.FILL)
entry = gtk.Entry()
entry.zim_type = type
if not value is None:
entry.set_text(str(value))
self.inputs[name] = entry
table.attach(entry, 1,2, i,i+1)
if type == 'page':
entry.set_completion(self._get_page_completion())
self._set_page_completion(entry)
elif type == 'namespace':
entry.set_completion(self._get_namespace_completion())
self._set_namespace_completion(entry)
elif type in ('dir', 'file', 'image'):
# FIXME use inline icon for newer versions of Gtk
browse = gtk.Button('_Browse')
Expand Down Expand Up @@ -481,13 +481,52 @@ def _select_file(self, button, data):
if not file is None:
entry.set_text(file.path)

def _get_page_completion(self):
print 'TODO page completion'
return gtk.EntryCompletion()
def _set_page_completion(self, entry):
# TODO: more advanced widget for this
if not (self.ui and hasattr(self.ui, 'notebook')):
logger.warn('Could not set page completion, no ui object')
return
completion = gtk.EntryCompletion()
model = gtk.ListStore(str)
completion.set_model(model)
completion.set_text_column(0)
completion.set_inline_completion(True)
entry.set_completion(completion)
entry.zim_completion_namespace = None
entry.connect('changed', self._update_page_completion)

def _set_namespace_completion(self, entry):
# TODO: more advanced widget for this
self._set_page_completion(entry)

def _update_page_completion(self, entry):
text = entry.get_text()
namespace = self.ui.page.namespace
prefix = len(namespace)+1
if ':' in text:
i = text.rfind(':')
if text.startswith(':'):
namespace = text[:i]
prefix = 0
else:
namespace += ':' + text[:i]

def _get_namespace_completion(self):
print 'TODO namespace completion'
return gtk.EntryCompletion()
if entry.zim_completion_namespace == namespace:
return
else:
entry.zim_completion_namespace = namespace
if namespace.strip(':'):
namespace = self.ui.notebook.resolve_path(namespace)
else:
namespace = Path(':')
#~ print 'Completing', namespace

completion = entry.get_completion()
model = completion.get_model()
model.clear()
for p in self.ui.notebook.index.list_pages(namespace):
#~ print '>', p, p.name[prefix:]
model.append((p.name[prefix:],))

def get_field(self, name):
'''Returns the value of a single field'''
Expand Down

0 comments on commit 450a291

Please sign in to comment.