From: TimePath Date: Fri, 29 Dec 2017 08:35:56 +0000 (+1100) Subject: GTK: wrap gtk_list_store_{append,set} X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6d89c0d85ada682828059c3c69be4747a4933c19;p=xonotic%2Fnetradiant.git GTK: wrap gtk_list_store_{append,set} --- diff --git a/contrib/bobtoolz/lists.cpp b/contrib/bobtoolz/lists.cpp index 38ec080e..74e31bc8 100644 --- a/contrib/bobtoolz/lists.cpp +++ b/contrib/bobtoolz/lists.cpp @@ -24,9 +24,6 @@ #pragma warning(disable : 4786) #endif -#include -#include - #include "misc.h" bool LoadExclusionList( char* filename, std::list* 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++; diff --git a/contrib/brushexport/callbacks.cpp b/contrib/brushexport/callbacks.cpp index 29fb3263..fd6a6000 100644 --- a/contrib/brushexport/callbacks.cpp +++ b/contrib/brushexport/callbacks.cpp @@ -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, "" ); } } diff --git a/libs/uilib/uilib.h b/libs/uilib/uilib.h index c6a3bb1f..482d720a 100644 --- a/libs/uilib/uilib.h +++ b/libs/uilib/uilib.h @@ -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 + 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 + 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 } diff --git a/radiant/build.cpp b/radiant/build.cpp index 941ea33a..8c733dd4 100644 --- a/radiant/build.cpp +++ b/radiant/build.cpp @@ -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( 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( ( *i ).c_str() ), -1 ); + store.append(0, (*i).c_str()); } GtkTreeIter lastIter; gtk_list_store_append( store, &lastIter ); diff --git a/radiant/commands.cpp b/radiant/commands.cpp index cf9c68ce..70aa4975 100644 --- a/radiant/commands.cpp +++ b/radiant/commands.cpp @@ -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 ); diff --git a/radiant/entityinspector.cpp b/radiant/entityinspector.cpp index ff567060..42889c61 100644 --- a/radiant/entityinspector.cpp +++ b/radiant/entityinspector.cpp @@ -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() ); diff --git a/radiant/feedback.cpp b/radiant/feedback.cpp index 44e9dd71..1fc3611f 100644 --- a/radiant/feedback.cpp +++ b/radiant/feedback.cpp @@ -282,9 +282,7 @@ void CDbgDlg::Push( ISAXHandler *pHandler ){ gtk_list_store_clear( m_clist ); for ( std::size_t i = 0; i < static_cast( 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(); diff --git a/radiant/map.cpp b/radiant/map.cpp index 33dcebe9..1905c60b 100644 --- a/radiant/map.cpp +++ b/radiant/map.cpp @@ -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); } } diff --git a/radiant/textureentry.cpp b/radiant/textureentry.cpp index 96a46dcd..c4bac5a1 100644 --- a/radiant/textureentry.cpp +++ b/radiant/textureentry.cpp @@ -43,9 +43,7 @@ void EntryCompletion::connect(ui::Entry entry) template void EntryCompletion::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 diff --git a/radiant/texwindow.cpp b/radiant/texwindow.cpp index 03b141ae..5c0e6467 100644 --- a/radiant/texwindow.cpp +++ b/radiant/texwindow.cpp @@ -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::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()); } }