1
# -*- coding: utf-8 -*-
2
# Copyright © 2005 Lateef Alabi-Oki
4
# This file is part of Scribes.
6
# Scribes is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# Scribes is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with Scribes; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
21
from gtk import ImageMenuItem
23
class BookmarkPopupMenuItem(ImageMenuItem):
25
This class creates the bookmarks popup menu for the text editor.
28
def __init__(self, editor, manager):
30
Initialize the popup menu.
32
@param self: Reference to the BookmarkPopupMenuItem instance.
33
@type self: A BookmarkPopupMenuItem object.
35
@param scribesview: The text editor's text view.
36
@type scribesview: A ScribesTextView object.
38
from i18n import msg0012
39
ImageMenuItem.__init__(self, msg0012)
40
self.__init_attributes(editor, manager)
41
self.__create_widgets()
42
self.__set_properties()
43
self.__signal_id_1 = self.bookmark_line_menuitem.connect("activate", self.__popup_activate_cb)
44
self.__signal_id_2 = self.remove_bookmark_menuitem.connect("map-event", self.__popup_map_event_cb)
45
self.__signal_id_3 = self.remove_bookmark_menuitem.connect("activate", self.__popup_activate_cb)
46
self.__signal_id_4 = self.remove_all_bookmarks_menuitem.connect("map-event", self.__popup_map_event2_cb)
47
self.__signal_id_5 = self.remove_all_bookmarks_menuitem.connect("activate", self.__popup_activate_cb)
48
self.__signal_id_6 = self.next_bookmark_menuitem.connect("activate", self.__popup_activate_cb)
49
self.__signal_id_7 = self.next_bookmark_menuitem.connect("map-event", self.__popup_map_event2_cb)
50
self.__signal_id_8 = self.previous_bookmark_menuitem.connect("activate", self.__popup_activate_cb)
51
self.__signal_id_9 = self.previous_bookmark_menuitem.connect("map-event", self.__popup_map_event2_cb)
52
self.__signal_id_10 = self.first_bookmark_menuitem.connect("activate", self.__popup_activate_cb)
53
self.__signal_id_11 = self.first_bookmark_menuitem.connect("map-event", self.__popup_map_event2_cb)
54
self.__signal_id_12 = self.last_bookmark_menuitem.connect("activate", self.__popup_activate_cb)
55
self.__signal_id_13 = self.last_bookmark_menuitem.connect("map-event", self.__popup_map_event2_cb)
56
self.__signal_id_14 = self.show_browser_menuitem.connect("activate", self.__popup_activate_cb)
57
self.__signal_id_15 = self.show_browser_menuitem.connect("map-event", self.__popup_map_event_cb)
58
self.__signal_id_16 = self.scribesview.connect("focus-in-event", self.__popup_destroy_cb)
60
def __init_attributes(self, editor, manager):
62
Initialize the popup's attributes.
64
@param self: Reference to the BookmarkPopupMenuItem instance.
65
@type self: A BookmarkPopupMenuItem object.
67
@param scribesview: The text editor's text view.
68
@type scribesview: A ScribesTextView object.
70
self.scribesview = editor.textview
72
self.__manager = manager
75
self.bookmark_line_menuitem = None
76
self.remove_bookmark_menuitem = None
77
self.remove_all_bookmarks_menuitem = None
78
self.next_bookmark_menuitem = None
79
self.previous_bookmark_menuitem = None
80
self.first_bookmark_menuitem = None
81
self.last_bookmark_menuitem = None
82
self.show_browser_menuitem = None
83
self.__signal_id_1 = None
84
self.__signal_id_2 = None
85
self.__signal_id_3 = None
86
self.__signal_id_4 = None
87
self.__signal_id_5 = None
88
self.__signal_id_6 = None
89
self.__signal_id_7 = None
90
self.__signal_id_8 = None
91
self.__signal_id_9 = None
92
self.__signal_id_10 = None
93
self.__signal_id_11 = None
94
self.__signal_id_12 = None
95
self.__signal_id_13 = None
96
self.__signal_id_14 = None
97
self.__signal_id_15 = None
98
self.__signal_id_16 = None
101
def __create_widgets(self):
103
Create menu items for the bookmarks menu.
105
@param self: Reference to the BookmarkPopupMenuItem instance.
106
@type self: A BookmarkPopupMenuItem object.
109
from SCRIBES.utils import create_image, create_menuitem
110
from SCRIBES.info import scribes_data_folder
111
image = scribes_data_folder + "/bookmarks.png"
112
self.image = create_image(image)
114
from i18n import msg0013, msg0014
115
from i18n import msg0015, msg0016, msg0017
116
from i18n import msg0018, msg0019, msg0020
117
self.bookmark_line_menuitem = create_menuitem(msg0013)
118
self.remove_bookmark_menuitem = create_menuitem(msg0014)
119
self.remove_all_bookmarks_menuitem = create_menuitem(msg0015)
120
self.next_bookmark_menuitem = create_menuitem(msg0016)
121
self.previous_bookmark_menuitem = create_menuitem(msg0017)
122
self.first_bookmark_menuitem = create_menuitem(msg0018)
123
self.last_bookmark_menuitem = create_menuitem(msg0019)
124
self.show_browser_menuitem = create_menuitem(msg0020)
127
def __set_properties(self):
129
Set the menu item's properties.
131
@param self: Reference to the BookmarkPopupMenuItem instance.
132
@type self: A BookmarkPopupMenuItem object.
134
self.set_image(self.image)
135
self.set_submenu(self.menu)
136
self.menu.append(self.bookmark_line_menuitem)
137
self.menu.append(self.remove_bookmark_menuitem)
138
self.menu.append(self.remove_all_bookmarks_menuitem)
139
self.menu.append(self.next_bookmark_menuitem)
140
self.menu.append(self.previous_bookmark_menuitem)
141
self.menu.append(self.first_bookmark_menuitem)
142
self.menu.append(self.last_bookmark_menuitem)
143
self.menu.append(self.show_browser_menuitem)
144
if self.editor.is_readonly:
145
self.set_property("sensitive", False)
148
def __popup_activate_cb(self, menuitem):
150
Handles callback when the "activate" signal is emitted.
152
@param self: Reference to the BookmarkPopupMenuItem instance.
153
@type self: A BookmarkPopupMenuItem object.
155
@param menuitem: The popup menu's menuitem.
156
@type menuitem: A gtk.MenuItem object.
158
@return: True to propagate signals to parent widgets.
159
@type: A Boolean Object.
161
if menuitem == self.show_browser_menuitem:
162
self.editor.triggermanager.trigger("show_bookmark_browser")
163
elif menuitem == self.bookmark_line_menuitem:
164
self.editor.triggermanager.trigger("bookmark_line")
165
elif menuitem == self.remove_bookmark_menuitem:
166
self.editor.triggermanager.trigger("remove_bookmark")
167
elif menuitem == self.remove_all_bookmarks_menuitem:
168
self.editor.triggermanager.trigger("remove_all_bookmarks")
169
elif menuitem == self.next_bookmark_menuitem:
170
self.editor.triggermanager.trigger("next_bookmark")
171
elif menuitem == self.previous_bookmark_menuitem:
172
self.editor.triggermanager.trigger("previous_bookmark")
173
elif menuitem == self.first_bookmark_menuitem:
174
self.editor.triggermanager.trigger("first_bookmark")
175
elif menuitem == self.last_bookmark_menuitem:
176
self.editor.triggermanager.trigger("last_bookmark")
179
def __popup_map_event_cb(self, menuitem, event):
181
Handles callback when the "map-event" signal is emitted.
183
@param self: Reference to the BookmarkPopupMenuItem instance.
184
@type self: A BookmarkPopupMenuItem object.
186
@param menuitem: The popup menu's menuitem.
187
@type menuitem: A gtk.MenuItem object.
189
@param event: An event that occurs when popup menu is displayed.
190
@type event: A gtk.Event object.
192
self.__sensitize_menuitem(menuitem)
195
def __popup_map_event2_cb(self, menuitem, event):
197
Handles callback when the "map-event" signal is emitted.
199
@param self: Reference to the BookmarkPopupMenuItem instance.
200
@type self: A BookmarkPopupMenuItem object.
202
@param menuitem: The popup menu's menuitem.
203
@type menuitem: A gtk.MenuItem object.
205
@param event: An event that occurs when popup menu is displayed.
206
@type event: A gtk.Event object.
208
self.__sensitize_menuitem(menuitem)
211
def __sensitize_menuitem(self, menuitem):
212
menuitem.set_property("sensitive", False)
214
self.__manager.is_initialized
215
lines = self.__manager.get_bookmarked_lines()
217
menuitem.set_property("sensitive", True)
222
def __popup_destroy_cb(self, textview, event):
223
if self.__signal_id_1 and self.bookmark_line_menuitem.handler_is_connected(self.__signal_id_1):
224
self.bookmark_line_menuitem.disconnect(self.__signal_id_1)
225
if self.__signal_id_2 and self.remove_bookmark_menuitem.handler_is_connected(self.__signal_id_2):
226
self.remove_bookmark_menuitem.disconnect(self.__signal_id_2)
227
if self.__signal_id_3 and self.remove_bookmark_menuitem.handler_is_connected(self.__signal_id_3):
228
self.remove_bookmark_menuitem.disconnect(self.__signal_id_3)
229
if self.__signal_id_4 and self.remove_all_bookmarks_menuitem.handler_is_connected(self.__signal_id_4):
230
self.remove_all_bookmarks_menuitem.disconnect(self.__signal_id_4)
231
if self.__signal_id_5 and self.remove_all_bookmarks_menuitem.handler_is_connected(self.__signal_id_5):
232
self.remove_all_bookmarks_menuitem.disconnect(self.__signal_id_5)
233
if self.__signal_id_6 and self.next_bookmark_menuitem.handler_is_connected(self.__signal_id_6):
234
self.next_bookmark_menuitem.disconnect(self.__signal_id_6)
235
if self.__signal_id_7 and self.next_bookmark_menuitem.handler_is_connected(self.__signal_id_7):
236
self.next_bookmark_menuitem.disconnect(self.__signal_id_7)
237
if self.__signal_id_8 and self.previous_bookmark_menuitem.handler_is_connected(self.__signal_id_8):
238
self.previous_bookmark_menuitem.disconnect(self.__signal_id_8)
239
if self.__signal_id_9 and self.previous_bookmark_menuitem.handler_is_connected(self.__signal_id_9):
240
self.previous_bookmark_menuitem.disconnect(self.__signal_id_9)
241
if self.__signal_id_10 and self.first_bookmark_menuitem.handler_is_connected(self.__signal_id_10):
242
self.first_bookmark_menuitem.disconnect(self.__signal_id_10)
243
if self.__signal_id_11 and self.first_bookmark_menuitem.handler_is_connected(self.__signal_id_11):
244
self.first_bookmark_menuitem.disconnect(self.__signal_id_11)
245
if self.__signal_id_12 and self.last_bookmark_menuitem.handler_is_connected(self.__signal_id_12):
246
self.last_bookmark_menuitem.disconnect(self.__signal_id_12)
247
if self.__signal_id_13 and self.last_bookmark_menuitem.handler_is_connected(self.__signal_id_13):
248
self.last_bookmark_menuitem.disconnect(self.__signal_id_13)
249
if self.__signal_id_14 and self.show_browser_menuitem.handler_is_connected(self.__signal_id_14):
250
self.show_browser_menuitem.disconnect(self.__signal_id_14)
251
if self.__signal_id_15 and self.show_browser_menuitem.handler_is_connected(self.__signal_id_15):
252
self.show_browser_menuitem.disconnect(self.__signal_id_15)
253
if self.__signal_id_16 and self.scribesview.handler_is_connected(self.__signal_id_16):
254
self.scribesview.disconnect(self.__signal_id_16)
255
if self.bookmark_line_menuitem:
256
self.bookmark_line_menuitem.destroy()
257
if self.remove_bookmark_menuitem:
258
self.remove_bookmark_menuitem.destroy()
259
if self.remove_all_bookmarks_menuitem:
260
self.remove_all_bookmarks_menuitem.destroy()
261
if self.next_bookmark_menuitem:
262
self.next_bookmark_menuitem.destroy()
263
if self.previous_bookmark_menuitem:
264
self.previous_bookmark_menuitem.destroy()
265
if self.first_bookmark_menuitem:
266
self.first_bookmark_menuitem.destroy()
267
if self.last_bookmark_menuitem:
268
self.last_bookmark_menuitem.destroy()
269
if self.show_browser_menuitem:
270
self.show_browser_menuitem.destroy()
276
del self.scribesview, self.editor, self.bookmark_line_menuitem
277
del self.remove_bookmark_menuitem, self.remove_all_bookmarks_menuitem
278
del self.next_bookmark_menuitem, self.previous_bookmark_menuitem
279
del self.first_bookmark_menuitem, self.last_bookmark_menuitem
280
del self.show_browser_menuitem, self.menu, self.image, self.__manager
281
del self.__signal_id_1, self.__signal_id_2, self.__signal_id_3
282
del self.__signal_id_4, self.__signal_id_5, self.__signal_id_6
283
del self.__signal_id_7, self.__signal_id_8, self.__signal_id_9
284
del self.__signal_id_10, self.__signal_id_11, self.__signal_id_12
285
del self.__signal_id_13, self.__signal_id_14, self.__signal_id_15
286
del self.__signal_id_16, self