Code

Refactored preferences handling into a new version of
[inkscape.git] / src / dialogs / swatches.cpp
index 3b62f018620ffca16d3444d6295b0f6885cd4937..5d76cc8f6dcc70d61da43214606dd2acb061b0b0 100644 (file)
@@ -26,7 +26,7 @@
 #include <gdkmm/pixbuf.h>
 #include "inkscape.h"
 #include "desktop.h"
-#include "message-stack.h"
+#include "message-context.h"
 #include "document.h"
 #include "desktop-handles.h"
 #include "extension/db.h"
@@ -37,7 +37,7 @@
 #include "path-prefix.h"
 #include "swatches.h"
 #include "sp-item.h"
-#include "prefs-utils.h"
+#include "preferences.h"
 
 #include "eek-preview.h"
 
@@ -240,17 +240,26 @@ static void handleSecondaryClick( GtkWidget* widget, gint arg1, gpointer callbac
     }
 }
 
-static gboolean handleEnterNotify( GtkWidget* widget, GdkEventCrossing* event, gpointer callback_data ) {
+static gboolean handleEnterNotify( GtkWidget* /*widget*/, GdkEventCrossing* /*event*/, gpointer callback_data ) {
     ColorItem* item = reinterpret_cast<ColorItem*>(callback_data);
     if ( item ) {
         SPDesktop *desktop = SP_ACTIVE_DESKTOP;
         if ( desktop ) {
-            desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, g_strconcat(
-              _("Swatch info: <b>"),
-              item->def.descr.c_str(),
-              _("</b>"),
-              NULL
-            ));
+            gchar* msg = g_strdup_printf(_("Color: <b>%s</b>; <b>Click</b> to set fill, <b>Shift+click</b> to set stroke"),
+                                         item->def.descr.c_str());
+            desktop->tipsMessageContext()->set(Inkscape::INFORMATION_MESSAGE, msg);
+            g_free(msg);
+        }
+    }
+    return FALSE;
+}
+
+static gboolean handleLeaveNotify( GtkWidget* /*widget*/, GdkEventCrossing* /*event*/, gpointer callback_data ) {
+    ColorItem* item = reinterpret_cast<ColorItem*>(callback_data);
+    if ( item ) {
+        SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+        if ( desktop ) {
+            desktop->tipsMessageContext()->clear();
         }
     }
     return FALSE;
@@ -610,6 +619,11 @@ Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, ::PreviewS
                           G_CALLBACK(handleEnterNotify),
                           this);
 
+        g_signal_connect( G_OBJECT(newBlot->gobj()),
+                          "leave-notify-event",
+                          G_CALLBACK(handleLeaveNotify),
+                          this);
+
 //         g_signal_connect( G_OBJECT(newBlot->gobj()),
 //                           "drag-drop",
 //                           G_CALLBACK(dragDropColorData),
@@ -1032,10 +1046,11 @@ SwatchesPanel::SwatchesPanel(gchar const* prefsPath) :
 
     if ( !possible.empty() ) {
         JustForNow* first = 0;
-        gchar const* targetName = 0;
+        Glib::ustring targetName;
         if ( _prefs_path ) {
-            targetName = prefs_get_string_attribute( _prefs_path, "palette" );
-            if ( targetName ) {
+            Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+            targetName = prefs->getString(_prefs_path, "palette");
+            if (!targetName.empty()) {
                 for ( std::vector<JustForNow*>::iterator iter = possible.begin(); iter != possible.end(); ++iter ) {
                     if ( (*iter)->_name == targetName ) {
                         first = *iter;
@@ -1109,7 +1124,8 @@ void SwatchesPanel::_handleAction( int setId, int itemId )
                 JustForNow* curr = possible[itemId];
 
                 if ( _prefs_path ) {
-                    prefs_set_string_attribute( _prefs_path, "palette", curr->_name.c_str() );
+                    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+                    prefs->setString(_prefs_path, "palette", curr->_name);
                 }
 
                 if ( curr->_prefWidth > 0 ) {