1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import gedit
import gtk
import subprocess
import os
import os.path
class DocBar (object):
def __init__(self, tab, commitDialog):
self.tab = tab
self.child = self.tab.get_children()[0]
self.tab.remove(self.child)
self.vbox = gtk.VBox()
self.commitDialog = commitDialog
self.doc = self.tab.get_document()
self.update_handler1 = self.doc.connect("saved",self.doc_changed)
self.update_handler2 = self.doc.connect("loaded",self.doc_changed)
hbox = gtk.HBox()
self.lbl_status = gtk.Label("État du fichier")
self.btn_add = gtk.Button("add")
self.btn_add.connect("clicked", self.add_file)
self.btn_commit = gtk.Button("commit")
self.btn_commit.connect("clicked", self.commit_file)
hbox.pack_start(self.lbl_status, True, False)
hbox.pack_start(self.btn_add, False, False)
hbox.pack_start(self.btn_commit, False, False)
self.vbox.pack_start(hbox, False, False)
self.vbox.pack_start(self.child)
self.tab.add(self.vbox)
self.getDocState()
self.tab.show_all()
def deactivate(self):
self.tab.remove(self.vbox)
self.vbox.remove(self.child)
self.tab.add(self.child)
self.doc.disconnect(self.update_handler1)
self.doc.disconnect(self.update_handler2)
self.doc = None
self.vbox = None
self.child = None
self.tab = None
def getDocState(self):
uri = self.doc.get_uri_for_display()
cwd = os.path.dirname(uri)
bname = os.path.basename(uri)
self.HEAD2index = None
self.index2WT = None
if not self.doc.is_untitled():
statusStr = subprocess.Popen(["git-diff","--cached","--name-status",os.path.basename(uri)],stdout=subprocess.PIPE,cwd=cwd).communicate()[0]
if statusStr != "":
status = statusStr[:-1].split()[0]
self.HEAD2index = status
statusStr = subprocess.Popen(["git-diff","--name-status",os.path.basename(uri)],stdout=subprocess.PIPE,cwd=cwd).communicate()[0]
if statusStr != "":
status = statusStr[:-1].split()[0]
self.index2WT = status
self.setDocInfo()
pass
def setDocInfo(self):
self.btn_add.set_sensitive(self.index2WT!=None)
self.btn_commit.set_sensitive(self.HEAD2index!=None)
if self.doc.is_untitled():
self.lbl_status.set_label("Nouveau fichier")
else:
text = "HEAD -- "
if self.HEAD2index == "A":
text = text + "Added"
elif self.HEAD2index == "C":
text = text + "Copied"
elif self.HEAD2index == "D":
text = text + "Deleted"
elif self.HEAD2index == "M":
text = text + "Modified"
elif self.HEAD2index == "R":
text = text + "Renamed"
elif self.HEAD2index == "T":
text = text + "Type changed"
elif self.HEAD2index == "U":
text = text + "Unmerged"
elif self.HEAD2index == "X":
text = text + "Unknown"
elif self.HEAD2index == "B":
text = text + "pairing Broken"
text = text + " --> INDEX -- "
if self.index2WT == "A":
text = text + "Added"
elif self.index2WT == "C":
text = text + "Copied"
elif self.index2WT == "D":
text = text + "Deleted"
elif self.index2WT == "M":
text = text + "Modified"
elif self.index2WT == "R":
text = text + "Renamed"
elif self.index2WT == "T":
text = text + "Type changed"
elif self.index2WT == "U":
text = text + "Unmerged"
elif self.index2WT == "X":
text = text + "Unknown"
elif self.index2WT == "B":
text = text + "pairing Broken"
text = text + " --> WT"
self.lbl_status.set_label(text)
pass
def doc_changed(self,doc,arg1):
self.getDocState()
def add_file(self,button):
uri = self.doc.get_uri_for_display()
subprocess.call(["git-add",os.path.basename(uri)],stdout=subprocess.PIPE,cwd=os.path.dirname(uri))
self.getDocState()
pass
def commit_file(self,button):
uri = self.doc.get_uri_for_display()
self.commitDialog.show(uri)
self.getDocState()
pass
|