|
46 | 46 | from diffuse.preferences import Preferences |
47 | 47 | from diffuse.resources import Resources |
48 | 48 | from diffuse.vcs.vcs_registry import VcsRegistry |
| 49 | +from diffuse.widgets import ScrolledWindow |
49 | 50 |
|
50 | 51 | # avoid some dictionary lookups when string.whitespace is used in loops |
51 | 52 | # this is sorted based upon frequency to speed up code for stripping whitespace |
@@ -178,111 +179,6 @@ def convert_to_format(s, format): |
178 | 179 | s += '\r' |
179 | 180 | return s |
180 | 181 |
|
181 | | -# utility method to step advance an adjustment |
182 | | -def step_adjustment(adj, delta): |
183 | | - v = adj.get_value() + delta |
184 | | - # clamp to the allowed range |
185 | | - v = max(v, int(adj.get_lower())) |
186 | | - v = min(v, int(adj.get_upper() - adj.get_page_size())) |
187 | | - adj.set_value(v) |
188 | | - |
189 | | -# This is a replacement for Gtk.ScrolledWindow as it forced expose events to be |
190 | | -# handled immediately after changing the viewport position. This could cause |
191 | | -# the application to become unresponsive for a while as it processed a large |
192 | | -# queue of keypress and expose event pairs. |
193 | | -class ScrolledWindow(Gtk.Grid): |
194 | | - scroll_directions = set((Gdk.ScrollDirection.UP, |
195 | | - Gdk.ScrollDirection.DOWN, |
196 | | - Gdk.ScrollDirection.LEFT, |
197 | | - Gdk.ScrollDirection.RIGHT)) |
198 | | - |
199 | | - def __init__(self, hadj, vadj): |
200 | | - Gtk.Grid.__init__(self) |
201 | | - self.position = (0, 0) |
202 | | - self.scroll_count = 0 |
203 | | - self.partial_redraw = False |
204 | | - |
205 | | - self.hadj, self.vadj = hadj, vadj |
206 | | - vport = Gtk.Viewport.new() |
207 | | - darea = Gtk.DrawingArea.new() |
208 | | - darea.add_events(Gdk.EventMask.SCROLL_MASK) |
209 | | - self.darea = darea |
210 | | - # replace darea's queue_draw_area with our own so we can tell when |
211 | | - # to disable/enable our scrolling optimisation |
212 | | - self.darea_queue_draw_area = darea.queue_draw_area |
213 | | - darea.queue_draw_area = self.redraw_region |
214 | | - vport.add(darea) |
215 | | - darea.show() |
216 | | - self.attach(vport, 0, 0, 1, 1) |
217 | | - vport.set_vexpand(True) |
218 | | - vport.set_hexpand(True) |
219 | | - vport.show() |
220 | | - |
221 | | - self.vbar = bar = Gtk.Scrollbar.new(Gtk.Orientation.VERTICAL, vadj) |
222 | | - self.attach(bar, 1, 0, 1, 1) |
223 | | - bar.show() |
224 | | - |
225 | | - self.hbar = bar = Gtk.Scrollbar.new(Gtk.Orientation.HORIZONTAL, hadj) |
226 | | - self.attach(bar, 0, 1, 1, 1) |
227 | | - bar.show() |
228 | | - |
229 | | - # listen to our signals |
230 | | - hadj.connect('value-changed', self.value_changed_cb) |
231 | | - vadj.connect('value-changed', self.value_changed_cb) |
232 | | - darea.connect('configure-event', self.configure_cb) |
233 | | - darea.connect('scroll-event', self.scroll_cb) |
234 | | - darea.connect('draw', self.draw_cb) |
235 | | - |
236 | | - # updates the adjustments to match the new widget size |
237 | | - def configure_cb(self, widget, event): |
238 | | - w, h = event.width, event.height |
239 | | - for adj, d in (self.hadj, w), (self.vadj, h): |
240 | | - v = adj.get_value() |
241 | | - if v + d > adj.get_upper(): |
242 | | - adj.set_value(max(0, adj.get_upper() - d)) |
243 | | - adj.set_page_size(d) |
244 | | - adj.set_page_increment(d) |
245 | | - |
246 | | - # update the vertical adjustment when the mouse's scroll wheel is used |
247 | | - def scroll_cb(self, widget, event): |
248 | | - d = event.direction |
249 | | - if d in self.scroll_directions: |
250 | | - delta = 100 |
251 | | - if d in (Gdk.ScrollDirection.UP, Gdk.ScrollDirection.LEFT): |
252 | | - delta = -delta |
253 | | - vertical = (d in (Gdk.ScrollDirection.UP, Gdk.ScrollDirection.DOWN)) |
254 | | - if event.state & Gdk.ModifierType.SHIFT_MASK: |
255 | | - vertical = not vertical |
256 | | - if vertical: |
257 | | - adj = self.vadj |
258 | | - else: |
259 | | - adj = self.hadj |
260 | | - step_adjustment(adj, delta) |
261 | | - |
262 | | - def value_changed_cb(self, widget): |
263 | | - old_x, old_y = self.position |
264 | | - pos_x = int(self.hadj.get_value()) |
265 | | - pos_y = int(self.vadj.get_value()) |
266 | | - self.position = (pos_x, pos_y) |
267 | | - if self.darea.get_window() is not None: |
268 | | - # window.scroll() although visually nice, is slow, revert to |
269 | | - # queue_draw() if scroll a lot without seeing an expose event |
270 | | - if self.scroll_count < 2 and not self.partial_redraw: |
271 | | - self.scroll_count += 1 |
272 | | - self.darea.get_window().scroll(old_x - pos_x, old_y - pos_y) |
273 | | - else: |
274 | | - self.partial_redraw = False |
275 | | - self.darea.queue_draw() |
276 | | - |
277 | | - def draw_cb(self, widget, cr): |
278 | | - self.scroll_count = 0 |
279 | | - |
280 | | - # replacement for darea.queue_draw_area that notifies us when a partial |
281 | | - # redraw happened |
282 | | - def redraw_region(self, x, y, w, h): |
283 | | - self.partial_redraw = True |
284 | | - self.darea_queue_draw_area(x, y, w, h) |
285 | | - |
286 | 182 | # Enforcing manual alignment is accomplished by dividing the lines of text into |
287 | 183 | # sections that are matched independently. 'blocks' is an array of integers |
288 | 184 | # describing how many lines (including null lines for spacing) that are in each |
@@ -2770,9 +2666,9 @@ def diffmap_button_press_cb(self, widget, event): |
2770 | 2666 | def diffmap_scroll_cb(self, widget, event): |
2771 | 2667 | delta = 100 |
2772 | 2668 | if event.direction == Gdk.ScrollDirection.UP: |
2773 | | - step_adjustment(self.vadj, -delta) |
| 2669 | + utils.step_adjustment(self.vadj, -delta) |
2774 | 2670 | elif event.direction == Gdk.ScrollDirection.DOWN: |
2775 | | - step_adjustment(self.vadj, delta) |
| 2671 | + utils.step_adjustment(self.vadj, delta) |
2776 | 2672 |
|
2777 | 2673 | # redraws the overview map when a portion is exposed |
2778 | 2674 | def diffmap_draw_cb(self, widget, cr): |
|
0 commit comments