@@ -2017,26 +2017,57 @@ impl NodeGraphMessageHandler {
2017
2017
let selection_all_locked = network_interface. selected_nodes ( ) . selected_unlocked_layers ( network_interface) . count ( ) == 0 ;
2018
2018
let selection_all_visible = selected_nodes. selected_nodes ( ) . all ( |node_id| network_interface. is_visible ( node_id, breadcrumb_network_path) ) ;
2019
2019
2020
+ let mut selected_layers = selected_nodes. selected_layers ( network_interface. document_metadata ( ) ) ;
2021
+ let selected_layer = selected_layers. next ( ) ;
2022
+ let has_multiple_selection = selected_layers. next ( ) . is_some ( ) ;
2023
+
2020
2024
let mut widgets = vec ! [
2021
2025
PopoverButton :: new( )
2022
2026
. icon( Some ( "Node" . to_string( ) ) )
2023
2027
. tooltip( "New Node (Right Click)" )
2024
2028
. popover_layout( {
2025
- let node_chooser = NodeCatalog :: new( )
2029
+ // Showing only compatible types
2030
+ let compatible_type = match ( selection_includes_layers, has_multiple_selection, selected_layer) {
2031
+ ( true , false , Some ( layer) ) => {
2032
+ let graph_layer = graph_modification_utils:: NodeGraphLayer :: new( layer, network_interface) ;
2033
+ let node_type = graph_layer. horizontal_layer_flow( ) . nth( 1 ) ;
2034
+ if let Some ( node_id) = node_type {
2035
+ let ( output_type, _) = network_interface. output_type( & node_id, 0 , & [ ] ) ;
2036
+ Some ( format!( "type:{}" , output_type. nested_type( ) ) )
2037
+ } else {
2038
+ None
2039
+ }
2040
+ }
2041
+ _ => None ,
2042
+ } ;
2043
+
2044
+ let single_layer_selected = selection_includes_layers && !has_multiple_selection;
2045
+
2046
+ let mut node_chooser = NodeCatalog :: new( ) ;
2047
+ node_chooser. intial_search = compatible_type. unwrap_or( "" . to_string( ) ) ;
2048
+
2049
+ let node_chooser = node_chooser
2026
2050
. on_update( move |node_type| {
2027
- let node_id = NodeId :: new( ) ;
2028
-
2029
- Message :: Batched {
2030
- messages: Box :: new( [
2031
- NodeGraphMessage :: CreateNodeFromContextMenu {
2032
- node_id: Some ( node_id) ,
2033
- node_type: node_type. clone( ) ,
2034
- xy: None ,
2035
- add_transaction: true ,
2036
- }
2037
- . into( ) ,
2038
- NodeGraphMessage :: SelectedNodesSet { nodes: vec![ node_id] } . into( ) ,
2039
- ] ) ,
2051
+ if let ( true , Some ( layer) ) = ( single_layer_selected, selected_layer) {
2052
+ NodeGraphMessage :: CreateNodeInLayerWithTransaction {
2053
+ node_type: node_type. clone( ) ,
2054
+ layer: LayerNodeIdentifier :: new_unchecked( layer. to_node( ) ) ,
2055
+ }
2056
+ . into( )
2057
+ } else {
2058
+ let node_id = NodeId :: new( ) ;
2059
+ Message :: Batched {
2060
+ messages: Box :: new( [
2061
+ NodeGraphMessage :: CreateNodeFromContextMenu {
2062
+ node_id: Some ( node_id) ,
2063
+ node_type: node_type. clone( ) ,
2064
+ xy: None ,
2065
+ add_transaction: true ,
2066
+ }
2067
+ . into( ) ,
2068
+ NodeGraphMessage :: SelectedNodesSet { nodes: vec![ node_id] } . into( ) ,
2069
+ ] ) ,
2070
+ }
2040
2071
}
2041
2072
} )
2042
2073
. widget_holder( ) ;
@@ -2308,7 +2339,22 @@ impl NodeGraphMessageHandler {
2308
2339
. icon( Some ( "Node" . to_string( ) ) )
2309
2340
. tooltip( "Add an operation to the end of this layer's chain of nodes" )
2310
2341
. popover_layout( {
2311
- let node_chooser = NodeCatalog :: new( )
2342
+ let layer_identifier = LayerNodeIdentifier :: new( layer, & context. network_interface) ;
2343
+ let compatible_type = {
2344
+ let graph_layer = graph_modification_utils:: NodeGraphLayer :: new( layer_identifier, & context. network_interface) ;
2345
+ let node_type = graph_layer. horizontal_layer_flow( ) . nth( 1 ) ;
2346
+ if let Some ( node_id) = node_type {
2347
+ let ( output_type, _) = context. network_interface. output_type( & node_id, 0 , & [ ] ) ;
2348
+ Some ( format!( "type:{}" , output_type. nested_type( ) ) )
2349
+ } else {
2350
+ None
2351
+ }
2352
+ } ;
2353
+
2354
+ let mut node_chooser = NodeCatalog :: new( ) ;
2355
+ node_chooser. intial_search = compatible_type. unwrap_or( "" . to_string( ) ) ;
2356
+
2357
+ let node_chooser = node_chooser
2312
2358
. on_update( move |node_type| {
2313
2359
NodeGraphMessage :: CreateNodeInLayerWithTransaction {
2314
2360
node_type: node_type. clone( ) ,
0 commit comments