[gnote] Don't change content modification time when autolinking



commit 08c29f78bcf7ee28fab2f5e6b8ff0a39fd9c2a06
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Sat Oct 8 13:36:49 2011 +0300

    Don't change content modification time when autolinking
    
    When link is created, it should change Meta modification time,
    but not the content modification time.
    ChangeType related changes are due to compilation problems.
    Ported fix of Tomboy bug 634035.

 .../noteoftheday/noteofthedaypreferences.cpp       |    3 +-
 .../stickynoteimport/stickynoteimportnoteaddin.cpp |    4 +-
 src/dbus/remotecontrol.cpp                         |    2 +-
 src/note.cpp                                       |    4 +-
 src/note.hpp                                       |    7 +---
 src/notebooks/notebook.cpp                         |    2 +-
 src/notemanager.cpp                                |    8 ++--
 src/notetag.cpp                                    |   37 ++++++++++++++++++++
 src/notetag.hpp                                    |   29 +++++++++++++++
 9 files changed, 79 insertions(+), 17 deletions(-)
---
diff --git a/src/addins/noteoftheday/noteofthedaypreferences.cpp b/src/addins/noteoftheday/noteofthedaypreferences.cpp
index 9759d3d..aea89a5 100644
--- a/src/addins/noteoftheday/noteofthedaypreferences.cpp
+++ b/src/addins/noteoftheday/noteofthedaypreferences.cpp
@@ -1,6 +1,7 @@
 /*
  * gnote
  *
+ * Copyright (C) 2011 Aurimas Cernius
  * Copyright (C) 2009 Debarshi Ray
  *
  * This program is free software: you can redistribute it and/or modify
@@ -64,7 +65,7 @@ void NoteOfTheDayPreferences::open_template_button_clicked() const
                                 NoteOfTheDay::s_template_title,
                                 NoteOfTheDay::get_template_content(
                                   NoteOfTheDay::s_template_title));
-      template_note->queue_save(gnote::Note::CONTENT_CHANGED);
+      template_note->queue_save(gnote::CONTENT_CHANGED);
     }
     catch (const sharp::Exception & e) {
       ERR_OUT("NoteOfTheDay could not create %s: %s",
diff --git a/src/addins/stickynoteimport/stickynoteimportnoteaddin.cpp b/src/addins/stickynoteimport/stickynoteimportnoteaddin.cpp
index 76fdfb0..847730f 100644
--- a/src/addins/stickynoteimport/stickynoteimportnoteaddin.cpp
+++ b/src/addins/stickynoteimport/stickynoteimportnoteaddin.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010 Aurimas Cernius
+ * Copyright (C) 2010-2011 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -299,7 +299,7 @@ bool StickyNoteImportNoteAddin::create_note_from_sticky(const char * stickyTitle
 
   try {
     Note::Ptr newNote = manager.create(title, noteXml);
-    newNote->queue_save (Note::NO_CHANGE);
+    newNote->queue_save (gnote::NO_CHANGE);
     newNote->save();
     return true;
   } 
diff --git a/src/dbus/remotecontrol.cpp b/src/dbus/remotecontrol.cpp
index 6ddb6f2..44c6b5a 100644
--- a/src/dbus/remotecontrol.cpp
+++ b/src/dbus/remotecontrol.cpp
@@ -347,7 +347,7 @@ bool RemoteControl::SetNoteCompleteXml(const std::string& uri,
     return false;
   }
     
-  note->load_foreign_note_xml(xml_contents, Note::CONTENT_CHANGED);
+  note->load_foreign_note_xml(xml_contents, CONTENT_CHANGED);
   return true;
 }
 
diff --git a/src/note.cpp b/src/note.cpp
index 158dab9..5b38b12 100644
--- a/src/note.cpp
+++ b/src/note.cpp
@@ -551,7 +551,7 @@ namespace gnote {
   {
     if(NoteTagTable::tag_is_serializable(tag)) {
       DBG_OUT("BufferTagApplied queueing save: %s", tag->property_name().get_value().c_str());
-      queue_save(CONTENT_CHANGED);
+      queue_save(get_tag_table()->get_change_type(tag));
     }
   }
 
@@ -561,7 +561,7 @@ namespace gnote {
   {
     if(NoteTagTable::tag_is_serializable(tag)) {
       DBG_OUT("BufferTagRemoved queueing save: %s", tag->property_name().get_value().c_str());
-      queue_save(CONTENT_CHANGED);
+      queue_save(get_tag_table()->get_change_type(tag));
     }
   }
 
diff --git a/src/note.hpp b/src/note.hpp
index 7110157..8f1659a 100644
--- a/src/note.hpp
+++ b/src/note.hpp
@@ -1,6 +1,7 @@
 /*
  * gnote
  *
+ * Copyright (C) 2011 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -120,12 +121,6 @@ public:
   typedef sigc::signal<void, const Note&, const Tag &>         TagRemovingHandler;  
   typedef sigc::signal<void, const Note::Ptr&, const std::string&>  TagRemovedHandler;  
 
-  typedef enum {
-    NO_CHANGE,
-    CONTENT_CHANGED,
-    OTHER_DATA_CHANGED
-  } ChangeType;
-
   ~Note();
 
 
diff --git a/src/notebooks/notebook.cpp b/src/notebooks/notebook.cpp
index d5317ec..746215e 100644
--- a/src/notebooks/notebook.cpp
+++ b/src/notebooks/notebook.cpp
@@ -152,7 +152,7 @@ namespace notebooks {
       Tag::Ptr notebook_tag = TagManager::obj().get_or_create_system_tag (NOTEBOOK_TAG_PREFIX + get_name());
       note->add_tag (notebook_tag);
         
-      note->queue_save (Note::CONTENT_CHANGED);
+      note->queue_save (CONTENT_CHANGED);
     }
 
     return note;
diff --git a/src/notemanager.cpp b/src/notemanager.cpp
index a92991c..fbf9f58 100644
--- a/src/notemanager.cpp
+++ b/src/notemanager.cpp
@@ -282,13 +282,13 @@ namespace gnote {
     try {
       Note::Ptr start_note = create (_("Start Here"),
                                 start_note_content);
-      start_note->queue_save (Note::CONTENT_CHANGED);
+      start_note->queue_save (CONTENT_CHANGED);
       Preferences::obj().get_schema_settings(Preferences::SCHEMA_GNOTE)->set_string(
           Preferences::START_NOTE_URI, start_note->uri());
 
       Note::Ptr links_note = create (_("Using Links in Gnote"),
                                 links_note_content);
-      links_note->queue_save (Note::CONTENT_CHANGED);
+      links_note->queue_save (CONTENT_CHANGED);
 
       m_signal_start_note_created(start_note);
     } 
@@ -369,7 +369,7 @@ namespace gnote {
         }
         
         note->set_is_open_on_startup(false);
-        note->queue_save (Note::NO_CHANGE);
+        note->queue_save (NO_CHANGE);
       }
     }
   }
@@ -666,7 +666,7 @@ namespace gnote {
       Tag::Ptr template_tag = TagManager::obj().get_or_create_system_tag (TagManager::TEMPLATE_NOTE_SYSTEM_TAG);
       template_note->add_tag(template_tag);
 
-      template_note->queue_save(Note::CONTENT_CHANGED);
+      template_note->queue_save(CONTENT_CHANGED);
     }
       
     return template_note;
diff --git a/src/notetag.cpp b/src/notetag.cpp
index fa323d0..f3e2c6d 100644
--- a/src/notetag.cpp
+++ b/src/notetag.cpp
@@ -62,6 +62,7 @@ namespace gnote {
   {
     m_element_name = element_name;
     m_flags = CAN_SERIALIZE | CAN_SPLIT;
+    m_save_type = CONTENT;
   }
   
 
@@ -418,6 +419,7 @@ namespace gnote {
     tag = NoteTag::create("find-match", NoteTag::CAN_SPELL_CHECK);
     tag->property_background() = "green";
     tag->set_can_serialize(false);
+    tag->set_save_type(META);
     add (tag);
 
     tag = NoteTag::create("note-title", 0);
@@ -426,12 +428,14 @@ namespace gnote {
     tag->property_scale() = Pango::SCALE_XX_LARGE;
     // FiXME: Hack around extra rewrite on open
     tag->set_can_serialize(false);
+    tag->set_save_type(META);
     add (tag);
       
     tag = NoteTag::create("related-to", 0);
     tag->property_scale() = Pango::SCALE_SMALL;
     tag->property_left_margin() = 40;
     tag->property_editable() = false;
+    tag->set_save_type(META);
     add (tag);
 
     // Used when inserting dropped URLs/text to Start Here
@@ -439,6 +443,7 @@ namespace gnote {
     tag->property_scale() = Pango::SCALE_SMALL;
     tag->property_style() = Pango::STYLE_ITALIC;
     tag->set_palette_foreground(CONTRAST_COLOR_GREY);
+    tag->set_save_type(META);
     add (tag);
 
     // Font sizes
@@ -464,18 +469,21 @@ namespace gnote {
     tag = NoteTag::create("link:broken", NoteTag::CAN_ACTIVATE);
     tag->property_underline() = Pango::UNDERLINE_SINGLE;
     tag->set_palette_foreground(CONTRAST_COLOR_GREY);
+    tag->set_save_type(META);
     add (tag);
     m_broken_link_tag = tag;
 
     tag = NoteTag::create("link:internal", NoteTag::CAN_ACTIVATE);
     tag->property_underline() = Pango::UNDERLINE_SINGLE;
     tag->set_palette_foreground(CONTRAST_COLOR_BLUE);
+    tag->set_save_type(META);
     add (tag);
     m_link_tag = tag;
 
     tag = NoteTag::create("link:url", NoteTag::CAN_ACTIVATE);
     tag->property_underline() = Pango::UNDERLINE_SINGLE;
     tag->set_palette_foreground(CONTRAST_COLOR_BLUE);
+    tag->set_save_type(META);
     add (tag);
     m_url_tag = tag;
   }
@@ -539,6 +547,35 @@ namespace gnote {
   {
     return iter.has_tag(get_link_tag()) || iter.has_tag(get_url_tag()) || iter.has_tag(get_broken_link_tag());
   }
+
+
+  ChangeType NoteTagTable::get_change_type(const Glib::RefPtr<Gtk::TextTag> &tag)
+  {
+    ChangeType change;
+
+    // Use tag Name for Gtk.TextTags
+    // For extensibility, add Gtk.TextTag names here
+    change = OTHER_DATA_CHANGED;
+
+    // Use SaveType for NoteTags
+    Glib::RefPtr<NoteTag> note_tag = Glib::RefPtr<NoteTag>::cast_dynamic(tag);
+    if(note_tag) {
+      switch(note_tag->save_type()) {
+        case META:
+          change = OTHER_DATA_CHANGED;
+          break;
+        case CONTENT:
+          change = CONTENT_CHANGED;
+          break;
+        case NO_SAVE:
+        default:
+          change = NO_CHANGE;
+        break;
+      }
+    }
+
+    return change;
+  }
   
 
   DepthNoteTag::Ptr NoteTagTable::get_depth_tag(int depth, Pango::Direction direction)
diff --git a/src/notetag.hpp b/src/notetag.hpp
index a05005e..aa33abe 100644
--- a/src/notetag.hpp
+++ b/src/notetag.hpp
@@ -43,6 +43,18 @@ namespace gnote {
   class NoteEditor;
 
 
+enum TagSaveType {
+  NO_SAVE,
+  META,
+  CONTENT
+};
+
+enum ChangeType {
+  NO_CHANGE,
+  CONTENT_CHANGED,
+  OTHER_DATA_CHANGED
+};
+
 
 
 class NoteTag
@@ -72,6 +84,14 @@ public:
     { 
       return m_element_name;
     }
+  TagSaveType save_type() const
+    {
+      return m_save_type;
+    }
+  void set_save_type(TagSaveType type)
+    {
+      m_save_type = type;
+    }
   bool can_serialize() const
     {
       return (m_flags & CAN_SERIALIZE) != 0;
@@ -162,6 +182,7 @@ private:
   TagActivatedHandler m_signal_activate;
   ContrastPaletteColor m_palette_foreground;
   sigc::signal<void,const Glib::RefPtr<Gtk::TextTag>&,bool> m_signal_changed;
+  TagSaveType         m_save_type;
 };
 
 
@@ -270,6 +291,14 @@ public:
   static bool tag_is_activatable(const Glib::RefPtr<Gtk::TextTag> & );
   static bool tag_has_depth(const Glib::RefPtr<Gtk::TextBuffer::Tag> & );
   bool has_link_tag(const Gtk::TextIter & iter);
+
+  /// <summary>
+  /// Maps a Gtk.TextTag to ChangeType for saving notes
+  /// </summary>
+  /// <param name="tag">Gtk.TextTag to map</param>
+  /// <returns>ChangeType to save this NoteTag</returns>
+  ChangeType get_change_type(const Glib::RefPtr<Gtk::TextTag> &tag);
+
   DepthNoteTag::Ptr get_depth_tag(int depth, Pango::Direction direction);
   DynamicNoteTag::Ptr create_dynamic_tag(const std::string & );
   void register_dynamic_tag (const std::string & tag_name, const Factory & factory);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]