summaryrefslogtreecommitdiffstats
path: root/g-ed-it/docBar.py
blob: 9d019c1d7ccf56463c576a19d09a041155d15848 (plain)
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
#!/usr/bin/env python
#-*- coding:utf-8 -*-

#    Copyright 2009 Matthieu Gautier

#    This file is part of g-ed-it.
#
#    g-ed-it is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    any later version.
#
#    g-ed-it is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with g-ed-it.  If not, see <http://www.gnu.org/licenses/>.

import gedit
import gtk
import subprocess

import os
import os.path

class DocBar (object):
	code2status = dict({None:'Unchanged',
	                    'A':'Added',
	                    'C':'Copied',
	                    'D':'Deleted',
	                    'M':'Modified',
	                    'R':'Renamed',
	                    'T':'Type changed',
	                    'U':'Unmerged',
	                    'X':'Unknown',
	                    'B':'pairing Broken'
	                   })
	def __init__(self, tab, gitAction, window, docHelper):
		self.tab = tab
		self.gitAction = gitAction
		self.docHelper = docHelper
		self.child = self.tab.get_children()[0]
		self.tab.remove(self.child)
		self.vbox = gtk.VBox()
		
		self.docBar = gtk.HBox() 
		
		self.lbl_status = gtk.Label("État du fichier")
		
		self.btn_add = gtk.Button("add")
		self.btn_add.connect("clicked", self.gitAction.add, self.tab.get_document().get_uri_for_display)
		
		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_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_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.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.btn_commit, 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()
		
		self.update_ui()
		
	def deactivate(self):
		self.tab.remove(self.vbox)
		self.vbox.remove(self.child)
		self.tab.add(self.child)
		
		self.doc = None
		self.vbox = None
		self.child = None
		self.tab = None
		
	def update_ui(self):
		if not self.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)
		text = "HEAD <-"
		text = text + DocBar.code2status[self.docHelper.HEAD2index]
		text = text + "-> INDEX <-"
		if self.docHelper.isCached :
			text = text + DocBar.code2status[self.docHelper.index2WT]
		else:
			text = text + DocBar.code2status['A']
		text = text + "-> WT"
		self.lbl_status.set_label(text)