@@ -76,6 +76,9 @@ sub new {
7676 $options_button -> signal_connect_swapped(clicked => \&run_options_dialogue, $self );
7777 $options_button -> set_tooltip_text(' Control some of the processing options' );
7878
79+ my $tree_combo = $self -> update_dendrogram_combo;
80+ $tree_combo -> show_all;
81+
7982 # Scrolled window for multi-line conditions
8083 my $scroll = Gtk3::ScrolledWindow-> new;
8184 $scroll -> set_policy(' automatic' , ' automatic' );
@@ -86,16 +89,23 @@ sub new {
8689 my $frame = Gtk3::Frame-> new();
8790 $frame -> add($text_view_no_scroll );
8891
89- my $hideable_widgets = [$scroll , $frame , $options_button , $syntax_button ];
92+ my $hideable_widgets = [
93+ $scroll , $frame ,
94+ $tree_combo ,
95+ $options_button , $syntax_button ,
96+ ];
9097
9198 # HBox
9299 $hbox -> pack_start($expander , 0, 0, 0);
93100 $hbox -> pack_start($scroll , 1, 1, 0);
94101 $hbox -> pack_start($frame , 1, 1, 0);
102+ $hbox -> pack_start($tree_combo , 0, 1, 0);
95103 $hbox -> pack_start($options_button , 0, 0, 0);
96104 $hbox -> pack_end($syntax_button , 0, 0, 0);
97105 $hbox -> show_all();
98106
107+ $self -> {tree_combo } = $tree_combo ;
108+
99109 my $cb_text_buffer = sub {
100110 if ($text_buffer -> get_line_count > 1) {
101111 $scroll -> show;
@@ -118,31 +128,33 @@ sub new {
118128
119129
120130 my $expander_cb = sub {
121- my $expand = !$expander -> get_expanded;
122- my $method = $expand ? ' show' : ' hide' ;
131+ my $visible = !$expander -> get_expanded;
123132 foreach my $widget (@$hideable_widgets ) {
124- if (not $widget =~ ' Button' and not $widget =~ $self -> {current_text_view }) {
133+ if (not $widget =~ ' Button|ComboBox ' and not $widget =~ $self -> {current_text_view }) {
125134 $widget -> hide; # hide the inactive textview regardless
126135 }
127136 else {
128- $widget -> $method ;
137+ $widget -> set_visible( $visible ) ;
129138 }
130139 }
131140 };
132- $expander -> set_tooltip_text (' Show or hide the edit and verify boxes. Use this to free up some screen real estate.' );
141+ $expander -> set_tooltip_text (
142+ ' Show or hide the edit box and other widgets. '
143+ . ' Use this to free up some screen real estate.'
144+ );
133145 $expander -> signal_connect_swapped (
134146 activate => $expander_cb ,
135147 $self ,
136148 );
137149 $expander -> set_expanded(!$start_hidden );
138150
139- my $method = $start_hidden ? ' hide ' : ' show ' ;
151+ my $visible = ! $start_hidden ;
140152 foreach my $widget (@$hideable_widgets ) {
141- if (not $widget =~ ' Button' and not $widget =~ $self -> {current_text_view }) {
153+ if (not $widget =~ ' Button|ComboBox ' and not $widget =~ $self -> {current_text_view }) {
142154 $widget -> hide; # hide the inactive textview regardless
143155 }
144156 else {
145- $widget -> $method ;
157+ $widget -> set_visible( $visible ) ;
146158 }
147159 }
148160
@@ -176,6 +188,7 @@ sub on_syntax_check {
176188 conditions => $expr ,
177189 basedata_ref => $bd ,
178190 promise_current_label => $self -> {promise_current_label },
191+ tree_ref => $self -> get_tree_ref,
179192 );
180193 };
181194 # croak $EVAL_ERROR if $EVAL_ERROR;
@@ -206,7 +219,8 @@ sub get_validated_conditions {
206219 my $self = shift ;
207220
208221 my $conditions = $self -> {validated_conditions };
209- croak " Conditions not yet validated\n " if !defined $conditions ;
222+ return if !defined $conditions ;
223+ # croak "Conditions not yet validated\n" if !defined $conditions;
210224
211225 my $options = $self -> get_options;
212226 $conditions -> set_no_recycling_flag ($options -> {no_recycling });
@@ -215,6 +229,26 @@ sub get_validated_conditions {
215229 return $conditions ;
216230}
217231
232+ sub get_tree_ref {
233+ my $self = shift ;
234+
235+ my $combo = $self -> {tree_combo };
236+ return if !$combo ;
237+
238+ my $iter = $combo -> get_active_iter;
239+ my $tree_ref = $iter ? $combo -> get_model-> get($iter , 1) : undef ;
240+
241+ if ($tree_ref eq ' no tree' ) {
242+ $tree_ref = undef ;
243+ }
244+ elsif ($tree_ref eq ' project' ) {
245+ my $gui = Biodiverse::GUI::GUIManager-> instance;
246+ $tree_ref = $gui -> get_project-> get_selected_phylogeny;
247+ }
248+
249+ return $tree_ref ;
250+ }
251+
218252sub get_object {
219253 my $self = shift ;
220254 return $self -> {hbox };
@@ -314,6 +348,62 @@ sub get_options {
314348 return wantarray ? %$options : $options ;
315349}
316350
351+ sub update_dendrogram_combo {
352+ my $self = shift ;
353+
354+ my $combobox = Gtk3::ComboBox-> new;
355+
356+ my $renderer_text = Gtk3::CellRendererText-> new();
357+ $combobox -> pack_start($renderer_text , 1);
358+ $combobox -> add_attribute($renderer_text , " text" , 0);
359+
360+ # Clear the current entries.
361+ # We need to load a new ListStore to avoid crashes due
362+ # to them being destroyed somewhere in the refresh process
363+ # (Not sure that is still the case)
364+ my $model = Gtk3::ListStore-> new(' Glib::String' , ' Glib::Scalar' );
365+
366+ my @combo_items ;
367+
368+ my $output_ref = eval {$self -> get_validated_conditions};
369+ if ($output_ref && $output_ref -> can(' get_tree_ref' ) && $output_ref -> get_tree_ref) {
370+ my $iter = $model -> append();
371+ $model -> set( $iter , 0 => ' analysis' , 1 => $output_ref -> get_tree_ref);
372+ push @combo_items , ' analysis' ;
373+ }
374+
375+ foreach my $option (' no tree' , ' project' ) {
376+ my $iter = $model -> append();
377+ $model -> set( $iter , 0 => $option , 1 => $option );
378+ push @combo_items , $option ;
379+ }
380+
381+ my $list = Biodiverse::GUI::GUIManager-> instance-> get_project-> get_phylogeny_list;
382+ foreach my $tree (@$list ) {
383+ my $name = $tree -> get_name;
384+ my $iter = $model -> append();
385+ $model -> set( $iter , 0 => $name , 1 => $tree );
386+ }
387+
388+ $combobox -> set_model ($model );
389+
390+ state $tooltip = <<~'EOT' ;
391+ Choose the tree to use in the spatial conditions.
392+
393+ The remainder of the options are the trees available at
394+ the project level. Note that this set is not updated as
395+ trees are added to and removed from the project.
396+ Changes can be triggered by closing and reopening the tab.
397+ EOT
398+ ;
399+
400+ $combobox -> set_tooltip_text ($tooltip );
401+ $combobox -> set_active(0);
402+ # $combobox->show_all;
403+
404+ return $combobox ;
405+ }
406+
317407
3184081;
319409
0 commit comments