[Xfce4-commits] <midori:master> Implement dragging of speed dial shortcuts

Christian Dywan noreply at xfce.org
Sun Dec 18 01:52:01 CET 2011


Updating branch refs/heads/master
         to ee055334ce5faf69869f61fd341e4a0785476d47 (commit)
       from b72e75d32c1bfc4e4b37621cab60ae4ea06851c0 (commit)

commit ee055334ce5faf69869f61fd341e4a0785476d47
Author: Paweł Forysiuk <tuxator at o2.pl>
Date:   Sun Dec 18 01:51:10 2011 +0100

    Implement dragging of speed dial shortcuts

 data/speeddial-head.html |  104 ++++++++++++++++++++++++++++++++++++++++++++++
 midori/midori-view.c     |   26 +++++++++++-
 2 files changed, 129 insertions(+), 1 deletions(-)

diff --git a/data/speeddial-head.html b/data/speeddial-head.html
index 01249cf..47dc7f8 100644
--- a/data/speeddial-head.html
+++ b/data/speeddial-head.html
@@ -196,6 +196,110 @@
         return false;
     }
 
+    var firstNode, secondNode;
+    var cursor;
+    var dial = document.getElementsByClassName("shortcut");
+
+    var click = function (ev) {
+        ev.preventDefault();
+        var ele = ev.target;
+        cursor = ele.style.cursor;
+        ele.style.cursor = 'move';
+
+        var eparent;
+
+        if (ele.nodeName == 'IMG')
+            eparent = ele.parentNode.parentNode.parentNode;
+        if (ele.className == 'title')
+            eparent = ele.parentNode;
+        if (ele.className == 'shortcut')
+            eparent = ele;
+        if (eparent != undefined) {
+            eparent.style.outline = '1px dotted black';
+            eparent.style.backgroundColor = '#eef';
+            firstNode = eparent.id;
+        }
+        out();
+        remove();
+    };
+
+    var remove  = function () {
+        document.RemoveEventListener('click', click, false);
+        document.RemoveEventListener('mouseout', out, false);
+    };
+
+    var up = function (ev) {
+        ele = ev.target;
+        var eparent;
+
+        if (ele.nodeName == 'IMG')
+            eparent = ele.parentNode.parentNode.parentNode;
+        if (ele.className == 'title')
+            eparent = ele.parentNode;
+        if (ele.className == 'shortcut')
+            eparent = ele;
+
+        ele.style.cursor = cursor;
+        secondNode = eparent.id;
+
+        /* ommit just mere clicking the dial */
+        if (firstNode != secondNode && firstNode != undefined)
+            swap();
+    };
+
+    var over = function (ev) {
+        var ele = ev.target;
+        var eparent;
+
+        if (ele.nodeName == 'IMG')
+            eparent = ele.parentNode.parentNode.parentNode;
+        if (ele.className == 'title')
+            eparent = ele.parentNode;
+        if (ele.className == 'shortcut')
+            eparent = ele;
+
+        if (firstNode != undefined)
+        {
+            eparent.style.outline = '1px dotted black';
+            eparent.style.backgroundColor = '#eef';
+            for (var i = 0; i <= dial.length; i++) {
+                if (eparent.id != firstNode.id && dial[i].id != eparent.id) {
+                    dial[i].style.outline = '0px';
+                    dial[i].style.backgroundColor = '#eee';
+                }
+            }
+        }
+        ele.style.cursor = cursor;
+    }
+    var out = function (ev) {
+         var ele = ev.target;
+         var eparent;
+
+        if (ele.nodeName == 'IMG')
+            eparent = ele.parentNode.parentNode.parentNode;
+        if (ele.className == 'title')
+            eparent = ele.parentNode;
+        if (ele.className == 'shortcut')
+            eparent = ele;
+        if (firstNode != undefined) {
+            for (var i = 0; i <= dial.length; i++) {
+                if (eparent.id != firstNode.id && dial[i].id != eparent.id) {
+                    dial[i].style.outline = '0px';
+                    dial[i].backgroundColor = '#eee';
+                }
+            }
+        }
+        ele.style.cursor = cursor;
+    }
+
+    function swap () {
+        console.log ("speed_dial-save-swap " + firstNode + " " + secondNode);
+    };
+
+    document.addEventListener('mousedown', click, false);
+    document.addEventListener('mouseup', up, false);
+    document.addEventListener('mouseover', over, false);
+    document.addEventListener('mouseout', out, false);
     </script>
 </head>
 <body>
diff --git a/midori/midori-view.c b/midori/midori-view.c
index b82939c..a71ffdb 100644
--- a/midori/midori-view.c
+++ b/midori/midori-view.c
@@ -5602,7 +5602,7 @@ midori_view_speed_dial_save (MidoriView*  view,
     action = parts[0];
 
     if (g_str_equal (action, "add") || g_str_equal (action, "rename")
-    ||  g_str_equal (action, "delete"))
+    ||  g_str_equal (action, "delete") || g_str_equal (action, "swap"))
     {
         gchar* tmp = g_strdup (parts[1] + 1);
         guint slot_id = atoi (tmp);
@@ -5633,6 +5633,30 @@ midori_view_speed_dial_save (MidoriView*  view,
             g_key_file_set_string (key_file, dial_id, "title", title);
             g_free (title);
         }
+        else if (g_str_equal (action, "swap"))
+        {
+            gchar* tmp1 = g_strdup (parts[2] + 1);
+            guint slot2_id = atoi (tmp1);
+            gchar* dial2_id = g_strdup_printf ("Dial %d", slot2_id);
+            gchar* uri, *uri2, *title, *title2;
+            g_free (tmp1);
+
+            uri = g_key_file_get_string (key_file, dial_id, "uri", NULL);
+            title = g_key_file_get_string (key_file, dial_id, "title", NULL);
+            uri2 = g_key_file_get_string (key_file, dial2_id, "uri", NULL);
+            title2 = g_key_file_get_string (key_file, dial2_id, "title", NULL);
+
+            g_key_file_set_string (key_file, dial_id, "uri", uri2);
+            g_key_file_set_string (key_file, dial2_id, "uri", uri);
+            g_key_file_set_string (key_file, dial_id, "title", title2);
+            g_key_file_set_string (key_file, dial2_id, "title", title);
+
+            g_free (uri);
+            g_free (uri2);
+            g_free (title);
+            g_free (title2);
+            g_free (dial2_id);
+        }
 
         g_free (dial_id);
     }


More information about the Xfce4-commits mailing list