]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/preferences.cpp
Group import/export callbacks
[xonotic/netradiant.git] / radiant / preferences.cpp
index 6ad88df4dc4b0b543343eafce843ccf0a484326b..ea3dbe44c7dff63864a92bdcc82a4b84d32dfbf5 100644 (file)
@@ -81,7 +81,7 @@ void Mouse_constructPage( PreferenceGroup& group ){
        Mouse_constructPreferences( page );
 }
 void Mouse_registerPreferencesPage(){
-       PreferencesDialog_addInterfacePage( FreeCaller1<PreferenceGroup&, Mouse_constructPage>() );
+       PreferencesDialog_addInterfacePage( makeCallbackF(Mouse_constructPage) );
 }
 
 
@@ -221,7 +221,7 @@ void LogConsole_importString( const char* string ){
        g_Console_enableLogging = string_equal( string, "true" );
        Sys_LogFile( g_Console_enableLogging );
 }
-typedef FreeCaller1<const char*, LogConsole_importString> LogConsoleImportStringCaller;
+typedef FreeCaller<void(const char*), LogConsole_importString> LogConsoleImportStringCaller;
 
 
 void RegisterGlobalPreferences( PreferenceSystem& preferences ){
@@ -280,7 +280,7 @@ void CGameDialog::GameFileImport( int value ){
        m_sGameFile = ( *iGame )->mGameFile;
 }
 
-void CGameDialog::GameFileExport( const IntImportCallback& importCallback ) const {
+void CGameDialog::GameFileExport( const ImportExportCallback<int>::Import_t& importCallback ) const {
        // use m_sGameFile to set value
        std::list<CGameDescription *>::const_iterator iGame;
        int i = 0;
@@ -299,7 +299,7 @@ void CGameDialog_GameFileImport( CGameDialog& self, int value ){
        self.GameFileImport( value );
 }
 
-void CGameDialog_GameFileExport( CGameDialog& self, const IntImportCallback& importCallback ){
+void CGameDialog_GameFileExport( CGameDialog& self, const ImportExportCallback<int>::Import_t& importCallback ){
        self.GameFileExport( importCallback );
 }
 
@@ -313,8 +313,8 @@ void CGameDialog::CreateGlobalFrame( PreferencesPage& page ){
        page.appendCombo(
                "Select the game",
                StringArrayRange( &( *games.begin() ), &( *games.end() ) ),
-               ReferenceCaller1<CGameDialog, int, CGameDialog_GameFileImport>( *this ),
-               ReferenceCaller1<CGameDialog, const IntImportCallback&, CGameDialog_GameFileExport>( *this )
+               {ReferenceCaller<CGameDialog, void(int), CGameDialog_GameFileImport>( *this ),
+               ReferenceCaller<CGameDialog, void(const ImportExportCallback<int>::Import_t&), CGameDialog_GameFileExport>( *this )}
                );
        page.appendCheckBox( "Startup", "Show Global Preferences", m_bGamePrompt );
 }
@@ -334,33 +334,6 @@ ui::Window CGameDialog::BuildDialog(){
        return create_simple_modal_dialog_window( "Global Preferences", m_modal, frame );
 }
 
-class LoadGameFile
-{
-std::list<CGameDescription*>& mGames;
-const char* mPath;
-public:
-LoadGameFile( std::list<CGameDescription*>& games, const char* path ) : mGames( games ), mPath( path ){
-}
-void operator()( const char* name ) const {
-       if ( !extension_equal( path_get_extension( name ), "game" ) ) {
-               return;
-       }
-       StringOutputStream strPath( 256 );
-       strPath << mPath << name;
-       globalOutputStream() << strPath.c_str() << '\n';
-
-       xmlDocPtr pDoc = xmlParseFile( strPath.c_str() );
-       if ( pDoc ) {
-               mGames.push_front( new CGameDescription( pDoc, name ) );
-               xmlFreeDoc( pDoc );
-       }
-       else
-       {
-               globalErrorStream() << "XML parser failed on '" << strPath.c_str() << "'\n";
-       }
-}
-};
-
 void CGameDialog::ScanForGames(){
        StringOutputStream strGamesPath( 256 );
        strGamesPath << AppPath_get() << "games/";
@@ -377,7 +350,22 @@ void CGameDialog::ScanForGames(){
           (if that's really needed)
         */
 
-       Directory_forEach( path, LoadGameFile( mGames, path ) );
+       Directory_forEach(path, [&](const char *name) {
+               if (!extension_equal(path_get_extension(name), "game")) {
+                       return;
+               }
+               StringOutputStream strPath(256);
+               strPath << path << name;
+               globalOutputStream() << strPath.c_str() << '\n';
+
+               xmlDocPtr pDoc = xmlParseFile(strPath.c_str());
+               if (pDoc) {
+                       mGames.push_front(new CGameDescription(pDoc, name));
+                       xmlFreeDoc(pDoc);
+               } else {
+                       globalErrorStream() << "XML parser failed on '" << strPath.c_str() << "'\n";
+               }
+       });
 }
 
 CGameDescription* CGameDialog::GameDescriptionForComboItem(){
@@ -542,7 +530,7 @@ void PrefsDlg::showPrefPage( ui::Widget prefpage ){
        return;
 }
 
-static void treeSelection( GtkTreeSelection* selection, gpointer data ){
+static void treeSelection( ui::TreeSelection selection, gpointer data ){
        PrefsDlg *dlg = (PrefsDlg*)data;
 
        GtkTreeModel* model;
@@ -680,7 +668,7 @@ PreferencesPage createPage( const char* treeName, const char* frameName ){
 };
 
 ui::Window PrefsDlg::BuildDialog(){
-       PreferencesDialog_addInterfacePreferences( FreeCaller1<PreferencesPage&, Interface_constructPreferences>() );
+       PreferencesDialog_addInterfacePreferences( makeCallbackF(Interface_constructPreferences) );
        Mouse_registerPreferencesPage();
 
        ui::Window dialog = ui::Window(create_floating_window( "NetRadiant Preferences", m_parent ));
@@ -734,16 +722,16 @@ ui::Window PrefsDlg::BuildDialog(){
                                        auto store = ui::TreeStore(gtk_tree_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER ));
 
                                        auto view = ui::TreeView(ui::TreeModel(store));
-                                       gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE );
+                                       gtk_tree_view_set_headers_visible(view, FALSE );
 
                                        {
                                                auto renderer = ui::CellRendererText(ui::New);
-                                               GtkTreeViewColumn* column = ui::TreeViewColumn( "Preferences", renderer, {{"text", 0}} );
-                                               gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
+                        auto column = ui::TreeViewColumn( "Preferences", renderer, {{"text", 0}} );
+                                               gtk_tree_view_append_column(view, column );
                                        }
 
                                        {
-                                               auto selection = ui::TreeSelection(gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) ));
+                                               auto selection = ui::TreeSelection(gtk_tree_view_get_selection(view ));
                                                selection.connect( "changed", G_CALLBACK( treeSelection ), this );
                                        }
 
@@ -765,7 +753,7 @@ ui::Window PrefsDlg::BuildDialog(){
                                                                PreferencesPage preferencesPage( *this, getVBox( global ) );
                                                                Global_constructPreferences( preferencesPage );
                                                        }
-                                                       GtkTreeIter group = PreferenceTree_appendPage( store, 0, "Global", global );
+                            auto group = PreferenceTree_appendPage( store, 0, "Global", global );
                                                        {
                                                                auto game = PreferencePages_addPage( m_notebook, "Game" );
                                                                PreferencesPage preferencesPage( *this, getVBox( game ) );
@@ -782,7 +770,7 @@ ui::Window PrefsDlg::BuildDialog(){
                                                                PreferencesPageCallbacks_constructPage( g_interfacePreferences, preferencesPage );
                                                        }
 
-                                                       GtkTreeIter group = PreferenceTree_appendPage( store, 0, "Interface", interfacePage );
+                            auto group = PreferenceTree_appendPage( store, 0, "Interface", interfacePage );
                                                        PreferenceTreeGroup preferenceGroup( *this, m_notebook, store, group );
 
                                                        PreferenceGroupCallbacks_constructGroup( g_interfaceCallbacks, preferenceGroup );
@@ -794,7 +782,7 @@ ui::Window PrefsDlg::BuildDialog(){
                                                                PreferencesPage preferencesPage( *this, getVBox( display ) );
                                                                PreferencesPageCallbacks_constructPage( g_displayPreferences, preferencesPage );
                                                        }
-                                                       GtkTreeIter group = PreferenceTree_appendPage( store, 0, "Display", display );
+                            auto group = PreferenceTree_appendPage( store, 0, "Display", display );
                                                        PreferenceTreeGroup preferenceGroup( *this, m_notebook, store, group );
 
                                                        PreferenceGroupCallbacks_constructGroup( g_displayCallbacks, preferenceGroup );
@@ -807,14 +795,14 @@ ui::Window PrefsDlg::BuildDialog(){
                                                                PreferencesPageCallbacks_constructPage( g_settingsPreferences, preferencesPage );
                                                        }
 
-                                                       GtkTreeIter group = PreferenceTree_appendPage( store, 0, "Settings", settings );
+                            auto group = PreferenceTree_appendPage( store, 0, "Settings", settings );
                                                        PreferenceTreeGroup preferenceGroup( *this, m_notebook, store, group );
 
                                                        PreferenceGroupCallbacks_constructGroup( g_settingsCallbacks, preferenceGroup );
                                                }
                                        }
 
-                                       gtk_tree_view_expand_all( GTK_TREE_VIEW( view ) );
+                                       gtk_tree_view_expand_all(view );
 
                                        g_object_unref( G_OBJECT( store ) );
                                }
@@ -933,20 +921,20 @@ void PreferencesDialog_showDialog(){
 void GameName_importString( const char* value ){
        gamename_set( value );
 }
-typedef FreeCaller1<const char*, GameName_importString> GameNameImportStringCaller;
-void GameName_exportString( const StringImportCallback& importer ){
+typedef FreeCaller<void(const char*), GameName_importString> GameNameImportStringCaller;
+void GameName_exportString( const ImportExportCallback<const char *>::Import_t& importer ){
        importer( gamename_get() );
 }
-typedef FreeCaller1<const StringImportCallback&, GameName_exportString> GameNameExportStringCaller;
+typedef FreeCaller<void(const ImportExportCallback<const char *>::Import_t&), GameName_exportString> GameNameExportStringCaller;
 
 void GameMode_importString( const char* value ){
        gamemode_set( value );
 }
-typedef FreeCaller1<const char*, GameMode_importString> GameModeImportStringCaller;
-void GameMode_exportString( const StringImportCallback& importer ){
+typedef FreeCaller<void(const char*), GameMode_importString> GameModeImportStringCaller;
+void GameMode_exportString( const ImportExportCallback<const char *>::Import_t& importer ){
        importer( gamemode_get() );
 }
-typedef FreeCaller1<const StringImportCallback&, GameMode_exportString> GameModeExportStringCaller;
+typedef FreeCaller<void(const ImportExportCallback<const char *>::Import_t&), GameMode_exportString> GameModeExportStringCaller;
 
 
 void RegisterPreferences( PreferenceSystem& preferences ){