Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

Commit 1497d3c

Browse files
add the possiblity to modify the branch name
1 parent b8f95ce commit 1497d3c

File tree

5 files changed

+154
-28
lines changed

5 files changed

+154
-28
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
build/
22
tags
3+
po/*.mo
4+
po/*.po~

nautilus-git/git.py

Lines changed: 120 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,31 @@ def get_stat(self, filename):
161161
return ", ".join(stat.split("\n")[1].split(",")[1:])
162162
return None
163163

164+
def get_project_branch(self):
165+
branch = ""
166+
project_name = self.get_project_name()
167+
if project_name:
168+
branch += project_name + "/"
169+
branch += self.get_branch()
170+
return branch
171+
172+
def check_branch_name(self, branch):
173+
return True
174+
175+
def get_branch_list(self):
176+
b_list = execute("git branch --list", self.dir).split("\n")
177+
def clean_branch_name(branch_name):
178+
return str(branch_name).lstrip("*").strip()
179+
return list(map(clean_branch_name, b_list))
180+
181+
def update_branch(self, branch):
182+
branches = self.get_branch_list()
183+
if branch in branches:
184+
execute("git checkout {}".format(branch), self.dir)
185+
else:
186+
execute("git checkout -b {0}".format(branch), self.dir)
187+
188+
164189
class NautilusPropertyPage(Gtk.Grid):
165190
"""Property page main widget class."""
166191
def __init__(self, git):
@@ -209,8 +234,9 @@ class NautilusLocation(Gtk.InfoBar):
209234
_popover = None
210235
_diff_button = None
211236

212-
def __init__(self, git):
237+
def __init__(self, git, window):
213238
Gtk.InfoBar.__init__(self)
239+
self._window = window
214240
self._git = git
215241
self.set_message_type(Gtk.MessageType.QUESTION)
216242
self.show()
@@ -229,16 +255,11 @@ def _build_widgets(self):
229255
image.show()
230256
container.attach(image, 0, 0, 1, 1)
231257

232-
label = Gtk.Label()
233-
project = self._git.get_project_name()
234-
branch = ""
235-
if project:
236-
branch = "{0}/".format(project)
237-
branch += self._git.get_branch()
238-
239-
label.set_text(branch)
240-
label.show()
241-
container.attach(label, 1, 0, 1, 1)
258+
branch_button = Gtk.Button()
259+
branch_button.set_label(self._git.get_project_branch())
260+
branch_button.connect("clicked", self._update_branch)
261+
branch_button.show()
262+
container.attach(branch_button, 1, 0, 1, 1)
242263
self.get_content_area().add(container)
243264

244265
status = self._git.get_status()
@@ -254,13 +275,17 @@ def _build_widgets(self):
254275

255276
self.get_action_area().pack_end(button, False, False, 0)
256277

278+
def _update_branch(self, button):
279+
commit = BranchWidget(self._git, self._window)
280+
257281
@staticmethod
258282
def _build_status_widget(status):
259283
"""Build a widget, contains a counter of modified/added/removed files."""
260284
i = 0
261285
grid = Gtk.Grid()
262286
grid.set_row_spacing(3)
263287
grid.set_column_spacing(3)
288+
grid.set_valign(Gtk.Align.CENTER)
264289
grid.show()
265290
for _status in status:
266291
if int(status[_status]) > 0:
@@ -408,6 +433,89 @@ def _build_main(self):
408433
box.show()
409434
self.add(box)
410435

436+
437+
class BranchWidget(Gtk.Window):
438+
439+
def __init__(self, git, window):
440+
self._git = git
441+
Gtk.Window.__init__(self, Gtk.WindowType.POPUP)
442+
# Header Bar
443+
self._build_headerbar()
444+
445+
self.set_position(Gtk.WindowPosition.CENTER)
446+
self.set_titlebar(self.hb)
447+
self.set_default_size(350, 100)
448+
self.set_transient_for(window)
449+
self.set_modal(True)
450+
self.set_resizable(False)
451+
self.set_border_width(18)
452+
self._build_main_widget()
453+
454+
self.show_all()
455+
456+
def _build_headerbar(self):
457+
self.hb = Gtk.HeaderBar()
458+
self.hb.set_title(self._git.get_project_branch())
459+
# self.hb.set_show_close_button(True)
460+
461+
self.apply = Gtk.Button()
462+
self.apply.set_label(_("Apply"))
463+
self.apply.get_style_context().add_class("suggested-action")
464+
self.apply.connect("clicked", self.update_branch)
465+
self.apply.set_sensitive(False)
466+
self.apply.show()
467+
self.hb.pack_end(self.apply)
468+
469+
self.cancel = Gtk.Button()
470+
self.cancel.set_label(_("Cancel"))
471+
self.cancel.connect("clicked", self.close_window)
472+
self.cancel.show()
473+
self.hb.pack_start(self.cancel)
474+
475+
def _build_main_widget(self):
476+
grid = Gtk.Grid()
477+
branches = self._git.get_branch_list()
478+
current_branch = self._git.get_branch()
479+
self.branch_entry = Gtk.ComboBoxText.new_with_entry()
480+
self.branch_entry.set_entry_text_column(0)
481+
i = 0
482+
for branch in branches:
483+
if branch == current_branch:
484+
active_id = i
485+
self.branch_entry.append_text(branch)
486+
i += 1
487+
self.branch_entry.set_active(active_id)
488+
self.branch_entry.connect("changed", self._validate_branch_name)
489+
self.branch_entry.show()
490+
grid.set_halign(Gtk.Align.CENTER)
491+
grid.add(self.branch_entry)
492+
grid.show()
493+
self.add(grid)
494+
495+
def _validate_branch_name(self, entry):
496+
branch = entry.get_active_text().strip()
497+
valid = True
498+
if branch == self._git.get_branch() or not branch:
499+
valid = False
500+
else:
501+
valid = self._git.check_branch_name(branch)
502+
503+
self.apply.set_sensitive(valid)
504+
if valid:
505+
entry.get_style_context().remove_class("error")
506+
else:
507+
entry.get_style_context().add_class("error")
508+
509+
510+
def update_branch(self, *args):
511+
branch = self.branch_entry.get_active_text().strip()
512+
self._git.update_branch(branch)
513+
self.close_window()
514+
# Todo : refresh the window if possible?
515+
516+
def close_window(self, *args):
517+
self.destroy()
518+
411519
class NautilusGitLocationWidget(GObject.GObject, Nautilus.LocationWidgetProvider):
412520
"""Location widget extension."""
413521
def __init__(self):
@@ -420,7 +528,7 @@ def get_widget(self, uri, window):
420528
self.window = window
421529
if is_git(uri):
422530
git = Git(uri)
423-
widget = NautilusLocation(git)
531+
widget = NautilusLocation(git, self.window)
424532
return widget
425533
else:
426534
return None

po/es.mo

-1005 Bytes
Binary file not shown.

po/es.po

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: \n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2017-04-17 17:32-0500\n"
10+
"POT-Creation-Date: 2017-04-20 16:31+0200\n"
1111
"PO-Revision-Date: 2017-04-17 17:36-0500\n"
12+
"Last-Translator: Adolfo Jayme Barrientos <fitojb@ubuntu.com>\n"
1213
"Language-Team: \n"
14+
"Language: es\n"
1315
"MIME-Version: 1.0\n"
1416
"Content-Type: text/plain; charset=UTF-8\n"
1517
"Content-Transfer-Encoding: 8bit\n"
1618
"X-Generator: Poedit 2.0.1\n"
17-
"Last-Translator: Adolfo Jayme Barrientos <fitojb@ubuntu.com>\n"
1819
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
19-
"Language: es\n"
2020

2121
#: nautilus-git/git.py:38
2222
msgid "Added files"
@@ -42,27 +42,35 @@ msgstr "Archivos modificados"
4242
msgid "Modified :"
4343
msgstr "Modificados:"
4444

45-
#: nautilus-git/git.py:178
45+
#: nautilus-git/git.py:203
4646
msgid "Branch:"
4747
msgstr "Rama:"
4848

49-
#: nautilus-git/git.py:250
49+
#: nautilus-git/git.py:271
5050
msgid "More..."
5151
msgstr "Más…"
5252

53-
#: nautilus-git/git.py:296
53+
#: nautilus-git/git.py:321
5454
msgid "Open remote URL"
5555
msgstr "Abrir un URL remoto"
5656

57-
#: nautilus-git/git.py:309
57+
#: nautilus-git/git.py:334
5858
msgid "Compare commits"
5959
msgstr "Comparar envíos"
6060

61-
#: nautilus-git/git.py:335
61+
#: nautilus-git/git.py:360
6262
#, python-brace-format
6363
msgid "Comparing commits of {0}"
6464
msgstr "Comparación de envíos de {0}"
6565

66-
#: nautilus-git/git.py:445
66+
#: nautilus-git/git.py:462
67+
msgid "Apply"
68+
msgstr ""
69+
70+
#: nautilus-git/git.py:470
71+
msgid "Cancel"
72+
msgstr ""
73+
74+
#: nautilus-git/git.py:553
6775
msgid "Git"
6876
msgstr "Git"

po/nautilus-git.pot

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2017-04-17 17:31-0500\n"
11+
"POT-Creation-Date: 2017-04-20 16:31+0200\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -41,27 +41,35 @@ msgstr ""
4141
msgid "Modified :"
4242
msgstr ""
4343

44-
#: nautilus-git/git.py:178
44+
#: nautilus-git/git.py:203
4545
msgid "Branch:"
4646
msgstr ""
4747

48-
#: nautilus-git/git.py:250
48+
#: nautilus-git/git.py:271
4949
msgid "More..."
5050
msgstr ""
5151

52-
#: nautilus-git/git.py:296
52+
#: nautilus-git/git.py:321
5353
msgid "Open remote URL"
5454
msgstr ""
5555

56-
#: nautilus-git/git.py:309
56+
#: nautilus-git/git.py:334
5757
msgid "Compare commits"
5858
msgstr ""
5959

60-
#: nautilus-git/git.py:335
60+
#: nautilus-git/git.py:360
6161
#, python-brace-format
6262
msgid "Comparing commits of {0}"
6363
msgstr ""
6464

65-
#: nautilus-git/git.py:445
65+
#: nautilus-git/git.py:462
66+
msgid "Apply"
67+
msgstr ""
68+
69+
#: nautilus-git/git.py:470
70+
msgid "Cancel"
71+
msgstr ""
72+
73+
#: nautilus-git/git.py:553
6674
msgid "Git"
6775
msgstr ""

0 commit comments

Comments
 (0)