From 4638e7b7b58d39ef1436034deead5d573ca81527 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 13 Oct 2012 15:33:32 +0200 Subject: Fixes #2376 (Only open one XMLTab) - Also make Core.focus_tab_named take an optional type, and return a boolean --- src/core.py | 22 ++++++++++++++-------- src/tabs.py | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/core.py b/src/core.py index c6d7d557..7e21a786 100644 --- a/src/core.py +++ b/src/core.py @@ -128,7 +128,7 @@ class Core(object): self.tab_win = windows.GlobalInfoBar() # Number of xml tabs opened, used to avoid useless memory consumption - self.xml_tabs = 0 + self.xml_tab = False self.xml_buffer = TextBuffer() self.tabs = [] @@ -848,10 +848,14 @@ class Core(object): return return - def focus_tab_named(self, tab_name): + def focus_tab_named(self, tab_name, type_=None): + """Returns True if it found a tab to focus on""" for tab in self.tabs: if tab.get_name() == tab_name: - self.command_win('%s' % (tab.nb,)) + if (type_ and (isinstance(tab, type_))) or not type_: + self.command_win('%s' % (tab.nb,)) + return True + return False @property def current_tab_nb(self): @@ -2258,9 +2262,11 @@ class Core(object): def command_xml_tab(self, arg=''): """/xml_tab""" - self.xml_tabs += 1 - tab = tabs.XMLTab() - self.add_tab(tab, True) + self.xml_tab = True + xml_tab = self.focus_tab_named('XMLTab', tabs.XMLTab) + if not xml_tab: + tab = tabs.XMLTab() + self.add_tab(tab, True) def command_self(self, arg=None): """ @@ -2854,7 +2860,7 @@ class Core(object): """ We are sending a new stanza, write it in the xml buffer if needed. """ - if self.xml_tabs: + if self.xml_tab: self.add_message_to_text_buffer(self.xml_buffer, '\x191}<--\x19o %s' % stanza) if isinstance(self.current_tab(), tabs.XMLTab): self.current_tab().refresh() @@ -2864,7 +2870,7 @@ class Core(object): """ We are receiving a new stanza, write it in the xml buffer if needed. """ - if self.xml_tabs: + if self.xml_tab: self.add_message_to_text_buffer(self.xml_buffer, '\x192}-->\x19o %s' % stanza) if isinstance(self.current_tab(), tabs.XMLTab): self.current_tab().refresh() diff --git a/src/tabs.py b/src/tabs.py index 27f79d9b..da6bceaf 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -3244,7 +3244,7 @@ class XMLTab(Tab): curses.curs_set(0) def on_close(self): - self.core.xml_tabs -= 1 + self.core.xml_tab = False class SimpleTextTab(Tab): """ -- cgit v1.2.3