1
# This file is part of the Frescobaldi project, http://www.frescobaldi.org/
3
# Copyright (c) 2008 - 2011 by Wilbert Berendsen
5
# This program is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU General Public License
7
# as published by the Free Software Foundation; either version 2
8
# of the License, or (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
# See http://www.gnu.org/licenses/ for more information.
21
Manages the actions that manipulate the bookmarks (see also bookmarks.py).
24
from __future__ import unicode_literals
26
from PyQt4.QtCore import Qt
27
from PyQt4.QtGui import QAction
29
import actioncollection
30
import actioncollectionmanager
36
class BookmarkManager(plugin.MainWindowPlugin):
37
def __init__(self, mainwindow):
38
ac = self.actionCollection = Actions()
39
actioncollectionmanager.manager(mainwindow).addActionCollection(ac)
40
ac.view_next_mark.triggered.connect(self.nextMark)
41
ac.view_previous_mark.triggered.connect(self.previousMark)
42
ac.view_bookmark.triggered.connect(self.markCurrentLine)
43
ac.view_clear_error_marks.triggered.connect(self.clearErrorMarks)
44
ac.view_clear_all_marks.triggered.connect(self.clearAllMarks)
45
mainwindow.currentViewChanged.connect(self.slotViewChanged)
46
mainwindow.currentDocumentChanged.connect(self.slotDocumentChanged)
47
if mainwindow.currentView():
48
self.slotViewChanged(mainwindow.currentView())
49
self.slotDocumentChanged(mainwindow.currentDocument())
51
def slotViewChanged(self, view, prev=None):
53
prev.cursorPositionChanged.disconnect(self.updateMarkStatus)
54
view.cursorPositionChanged.connect(self.updateMarkStatus)
56
def slotDocumentChanged(self, doc, prev=None):
58
bookmarks.bookmarks(prev).marksChanged.disconnect(self.updateMarkStatus)
59
bookmarks.bookmarks(doc).marksChanged.connect(self.updateMarkStatus)
61
def updateMarkStatus(self):
62
view = self.mainwindow().currentView()
63
self.actionCollection.view_bookmark.setChecked(
64
bookmarks.bookmarks(view.document()).hasMark(view.textCursor().blockNumber(), 'mark'))
66
def markCurrentLine(self):
67
view = self.mainwindow().currentView()
68
lineNumber = view.textCursor().blockNumber()
69
bookmarks.bookmarks(view.document()).toggleMark(lineNumber, 'mark')
71
def clearErrorMarks(self):
72
doc = self.mainwindow().currentDocument()
73
bookmarks.bookmarks(doc).clear('error')
75
def clearAllMarks(self):
76
doc = self.mainwindow().currentDocument()
77
bookmarks.bookmarks(doc).clear()
80
view = self.mainwindow().currentView()
81
cursor = view.textCursor()
82
cursor = bookmarks.bookmarks(view.document()).nextMark(cursor)
84
view.setTextCursor(cursor)
86
def previousMark(self):
87
view = self.mainwindow().currentView()
88
cursor = view.textCursor()
89
cursor = bookmarks.bookmarks(view.document()).previousMark(cursor)
91
view.setTextCursor(cursor)
94
class Actions(actioncollection.ActionCollection):
95
name = "bookmarkmanager"
96
def createActions(self, parent):
97
self.view_bookmark = QAction(parent)
98
self.view_bookmark.setCheckable(True)
99
self.view_clear_error_marks = QAction(parent)
100
self.view_clear_all_marks = QAction(parent)
101
self.view_next_mark = QAction(parent)
102
self.view_previous_mark = QAction(parent)
104
self.view_bookmark.setShortcut(Qt.CTRL + Qt.Key_B)
105
self.view_next_mark.setShortcut(Qt.ALT + Qt.Key_PageDown)
106
self.view_previous_mark.setShortcut(Qt.ALT + Qt.Key_PageUp)
108
self.view_bookmark.setIcon(icons.get('bookmark-new'))
109
self.view_clear_all_marks.setIcon(icons.get('edit-clear'))
111
def translateUI(self):
112
self.view_bookmark.setText(_("&Mark Current Line"))
113
self.view_clear_error_marks.setText(_("Clear &Error Marks"))
114
self.view_clear_all_marks.setText(_("Clear &All Marks"))
115
self.view_next_mark.setText(_("Next Mark"))
116
self.view_previous_mark.setText(_("Previous Mark"))