Commits

Anonymous committed b31ff84

Add "Sync Scroll" menu item.

  • Participants
  • Parent commits afd9da6

Comments (0)

Files changed (1)

     def get_padding(self):
         return self._terminal.get_padding()
 
+    def get_adjustment(self):
+        return self._terminal.get_adjustment()
+
     def get_utext_as_seen(self):
         enc = self._terminal.get_encoding()
         text = self._terminal.get_text(lambda *x: True).decode(enc, 'replace')
     title= 'Yomogi'
 
     highlight_diff = False
+    sync_scroll = False
 
     def __init__(self, opts):
         gtk.Window.__init__(self)
         terminal._terminal.connect('char-size-changed',
                                    self.do_term_title_changed)
         terminal.connect('size-allocate', self.do_term_size_allocate)
+        adjustment = terminal.get_adjustment()
+        adjustment.connect_object('value-changed',
+                                  self.do_term_adjustment_value_changed,
+                                  terminal)
+
         self.terminal_list.append(terminal)
         return terminal
 
         sync_all_item = gtk.MenuItem('S_ync All Frames in This Window')
         async_all_item = gtk.MenuItem('_Async All Frames in This Window')
 
+        sync_scroll_item = gtk.CheckMenuItem('Sy_nc Scroll')
+        if MainWindow.sync_scroll:
+            sync_scroll_item.set_active(True)
+
         highlight_diff_item = gtk.CheckMenuItem('Highlight _Diffs in the Synced Frames')
         if MainWindow.highlight_diff:
             highlight_diff_item.set_active(True)
 
         menu.prepend(gtk.SeparatorMenuItem())
         menu.prepend(highlight_diff_item)
+        menu.prepend(sync_scroll_item)
         menu.prepend(async_all_item)
         menu.prepend(sync_all_item)
         menu.prepend(sync_frame_item)
         close_other_item.connect('activate',
                 lambda x: self.close_other_frame(terminal))
         sync_frame_item.connect('toggled', self.toggle_term_sync, terminal)
+        sync_scroll_item.connect('toggle', self.toggle_sync_scroll)
         highlight_diff_item.connect('toggled', self.toggle_highlight_diff, terminal)
         sync_all_item.connect('activate', self.sync_term_all)
         async_all_item.connect('activate', self.async_term_all)
         # reset dim
         terminal.do_focus_in(None, None)
 
+    def toggle_sync_scroll(self, sync_scroll_item):
+        MainWindow.sync_scroll = sync_scroll_item.get_active()
+
     def toggle_highlight_diff(self, highlight_diff_item, terminal):
         MainWindow.highlight_diff = highlight_diff_item.get_active()
 
         else:
             return self.destroy()
 
+    def do_term_adjustment_value_changed(self, terminal):
+        if not MainWindow.sync_scroll or \
+           not terminal.is_focus() or \
+           not self.is_active() or \
+           terminal not in synced_terminal:
+            return
+
+        adjustment = terminal.get_adjustment()
+
+        value_from_bottom = adjustment.upper - (adjustment.value + adjustment.page_size)
+
+        for t in synced_terminal:
+            if t is terminal:
+                continue
+
+            adjustment = t.get_adjustment()
+            value = adjustment.upper - (value_from_bottom + adjustment.page_size)
+            adjustment.set_value(value)
+
     def do_term_contents_changed(self, terminal):
         if not MainWindow.highlight_diff or \
            not terminal.is_focus() or \