Edit note working with undo/redo

svn: r19969
This commit is contained in:
Benny Malengier 2012-07-10 12:32:50 +00:00
parent 6955382107
commit 2ff2f4ff57
3 changed files with 123 additions and 75 deletions

View File

@ -263,8 +263,7 @@ class EditNote(EditPrimary):
# create a formatting toolbar
if not self.dbstate.db.readonly:
vbox = self.top.get_object('container')
vbox.pack_start(label=self.texteditor.get_toolbar(),
expand=False, fill=False)
vbox.pack_start(self.texteditor.get_toolbar(), False, False, 0)
# setup initial values for textview and textbuffer
if self.obj:

View File

@ -1,15 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires grampswidgets 0.0 -->
<!-- interface-requires gtk+ 2.12 -->
<!-- interface-naming-policy project-wide -->
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkDialog" id="editnote">
<property name="can_focus">False</property>
<property name="default_width">500</property>
<property name="default_height">400</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox21">
<object class="GtkBox" id="dialog-vbox21">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area21">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="cancel">
<property name="label">gtk-cancel</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="ok">
<property name="label">gtk-ok</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="help">
<property name="label">gtk-help</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkNotebook" id="note_notebook">
<property name="visible">True</property>
@ -17,17 +83,17 @@
<child>
<object class="GtkVBox" id="vbox131">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkVBox" id="container">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="spacing">6</property>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow90">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">automatic</property>
<property name="vscrollbar_policy">automatic</property>
<child>
<object class="StyledTextEditor" id="texteditor">
<property name="visible">True</property>
@ -41,26 +107,35 @@
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkTable" id="table79">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="n_rows">3</property>
<property name="n_columns">5</property>
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkLabel" id="label707">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">_Type:</property>
<property name="use_underline">True</property>
@ -78,12 +153,13 @@
<child>
<object class="GtkComboBox" id="type">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">A type to classify the note.</property>
<property name="has_entry">True</property>
<child internal-child="entry">
<object class="GtkEntry" id="type-entry">
<property name="can_focus">True</property>
<property name="overwrite_mode">True</property>
<property name="can_focus">True</property>
<property name="overwrite_mode">True</property>
</object>
</child>
</object>
@ -98,6 +174,7 @@
<child>
<object class="GtkLabel" id="label708">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">_ID:</property>
<property name="use_underline">True</property>
@ -128,6 +205,7 @@
<child>
<object class="GtkCheckButton" id="format">
<property name="label" translatable="yes">_Preformatted</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
@ -137,7 +215,10 @@ When not checked, notes are automatically cleaned in the reports, which will imp
<property name="tooltip_text" translatable="yes">When active the whitespace in your note will be respected in reports. Use this to add formatting layout with spaces, eg a table.
When not checked, notes are automatically cleaned in the reports, which will improve the report layout.
Use monospace font to keep preformatting.</property>
<property name="halign">end</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="xalign">0.5</property>
<property name="draw_indicator">True</property>
</object>
<packing>
@ -149,9 +230,11 @@ Use monospace font to keep preformatting.</property>
</child>
<child>
<object class="GtkToggleButton" id="private">
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="relief">none</property>
<accelerator key="p" signal="activate" modifiers="GDK_CONTROL_MASK"/>
<child internal-child="accessible">
@ -162,6 +245,7 @@ Use monospace font to keep preformatting.</property>
<child>
<object class="GtkImage" id="image2721">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">gtk-dialog-authentication</property>
<child internal-child="accessible">
<object class="AtkObject" id="image2721-atkobject">
@ -182,6 +266,7 @@ Use monospace font to keep preformatting.</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">_Tags:</property>
<property name="use_underline">True</property>
@ -197,19 +282,25 @@ Use monospace font to keep preformatting.</property>
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="tag_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="tag_button">
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<accessibility>
<relation type="labelled-by" target="label1"/>
</accessibility>
@ -231,6 +322,7 @@ Use monospace font to keep preformatting.</property>
<property name="right_attach">5</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="y_options"></property>
</packing>
</child>
<child>
@ -245,9 +337,19 @@ Use monospace font to keep preformatting.</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
@ -256,6 +358,7 @@ Use monospace font to keep preformatting.</property>
<child type="tab">
<object class="GtkLabel" id="label715">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">&lt;b&gt;Note&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
@ -264,64 +367,10 @@ Use monospace font to keep preformatting.</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area21">
<property name="visible">True</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="cancel">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="ok">
<property name="label">gtk-ok</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="help">
<property name="label">gtk-help</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="pack_type">end</property>
<property name="position">0</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>

View File

@ -40,7 +40,7 @@ class UndoableInsertStyled(UndoableInsert):
#we obtain the buffer before the text has been inserted
UndoableInsert.__init__(self, text_iter, text, length, text_buffer)
self.tags = text_buffer.get_text(text_buffer.get_start_iter(),
text_buffer.get_end_iter()).get_tags()
text_buffer.get_end_iter(), True).get_tags()
self.tagsafter = None
class UndoableDeleteStyled(UndoableDelete):
@ -48,7 +48,7 @@ class UndoableDeleteStyled(UndoableDelete):
#we obtain the buffer before the text has been deleted
UndoableDelete.__init__(self, text_buffer, start_iter, end_iter)
self.tags = text_buffer.get_text(text_buffer.get_start_iter(),
text_buffer.get_end_iter()).get_tags()
text_buffer.get_end_iter(), True).get_tags()
class UndoableApplyStyle():
"""a style has been applied to our textbuffer"""
@ -57,7 +57,7 @@ class UndoableApplyStyle():
self.mergeable = False
self.tags = text_buffer.get_text(text_buffer.get_start_iter(),
text_buffer.get_end_iter()).get_tags()
text_buffer.get_end_iter(), True).get_tags()
#
self.tags_after = None
self.offset_after = None
@ -100,7 +100,7 @@ class UndoableStyledBuffer(StyledTextBuffer):
UndoableApplyStyle):
return
self.undo_stack[-1].set_after(buffer.get_text(buffer.get_start_iter(),
buffer.get_end_iter()).get_tags(),
buffer.get_end_iter(), True).get_tags(),
buffer.get_iter_at_mark(buffer.get_insert()).get_offset())
def _undo_insert(self, undo_action):
@ -111,7 +111,7 @@ class UndoableStyledBuffer(StyledTextBuffer):
self.delete(start, stop)
#the text is correct again, now we create correct styled text
s_text = StyledText(Gtk.TextBuffer.get_text(self,
self.get_start_iter(), self.get_end_iter()), undo_action.tags)
self.get_start_iter(), self.get_end_iter(), True), undo_action.tags)
self.set_text(s_text)
self.place_cursor(self.get_iter_at_offset(undo_action.offset))
@ -120,7 +120,7 @@ class UndoableStyledBuffer(StyledTextBuffer):
self.insert(start, undo_action.text)
#the text is correct again, now we create correct styled text
s_text = StyledText(Gtk.TextBuffer.get_text(self,
self.get_start_iter(), self.get_end_iter()), undo_action.tags)
self.get_start_iter(), self.get_end_iter(), True), undo_action.tags)
self.set_text(s_text)
if undo_action.delete_key_used:
self.place_cursor(self.get_iter_at_offset(undo_action.start))
@ -129,7 +129,7 @@ class UndoableStyledBuffer(StyledTextBuffer):
def _redo_insert(self, redo_action):
s_text = StyledText(Gtk.TextBuffer.get_text(self,
self.get_start_iter(), self.get_end_iter()), redo_action.tags)
self.get_start_iter(), self.get_end_iter(), True), redo_action.tags)
self.set_text(s_text)
start = self.get_iter_at_offset(redo_action.offset)
self.insert(start, redo_action.text)
@ -144,21 +144,21 @@ class UndoableStyledBuffer(StyledTextBuffer):
self.delete(start, stop)
#the text is correct again, now we create correct styled text
#s_text = StyledText(Gtk.TextBuffer.get_text(self,
# self.get_start_iter(), self.get_end_iter()), redo_action.tags)
# self.get_start_iter(), self.get_end_iter(), True), redo_action.tags)
#self.set_text(s_text)
self.place_cursor(self.get_iter_at_offset(redo_action.start))
def _handle_undo(self, undo_action):
""" undo of apply of style """
s_text = StyledText(Gtk.TextBuffer.get_text(self,
self.get_start_iter(), self.get_end_iter()), undo_action.tags)
self.get_start_iter(), self.get_end_iter(), True), undo_action.tags)
self.set_text(s_text)
self.place_cursor(self.get_iter_at_offset(undo_action.offset))
def _handle_redo(self, redo_action):
""" redo of apply of style """
s_text = StyledText(Gtk.TextBuffer.get_text(self,
self.get_start_iter(), self.get_end_iter()),
self.get_start_iter(), self.get_end_iter(), True),
redo_action.tags_after)
self.set_text(s_text)
self.place_cursor(self.get_iter_at_offset(redo_action.offset_after))