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

Method updateRecentFiles

src/tools/ecode/ecode.cpp:1166–1223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1164}
1165
1166void App::updateRecentFiles() {
1167 UINode* node = nullptr;
1168 if ( mSettings && mSettings->getSettingsMenu() &&
1169 ( node = mSettings->getSettingsMenu()->getItemId( "menu-recent-files" ) ) ) {
1170 UIMenuSubMenu* uiMenuSubMenu = static_cast<UIMenuSubMenu*>( node );
1171 UIMenu* menu = uiMenuSubMenu->getSubMenu();
1172 uiMenuSubMenu->setEnabled( !mRecentFiles.empty() );
1173 menu->removeAll();
1174 menu->removeEventsOfType( Event::OnItemClicked );
1175 if ( mRecentFiles.empty() )
1176 return;
1177 menu->add( i18n( "reopen_closed_document", "Reopen Closed Document" ), nullptr,
1178 getKeybind( "reopen-closed-tab" ) )
1179 ->setId( "reopen-closed-tab" )
1180 ->setEnabled( !mRecentClosedFiles.empty() );
1181 menu->addSeparator();
1182 for ( const auto& file : mRecentFiles ) {
1183 if ( ( FileSystem::fileExists( file ) && !FileSystem::isDirectory( file ) ) ||
1184 String::startsWith( file, "https://" ) || String::startsWith( file, "http://" ) )
1185 menu->add( file );
1186 }
1187 menu->addSeparator();
1188 menu->add( i18n( "clear_menu", "Clear Menu" ) )->setId( "clear-menu" );
1189 menu->on( Event::OnItemClicked, [this]( const Event* event ) {
1190 if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) )
1191 return;
1192 const std::string& id = event->getNode()->asType<UIMenuItem>()->getId();
1193 if ( id == "reopen-closed-tab" ) {
1194 reopenClosedTab();
1195 } else if ( id == "clear-menu" ) {
1196 mRecentFiles.clear();
1197 updateRecentFiles();
1198 updateRecentButtons();
1199 } else {
1200 const String& txt = event->getNode()->asType<UIMenuItem>()->getText();
1201 std::string path( txt.toUtf8() );
1202 if ( ( FileSystem::fileExists( path ) && !FileSystem::isDirectory( path ) ) ||
1203 String::startsWith( path, "https://" ) ||
1204 String::startsWith( path, "http://" ) ) {
1205 loadFileFromPathOrFocus( path );
1206 } else {
1207 auto msgBox = UIMessageBox::New(
1208 UIMessageBox::YES_NO,
1209 i18n( "file_does_not_exists_anymore_recreate",
1210 "File does not exists anymore.\nDo you want to recreate it?" ) );
1211 msgBox->setTitle( i18n( "file_not_found", "File not found" ) );
1212 msgBox->on( Event::OnConfirm, [path, this]( auto ) {
1213 FileSystem::fileWrite( path, "" );
1214 loadFileFromPathOrFocus( path );
1215 } );
1216 msgBox->center();
1217 msgBox->showWhenReady();
1218 updateRecentFiles();
1219 }
1220 }
1221 } );
1222 }
1223}

Callers 1

createSettingsMenuMethod · 0.45

Calls 15

getItemIdMethod · 0.80
getSubMenuMethod · 0.80
removeAllMethod · 0.80
removeEventsOfTypeMethod · 0.80
addSeparatorMethod · 0.80
getNodeMethod · 0.80
toUtf8Method · 0.80
centerMethod · 0.80
showWhenReadyMethod · 0.80
getIdMethod · 0.65
NewFunction · 0.50
getSettingsMenuMethod · 0.45

Tested by

no test coverage detected