Commit c8eb4d65 authored by Kai Willadsen's avatar Kai Willadsen

Move undo-related logic to FileDiff and improve undo signal handling

Previously the undo logic relied on only ever getting an undo signal
from the currently focussed tab, but connected to everything. With this
change, we only listen to the current tab.
parent d1bf645a
......@@ -38,6 +38,7 @@ import melddoc
import patchdialog
import paths
import merge
import undo
from meldapp import app
from util.sourceviewer import srcviewer
......@@ -158,6 +159,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
self.textview_overwrite_handlers = [ t.connect("toggle-overwrite", self.on_textview_toggle_overwrite) for t in self.textview ]
self.textbuffer = [v.get_buffer() for v in self.textview]
self.buffer_texts = [meldbuffer.BufferLines(b) for b in self.textbuffer]
self.undosequence = undo.UndoSequence()
self.text_filters = []
self.create_text_filters()
app.connect("text-filters-changed", self.on_text_filters_changed)
......@@ -743,6 +745,15 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
#
# text buffer undo/redo
#
def on_undo_activate(self):
if self.undosequence.can_undo():
self.undosequence.undo()
def on_redo_activate(self):
if self.undosequence.can_redo():
self.undosequence.redo()
def on_textbuffer__begin_user_action(self, *buffer):
self.undosequence.begin_group()
......
......@@ -21,7 +21,6 @@ import sys
import gobject
import task
import undo
import gtk
import os
from gettext import gettext as _
......@@ -48,7 +47,6 @@ class MeldDoc(gobject.GObject):
def __init__(self, prefs):
gobject.GObject.__init__(self)
self.undosequence = undo.UndoSequence()
self.scheduler = task.FifoScheduler()
self.prefs = prefs
self.prefs.notify_add(self.on_preference_changed)
......@@ -91,14 +89,6 @@ class MeldDoc(gobject.GObject):
def open_external(self):
pass
def on_undo_activate(self):
if self.undosequence.can_undo():
self.undosequence.undo()
def on_redo_activate(self):
if self.undosequence.can_redo():
self.undosequence.redo()
def on_refresh_activate(self, *extra):
self.on_reload_activate(self, *extra)
......
......@@ -218,6 +218,7 @@ class MeldWindow(gnomeglade.Component):
self.ui.ensure_update()
self.widget.show()
self.diff_handler = None
self.undo_handlers = tuple()
self.widget.connect('focus_in_event', self.on_focus_change)
self.widget.connect('focus_out_event', self.on_focus_change)
......@@ -314,15 +315,30 @@ class MeldWindow(gnomeglade.Component):
self.actiongroup.get_action("MoveTabNext").set_sensitive(have_next_tab)
def on_switch_page(self, notebook, page, which):
newdoc = notebook.get_nth_page(which).get_data("pyobject")
newseq = newdoc.undosequence
oldidx = notebook.get_current_page()
if oldidx >= 0:
olddoc = notebook.get_nth_page(oldidx).get_data("pyobject")
olddoc.disconnect(self.diff_handler)
olddoc.on_container_switch_out_event(self.ui)
self.actiongroup.get_action("Undo").set_sensitive(newseq.can_undo())
self.actiongroup.get_action("Redo").set_sensitive(newseq.can_redo())
if self.undo_handlers:
undoseq = olddoc.undosequence
for handler in self.undo_handlers:
undoseq.disconnect(handler)
self.undo_handlers = tuple()
newdoc = notebook.get_nth_page(which).get_data("pyobject")
try:
undoseq = newdoc.undosequence
can_undo = undoseq.can_undo()
can_redo = undoseq.can_redo()
undo_handler = undoseq.connect("can-undo", self.on_can_undo)
redo_handler = undoseq.connect("can-redo", self.on_can_redo)
self.undo_handlers = (undo_handler, redo_handler)
except AttributeError:
can_undo, can_redo = False, False
self.actiongroup.get_action("Undo").set_sensitive(can_undo)
self.actiongroup.get_action("Redo").set_sensitive(can_redo)
nbl = self.notebook.get_tab_label( newdoc.widget )
self.widget.set_title(nbl.get_label_text() + " - Meld")
self.statusbar.set_doc_status("")
......@@ -614,10 +630,6 @@ class MeldWindow(gnomeglade.Component):
doc = filemerge.FileMerge(app.prefs, 3)
else:
doc = filediff.FileDiff(app.prefs, len(files))
seq = doc.undosequence
seq.clear()
seq.connect("can-undo", self.on_can_undo)
seq.connect("can-redo", self.on_can_redo)
self._append_page(doc, "text-x-generic")
doc.set_files(files)
return doc
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment