summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--g-ed-it/commitDialog.py8
-rw-r--r--g-ed-it/docBar.py94
-rw-r--r--g-ed-it/docHelper.py20
-rw-r--r--g-ed-it/gitAction.py40
-rw-r--r--g-ed-it/windowHelper.py8
5 files changed, 94 insertions, 76 deletions
diff --git a/g-ed-it/commitDialog.py b/g-ed-it/commitDialog.py
index 683e888..668a5c0 100644
--- a/g-ed-it/commitDialog.py
+++ b/g-ed-it/commitDialog.py
@@ -49,11 +49,9 @@ class CommitDialog (object):
self.cwd = os.path.dirname(fileURI)
if allFile:
self.fileName = None
- templateMsg = subprocess.Popen(["git-status","-s"],stdout=subprocess.PIPE,cwd=self.cwd).communicate()[0]
else:
self.fileName = os.path.basename(fileURI)
- templateMsg = subprocess.Popen(["git-status","-s",self.fileName],stdout=subprocess.PIPE,cwd=self.cwd).communicate()[0]
- self.commit_text_box.get_buffer().set_text(templateMsg)
+ self.commit_text_box.get_buffer().set_text("")
self.commit_dialog.show()
def on_cancel_button_clicked(self, close_button):
@@ -63,9 +61,9 @@ class CommitDialog (object):
commit_text_buffer = self.commit_text_box.get_buffer()
commit_text = commit_text_buffer.get_text(commit_text_buffer.get_start_iter(),commit_text_buffer.get_end_iter())
if self.fileName :
- subprocess.call(["git-commit","-m'"+commit_text+"'", self.fileName],stdout=subprocess.PIPE,cwd=self.cwd)
+ subprocess.call('git-commit -m "'+commit_text+'" '+self.fileName,stdout=subprocess.PIPE,cwd=self.cwd, shell=True)
else:
- subprocess.call(["git-commit","-m'"+commit_text+"'"],stdout=subprocess.PIPE,cwd=self.cwd)
+ subprocess.call('git-commit -m "'+commit_text+'"',stdout=subprocess.PIPE,cwd=self.cwd, shell=True)
commit_text_buffer.set_text("")
self.commit_dialog.hide()
self.plugin.fast_update_ui()
diff --git a/g-ed-it/docBar.py b/g-ed-it/docBar.py
index 9d019c1..29d2027 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,69 +39,89 @@ 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.child = self.tab.get_children()[0]
- self.tab.remove(self.child)
- self.vbox = gtk.VBox()
+ 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.window)
self.btn_commit = gtk.Button("commit")
- self.btn_commit.connect("clicked", self.gitAction.commit, window, self.tab.get_document().get_uri_for_display)
+ self.btn_commit.connect("clicked", self.gitAction.commit_current_file, self.window)
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.window)
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.window)
self.docBar.pack_start(self.btn_diff_head_index, False, False)
self.docBar.pack_start(self.btn_diff_index_wt, False, False)
- self.docBar.pack_start(self.lbl_status, True, False)
- self.docBar.pack_start(self.btn_add, False, False)
+ self.docBar.pack_start(self.lbl_status, True, True)
+ self.docBar.pack_start(self.commit_text, True, True)
self.docBar.pack_start(self.btn_commit, False, False)
+ self.docBar.pack_start(self.btn_add, False, False)
- self.vbox.pack_start(self.docBar, False, False)
- self.vbox.pack_start(self.child)
-
- self.tab.add(self.vbox)
-
- 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 deactivate(self):
- self.tab.remove(self.vbox)
- self.vbox.remove(self.child)
- self.tab.add(self.child)
+ if self.currentTab:
+ self.currentTab.remove(self.docBar)
- self.doc = None
- self.vbox = None
- self.child = None
- self.tab = None
+ self.docBar = 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 :
+ self.docBar.hide()
+ return
+ _docHelper.getDocState()
+ if 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.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 dcd2c29..428344a 100644
--- a/g-ed-it/docHelper.py
+++ b/g-ed-it/docHelper.py
@@ -21,32 +21,22 @@
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.getDocState()
- self.docBar = docBar.DocBar(tab,self.gitAction, window, self)
+ self.tab.set_data(self.KEY,self)
- self.update_handler1 = self.doc.connect("saved",self.doc_changed)
- self.update_handler2 = self.doc.connect("loaded",self.doc_changed)
+ self.getDocState()
pass
def deactivate(self):
- self.doc.disconnect(self.update_handler1)
- self.doc.disconnect(self.update_handler2)
- self.docBar.deactivate()
-
- def update_ui(self):
- self.getDocState()
- self.docBar.update_ui()
-
- def doc_changed(self,doc,arg1):
- self.getDocState()
+ self.tab.set_data(self.KEY,None)
def getDocState(self):
uri = self.doc.get_uri_for_display()
diff --git a/g-ed-it/gitAction.py b/g-ed-it/gitAction.py
index bf4670d..fa51551 100644
--- a/g-ed-it/gitAction.py
+++ b/g-ed-it/gitAction.py
@@ -33,28 +33,32 @@ class GitAction (object):
self.plugin = plugin
pass
- def commit(self,launcher,window,fileUriMethod = None):
- if fileUriMethod :
- fileUri = fileUriMethod()
- allFile = False
+ def commit(self, button, window):
+ fileUri = window.get_active_tab().get_document().get_uri_for_display()
+ self.commitDialog.run(window,fileUri,True)
+
+ def commit_current_file(self, button, window):
+ fileUri = window.get_active_tab().get_document().get_uri_for_display()
+ text = self.plugin.windowHelpers[window].docBar.commit_text.get_text()
+ self.plugin.windowHelpers[window].docBar.commit_text.set_text("")
+ if text != "":
+ subprocess.call('git-commit -m "'+text+'" '+os.path.basename(fileUri),stdout=subprocess.PIPE,cwd=os.path.dirname(fileUri), shell=True)
+ window.emit("active-tab-state-changed")
else:
- fileUri = window.get_active_document().get_uri_for_display()
- allFile = True
- self.commitDialog.run(window,fileUri,allFile)
- pass
+ self.commitDialog.run(window,fileUri,False)
- def add(self,launcher,fileUriMethod = None):
- if fileUriMethod : fileUri = fileUriMethod()
- subprocess.call(["git-add",os.path.basename(fileUri)],stdout=subprocess.PIPE,cwd=os.path.dirname(fileUri))
- self.plugin.fast_update_ui()
+ def add(self, button, window):
+ fileUri = window.get_active_tab().get_document().get_uri_for_display()
+ subprocess.call("git-add "+os.path.basename(fileUri),stdout=subprocess.PIPE,cwd=os.path.dirname(fileUri), shell=True)
+ window.emit("active-tab-state-changed")
pass
- def diff_head_index(self,launcher, fileUriMethod = None):
- if fileUriMethod : fileUri = fileUriMethod()
- subprocess.call(["git-difftool","--tool=meld","--no-prompt","--cached",os.path.basename(fileUri)],stdout=subprocess.PIPE,cwd=os.path.dirname(fileUri))
+ def diff_head_index(self, button, window):
+ fileUri = window.get_active_tab().get_document().get_uri_for_display()
+ subprocess.call("git-diff --cached "+os.path.basename(fileUri),stdout=subprocess.PIPE,cwd=os.path.dirname(fileUri), shell=True)
pass
- def diff_index_wt(self, launcher, fileUriMethod = None):
- if fileUriMethod : fileUri = fileUriMethod()
- subprocess.call(["git-difftool","--tool=meld","--no-prompt",os.path.basename(fileUri)],stdout=subprocess.PIPE,cwd=os.path.dirname(fileUri))
+ def diff_index_wt(self, button, window):
+ fileUri = window.get_active_tab().get_document().get_uri_for_display()
+ subprocess.call("git-diff "+os.path.basename(fileUri),stdout=subprocess.PIPE,cwd=os.path.dirname(fileUri), shell=True)
pass
diff --git a/g-ed-it/windowHelper.py b/g-ed-it/windowHelper.py
index b45d911..68f417b 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)
@@ -74,8 +80,6 @@ class WindowHelper:
self.gitAction = None
def update_ui(self):
- for docHelper in self.docHelpers:
- self.docHelpers[docHelper].update_ui()
return
def fast_update_ui(self):