Skip to content

Commit

Permalink
Fix startup warnings (#1250)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Wootten authored Jan 24, 2023
1 parent 9e9c3ef commit 8b55723
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,6 @@ namespace Scratch {
toolbar = new Scratch.HeaderBar ();
toolbar.title = title;

sidebar.choose_project_button.project_chosen.connect (() => {
folder_manager_view.collapse_other_projects ();
});

// SearchBar
search_bar = new Scratch.Widgets.SearchBar (this);
search_revealer = new Gtk.Revealer ();
Expand Down Expand Up @@ -524,6 +520,10 @@ namespace Scratch {
}
});

sidebar.choose_project_button.project_chosen.connect (() => {
folder_manager_view.collapse_other_projects ();
});

set_widgets_sensitive (false);
}

Expand Down
7 changes: 4 additions & 3 deletions src/Services/Document.vala
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ namespace Scratch.Services {
}

public void toggle_changed_handlers (bool enabled) {
if (enabled) {
if (enabled && onchange_handler_id == 0) {
onchange_handler_id = this.source_view.buffer.changed.connect (() => {
if (onchange_handler_id != 0) {
this.source_view.buffer.disconnect (onchange_handler_id);
Expand All @@ -224,7 +224,7 @@ namespace Scratch.Services {
// Signals for SourceView
uint timeout_saving = 0;
check_undoable_actions ();
this.source_view.buffer.changed.connect (() => {
onchange_handler_id = source_view.buffer.changed.connect (() => {
check_undoable_actions ();
// Save if autosave is ON
if (Scratch.settings.get_boolean ("autosave")) {
Expand All @@ -240,8 +240,9 @@ namespace Scratch.Services {
}
});
});
} else if (onchange_handler_id != 0) {
} else if (!enabled && onchange_handler_id != 0) {
this.source_view.buffer.disconnect (onchange_handler_id);
onchange_handler_id = 0;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Services/GitManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace Scratch.Services {
}

private GitManager () {
// Used to populate the ChooseProject popover in sorted order
project_liststore = new ListStore (typeof (FolderManager.ProjectFolderItem));
}

Expand Down
37 changes: 30 additions & 7 deletions src/Widgets/ChooseProjectButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,22 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {

popover = project_popover;

project_listbox.bind_model (
Scratch.Services.GitManager.get_instance ().project_liststore,
create_project_row
);
var model = Scratch.Services.GitManager.get_instance ().project_liststore;

model.items_changed.connect ((pos, n_removed, n_added) => {
// This model is put in sort order by the GitManager so model pos the same as listbox index
var project_folder = (Scratch.FolderManager.ProjectFolderItem)(model.get_item (pos));
if (n_added > 0) {
var row = create_project_row (project_folder);
project_listbox.insert (row, (int)pos);
} else {
// Double check we are removing correct row (do not rely on pos)
var row = find_row_for_path (project_folder.file.file.get_path ());
if (row != null) {
project_listbox.remove (row);
}
}
});

project_listbox.remove.connect ((row) => {
var project_row = row as ProjectRow;
Expand All @@ -109,9 +121,7 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {
});
}

private Gtk.Widget create_project_row (GLib.Object object) {
unowned var project_folder = (Scratch.FolderManager.ProjectFolderItem) object;

private Gtk.Widget create_project_row (Scratch.FolderManager.ProjectFolderItem project_folder) {
var project_row = new ProjectRow (project_folder.file.file.get_path ());
project_folder.bind_property ("name", project_row.project_radio, "label", BindingFlags.DEFAULT | BindingFlags.SYNC_CREATE,
(binding, srcval, ref targetval) => {
Expand All @@ -132,6 +142,19 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {
return project_row;
}

private ProjectRow? find_row_for_path (string project_path) {
foreach (var child in project_listbox.get_children ()) {
if (child is ProjectRow) {
var row = (ProjectRow)child;
if (row.project_path == project_path) {
return row;
}
}
}

return null;
}

private void select_project (ProjectRow project_entry) {
project_listbox.select_row (project_entry);
label_widget.label = project_entry.project_name;
Expand Down

0 comments on commit 8b55723

Please sign in to comment.