@@ -48,8 +48,8 @@ public class Code.ChooseProjectButton : Gtk.Bin {
4848 };
4949
5050 project_listbox.set_filter_func ((row ) => {
51- // Both are lowercased so that the case doesn't matter when comparing.
52- return ((( ProjectRow ) row) . project_name . down () . contains (project_filter. text. down () . strip ()));
51+ var name = Path . get_basename ((( ProjectRow ) row) . project_path);
52+ return name . contains (project_filter. text); // TODO Is "has_prefix" more useful?
5353 });
5454
5555 project_filter.changed.connect (() => {
@@ -98,6 +98,7 @@ public class Code.ChooseProjectButton : Gtk.Bin {
9898 child = menu_button;
9999
100100 // Initialise with any pre-existing projects (needed for second and subsequent window)
101+ // Note: for 1st window this happens too early. Rows are added by the item changed handler
101102 var git_manager = Scratch.Services.GitManager.get_instance ();
102103 var src = git_manager. project_liststore;
103104 for (int index = 0 ; index < src .n_items ; index ++) {
@@ -124,22 +125,12 @@ public class Code.ChooseProjectButton : Gtk.Bin {
124125 }
125126 });
126127
127- menu_button.toggled.connect (() => {
128- if (menu_button. active) {
129- unowned var active_path = Scratch . Services . GitManager . get_instance (). active_project_path;
130- foreach (var child in project_listbox. get_children ()) {
131- var project_row = ((ProjectRow ) child);
132- // All paths must not end in directory separator so can be compared directly
133- project_row. is_active_project = active_path == project_row. project_path;
134- }
135- }
136- });
137-
128+ menu_button.toggled.connect (update_active_row );
138129 git_manager.notify["active-project-path"].connect (update_button );
139130 update_button ();
140131 }
141132
142- // Set appearance (only) of project chooser button and list according to active path
133+ // Set appearance (only) of project chooser button according to active path
143134 private void update_button () {
144135 unowned var active_path = Scratch . Services . GitManager . get_instance (). active_project_path;
145136 if (active_path != " " ) {
@@ -151,6 +142,17 @@ public class Code.ChooseProjectButton : Gtk.Bin {
151142 }
152143 }
153144
145+ // Ensure correct row is checked
146+ private void update_active_row () {
147+ unowned var active_path = Scratch . Services . GitManager . get_instance (). active_project_path;
148+ var index = 0 ;
149+ var project_row = project_listbox. get_row_at_index (index);
150+ while (project_row != null ) {
151+ ((ProjectRow ) project_row). update_active (active_path);
152+ project_row = project_listbox. get_row_at_index (++ index);
153+ }
154+ }
155+
154156 private Gtk . Widget create_project_row (Scratch . FolderManager . ProjectFolderItem project_folder) {
155157 var project_path = project_folder. file. file. get_path ();
156158 var project_row = new ProjectRow (project_path);
@@ -160,38 +162,24 @@ public class Code.ChooseProjectButton : Gtk.Bin {
160162 }
161163
162164 public class ProjectRow : Gtk .ListBoxRow {
163- private Gtk . CheckButton check_button;
164- public bool is_active_project {
165- get {
166- return check_button. active;
167- }
168-
169- set {
170- check_button. active = value ;
171- }
172- }
173-
174165 public string project_path { get ; construct; }
175- public string project_name {
176- get {
177- return check_button. label;
178- }
179- }
166+ private Gtk . CheckButton check_button;
167+ private Gtk . GestureMultiPress button_controller;
180168
181169 public ProjectRow (string project_path ) {
182170 Object (
183171 project_path: project_path
184172 );
185173 }
186174
187- private Gtk . GestureMultiPress button_controller;
188-
189175 class construct {
190176 set_css_name (Gtk .STYLE_CLASS_MENUITEM );
191177 }
192178
193179 construct {
194180 can_focus = true ;
181+ activatable = true ;
182+
195183 action_name = Scratch . MainWindow . ACTION_PREFIX + Scratch . MainWindow . ACTION_SET_ACTIVE_PROJECT ;
196184 action_target = new Variant .string (project_path);
197185
@@ -206,10 +194,14 @@ public class Code.ChooseProjectButton : Gtk.Bin {
206194 button = 0
207195 };
208196 button_controller. released. connect (() = > {
209- activate ();
197+ activate (); // This activates the *action* (no "row-activated" signal sent)
210198 });
211199
212200 show_all ();
213201 }
202+
203+ public void update_active (string active_path ) {
204+ check_button. active = active_path == project_path;
205+ }
214206 }
215207}
0 commit comments