~ubuntu-branches/ubuntu/vivid/frescobaldi/vivid

« back to all changes in this revision

Viewing changes to frescobaldi_app/bookmarkmanager.py

  • Committer: Package Import Robot
  • Author(s): Ryan Kavanagh
  • Date: 2012-01-03 16:20:11 UTC
  • mfrom: (1.4.1)
  • Revision ID: package-import@ubuntu.com-20120103162011-tsjkwl4sntwmprea
Tags: 2.0.0-1
* New upstream release 
* Drop the following uneeded patches:
  + 01_checkmodules_no_python-kde4_build-dep.diff
  + 02_no_pyc.diff
  + 04_no_binary_lilypond_upgrades.diff
* Needs new dependency python-poppler-qt4
* Update debian/watch for new download path
* Update copyright file with new holders and years

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This file is part of the Frescobaldi project, http://www.frescobaldi.org/
 
2
#
 
3
# Copyright (c) 2008 - 2011 by Wilbert Berendsen
 
4
#
 
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.
 
9
#
 
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.
 
14
#
 
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.
 
19
 
 
20
"""
 
21
Manages the actions that manipulate the bookmarks (see also bookmarks.py).
 
22
"""
 
23
 
 
24
from __future__ import unicode_literals
 
25
 
 
26
from PyQt4.QtCore import Qt
 
27
from PyQt4.QtGui import QAction
 
28
 
 
29
import actioncollection
 
30
import actioncollectionmanager
 
31
import icons
 
32
import bookmarks
 
33
import plugin
 
34
 
 
35
 
 
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())
 
50
    
 
51
    def slotViewChanged(self, view, prev=None):
 
52
        if prev:
 
53
            prev.cursorPositionChanged.disconnect(self.updateMarkStatus)
 
54
        view.cursorPositionChanged.connect(self.updateMarkStatus)
 
55
 
 
56
    def slotDocumentChanged(self, doc, prev=None):
 
57
        if prev:
 
58
            bookmarks.bookmarks(prev).marksChanged.disconnect(self.updateMarkStatus)
 
59
        bookmarks.bookmarks(doc).marksChanged.connect(self.updateMarkStatus)
 
60
 
 
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'))
 
65
 
 
66
    def markCurrentLine(self):
 
67
        view = self.mainwindow().currentView()
 
68
        lineNumber = view.textCursor().blockNumber()
 
69
        bookmarks.bookmarks(view.document()).toggleMark(lineNumber, 'mark')
 
70
    
 
71
    def clearErrorMarks(self):
 
72
        doc = self.mainwindow().currentDocument()
 
73
        bookmarks.bookmarks(doc).clear('error')
 
74
        
 
75
    def clearAllMarks(self):
 
76
        doc = self.mainwindow().currentDocument()
 
77
        bookmarks.bookmarks(doc).clear()
 
78
    
 
79
    def nextMark(self):
 
80
        view = self.mainwindow().currentView()
 
81
        cursor = view.textCursor()
 
82
        cursor = bookmarks.bookmarks(view.document()).nextMark(cursor)
 
83
        if cursor:
 
84
            view.setTextCursor(cursor)
 
85
            
 
86
    def previousMark(self):
 
87
        view = self.mainwindow().currentView()
 
88
        cursor = view.textCursor()
 
89
        cursor = bookmarks.bookmarks(view.document()).previousMark(cursor)
 
90
        if cursor:
 
91
            view.setTextCursor(cursor)
 
92
 
 
93
 
 
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)
 
103
 
 
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)
 
107
 
 
108
        self.view_bookmark.setIcon(icons.get('bookmark-new'))
 
109
        self.view_clear_all_marks.setIcon(icons.get('edit-clear'))
 
110
 
 
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"))
 
117
 
 
118