1 """Provides BookmarksDialog."""
4 from PyQt4
import QtGui
5 from PyQt4
.QtCore
import Qt
6 from PyQt4
.QtCore
import SIGNAL
9 from cola
import qtutils
10 from cola
import settings
11 from cola
.i18n
import N_
12 from cola
.interaction
import Interaction
13 from cola
.widgets
import defs
14 from cola
.widgets
import standard
17 def manage_bookmarks():
18 dlg
= BookmarksDialog(qtutils
.active_window())
24 class BookmarksDialog(standard
.Dialog
):
25 def __init__(self
, parent
):
26 standard
.Dialog
.__init
__(self
, parent
)
27 self
.model
= settings
.Settings()
30 self
.setWindowTitle(N_('Bookmarks'))
31 self
.setWindowModality(Qt
.WindowModal
)
32 self
.layt
= QtGui
.QVBoxLayout(self
)
33 self
.layt
.setMargin(defs
.margin
)
34 self
.layt
.setSpacing(defs
.spacing
)
36 self
.bookmarks
= QtGui
.QListWidget(self
)
37 self
.bookmarks
.setAlternatingRowColors(True)
38 self
.bookmarks
.setSelectionMode(QtGui
.QAbstractItemView
41 self
.layt
.addWidget(self
.bookmarks
)
42 self
.button_layout
= QtGui
.QHBoxLayout()
44 self
.open_button
= QtGui
.QPushButton(self
)
45 self
.open_button
.setText(N_('Open'))
46 self
.open_button
.setIcon(qtutils
.open_icon())
47 self
.open_button
.setEnabled(False)
48 self
.button_layout
.addWidget(self
.open_button
)
50 self
.add_button
= QtGui
.QPushButton(self
)
51 self
.add_button
.setText(N_('Add'))
52 self
.add_button
.setIcon(qtutils
.icon('add.svg'))
53 self
.button_layout
.addWidget(self
.add_button
)
55 self
.delete_button
= QtGui
.QPushButton(self
)
56 self
.delete_button
.setText(N_('Delete'))
57 self
.delete_button
.setIcon(qtutils
.discard_icon())
58 self
.delete_button
.setEnabled(False)
59 self
.button_layout
.addWidget(self
.delete_button
)
60 self
.button_layout
.addStretch()
62 self
.save_button
= QtGui
.QPushButton(self
)
63 self
.save_button
.setText(N_('Save'))
64 self
.save_button
.setIcon(qtutils
.save_icon())
65 self
.save_button
.setEnabled(False)
66 self
.button_layout
.addWidget(self
.save_button
)
68 self
.close_button
= QtGui
.QPushButton(self
)
69 self
.close_button
.setText(N_('Close'))
70 self
.button_layout
.addWidget(self
.close_button
)
72 self
.layt
.addLayout(self
.button_layout
)
74 self
.connect(self
.bookmarks
, SIGNAL('itemSelectionChanged()'),
75 self
.item_selection_changed
)
77 qtutils
.connect_button(self
.open_button
, self
.open_repo
)
78 qtutils
.connect_button(self
.add_button
, self
.add
)
79 qtutils
.connect_button(self
.delete_button
, self
.delete
)
80 qtutils
.connect_button(self
.save_button
, self
.save
)
81 qtutils
.connect_button(self
.close_button
, self
.accept
)
83 self
.update_bookmarks()
85 def update_bookmarks(self
):
86 self
.bookmarks
.clear()
87 self
.bookmarks
.addItems(self
.model
.bookmarks
)
90 return qtutils
.selection_list(self
.bookmarks
, self
.model
.bookmarks
)
92 def item_selection_changed(self
):
93 has_selection
= bool(self
.selection())
94 self
.open_button
.setEnabled(has_selection
)
95 self
.delete_button
.setEnabled(has_selection
)
98 """Saves the bookmarks settings and exits"""
100 Interaction
.information(N_('Bookmarks Saved'),
101 N_('Successfully saved bookmarks'))
102 self
.save_button
.setEnabled(False)
105 path
, ok
= qtutils
.prompt(N_('Path to git repository'),
106 title
=N_('Enter Git Repository'),
110 self
.model
.bookmarks
.append(path
)
111 self
.update_bookmarks()
115 """Opens a new git-cola session on a bookmark"""
116 for repo
in self
.selection():
117 core
.fork([sys
.executable
, sys
.argv
[0], '--repo', repo
])
120 """Removes a bookmark from the bookmarks list"""
121 selection
= self
.selection()
124 for repo
in selection
:
125 self
.model
.remove_bookmark(repo
)
126 self
.update_bookmarks()
127 self
.save_button
.setEnabled(True)