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 # create a formatting toolbar
if not self.dbstate.db.readonly: if not self.dbstate.db.readonly:
vbox = self.top.get_object('container') vbox = self.top.get_object('container')
vbox.pack_start(label=self.texteditor.get_toolbar(), vbox.pack_start(self.texteditor.get_toolbar(), False, False, 0)
expand=False, fill=False)
# setup initial values for textview and textbuffer # setup initial values for textview and textbuffer
if self.obj: if self.obj:

View File

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

View File

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