From: Paweł Forysiuk Date: Sun, 18 Dec 2011 00:51:10 +0000 (+0100) Subject: Implement dragging of speed dial shortcuts X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee055334ce5faf69869f61fd341e4a0785476d47;p=midori Implement dragging of speed dial shortcuts --- diff --git a/data/speeddial-head.html b/data/speeddial-head.html index 01249cf9..47dc7f88 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); diff --git a/midori/midori-view.c b/midori/midori-view.c index b82939c0..a71ffdb8 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); }