1 """Provides BookmarksDialog."""
5 from PyQt4
import QtGui
6 from PyQt4
import QtCore
7 from PyQt4
.QtCore
import Qt
8 from PyQt4
.QtCore
import SIGNAL
11 from cola
import qtutils
12 from cola
import settings
13 from cola
import utils
14 from cola
.widgets
import defs
15 from cola
.widgets
import standard
18 def manage_bookmarks():
19 dlg
= BookmarksDialog(qtutils
.active_window())
25 class BookmarksDialog(standard
.Dialog
):
26 def __init__(self
, parent
):
27 standard
.Dialog
.__init
__(self
, parent
)
28 self
.model
= settings
.Settings()
31 self
.setWindowTitle(self
.tr('Bookmarks'))
32 self
.setWindowModality(Qt
.WindowModal
)
33 self
.layt
= QtGui
.QVBoxLayout(self
)
34 self
.layt
.setMargin(defs
.margin
)
35 self
.layt
.setSpacing(defs
.spacing
)
37 self
.bookmarks
= QtGui
.QListWidget(self
)
38 self
.bookmarks
.setAlternatingRowColors(True)
39 self
.bookmarks
.setSelectionMode(QtGui
.QAbstractItemView
42 self
.layt
.addWidget(self
.bookmarks
)
43 self
.button_layout
= QtGui
.QHBoxLayout()
45 self
.open_button
= QtGui
.QPushButton(self
)
46 self
.open_button
.setText(self
.tr('Open'))
47 self
.open_button
.setIcon(qtutils
.open_icon())
48 self
.button_layout
.addWidget(self
.open_button
)
50 self
.add_button
= QtGui
.QPushButton(self
)
51 self
.add_button
.setText(self
.tr('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(self
.tr('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(self
.tr('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(self
.tr('Close'))
70 self
.button_layout
.addWidget(self
.close_button
)
72 self
.layt
.addLayout(self
.button_layout
)
74 self
.connect(self
.open_button
, SIGNAL('clicked()'), self
.open_repo
)
75 self
.connect(self
.add_button
, SIGNAL('clicked()'), self
.add
)
76 self
.connect(self
.delete_button
, SIGNAL('clicked()'), self
.delete
)
77 self
.connect(self
.save_button
, SIGNAL('clicked()'), self
.save
)
78 self
.connect(self
.close_button
, SIGNAL('clicked()'), self
.accept
)
79 self
.connect(self
.bookmarks
, SIGNAL('itemSelectionChanged()'),
80 self
.item_selection_changed
)
82 self
.update_bookmarks()
84 def update_bookmarks(self
):
85 self
.bookmarks
.clear()
86 self
.bookmarks
.addItems(self
.model
.bookmarks
)
89 return qtutils
.selection_list(self
.bookmarks
, self
.model
.bookmarks
)
91 def item_selection_changed(self
):
92 has_selection
= bool(self
.selection())
93 self
.delete_button
.setEnabled(has_selection
)
96 """Saves the bookmarks settings and exits"""
98 qtutils
.information("Bookmarks Saved")
99 self
.save_button
.setEnabled(False)
102 path
, ok
= qtutils
.prompt('Path to git repository:',
103 title
='Enter Git Repository',
104 text
=core
.decode(os
.getcwd()))
107 self
.model
.bookmarks
.append(path
)
108 self
.update_bookmarks()
112 """Opens a new git-cola session on a bookmark"""
113 for repo
in self
.selection():
114 utils
.fork([sys
.executable
, sys
.argv
[0], '--repo', repo
])
117 """Removes a bookmark from the bookmarks list"""
118 selection
= self
.selection()
121 for repo
in selection
:
122 self
.model
.remove_bookmark(repo
)
123 self
.update_bookmarks()
124 self
.save_button
.setEnabled(True)