diff options
author | Florent Le Coz <louiz@louiz.org> | 2011-06-21 02:43:59 +0200 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2011-06-21 02:43:59 +0200 |
commit | 76cacb32a6a13fbd69593fffba011c97bcf8825e (patch) | |
tree | 1f21274744e231c356c40b606b55bcd2f65af8fb /src | |
parent | 0fa3cf756a50dffe01e46c725245445dc1cfd39b (diff) | |
download | poezio-76cacb32a6a13fbd69593fffba011c97bcf8825e.tar.gz poezio-76cacb32a6a13fbd69593fffba011c97bcf8825e.tar.bz2 poezio-76cacb32a6a13fbd69593fffba011c97bcf8825e.tar.xz poezio-76cacb32a6a13fbd69593fffba011c97bcf8825e.zip |
Enter displays the content of the selected item
Diffstat (limited to 'src')
-rw-r--r-- | src/pubsub.py | 42 | ||||
-rw-r--r-- | src/windows.py | 4 |
2 files changed, 41 insertions, 5 deletions
diff --git a/src/pubsub.py b/src/pubsub.py index 30ffd624..af9ca001 100644 --- a/src/pubsub.py +++ b/src/pubsub.py @@ -89,6 +89,8 @@ class PubsubBrowserTab(tabs.Tab): self.item_list_header = windows.ColumnHeaderWin(item_columns) self.item_listview = windows.ListWin(item_columns) + # Item viewer + self.item_viewer = windows.SimpleTextWin('') self.default_help_message = windows.HelpText("ācā: create a node.") self.input = self.default_help_message @@ -97,6 +99,7 @@ class PubsubBrowserTab(tabs.Tab): self.key_func["M-KEY_UP"] = self.scroll_node_up self.key_func["KEY_DOWN"] = self.item_listview.move_cursor_down self.key_func["KEY_UP"] = self.item_listview.move_cursor_up + self.key_func["^M"] = self.open_selected_item self.resize() self.get_nodes() @@ -118,6 +121,7 @@ class PubsubBrowserTab(tabs.Tab): self.item_listview.resize_columns(column_size) self.item_listview.resize(self.height//2-3, self.width//2, self.height//2+1, 0) + self.item_viewer.resize(self.height-3, self.width//2+1, 1, self.width//2) self.input.resize(1, self.width, self.height-1, 0) def refresh(self): @@ -129,6 +133,7 @@ class PubsubBrowserTab(tabs.Tab): self.node_listview.refresh() self.item_list_header.refresh() self.item_listview.refresh() + self.item_viewer.refresh() self.tab_win.refresh() self.input.refresh() @@ -154,7 +159,7 @@ class PubsubBrowserTab(tabs.Tab): def get_node_by_name(self, name): """ - in the current browsed node (or on the root), return the node with that name + in the currently browsed node (or on the root), return the node with that name """ nodes = self.current_node and self.current_node.subnodes or self.nodes for node in nodes: @@ -162,6 +167,30 @@ class PubsubBrowserTab(tabs.Tab): return node return None + def get_item_by_id(self, idd): + """ + in the currently selected node, return the item with that id + """ + selected_node_name = self.get_selected_node_name() + if not selected_node_name: + return None + selected_node = self.get_node_by_name(selected_node_name) + if not selected_node: + return None + for item in selected_node.items: + if item.id == idd: + return item + return None + + def get_selected_item_id(self): + """ + returns the id of the currently selected item + """ + line = self.item_listview.get_selected_row() + if not line: + return None + return line['id'] + def get_items(self, node): """ Get all items in the given node @@ -265,3 +294,14 @@ class PubsubBrowserTab(tabs.Tab): return True return False + def open_selected_item(self): + """ + displays the currently selected item in the item view window + """ + selected_item = self.get_item_by_id(self.get_selected_item_id()) + if not selected_item: + return + log.debug('Content: %s'%ET.tostring(selected_item.content)) + self.item_viewer._text = str(ET.tostring(selected_item.content)) + self.item_viewer.rebuild_text() + return True diff --git a/src/windows.py b/src/windows.py index 9f6fc676..8176da67 100644 --- a/src/windows.py +++ b/src/windows.py @@ -1633,10 +1633,6 @@ class SimpleTextWin(Win): self._text = text self.built_lines = [] - def resize(self, height, width, y, x, stdscr): - self._resize(height, width, y, x, stdscr) - self.rebuild_text() - def rebuild_text(self): """ Transform the text in lines than can then be |