Code

Added preference to keep last selected item shown.
authorJon A. Cruz <jon@joncruz.org>
Sun, 25 Jul 2010 04:54:39 +0000 (21:54 -0700)
committerJon A. Cruz <jon@joncruz.org>
Sun, 25 Jul 2010 04:54:39 +0000 (21:54 -0700)
src/preferences-skeleton.h
src/ui/dialog/icon-preview.cpp
src/ui/dialog/icon-preview.h

index 283960b807a055fe634b36549fa32f142802a83d..e117e85a5c7471fdf33e951cf7e67a259af30cfe 100644 (file)
@@ -393,6 +393,7 @@ static char const preferences_skeleton[] =
 "  <group\n"
 "     id=\"iconpreview\"\n"
 "     pack=\"1\"\n"
+"     selectionHold=\"0\"\n"
 "     selectionOnly=\"0\">\n"
 "    <group\n"
 "       id=\"sizes\">\n"
index 7be667383a82b1c6f445065cae1f8168284a5849..d3a28d96ff3bb4b5485b0b527d05da6804a5730f 100644 (file)
@@ -86,6 +86,7 @@ IconPreviewPanel::IconPreviewPanel() :
     document(0),
     timer(0),
     pending(false),
+    targetId(),
     hot(1),
     selectionButton(0),
     desktopChangeConn(),
@@ -302,28 +303,33 @@ void IconPreviewPanel::refreshPreview()
         // Do not refresh too quickly
         queueRefresh();
     } else if ( desktop ) {
+        bool hold = Inkscape::Preferences::get()->getBool("/iconpreview/selectionHold", false);
         if ( selectionButton && selectionButton->get_active() )
         {
-            Inkscape::Selection * sel = sp_desktop_selection(desktop);
-            if ( sel ) {
-                //g_message("found a selection to play with");
-
-                GSList const *items = sel->itemList();
-                SPObject *target = 0;
-                while ( items && !target ) {
-                    SPItem* item = SP_ITEM( items->data );
-                    SPObject * obj = SP_OBJECT(item);
-                    gchar const *id = obj->getId();
-                    if ( id ) {
-                        target = obj;
+            SPObject *target = (hold && !targetId.empty()) ? desktop->doc()->getObjectById( targetId.c_str() ) : 0;
+            if ( !target ) {
+                targetId.clear();
+                Inkscape::Selection * sel = sp_desktop_selection(desktop);
+                if ( sel ) {
+                    //g_message("found a selection to play with");
+
+                    GSList const *items = sel->itemList();
+                    while ( items && !target ) {
+                        SPItem* item = SP_ITEM( items->data );
+                        SPObject * obj = SP_OBJECT(item);
+                        gchar const *id = obj->getId();
+                        if ( id ) {
+                            targetId = id;
+                            target = obj;
+                        }
+
+                        items = g_slist_next(items);
                     }
-
-                    items = g_slist_next(items);
-                }
-                if ( target ) {
-                    renderPreview(target);
                 }
             }
+            if ( target ) {
+                renderPreview(target);
+            }
         } else {
             SPObject *target = desktop->currentRoot();
             if ( target ) {
@@ -362,7 +368,11 @@ void IconPreviewPanel::queueRefresh()
 void IconPreviewPanel::modeToggled()
 {
     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
-    prefs->setBool("/iconpreview/selectionOnly", (selectionButton && selectionButton->get_active()));
+    bool selectionOnly = (selectionButton && selectionButton->get_active());
+    prefs->setBool("/iconpreview/selectionOnly", selectionOnly);
+    if ( !selectionOnly ) {
+        targetId.clear();
+    }
 
     refreshPreview();
 }
index 9de8825697fa2349b23cd0a69974f24a8d460563..0842c3c5eb226de114b9f990b0dc4a6028540382 100644 (file)
@@ -68,6 +68,7 @@ private:
     Gtk::VBox       iconBox;
     Gtk::HPaned     splitter;
 
+    Glib::ustring targetId;
     int hot;
     int numEntries;
     int* sizes;