marcelklehr / buzzmap

draw and edit mindmaps interactively, using force-directed layouts (jQuery plugin)
marcelklehr.github.com/buzzmap
Other
22 stars 17 forks source link

Supporting cut and paste #2

Open vishalpai opened 11 years ago

vishalpai commented 11 years ago

Hi,

Currently buzzmap does not support cut and paste of nodes. Typically when a mind map is created nodes are moved around as the thought process evolves. So this would be a good to have feature.

Here is an easy way in which I managed to do it (I did not want to play with the data structures today)

  1. Just like the existing add (+) and remove (x) buttons add cut and paste buttons.
  2. In the cut action, serialize the node into json and call remove
  3. In the paste action, de-serialize the json in the same way as is done in the load of buzz map
  4. Fire the onchange trigger.

Sample code (Not production ready):

// build 'cut' button
$('<button class="edit-button">cut</button>').click(function ()
{
    cancel();
    clipboardNode = thisnode.serialize();
    thisnode.removeNode();
    thisnode.obj.animate();
    return false;
}).appendTo(thisnode.el);

$('<button class="edit-button">paste</button>').click(function ()
 {
     cancel();

     var map = JSON.parse(clipboardNode);

     var nodeCreate = function (parent, children) 
     {
          $.each(children, function (index, n) 
          {
               if(!n.label || !n.children) return;

               var node = parent.obj.addNode(parent, decodeURIComponent(n.label))
               nodeCreate(node, n.children);
          });
      };

      var firstnode = thisnode.obj.addNode(thisnode,decodeURIComponent(map.label));
      nodeCreate(firstnode, map.children);

      thisnode.obj.trigger('onchange', thisnode, thisnode.obj.serialize());

      return false;
}).appendTo(thisnode.el);

Best Regards, Vishal

marcelklehr commented 11 years ago

I could also imagine, stopping aninmation during editing (so, no nodes floating around, and no dragging), but if you dragged a node while editing it, you could put it somewhere else (like you put files in another folder; drag and drop basically...)

If you want to implement this, or your own ideas:

Fork this repo, clone your fork, create a feature branch, commit, push and submit a pull request on this (my) repo, again. That's how things work on github, basically :)