| 342 | } |
| 343 | |
| 344 | UIMenu* SettingsMenu::createDocumentMenu() { |
| 345 | auto shouldCloseCb = []( UIMenuItem* ) -> bool { return false; }; |
| 346 | |
| 347 | auto setupAutoIndentMenu = [this]( |
| 348 | UIPopUpMenu* parentMenu, const std::string& menuId, |
| 349 | std::function<TextDocument::AutoIndentConfig()> getConfig, |
| 350 | std::function<void( TextDocument::AutoIndentConfig )> onClick ) { |
| 351 | UIPopUpMenu* autoIndentMenu = UIPopUpMenu::New(); |
| 352 | auto subMenu = |
| 353 | parentMenu->addSubMenu( i18n( "auto_indent", "Auto-Indent" ), nullptr, autoIndentMenu ); |
| 354 | subMenu |
| 355 | ->setTooltipText( |
| 356 | i18n( "auto_indent_tooltip", |
| 357 | "Configures the automatic indentation behavior when pressing Enter.\n" |
| 358 | "None: No automatic indentation.\n" |
| 359 | "Preserve: Preserves the indentation level of the previous line.\n" |
| 360 | "Smart: Preserves indentation and automatically indents between auto-closed " |
| 361 | "brackets." ) ) |
| 362 | ->setId( menuId ); |
| 363 | subMenu->on( Event::OnMenuShow, [this, autoIndentMenu, getConfig, onClick]( const Event* ) { |
| 364 | if ( autoIndentMenu->getCount() == 0 ) { |
| 365 | autoIndentMenu->addRadioButton( i18n( "auto_indent_none", "None" ) ) |
| 366 | ->setId( "auto_indent_none" ); |
| 367 | autoIndentMenu->addRadioButton( i18n( "auto_indent_preserve", "Preserve" ) ) |
| 368 | ->setId( "auto_indent_preserve" ); |
| 369 | autoIndentMenu->addRadioButton( i18n( "auto_indent_smart", "Smart" ) ) |
| 370 | ->setId( "auto_indent_smart" ); |
| 371 | autoIndentMenu->on( Event::OnItemClicked, [onClick]( const Event* event ) { |
| 372 | const String& text = event->getNode()->asType<UIMenuRadioButton>()->getId(); |
| 373 | TextDocument::AutoIndentConfig autoIndent = |
| 374 | text == "auto_indent_none" ? TextDocument::AutoIndentConfig::None |
| 375 | : text == "auto_indent_preserve" ? TextDocument::AutoIndentConfig::Preserve |
| 376 | : TextDocument::AutoIndentConfig::Smart; |
| 377 | onClick( autoIndent ); |
| 378 | } ); |
| 379 | } |
| 380 | TextDocument::AutoIndentConfig currentConfig = getConfig(); |
| 381 | autoIndentMenu->getItemId( "auto_indent_none" ) |
| 382 | ->asType<UIMenuRadioButton>() |
| 383 | ->setActive( currentConfig == TextDocument::AutoIndentConfig::None ); |
| 384 | autoIndentMenu->getItemId( "auto_indent_preserve" ) |
| 385 | ->asType<UIMenuRadioButton>() |
| 386 | ->setActive( currentConfig == TextDocument::AutoIndentConfig::Preserve ); |
| 387 | autoIndentMenu->getItemId( "auto_indent_smart" ) |
| 388 | ->asType<UIMenuRadioButton>() |
| 389 | ->setActive( currentConfig == TextDocument::AutoIndentConfig::Smart ); |
| 390 | } ); |
| 391 | return subMenu; |
| 392 | }; |
| 393 | |
| 394 | mDocMenu = UIPopUpMenu::New(); |
| 395 | |
| 396 | // **** CURRENT DOCUMENT **** |
| 397 | mDocMenu->add( i18n( "current_document", "Current Document" ) ) |
| 398 | ->setTextAlign( UI_HALIGN_CENTER ); |
| 399 | |
| 400 | mDocMenu |
| 401 | ->addCheckBox( |
nothing calls this directly
no test coverage detected