void FrameAttachmentPoint::showContextMenu(QPoint point)
{
    //Show menus with all attached frames and submenu where to attach it to
    clearActionReceivers();

    WindowManager* windowManager = Carbon::get()->getWindowManager();
    QMenu menu(windowManager->getMainWindow());
    QMenu* submenu;
    QAction* action;

    //For all attached frames, add frame menu
    int frame = 0;
    for (auto it = mAttachedFrames.begin(); it != mAttachedFrames.end(); it++) 
    {
        submenu = menu.addMenu((*it)->getCaption());
     
        //for all possible targets, add commands
        {
            NumberedActionReceiver* receiver;
            
            //Copy command
            receiver = new NumberedActionReceiver(frame, COMMAND_COPY);
            mActionReceivers.push_back(receiver);
            connect(receiver, SIGNAL(actionReceived(int,int)), this, SLOT(onContextMenuClick(int,int)));
            action = submenu->addAction(QIcon(":copy"), "Copy", receiver, SLOT(receiveAction()));
            action->setToolTip("Create a copy of the plugin.");
            if (!PluginFactory::getFactory().canCreatePlugin((*it)->getClassId())) //Disable copy if plugin cant be created anymore
                action->setEnabled(false);

            //Delete command
            receiver = new NumberedActionReceiver(frame, COMMAND_DELETE);
            mActionReceivers.push_back(receiver);
            connect(receiver, SIGNAL(actionReceived(int,int)), this, SLOT(onContextMenuClick(int,int)));
            action = submenu->addAction(QIcon(":delete"), "Delete", receiver, SLOT(receiveAction()));
            action->setToolTip("Delete the plugin.");
        }

        submenu->addSeparator();

        //for all possible targets, add target frames
        int target = COMMAND_MAX_ID;
        for (auto tar_it = windowManager->getFrameAttachmentPoints().begin(); tar_it != windowManager->getFrameAttachmentPoints().end(); tar_it++)
        {
            NumberedActionReceiver* receiver = new NumberedActionReceiver(frame, target);
            mActionReceivers.push_back(receiver);

            connect(receiver, SIGNAL(actionReceived(int,int)), this, SLOT(onContextMenuClick(int,int)));

            if (tar_it->second == this)
                action = submenu->addAction(QIcon(":accept"), tar_it->second->getName(), receiver, SLOT(receiveAction()));
            else
                action = submenu->addAction(tar_it->second->getName(), receiver, SLOT(receiveAction()));
            
            target++;
        }
        frame++;
    }

    menu.exec(mAttachmentPoint->mapToGlobal(point));
}