From: Jon A. Cruz Date: Fri, 10 Sep 2010 08:34:09 +0000 (-0700) Subject: Fixed valgrind-detected issue with tooltip shortcuts and profile manager on delete. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7470494cb0c0634ac4278a274fdf7f1814b81ab5;p=inkscape.git Fixed valgrind-detected issue with tooltip shortcuts and profile manager on delete. --- diff --git a/src/profile-manager.cpp b/src/profile-manager.cpp index 1cd965e39..b5ac861e1 100644 --- a/src/profile-manager.cpp +++ b/src/profile-manager.cpp @@ -23,6 +23,8 @@ ProfileManager::ProfileManager(SPDocument *document) : ProfileManager::~ProfileManager() { + _resource_connection.disconnect(); + _doc = 0; } void ProfileManager::_resourcesChanged() diff --git a/src/shortcuts.cpp b/src/shortcuts.cpp index d02ef6e48..bf7fb8a43 100644 --- a/src/shortcuts.cpp +++ b/src/shortcuts.cpp @@ -199,16 +199,17 @@ sp_shortcut_get_verb(unsigned int shortcut) return (Inkscape::Verb *)(g_hash_table_lookup(verbs, GINT_TO_POINTER(shortcut))); } -unsigned int -sp_shortcut_get_primary(Inkscape::Verb *verb) +unsigned int sp_shortcut_get_primary(Inkscape::Verb *verb) { - if (!primary_shortcuts) sp_shortcut_init(); - gpointer value; - if (g_hash_table_lookup_extended(primary_shortcuts, (gpointer)(verb), NULL, &value)) { - return (unsigned int)GPOINTER_TO_INT(value); - } else { - return GDK_VoidSymbol; + unsigned int result = GDK_VoidSymbol; + if (!primary_shortcuts) { + sp_shortcut_init(); } + gpointer value = 0; + if (g_hash_table_lookup_extended(primary_shortcuts, static_cast(verb), NULL, &value)) { + result = static_cast(GPOINTER_TO_INT(value)); + } + return result; } gchar* sp_shortcut_get_label (unsigned int shortcut) diff --git a/src/verbs.cpp b/src/verbs.cpp index 67211e38e..eaf16e93f 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -335,7 +335,15 @@ Verb::VerbIDTable Verb::_verb_ids; in the \c _verbs hashtable which is indexed by the \c code. */ Verb::Verb(gchar const *id, gchar const *name, gchar const *tip, gchar const *image) : - _actions(NULL), _id(id), _name(name), _tip(tip), _full_tip(0), _image(image) + _actions(0), + _id(id), + _name(name), + _tip(tip), + _full_tip(0), + _shortcut(0), + _image(image), + _code(0), + _default_sensitive(false) { static int count = SP_VERB_LAST; @@ -343,8 +351,6 @@ Verb::Verb(gchar const *id, gchar const *name, gchar const *tip, gchar const *im _code = count; _verbs.insert(VerbTable::value_type(count, this)); _verb_ids.insert(VerbIDTable::value_type(_id, this)); - - return; } /** \brief Destroy a verb. @@ -359,9 +365,10 @@ Verb::~Verb(void) delete _actions; } - if (_full_tip) g_free(_full_tip); - - return; + if (_full_tip) { + g_free(_full_tip); + _full_tip = 0; + } } /** \brief Verbs are no good without actions. This is a place holder @@ -631,23 +638,30 @@ Verb::sensitive(SPDocument *in_doc, bool in_sensitive) } /** \brief Accessor to get the tooltip for verb as localised string */ -gchar const * -Verb::get_tip (void) +gchar const *Verb::get_tip(void) { - if (!_tip) return 0; - unsigned int shortcut = sp_shortcut_get_primary(this); - if (shortcut!=_shortcut || !_full_tip) { - if (_full_tip) g_free(_full_tip); - _shortcut = shortcut; - gchar* shortcutString = sp_shortcut_get_label(shortcut); - if (shortcutString) { - _full_tip = g_strdup_printf("%s (%s)", _(_tip), shortcutString); - g_free(shortcutString); - } else { + gchar const *result = 0; + if (_tip) { + unsigned int shortcut = sp_shortcut_get_primary(this); + if ( (shortcut != _shortcut) || !_full_tip) { + if (_full_tip) { + g_free(_full_tip); + _full_tip = 0; + } + _shortcut = shortcut; + gchar* shortcutString = sp_shortcut_get_label(shortcut); + if (shortcutString) { + _full_tip = g_strdup_printf("%s (%s)", _(_tip), shortcutString); + g_free(shortcutString); + shortcutString = 0; + } else { _full_tip = g_strdup(_(_tip)); + } } + result = _full_tip; } - return _full_tip; + + return result; } void diff --git a/src/verbs.h b/src/verbs.h index 16d4d795a..f118014d2 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -303,12 +303,15 @@ class Verb { private: /** \brief An easy to use defition of the table of verbs by code. */ typedef std::map VerbTable; + /** \brief A table of all the dynamically created verbs. */ static VerbTable _verbs; + /** \brief The table of statically created verbs which are mostly 'base verbs'. */ static Verb * _base_verbs[SP_VERB_LAST + 1]; /* Plus one because there is an entry for SP_VERB_LAST */ + /** A string comparison function to be used in the Verb ID lookup to find the different verbs in the hash map. */ struct ltstr { @@ -322,8 +325,10 @@ private: } } }; + /** \brief An easy to use definition of the table of verbs by ID. */ typedef std::map VerbIDTable; + /** \brief Quick lookup of verbs by ID */ static VerbIDTable _verb_ids; @@ -335,14 +340,20 @@ private: /** \brief A unique textual ID for the verb. */ gchar const * _id; + /** \brief The full name of the verb. (shown on menu entries) */ gchar const * _name; + /** \brief Tooltip for the verb. */ gchar const * _tip; + gchar * _full_tip; // includes shortcut + unsigned int _shortcut; + /** \brief Name of the image that represents the verb. */ gchar const * _image; + /** \brief Unique numerical representation of the verb. In most cases it is a value from the anonymous enum at the top of this file. */ @@ -351,6 +362,7 @@ private: /** \brief Whether this verb is set to default to sensitive or insensitive when new actions are created. */ bool _default_sensitive; + protected: /** \brief Allows for preliminary setting of the \c _default_sensitive value without effecting existing actions @@ -411,7 +423,16 @@ public: gchar const * name, gchar const * tip, gchar const * image) : - _actions(NULL), _id(id), _name(name), _tip(tip), _full_tip(0), _image(image), _code(code), _default_sensitive(true) { + _actions(0), + _id(id), + _name(name), + _tip(tip), + _full_tip(0), + _shortcut(0), + _image(image), + _code(code), + _default_sensitive(true) + { _verbs.insert(VerbTable::value_type(_code, this)); _verb_ids.insert(VerbIDTable::value_type(_id, this)); }