Added UndoableBuffer to text gramplets; fixed an issue in recognizing keypresses accurately; rewrote keypress handler
svn: r15759
This commit is contained in:
parent
3154f970ac
commit
d86759b5a7
@ -52,6 +52,7 @@ from QuickReports import run_quick_report_by_name
|
||||
import GrampsDisplay
|
||||
from glade import Glade
|
||||
from gui.pluginmanager import GuiPluginManager
|
||||
from gui.widgets.undoablebuffer import UndoableBuffer
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -346,7 +347,10 @@ class GuiGramplet(object):
|
||||
self.gvwin.remove(self.mainframe)
|
||||
|
||||
self.textview = self.xml.get_object('gvtextview')
|
||||
self.buffer = self.textview.get_buffer()
|
||||
self.buffer = UndoableBuffer()
|
||||
self.textview.set_buffer(self.buffer)
|
||||
self.textview.connect("key-press-event", self.on_key_press_event)
|
||||
#self.buffer = self.textview.get_buffer()
|
||||
self.scrolledwindow = self.xml.get_object('gvscrolledwindow')
|
||||
self.vboxtop = self.xml.get_object('vboxtop')
|
||||
self.titlelabel = self.xml.get_object('gvtitle')
|
||||
@ -373,6 +377,31 @@ class GuiGramplet(object):
|
||||
[GuiGramplet.LOCAL_DRAG_TARGET],
|
||||
gtk.gdk.ACTION_COPY)
|
||||
|
||||
def undo(self):
|
||||
self.buffer.undo()
|
||||
|
||||
def redo(self):
|
||||
self.buffer.redo()
|
||||
|
||||
def on_key_press_event(self, widget, event):
|
||||
"""Signal handler.
|
||||
|
||||
Handle formatting shortcuts.
|
||||
|
||||
"""
|
||||
if ((gtk.gdk.keyval_name(event.keyval) == 'z') and
|
||||
(event.state & gtk.gdk.CONTROL_MASK) and
|
||||
(event.state & gtk.gdk.MOD2_MASK)):
|
||||
self.undo()
|
||||
return True
|
||||
elif ((gtk.gdk.keyval_name(event.keyval) == 'Z') and
|
||||
(event.state & gtk.gdk.CONTROL_MASK) and
|
||||
(event.state & gtk.gdk.MOD2_MASK) and
|
||||
(event.state & gtk.gdk.SHIFT_MASK)):
|
||||
self.redo()
|
||||
return True
|
||||
return False
|
||||
|
||||
def edit_title(self, widget):
|
||||
"""
|
||||
Edit the the title in the GUI.
|
||||
@ -632,6 +661,7 @@ class GuiGramplet(object):
|
||||
def set_text(self, text, scroll_to='start'):
|
||||
self.buffer.set_text('')
|
||||
self.append_text(text, scroll_to)
|
||||
self.buffer.reset()
|
||||
|
||||
def get_source_widget(self):
|
||||
"""
|
||||
|
@ -240,15 +240,25 @@ class StyledTextEditor(gtk.TextView):
|
||||
Handle formatting shortcuts.
|
||||
|
||||
"""
|
||||
for accel, accel_name in self.action_accels.iteritems():
|
||||
key, mod = gtk.accelerator_parse(accel)
|
||||
if (((event.keyval == key) or
|
||||
(event.keyval + 32 == key)) and
|
||||
bool((event.state & mod) == mod)):
|
||||
action_name = accel_name
|
||||
action = self.action_group.get_action(action_name)
|
||||
action.activate()
|
||||
return True
|
||||
if ((gtk.gdk.keyval_name(event.keyval) == 'z') and
|
||||
(event.state & gtk.gdk.CONTROL_MASK) and
|
||||
(event.state & gtk.gdk.MOD2_MASK)):
|
||||
self.undo()
|
||||
return True
|
||||
elif ((gtk.gdk.keyval_name(event.keyval) == 'Z') and
|
||||
(event.state & gtk.gdk.CONTROL_MASK) and
|
||||
(event.state & gtk.gdk.MOD2_MASK) and
|
||||
(event.state & gtk.gdk.SHIFT_MASK)):
|
||||
self.redo()
|
||||
return True
|
||||
else:
|
||||
for accel, accel_name in self.action_accels.iteritems():
|
||||
key, mod = gtk.accelerator_parse(accel)
|
||||
if ((event.keyval == key) and (event.state & mod)):
|
||||
action_name = accel_name
|
||||
action = self.action_group.get_action(action_name)
|
||||
action.activate()
|
||||
return True
|
||||
return False
|
||||
|
||||
def on_insert_at_cursor(self, widget, string):
|
||||
@ -418,8 +428,6 @@ class StyledTextEditor(gtk.TextView):
|
||||
_('Bold'), self._on_toggle_action_activate),
|
||||
(str(StyledTextTagType.UNDERLINE), gtk.STOCK_UNDERLINE, None, None,
|
||||
_('Underline'), self._on_toggle_action_activate),
|
||||
("Undo", gtk.STOCK_UNDO, None, None, _('Undo'), self.undo),
|
||||
("Redo", gtk.STOCK_REDO, None, None, _('Redo'), self.redo),
|
||||
]
|
||||
|
||||
self.toggle_actions = [action[0] for action in format_toggle_actions]
|
||||
@ -469,8 +477,6 @@ class StyledTextEditor(gtk.TextView):
|
||||
'<Control>i': str(StyledTextTagType.ITALIC),
|
||||
'<Control>b': str(StyledTextTagType.BOLD),
|
||||
'<Control>u': str(StyledTextTagType.UNDERLINE),
|
||||
'<Control>z' : "Undo",
|
||||
'<Control><Shift>z': "Redo",
|
||||
}
|
||||
|
||||
# create the action group and insert all the actions
|
||||
@ -741,10 +747,10 @@ class StyledTextEditor(gtk.TextView):
|
||||
"""
|
||||
return self.toolbar
|
||||
|
||||
def undo(self, obj):
|
||||
def undo(self):
|
||||
self.textbuffer.undo()
|
||||
|
||||
def redo(self, obj):
|
||||
def redo(self):
|
||||
self.textbuffer.redo()
|
||||
|
||||
def uri_dialog(self, uri, callback):
|
||||
|
Loading…
x
Reference in New Issue
Block a user