]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
GTK: wrap gtk_list_store_{append,set}
authorTimePath <andrew.hardaker1995@gmail.com>
Fri, 29 Dec 2017 08:35:56 +0000 (19:35 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Fri, 29 Dec 2017 08:35:56 +0000 (19:35 +1100)
contrib/bobtoolz/lists.cpp
contrib/brushexport/callbacks.cpp
libs/uilib/uilib.h
radiant/build.cpp
radiant/commands.cpp
radiant/entityinspector.cpp
radiant/feedback.cpp
radiant/map.cpp
radiant/textureentry.cpp
radiant/texwindow.cpp

index 38ec080e794a65a2ebe7bd38b0976ed16f18f26f..74e31bc89a2a00f07d2fcc206f1076ff8f92220b 100644 (file)
@@ -24,9 +24,6 @@
 #pragma warning(disable : 4786)
 #endif
 
-#include <glib.h>
-#include <gtk/gtk.h>
-
 #include "misc.h"
 
 bool LoadExclusionList( char* filename, std::list<Str>* exclusionList ){
@@ -69,9 +66,7 @@ bool LoadGList( char* filename, ui::ListStore loadlist ){
                        if ( strlen( buffer ) > 0 ) {
                                char* buffer2 = new char[strlen( buffer ) + 1];
                                strcpy( buffer2, buffer );
-                               GtkTreeIter iter;
-                               gtk_list_store_append(loadlist, &iter);
-                               gtk_list_store_set(loadlist, &iter, 0, buffer2, -1);
+                               loadlist.append(0, buffer2);
                        }
                        else{
                                cnt++;
index 29fb3263aeb1abe6542961424ddff6f7f87460f2..fd6a6000843d823ea0f4446794ac8a7826600cb5 100644 (file)
@@ -114,9 +114,7 @@ void OnAddMaterial( GtkButton* button, gpointer user_data ){
        const gchar* name = gtk_entry_get_text( edit );
        if ( g_utf8_strlen( name, -1 ) > 0 ) {
                ui::ListStore list = ui::ListStore(GTK_LIST_STORE( gtk_tree_view_get_model( GTK_TREE_VIEW( lookup_widget( GTK_WIDGET( button ), "t_materialist" ) ) ) ));
-               GtkTreeIter iter;
-               gtk_list_store_append( list, &iter );
-               gtk_list_store_set( list, &iter, 0, name, -1 );
+               list.append(0, name);
                gtk_entry_set_text( edit, "" );
        }
 }
index c6a3bb1fb1ff2bd858b234dbda6338f63ce0e808..482d720af0f2aef8ae831cf203746c7c8641796b 100644 (file)
@@ -31,6 +31,7 @@ struct _GtkImage;
 struct _GtkItem;
 struct _GtkLabel;
 struct _GtkListStore;
+struct _GtkTreeIter;
 struct _GtkMenu;
 struct _GtkMenuBar;
 struct _GtkMenuItem;
@@ -524,6 +525,9 @@ namespace ui {
     WRAP(ListStore, Object, _GtkListStore, (ITreeModel),
     ,
          void clear();
+
+         template<class... T>
+         void append(T... args);
     );
 
     WRAP(TreeSelection, Object, _GtkTreeSelection, (),
@@ -580,6 +584,18 @@ namespace ui {
         gtk_container_foreach(this, cb, &lambda);
     }
 
+    namespace {
+        extern "C" {
+        void gtk_list_store_insert_with_values(_GtkListStore *, _GtkTreeIter *, gint position, ...);
+        }
+    }
+
+    template<class... T>
+    void IListStore::append(T... args) {
+        static_assert(sizeof...(args) % 2 == 0, "received an odd number of arguments");
+        gtk_list_store_insert_with_values(this, NULL, -1, args..., -1);
+    }
+
 #undef this
 
 }
index 941ea33a3bdb720263b64c516e6121d953a643b2..8c733dd45ac196412460f7eac7fc414e587d78bd 100644 (file)
@@ -650,11 +650,7 @@ void BSPCommandList_Construct( ui::ListStore store, Project& project ){
 
        for ( Project::iterator i = project.begin(); i != project.end(); ++i )
        {
-               const char* buildName = ( *i ).first.c_str();
-
-               GtkTreeIter buildIter;
-               gtk_list_store_append( store, &buildIter );
-               gtk_list_store_set( store, &buildIter, 0, const_cast<char*>( buildName ), -1 );
+               store.append(0, (*i).first.c_str());
        }
 
        GtkTreeIter lastIter;
@@ -755,9 +751,7 @@ gboolean project_selection_changed( GtkTreeSelection* selection, ui::ListStore s
 
                        for ( Build::iterator i = build.begin(); i != build.end(); ++i )
                        {
-                               GtkTreeIter commandIter;
-                               gtk_list_store_append( store, &commandIter );
-                               gtk_list_store_set( store, &commandIter, 0, const_cast<char*>( ( *i ).c_str() ), -1 );
+                               store.append(0, (*i).c_str());
                        }
                        GtkTreeIter lastIter;
                        gtk_list_store_append( store, &lastIter );
index cf9c68ce8c3efad75fd5299a0377751da70ec403..70aa49752c87bd653b26652ac8fa1202ed340238 100644 (file)
@@ -441,11 +441,7 @@ public:
                                        StringOutputStream modifiers;
                                        modifiers << accelerator;
 
-                                       {
-                                               GtkTreeIter iter;
-                                               gtk_list_store_append( m_store, &iter );
-                                               gtk_list_store_set( m_store, &iter, 0, name, 1, modifiers.c_str(), 2, false, 3, 800, -1 );
-                                       }
+                                       m_store.append(0, name, 1, modifiers.c_str(), 2, false, 3, 800);
 
                                        if ( !m_commandList.failed() ) {
                                                int l = strlen( name );
index ff56706001126681a42a49c2b7e6b4dc4d4110e9..42889c61ce7639828f43127b5068e02e81d76d50 100644 (file)
@@ -810,9 +810,7 @@ public:
 EntityClassListStoreAppend( ui::ListStore store_ ) : store( store_ ){
 }
 void visit( EntityClass* e ){
-       GtkTreeIter iter;
-       gtk_list_store_append( store, &iter );
-       gtk_list_store_set( store, &iter, 0, e->name(), 1, e, -1 );
+       store.append(0, e->name(), 1, e);
 }
 };
 
@@ -1047,13 +1045,11 @@ void EntityInspector_updateKeyValues(){
        // Walk through list and add pairs
        for ( KeyValues::iterator i = g_selectedKeyValues.begin(); i != g_selectedKeyValues.end(); ++i )
        {
-               GtkTreeIter iter;
-               gtk_list_store_append( store, &iter );
                StringOutputStream key( 64 );
                key << ( *i ).first.c_str();
                StringOutputStream value( 64 );
                value << ( *i ).second.c_str();
-               gtk_list_store_set( store, &iter, 0, key.c_str(), 1, value.c_str(), -1 );
+               store.append(0, key.c_str(), 1, value.c_str());
        }
 
        g_entityKeyEntry.text( strKey.c_str() );
index 44e9dd71e0421fc300c3dc1dc3e20787df808f03..1fc3611f22ae469d19d7b6fd0562fa11ac7296ab 100644 (file)
@@ -282,9 +282,7 @@ void CDbgDlg::Push( ISAXHandler *pHandler ){
        gtk_list_store_clear( m_clist );
        for ( std::size_t i = 0; i < static_cast<std::size_t>( m_pFeedbackElements->len ); ++i )
        {
-               GtkTreeIter iter;
-               gtk_list_store_append( m_clist, &iter );
-               gtk_list_store_set( m_clist, &iter, 0, GetElement( i )->getName(), -1 );
+               m_clist.append(0, GetElement(i)->getName());
        }
 
        ShowDlg();
index 33dcebe9a51a79301430ad559015486f421fe331..1905c60b3901f332f9d966fe1f35b7fbfdb40b6b 100644 (file)
@@ -879,9 +879,7 @@ void DoMapInfo(){
                {
                        char tmp[16];
                        sprintf( tmp, "%u", Unsigned( ( *i ).second ) );
-                       GtkTreeIter iter;
-                       gtk_list_store_append( GTK_LIST_STORE( EntityBreakdownWalker ), &iter );
-                       gtk_list_store_set( GTK_LIST_STORE( EntityBreakdownWalker ), &iter, 0, ( *i ).first.c_str(), 1, tmp, -1 );
+                       EntityBreakdownWalker.append(0, (*i).first.c_str(), 1, tmp);
                }
        }
 
index 96a46dcda1d31a1b11d70a794c9c9a6c9e0dc2a6..c4bac5a1b9b81b1789aa4328c76d25aac5628751 100644 (file)
@@ -43,9 +43,7 @@ void EntryCompletion<StringList>::connect(ui::Entry entry)
 template<class StringList>
 void EntryCompletion<StringList>::append(const char *string)
 {
-    GtkTreeIter iter;
-    gtk_list_store_append(m_store, &iter);
-    gtk_list_store_set(m_store, &iter, 0, string, -1);
+    m_store.append(0, string);
 }
 
 template<class StringList>
index 03b141ae67960b4f10ce4db9a90ffda6d00cb871..5c0e6467a8de186565d197d0a36052fefcc68e42 100644 (file)
@@ -1306,8 +1306,7 @@ void BuildStoreAssignedTags( ui::ListStore store, const char* shader, TextureBro
 
        for ( size_t i = 0; i < assigned_tags.size(); i++ )
        {
-               gtk_list_store_append( store, &iter );
-               gtk_list_store_set( store, &iter, TAG_COLUMN, assigned_tags[i].c_str(), -1 );
+               store.append(TAG_COLUMN, assigned_tags[i].c_str());
        }
 }
 
@@ -1327,8 +1326,7 @@ void BuildStoreAvailableTags(   ui::ListStore storeAvailable,
        if ( !row ) { // does the shader have tags assigned?
                for ( iterAll = allTags.begin(); iterAll != allTags.end(); ++iterAll )
                {
-                       gtk_list_store_append( storeAvailable, &iterAvailable );
-                       gtk_list_store_set( storeAvailable, &iterAvailable, TAG_COLUMN, ( *iterAll ).c_str(), -1 );
+                       storeAvailable.append(TAG_COLUMN, (*iterAll).c_str());
                }
        }
        else
@@ -1340,8 +1338,7 @@ void BuildStoreAvailableTags(   ui::ListStore storeAvailable,
                        for ( iterAll = allTags.begin(); iterAll != allTags.end(); ++iterAll )
                        {
                                if ( strcmp( (char*)tag_assigned, ( *iterAll ).c_str() ) != 0 ) {
-                                       gtk_list_store_append( storeAvailable, &iterAvailable );
-                                       gtk_list_store_set( storeAvailable, &iterAvailable, TAG_COLUMN, ( *iterAll ).c_str(), -1 );
+                                       storeAvailable.append(TAG_COLUMN, (*iterAll).c_str());
                                }
                                else
                                {
@@ -1781,8 +1778,7 @@ void TextureBrowser_assignTags(){
                                        TagBuilder.AddShaderTag( g_TextureBrowser.shader.c_str(), (char*)tag_assigned, TAG );
 
                                        gtk_list_store_remove( g_TextureBrowser.m_available_store, &iter );
-                                       gtk_list_store_append( g_TextureBrowser.m_assigned_store, &iter );
-                                       gtk_list_store_set( g_TextureBrowser.m_assigned_store, &iter, TAG_COLUMN, (char*)tag_assigned, -1 );
+                                       g_TextureBrowser.m_assigned_store.append(TAG_COLUMN, tag_assigned);
                                }
                        }
                }
@@ -1832,15 +1828,13 @@ void TextureBrowser_removeTags(){
 }
 
 void TextureBrowser_buildTagList(){
-       GtkTreeIter treeIter;
        gtk_list_store_clear( g_TextureBrowser.m_all_tags_list );
 
        std::set<CopiedString>::iterator iter;
 
        for ( iter = g_TextureBrowser.m_all_tags.begin(); iter != g_TextureBrowser.m_all_tags.end(); ++iter )
        {
-               gtk_list_store_append( g_TextureBrowser.m_all_tags_list, &treeIter );
-               gtk_list_store_set( g_TextureBrowser.m_all_tags_list, &treeIter, TAG_COLUMN, ( *iter ).c_str(), -1 );
+               g_TextureBrowser.m_all_tags_list.append(TAG_COLUMN, (*iter).c_str());
        }
 }
 
@@ -2268,7 +2262,7 @@ void TextureBrowser_addTag(){
        EMessageBoxReturn result = DoShaderTagDlg( &tag, "Add shader tag" );
 
        if ( result == eIDOK && !tag.empty() ) {
-               GtkTreeIter iter, iter2;
+               GtkTreeIter iter;
                g_TextureBrowser.m_all_tags.insert( tag.c_str() );
                gtk_list_store_append( g_TextureBrowser.m_available_store, &iter );
                gtk_list_store_set( g_TextureBrowser.m_available_store, &iter, TAG_COLUMN, tag.c_str(), -1 );
@@ -2277,8 +2271,7 @@ void TextureBrowser_addTag(){
                GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( g_TextureBrowser.m_available_tree ) );
                gtk_tree_selection_select_iter( selection, &iter );
 
-               gtk_list_store_append( g_TextureBrowser.m_all_tags_list, &iter2 );
-               gtk_list_store_set( g_TextureBrowser.m_all_tags_list, &iter2, TAG_COLUMN, tag.c_str(), -1 );
+               g_TextureBrowser.m_all_tags_list.append(TAG_COLUMN, tag.c_str());
        }
 }