MCPcopy Create free account
hub / github.com/SpartanJ/eepp / onCreateContextMenu

Method onCreateContextMenu

src/eepp/ui/uicodeeditor.cpp:1456–1511  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1454}
1455
1456bool UICodeEditor::onCreateContextMenu( const Vector2i& position, const Uint32& flags ) {
1457 if ( mCurrentMenu )
1458 return false;
1459
1460 UIPopUpMenu* menu = UIPopUpMenu::New();
1461 menu->addClass( "uicodeeditor_menu" );
1462
1463 createDefaultContextMenuOptions( menu );
1464
1465 ContextMenuEvent event( this, menu, Event::OnCreateContextMenu, position, flags );
1466 sendEvent( &event );
1467
1468 for ( auto& plugin : mPlugins )
1469 if ( plugin->onCreateContextMenu( this, menu, position, flags ) )
1470 return false;
1471
1472 if ( menu->getCount() == 0 ) {
1473 menu->close();
1474 return false;
1475 }
1476
1477 menu->setCloseOnHide( true );
1478 menu->setCloseSubMenusOnClose( true );
1479
1480 UICodeEditor* editor = this;
1481 const auto registerMenu = [editor, this]( UIMenu* menu ) {
1482 menu->on( Event::OnItemClicked, [this, menu, editor]( const Event* event ) {
1483 if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) )
1484 return;
1485 UIMenuItem* item = event->getNode()->asType<UIMenuItem>();
1486 std::string txt( item->getId() );
1487 mDoc->execute( txt, editor );
1488 menu->hide();
1489 } );
1490 };
1491 registerMenu( menu );
1492 auto subMenus = menu->findAllByType<UIMenuSubMenu>( UI_TYPE_MENUSUBMENU );
1493 for ( auto* subMenu : subMenus )
1494 registerMenu( subMenu->getSubMenu() );
1495
1496 Vector2f pos( position.asFloat() );
1497 runOnMainThread( [this, menu, pos]() {
1498 Vector2f npos( pos );
1499 menu->nodeToWorldTranslation( npos );
1500 UIMenu::findBestMenuPos( npos, menu );
1501 menu->setPixelsPosition( npos );
1502 menu->show();
1503 mCurrentMenu = menu;
1504 } );
1505 menu->on( Event::OnMenuHide, [this]( const Event* ) {
1506 if ( !isClosing() )
1507 setFocus();
1508 } );
1509 menu->on( Event::OnClose, [this]( const Event* ) { mCurrentMenu = nullptr; } );
1510 return true;
1511}
1512
1513Int64 UICodeEditor::calculateMinimapClickedLine( const Vector2i& position ) {

Callers

nothing calls this directly

Calls 15

addClassMethod · 0.80
setCloseOnHideMethod · 0.80
getNodeMethod · 0.80
getSubMenuMethod · 0.80
setPixelsPositionMethod · 0.80
closeMethod · 0.65
getIdMethod · 0.65
NewFunction · 0.50
getCountMethod · 0.45
onMethod · 0.45
isTypeMethod · 0.45

Tested by

no test coverage detected