Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting cut and paste #2

Open
vishalpai opened this issue Oct 6, 2012 · 1 comment
Open

Supporting cut and paste #2

vishalpai opened this issue Oct 6, 2012 · 1 comment

Comments

@vishalpai
Copy link

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
Copy link
Owner

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants