]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/entityinspector.cpp
Merge commit 'dd7f4f1689e8ede7580bdfa8e08d0b78d08f5253' into garux-merge
[xonotic/netradiant.git] / radiant / entityinspector.cpp
index e74dd3f0834f637719ed9c0c2d9fcda4b72d0638..81bcd06c8031cd65741b8ad2b3b18da84e8e9572 100644 (file)
@@ -703,8 +703,10 @@ typedef MemberCaller<ListAttribute, void(), &ListAttribute::update> UpdateCaller
 
 namespace
 {
+GtkWidget* g_entity_split0 = 0;
 ui::Widget g_entity_split1{ui::null};
 ui::Widget g_entity_split2{ui::null};
+int g_entitysplit0_position;
 int g_entitysplit1_position;
 int g_entitysplit2_position;
 
@@ -1153,6 +1155,23 @@ void EntityInspector_clearKeyValue(){
        }
 }
 
+static gint EntityInspector_clearKeyValueKB( GtkEntry* widget, GdkEventKey* event, gpointer data ){
+       if ( event->keyval == GDK_Delete ) {
+               // Get current selection text
+               StringOutputStream key( 64 );
+               key << gtk_entry_get_text( g_entityKeyEntry );
+
+               if ( strcmp( key.c_str(), "classname" ) != 0 ) {
+                       StringOutputStream command;
+                       command << "entityDeleteKey -key " << key.c_str();
+                       UndoableCommand undo( command.c_str() );
+                       Scene_EntitySetKeyValue_Selected( key.c_str(), "" );
+               }
+               return TRUE;
+       }
+       return FALSE;
+}
+
 void EntityInspector_clearAllKeyValues(){
        UndoableCommand undo( "entityClear" );
 
@@ -1268,8 +1287,18 @@ static gint EntityEntry_keypress( ui::Entry widget, GdkEventKey* event, gpointer
                }
                return TRUE;
        }
-       if ( event->keyval == GDK_KEY_Escape ) {
-               gtk_window_set_focus( widget.window(), NULL );
+       if ( event->keyval == GDK_Tab ) {
+               if ( widget._handle == g_entityKeyEntry._handle ) {
+                       gtk_window_set_focus( widget.window(), g_entityValueEntry );
+               }
+               else
+               {
+                       gtk_window_set_focus( widget.window(), g_entityKeyEntry );
+               }
+               return TRUE;
+       }
+       if ( event->keyval == GDK_Escape ) {
+               // gtk_window_set_focus( widget.window(), NULL );
                return TRUE;
        }
 
@@ -1277,18 +1306,34 @@ static gint EntityEntry_keypress( ui::Entry widget, GdkEventKey* event, gpointer
 }
 
 void EntityInspector_destroyWindow( ui::Widget widget, gpointer data ){
+       g_entitysplit0_position = gtk_paned_get_position( GTK_PANED( g_entity_split0 ) );
        g_entitysplit1_position = gtk_paned_get_position( GTK_PANED( g_entity_split1 ) );
        g_entitysplit2_position = gtk_paned_get_position( GTK_PANED( g_entity_split2 ) );
-
        g_entityInspector_windowConstructed = false;
        GlobalEntityAttributes_clear();
 }
 
+static gint EntityInspector_hideWindowKB( GtkWidget* widget, GdkEventKey* event, gpointer data ){
+       //if ( event->keyval == GDK_Escape && GTK_WIDGET_VISIBLE( GTK_WIDGET( widget ) ) ) {
+       if ( event->keyval == GDK_Escape  ) {
+               //GroupDialog_showPage( g_page_entity );
+               gtk_widget_hide( GTK_WIDGET( GroupDialog_getWindow() ) );
+               return TRUE;
+       }
+       /* this doesn't work, if tab is bound (func is not called then) */
+       if ( event->keyval == GDK_Tab  ) {
+               gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( widget ) ) ), GTK_WIDGET( g_entityKeyEntry ) );
+               return TRUE;
+       }
+       return FALSE;
+}
+
 ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){
     auto vbox = ui::VBox( FALSE, 2 );
        vbox.show();
        gtk_container_set_border_width( GTK_CONTAINER( vbox ), 2 );
 
+       g_signal_connect( G_OBJECT( toplevel ), "key_press_event", G_CALLBACK( EntityInspector_hideWindowKB ), 0 );
        vbox.connect( "destroy", G_CALLBACK( EntityInspector_destroyWindow ), 0 );
 
        {
@@ -1300,7 +1345,8 @@ ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){
 
                {
                        ui::Widget split2 = ui::VPaned(ui::New);
-                       gtk_paned_add1( GTK_PANED( split1 ), split2 );
+                       //gtk_paned_add1( GTK_PANED( split1 ), split2 );
+                       gtk_paned_pack1( GTK_PANED( split1 ), split2, FALSE, FALSE );
                        split2.show();
 
                        g_entity_split2 = split2;
@@ -1309,7 +1355,8 @@ ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){
                                // class list
                                auto scr = ui::ScrolledWindow(ui::New);
                                scr.show();
-                               gtk_paned_add1( GTK_PANED( split2 ), scr );
+                               //gtk_paned_add1( GTK_PANED( split2 ), scr );
+                               gtk_paned_pack1( GTK_PANED( split2 ), scr, FALSE, FALSE );
                                gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
                                gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
 
@@ -1346,7 +1393,8 @@ ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){
                        {
                                auto scr = ui::ScrolledWindow(ui::New);
                                scr.show();
-                               gtk_paned_add2( GTK_PANED( split2 ), scr );
+                               //gtk_paned_add2( GTK_PANED( split2 ), scr );
+                               gtk_paned_pack2( GTK_PANED( split2 ), scr, FALSE, FALSE );
                                gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
                                gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
 
@@ -1363,14 +1411,16 @@ ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){
                }
 
                {
-                       ui::Widget split2 = ui::VPaned(ui::New);
-                       gtk_paned_add2( GTK_PANED( split1 ), split2 );
-                       split2.show();
+                       ui::Widget split0 = ui::VPaned(ui::New);
+                       //gtk_paned_add2( GTK_PANED( split1 ), split0 );
+                       gtk_paned_pack2( GTK_PANED( split1 ), split0, FALSE, FALSE );
+                       split0.show();
+                       g_entity_split0 = split0;
 
                        {
                 auto vbox2 = ui::VBox( FALSE, 2 );
                                vbox2.show();
-                               gtk_paned_pack1( GTK_PANED( split2 ), vbox2, FALSE, FALSE );
+                               gtk_paned_pack1( GTK_PANED( split0 ), vbox2, FALSE, FALSE );
 
                                {
                                        // Spawnflags (4 colums wide max, or window gets too wide.)
@@ -1403,6 +1453,7 @@ ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){
                                                auto view = ui::TreeView(ui::TreeModel::from(store._handle));
                                                gtk_tree_view_set_enable_search(view, FALSE );
                                                gtk_tree_view_set_headers_visible(view, FALSE );
+                                               g_signal_connect( G_OBJECT( view ), "key_press_event", G_CALLBACK( EntityInspector_clearKeyValueKB ), 0 );
 
                                                {
                                                        auto renderer = ui::CellRendererText(ui::New);
@@ -1506,27 +1557,23 @@ ui::Widget EntityInspector_constructWindow( ui::Window toplevel ){
 
                                viewport.add(g_attributeBox);
                                scr.add(viewport);
-                               gtk_paned_pack2( GTK_PANED( split2 ), scr, FALSE, FALSE );
+                               gtk_paned_pack2( GTK_PANED( split0 ), scr, FALSE, FALSE );
                        }
                }
        }
 
 
        {
-               // show the sliders in any case
-               if ( g_entitysplit2_position > 22 ) {
-                       gtk_paned_set_position( GTK_PANED( g_entity_split2 ), g_entitysplit2_position );
-               }
-               else {
+               // show the sliders in any case //no need, gtk can care
+               /*if ( g_entitysplit2_position < 22 ) {
                        g_entitysplit2_position = 22;
-                       gtk_paned_set_position( GTK_PANED( g_entity_split2 ), 22 );
-               }
-               if ( ( g_entitysplit1_position - g_entitysplit2_position ) > 27 ) {
-                       gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit1_position );
-               }
-               else {
-                       gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit2_position + 27 );
-               }
+               }*/
+               gtk_paned_set_position( GTK_PANED( g_entity_split2 ), g_entitysplit2_position );
+               /*if ( ( g_entitysplit1_position - g_entitysplit2_position ) < 27 ) {
+                       g_entitysplit1_position = g_entitysplit2_position + 27;
+               }*/
+               gtk_paned_set_position( GTK_PANED( g_entity_split1 ), g_entitysplit1_position );
+               gtk_paned_set_position( GTK_PANED( g_entity_split0 ), g_entitysplit0_position );
        }
 
        g_entityInspector_windowConstructed = true;
@@ -1574,6 +1621,7 @@ EntityInspector g_EntityInspector;
 void EntityInspector_construct(){
        GlobalEntityClassManager().attach( g_EntityInspector );
 
+       GlobalPreferenceSystem().registerPreference( "EntitySplit0", make_property_string( g_entitysplit0_position ) );
        GlobalPreferenceSystem().registerPreference( "EntitySplit1", make_property_string( g_entitysplit1_position ) );
        GlobalPreferenceSystem().registerPreference( "EntitySplit2", make_property_string( g_entitysplit2_position ) );