Code

Cmake: restructure build files to be more like current build system. Should reduce...
[inkscape.git] / src / dialogs / swatches.cpp
index 3b62f018620ffca16d3444d6295b0f6885cd4937..2eb30f27cadca86a3906b3ce1931ff0f6f91a46f 100644 (file)
@@ -1,7 +1,7 @@
-/*
- * A simple panel for color swatches
- *
- * Authors:
+/** @file
+ * @brief Color swatches dialog
+ */
+/* Authors:
  *   Jon A. Cruz
  *   John Bintz
  *
@@ -10,9 +10,6 @@
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
 
 #include <errno.h>
 
@@ -26,7 +23,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 +34,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 +237,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 +616,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 +1043,11 @@ SwatchesPanel::SwatchesPanel(gchar const* prefsPath) :
 
     if ( !possible.empty() ) {
         JustForNow* first = 0;
-        gchar const* targetName = 0;
-        if ( _prefs_path ) {
-            targetName = prefs_get_string_attribute( _prefs_path, "palette" );
-            if ( targetName ) {
+        Glib::ustring targetName;
+        if ( !_prefs_path.empty() ) {
+            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;
@@ -1108,8 +1120,9 @@ void SwatchesPanel::_handleAction( int setId, int itemId )
                 _holder->clear();
                 JustForNow* curr = possible[itemId];
 
-                if ( _prefs_path ) {
-                    prefs_set_string_attribute( _prefs_path, "palette", curr->_name.c_str() );
+                if ( !_prefs_path.empty() ) {
+                    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+                    prefs->setString(_prefs_path + "/palette", curr->_name);
                 }
 
                 if ( curr->_prefWidth > 0 ) {