]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/preferences.cpp
radiant/tools: use RADIANT_NAME instead of hardcoding NetRadiant or Radiant
[xonotic/netradiant.git] / radiant / preferences.cpp
index 0fee7ef9377e3ef9c83dd36857429de7dcc20bb1..2bd3ce44736ef7647bb1751fc13c5c076f416cd0 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) );
 }
 
 
@@ -121,7 +121,7 @@ CGameDescription::CGameDescription( xmlDocPtr pDoc, const CopiedString& gameFile
 
        {
                StringOutputStream path( 256 );
-               path << AppPath_get() << gameFile.c_str() << "/";
+               path << DataPath_get() << gameFile.c_str() << "/";
                mGameToolsPath = path.c_str();
        }
 
@@ -216,18 +216,22 @@ bool Preferences_Save_Safe( PreferenceDictionary& preferences, const char* filen
 }
 
 
+struct LogConsole {
+       static void Export(const Callback<void(bool)> &returnz) {
+               returnz(g_Console_enableLogging);
+       }
 
-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;
+       static void Import(bool value) {
+               g_Console_enableLogging = value;
+               Sys_LogFile(g_Console_enableLogging);
+       }
+};
 
 
 void RegisterGlobalPreferences( PreferenceSystem& preferences ){
-       preferences.registerPreference( "gamefile", CopiedStringImportStringCaller( g_GamesDialog.m_sGameFile ), CopiedStringExportStringCaller( g_GamesDialog.m_sGameFile ) );
-       preferences.registerPreference( "gamePrompt", BoolImportStringCaller( g_GamesDialog.m_bGamePrompt ), BoolExportStringCaller( g_GamesDialog.m_bGamePrompt ) );
-       preferences.registerPreference( "log console", LogConsoleImportStringCaller(), BoolExportStringCaller( g_Console_enableLogging ) );
+       preferences.registerPreference( "gamefile", make_property_string( g_GamesDialog.m_sGameFile ) );
+       preferences.registerPreference( "gamePrompt", make_property_string( g_GamesDialog.m_bGamePrompt ) );
+       preferences.registerPreference( "log console", make_property_string<LogConsole>() );
 }
 
 
@@ -280,7 +284,7 @@ void CGameDialog::GameFileImport( int value ){
        m_sGameFile = ( *iGame )->mGameFile;
 }
 
-void CGameDialog::GameFileExport( const IntImportCallback& importCallback ) const {
+void CGameDialog::GameFileExport( const Callback<void(int)> & importCallback ) const {
        // use m_sGameFile to set value
        std::list<CGameDescription *>::const_iterator iGame;
        int i = 0;
@@ -295,13 +299,15 @@ void CGameDialog::GameFileExport( const IntImportCallback& importCallback ) cons
        importCallback( m_nComboSelect );
 }
 
-void CGameDialog_GameFileImport( CGameDialog& self, int value ){
-       self.GameFileImport( value );
-}
+struct CGameDialog_GameFile {
+       static void Export(const CGameDialog &self, const Callback<void(int)> &returnz) {
+               self.GameFileExport(returnz);
+       }
 
-void CGameDialog_GameFileExport( CGameDialog& self, const IntImportCallback& importCallback ){
-       self.GameFileExport( importCallback );
-}
+       static void Import(CGameDialog &self, int value) {
+               self.GameFileImport(value);
+       }
+};
 
 void CGameDialog::CreateGlobalFrame( PreferencesPage& page ){
        std::vector<const char*> games;
@@ -313,8 +319,7 @@ 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 )
+               make_property<CGameDialog_GameFile>(*this)
                );
        page.appendCheckBox( "Startup", "Show Global Preferences", m_bGamePrompt );
 }
@@ -336,7 +341,7 @@ ui::Window CGameDialog::BuildDialog(){
 
 void CGameDialog::ScanForGames(){
        StringOutputStream strGamesPath( 256 );
-       strGamesPath << AppPath_get() << "games/";
+       strGamesPath << DataPath_get() << "games/";
        const char *path = strGamesPath.c_str();
 
        globalOutputStream() << "Scanning for game description files: " << path << '\n';
@@ -470,8 +475,8 @@ CGameDialog g_GamesDialog;
 
 static void OnButtonClean( ui::Widget widget, gpointer data ){
        // make sure this is what the user wants
-       if ( g_Preferences.GetWidget().alert( "This will close Radiant and clean the corresponding registry entries.\n"
-                                                                                                                                 "Next time you start Radiant it will be good as new. Do you wish to continue?",
+       if ( ui::alert( g_Preferences.GetWidget(), "This will close " RADIANT_NAME " and clean the corresponding registry entries.\n"
+                                                                                                                                 "Next time you start " RADIANT_NAME " it will be good as new. Do you wish to continue?",
                                                 "Reset Registry", ui::alert_type::YESNO, ui::alert_icon::Asterisk ) == ui::alert_response::YES ) {
                PrefsDlg *dlg = (PrefsDlg*)data;
                dlg->EndModal( eIDCANCEL );
@@ -668,10 +673,10 @@ 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 ));
+       ui::Window dialog = ui::Window(create_floating_window( RADIANT_NAME " Preferences", m_parent ));
 
        {
                auto mainvbox = ui::VBox( FALSE, 5 );
@@ -711,7 +716,7 @@ ui::Window PrefsDlg::BuildDialog(){
                                gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( sc_win ), GTK_SHADOW_IN );
 
                                // prefs pages notebook
-                               m_notebook = ui::Widget(gtk_notebook_new());
+                               m_notebook = ui::Widget::from(gtk_notebook_new());
                                // hide the notebook tabs since its not supposed to look like a notebook
                                gtk_notebook_set_show_tabs( GTK_NOTEBOOK( m_notebook ), FALSE );
                                hbox.pack_start( m_notebook, TRUE, TRUE, 0 );
@@ -719,9 +724,9 @@ ui::Window PrefsDlg::BuildDialog(){
 
 
                                {
-                                       auto store = ui::TreeStore(gtk_tree_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER ));
+                                       auto store = ui::TreeStore::from(gtk_tree_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER ));
 
-                                       auto view = ui::TreeView(ui::TreeModel(store));
+                                       auto view = ui::TreeView(ui::TreeModel::from(store._handle));
                                        gtk_tree_view_set_headers_visible(view, FALSE );
 
                                        {
@@ -731,7 +736,7 @@ ui::Window PrefsDlg::BuildDialog(){
                                        }
 
                                        {
-                                               auto selection = ui::TreeSelection(gtk_tree_view_get_selection(view ));
+                                               auto selection = ui::TreeSelection::from(gtk_tree_view_get_selection(view));
                                                selection.connect( "changed", G_CALLBACK( treeSelection ), this );
                                        }
 
@@ -908,45 +913,42 @@ void PreferencesDialog_showDialog(){
                        {
                                message << ( *i ) << '\n';
                        }
-                       MainFrame_getWindow().alert( message.c_str() );
+                       ui::alert( MainFrame_getWindow(), message.c_str() );
                        g_restart_required.clear();
                }
        }
 }
 
+struct GameName {
+       static void Export(const Callback<void(const char *)> &returnz) {
+               returnz(gamename_get());
+       }
 
+       static void Import(const char *value) {
+               gamename_set(value);
+       }
+};
 
+struct GameMode {
+       static void Export(const Callback<void(const char *)> &returnz) {
+               returnz(gamemode_get());
+       }
 
-
-void GameName_importString( const char* value ){
-       gamename_set( value );
-}
-typedef FreeCaller1<const char*, GameName_importString> GameNameImportStringCaller;
-void GameName_exportString( const StringImportCallback& importer ){
-       importer( gamename_get() );
-}
-typedef FreeCaller1<const StringImportCallback&, 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 ){
-       importer( gamemode_get() );
-}
-typedef FreeCaller1<const StringImportCallback&, GameMode_exportString> GameModeExportStringCaller;
-
+       static void Import(const char *value) {
+               gamemode_set(value);
+       }
+};
 
 void RegisterPreferences( PreferenceSystem& preferences ){
 #if GDEF_OS_WINDOWS
-       preferences.registerPreference( "UseCustomShaderEditor", BoolImportStringCaller( g_TextEditor_useWin32Editor ), BoolExportStringCaller( g_TextEditor_useWin32Editor ) );
+       preferences.registerPreference( "UseCustomShaderEditor", make_property_string( g_TextEditor_useWin32Editor ) );
 #else
-       preferences.registerPreference( "UseCustomShaderEditor", BoolImportStringCaller( g_TextEditor_useCustomEditor ), BoolExportStringCaller( g_TextEditor_useCustomEditor ) );
-       preferences.registerPreference( "CustomShaderEditorCommand", CopiedStringImportStringCaller( g_TextEditor_editorCommand ), CopiedStringExportStringCaller( g_TextEditor_editorCommand ) );
+       preferences.registerPreference( "UseCustomShaderEditor", make_property_string( g_TextEditor_useCustomEditor ) );
+       preferences.registerPreference( "CustomShaderEditorCommand", make_property_string( g_TextEditor_editorCommand ) );
 #endif
 
-       preferences.registerPreference( "GameName", GameNameImportStringCaller(), GameNameExportStringCaller() );
-       preferences.registerPreference( "GameMode", GameModeImportStringCaller(), GameModeExportStringCaller() );
+       preferences.registerPreference( "GameName", make_property<GameName>() );
+       preferences.registerPreference( "GameMode", make_property<GameMode>() );
 }
 
 void Preferences_Init(){