summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthieu Gautier <mgautier@fedoraproject.org>2009-05-03 22:49:02 +0200
committerMatthieu Gautier <mgautier@fedoraproject.org>2009-05-04 18:55:17 +0200
commit37e613ff2b5b71228d158a3e8455d80f3b019622 (patch)
tree76b5db8ab3732cc674f0e20c866ff2e2e9c0f1c8
parent84f3c1a56d3de4b22688adcdb4773ed2a94a59b9 (diff)
downloadg-ed-it-37e613ff2b5b71228d158a3e8455d80f3b019622.zip
g-ed-it-37e613ff2b5b71228d158a3e8455d80f3b019622.tar.gz
g-ed-it-37e613ff2b5b71228d158a3e8455d80f3b019622.tar.xz
switch to an unique docBar
-rw-r--r--g-ed-it/docBar.py73
-rw-r--r--g-ed-it/docHelper.py9
-rw-r--r--g-ed-it/windowHelper.py6
3 files changed, 62 insertions, 26 deletions
diff --git a/g-ed-it/docBar.py b/g-ed-it/docBar.py
index 990c850..a3d1712 100644
--- a/g-ed-it/docBar.py
+++ b/g-ed-it/docBar.py
@@ -22,6 +22,8 @@ import gedit
import gtk
import subprocess
+import docHelper
+
import os
import os.path
@@ -37,28 +39,35 @@ class DocBar (object):
'X':'Unknown',
'B':'pairing Broken'
})
- def __init__(self, tab, gitAction, window, docHelper):
- self.tab = tab
+ def __init__(self, gitAction, window):
self.gitAction = gitAction
- self.docHelper = docHelper
+ self.window = window
- self.docBar = gtk.HBox()
+ self.currentTab = None
+ self.create_docBar()
+
+ self.swap_to_currentTab(window.get_active_tab())
+
+ self.window.connect("active-tab-changed",self.active_tab_changed)
+ self.window.connect("active-tab-state-changed",self.active_tab_state_changed)
+ def create_docBar(self):
+ self.docBar = gtk.HBox()
self.lbl_status = gtk.Label("√Čtat du fichier")
self.commit_text = gtk.Entry()
self.btn_add = gtk.Button("add")
- self.btn_add.connect("clicked", self.gitAction.add, self.tab.get_document().get_uri_for_display)
+ self.btn_add.connect("clicked", self.gitAction.add)
self.btn_commit = gtk.Button("commit")
- self.btn_commit.connect("clicked", self.gitAction.commit, window, self.tab.get_document().get_uri_for_display,self.get_and_clear_commitText)
+ self.btn_commit.connect("clicked", self.gitAction.commit, self.window,self.get_and_clear_commitText)
self.btn_diff_head_index = gtk.Button("diff HEAD/INDEX")
- self.btn_diff_head_index.connect("clicked", self.gitAction.diff_head_index, self.tab.get_document().get_uri_for_display)
+ self.btn_diff_head_index.connect("clicked", self.gitAction.diff_head_index)
self.btn_diff_index_wt = gtk.Button("diff INDEX/WT")
- self.btn_diff_index_wt.connect("clicked", self.gitAction.diff_index_wt, self.tab.get_document().get_uri_for_display)
+ self.btn_diff_index_wt.connect("clicked", self.gitAction.diff_index_wt)
self.docBar.pack_start(self.btn_diff_head_index, False, False)
self.docBar.pack_start(self.btn_diff_index_wt, False, False)
@@ -67,11 +76,22 @@ class DocBar (object):
self.docBar.pack_start(self.btn_commit, False, False)
self.docBar.pack_start(self.btn_add, False, False)
- self.tab.pack_start(self.docBar, False, False)
-
- self.tab.show_all()
+ def active_tab_changed(self,window,tab):
+ print "tab_change"
+ self.swap_to_currentTab(tab)
+
+ def active_tab_state_changed(self,window):
+ print "tab_state_changed"
+ self.update_docBar_ui()
- self.update_ui()
+ def swap_to_currentTab(self, tab):
+ if self.currentTab:
+ self.currentTab.remove(self.docBar)
+ self.currentTab = tab
+ if self.currentTab:
+ self.currentTab.pack_start(self.docBar, False, False)
+ self.currentTab.show_all()
+ self.update_docBar_ui()
def get_and_clear_commitText(self):
text = self.commit_text.get_text()
@@ -79,26 +99,31 @@ class DocBar (object):
return text
def deactivate(self):
- self.tab.remove(self.docBar)
+ if self.currentTab:
+ self.currentTab.remove(self.docBar)
self.docBar = None
- self.tab = None
+ self.currentTab = None
- def update_ui(self):
- if not self.docHelper.inGitDir :
+ def update_docBar_ui(self):
+ if not self.currentTab:
+ return
+ _docHelper = self.currentTab.get_data(docHelper.DocHelper.KEY)
+ if not _docHelper or not _docHelper.inGitDir :
self.docBar.hide()
return
+
self.docBar.show()
- self.btn_add.set_sensitive(self.docHelper.index2WT!=None or not self.docHelper.isCached)
- self.btn_commit.set_sensitive(self.docHelper.HEAD2index!=None)
- self.commit_text.set_sensitive(self.docHelper.HEAD2index!=None)
- self.btn_diff_head_index.set_sensitive(self.docHelper.HEAD2index!=None)
- self.btn_diff_index_wt.set_sensitive(self.docHelper.index2WT!=None)
+ self.btn_add.set_sensitive(_docHelper.index2WT!=None or not _docHelper.isCached)
+ self.btn_commit.set_sensitive(_docHelper.HEAD2index!=None)
+ self.commit_text.set_sensitive(_docHelper.HEAD2index!=None)
+ self.btn_diff_head_index.set_sensitive(_docHelper.HEAD2index!=None)
+ self.btn_diff_index_wt.set_sensitive(_docHelper.index2WT!=None)
text = "HEAD <-"
- text = text + DocBar.code2status[self.docHelper.HEAD2index]
+ text = text + DocBar.code2status[_docHelper.HEAD2index]
text = text + "-> INDEX <-"
- if self.docHelper.isCached :
- text = text + DocBar.code2status[self.docHelper.index2WT]
+ if _docHelper.isCached :
+ text = text + DocBar.code2status[_docHelper.index2WT]
else:
text = text + DocBar.code2status['A']
text = text + "-> WT"
diff --git a/g-ed-it/docHelper.py b/g-ed-it/docHelper.py
index e44ab2f..043be86 100644
--- a/g-ed-it/docHelper.py
+++ b/g-ed-it/docHelper.py
@@ -21,15 +21,19 @@
import os.path
import subprocess
-import docBar
+
class DocHelper (object):
+ KEY = "G-ED-IT_DOCHELPER_KEY"
def __init__(self, tab, window, gitAction):
self.doc = tab.get_document()
self.gitAction = gitAction
self.tab = tab
+
+ self.tab.set_data(self.KEY,self)
+
self.getDocState()
-
+
self.update_handler1 = self.doc.connect("saved",self.doc_changed)
self.update_handler2 = self.doc.connect("loaded",self.doc_changed)
pass
@@ -37,6 +41,7 @@ class DocHelper (object):
def deactivate(self):
self.doc.disconnect(self.update_handler1)
self.doc.disconnect(self.update_handler2)
+ self.tab.set_data(self.KEY,self)
def update_ui(self):
self.getDocState()
diff --git a/g-ed-it/windowHelper.py b/g-ed-it/windowHelper.py
index b45d911..4cf4d3c 100644
--- a/g-ed-it/windowHelper.py
+++ b/g-ed-it/windowHelper.py
@@ -29,6 +29,7 @@ import os
import time
import docHelper
+import docBar
ui_string = """<ui>
<menubar name="MenuBar">
@@ -48,8 +49,11 @@ class WindowHelper:
self.plugin = plugin
self.gitAction = gitAction
+
self.docHelpers = {}
self.create_all_docHelper()
+
+ self.docBar = docBar.DocBar(self.gitAction,window)
self.create_actionManager()
# add menu
@@ -63,6 +67,8 @@ class WindowHelper:
self.manager.ensure_update()
self.manager = None
+ self.docBar.deactivate()
+
self.window.disconnect(self.added_hid)
self.window.disconnect(self.removed_hid)