Merge pull request #480 from Pan7/multiselect2

Multiselect and description for the Entity Info dialog
This commit is contained in:
Timothee "TTimo" Besset 2017-05-07 15:52:47 -05:00 committed by GitHub
commit 0bf677c42d

View file

@ -1129,6 +1129,41 @@ static void entitylist_select( GtkWidget *widget, gpointer data ){
}
}
static void add_entity_selection( entity_t *pEntity ) {
if( pEntity ) {
for ( epair_t* pEpair = pEntity->epairs; pEpair; pEpair = pEpair->next )
{
Select_Brush( pEntity->brushes.onext );
}
}
}
static void entitylist_selected_foreach( GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data ) {
entity_t* pEntity;
gtk_tree_model_get( model, iter, 1, &pEntity, -1 );
add_entity_selection( pEntity );
//if parent (classname) node is selected then all child nodes are included
if( !pEntity ) {
GtkTreeIter child;
unsigned int i = 0;
while( gtk_tree_model_iter_nth_child( model, &child, iter, i++ ) ) {
gtk_tree_model_get( model, &child, 1, &pEntity, -1 );
add_entity_selection( pEntity );
}
}
}
static void entitylist_multiselect( GtkWidget *widget, gpointer data ) {
GtkTreeView *view = GTK_TREE_VIEW( g_object_get_data( G_OBJECT( data ), "entities" ) );
GtkTreeSelection *selection = gtk_tree_view_get_selection( view );
Select_Deselect();
gtk_tree_selection_selected_foreach( selection, entitylist_selected_foreach, NULL );
Sys_UpdateWindows( W_ALL );
}
static gint entitylist_click( GtkWidget *widget, GdkEventButton *event, gpointer data ){
if ( event->type == GDK_2BUTTON_PRESS ) {
entitylist_select( NULL, data );
@ -1137,17 +1172,43 @@ static gint entitylist_click( GtkWidget *widget, GdkEventButton *event, gpointer
return FALSE;
}
static void entitylist_selection_changed( GtkTreeSelection* selection, gpointer data ){
GtkTreeModel *model;
GtkTreeIter selected;
GtkTreeIter child;
entity_t *pEntity = NULL;
entity_t *firstEntity = NULL;
GtkListStore* store = GTK_LIST_STORE( g_object_get_data( G_OBJECT( data ), "keyvalues" ) );
GtkWidget *notebook = (GtkWidget*)g_object_get_data( G_OBJECT( data ), "notebook" );
GtkWidget *keyvalue_page = (GtkWidget*)g_object_get_data( G_OBJECT( data ), "keyvalue_page" );
GtkWidget *desc_page = (GtkWidget*)g_object_get_data( G_OBJECT( data ), "description_page" );
GtkWidget *textview = (GtkWidget*)g_object_get_data( G_OBJECT( data ), "description_textview" );
gtk_list_store_clear( store );
GtkTreeModel* model;
GtkTreeIter selected;
if ( gtk_tree_selection_get_selected( selection, &model, &selected ) ) {
if ( gtk_tree_selection_get_mode( selection ) == GTK_SELECTION_MULTIPLE ) {
GList *rows, *last;
rows = gtk_tree_selection_get_selected_rows( selection, &model );
//only the keys/values of the last selected node with entity
last = g_list_last( rows );
if ( last ) {
if ( gtk_tree_model_get_iter( model, &selected, (GtkTreePath *)last->data ) == TRUE ) {
gtk_tree_model_get( model, &selected, 1, &pEntity, -1 );
if ( !pEntity ) {
if( gtk_tree_model_iter_nth_child( model, &child, &selected, 0 ) ) {
gtk_tree_model_get( model, &child, 1, &firstEntity, -1 );
}
}
}
}
g_list_free_full( rows, (GDestroyNotify)gtk_tree_path_free );
} else if ( gtk_tree_selection_get_selected( selection, &model, &selected ) ) {
entity_t* pEntity;
gtk_tree_model_get( model, &selected, 1, &pEntity, -1 );
}
if ( pEntity ) {
for ( epair_t* pEpair = pEntity->epairs; pEpair; pEpair = pEpair->next )
{
@ -1155,8 +1216,18 @@ static void entitylist_selection_changed( GtkTreeSelection* selection, gpointer
gtk_list_store_append( store, &appended );
gtk_list_store_set( store, &appended, 0, pEpair->key, 1, pEpair->value, -1 );
}
gtk_notebook_set_current_page( GTK_NOTEBOOK( notebook ), gtk_notebook_page_num( GTK_NOTEBOOK( notebook ), keyvalue_page ) );
} else {
GtkTextBuffer *buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW( textview ) );
if( firstEntity && firstEntity->eclass && firstEntity->eclass->comments ) {
gtk_text_buffer_set_text( buffer, firstEntity->eclass->comments, -1 );
} else {
gtk_text_buffer_set_text( buffer, _( "No description available." ), -1 );
}
gtk_notebook_set_current_page( GTK_NOTEBOOK( notebook ), gtk_notebook_page_num( GTK_NOTEBOOK( notebook ), desc_page ) );
}
}
static void EnitityList_response( GtkDialog *dialog, gint response_id, gpointer user_data )
@ -1170,6 +1241,8 @@ static void EnitityList_response( GtkDialog *dialog, gint response_id, gpointer
void DoEntityList(){
static GtkWidget *dialog;
GtkWidget *vbox, *hbox, *hbox2, *button, *scr, *content_area;
GtkWidget *notebook, *label, *textview, *keyvalue_scr, *desc_scr;
gint keyvalue_index;
GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
if ( EntityList_dialog != NULL ) {
@ -1211,6 +1284,7 @@ void DoEntityList(){
{
GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) );
gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE );
g_signal_connect( G_OBJECT( selection ), "changed", G_CALLBACK( entitylist_selection_changed ), dialog );
}
@ -1279,8 +1353,17 @@ void DoEntityList(){
gtk_box_pack_start( GTK_BOX( hbox ), vbox, TRUE, TRUE, 0 );
gtk_widget_show( vbox );
scr = gtk_scrolled_window_new( (GtkAdjustment*)NULL, (GtkAdjustment*)NULL );
gtk_box_pack_start( GTK_BOX( vbox ), scr, TRUE, TRUE, 0 );
notebook = gtk_notebook_new();
// hide the notebook tabs since its not supposed to look like a notebook
gtk_notebook_set_show_tabs( GTK_NOTEBOOK( notebook ), FALSE );
gtk_box_pack_start( GTK_BOX( vbox ), notebook, TRUE, TRUE, 0 );
gtk_widget_show( notebook );
label = gtk_label_new( _( "Keys/Values" ) );
gtk_widget_show( label );
keyvalue_scr = scr = gtk_scrolled_window_new( NULL, NULL );
keyvalue_index = gtk_notebook_append_page( GTK_NOTEBOOK( notebook ), scr, label );
gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
gtk_widget_show( scr );
@ -1310,6 +1393,29 @@ void DoEntityList(){
g_object_unref( G_OBJECT( store ) );
}
label = gtk_label_new( _( "Description" ) );
gtk_widget_show( label );
desc_scr = scr = gtk_scrolled_window_new( NULL, NULL );
gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
gtk_notebook_append_page( GTK_NOTEBOOK( notebook ), scr, label );
gtk_widget_show( scr );
textview = gtk_text_view_new();
gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW( textview ), GTK_WRAP_WORD );
gtk_text_view_set_editable( GTK_TEXT_VIEW( textview ), FALSE );
gtk_container_add( GTK_CONTAINER( scr ), textview );
gtk_widget_show( textview );
gtk_notebook_set_current_page( GTK_NOTEBOOK( notebook ), keyvalue_index );
g_object_set_data( G_OBJECT( dialog ), "notebook", notebook );
g_object_set_data( G_OBJECT( dialog ), "keyvalue_page", keyvalue_scr );
g_object_set_data( G_OBJECT( dialog ), "description_page", desc_scr );
g_object_set_data( G_OBJECT( dialog ), "description_textview", textview );
hbox2 = gtk_hbox_new( FALSE, 5 );
gtk_box_pack_start( GTK_BOX( vbox ), hbox2, FALSE, FALSE, 0 );
gtk_widget_show( hbox2 );
@ -1317,7 +1423,7 @@ void DoEntityList(){
button = gtk_button_new_with_label( _( "Select" ) );
gtk_box_pack_start( GTK_BOX( hbox2 ), button, FALSE, FALSE, 0 );
g_signal_connect( G_OBJECT( button ), "clicked",
G_CALLBACK( entitylist_select ), dialog );
G_CALLBACK( entitylist_multiselect ), dialog );
gtk_widget_set_size_request( button, 60, -1 );
gtk_widget_show( button );