Repository navigation
ChooseProjectButton: Use ListStore and bind to git_manager model #1825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jeremypw
wants to merge
3
commits into
master
Choose a base branch
from
jeremypw/projectchooserbutton/liststore-only
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,9 @@ public class Code.ChooseProjectButton : Gtk.Bin { | |
| private const string PROJECT_TOOLTIP = N_("Active Git Project: %s"); | ||
| private Gtk.Label label_widget; | ||
| private Gtk.ListBox project_listbox; | ||
| private Gtk.SearchEntry project_filter; | ||
| private ListStore project_liststore; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why this is being cached here. Seems like it's only used during bind_model? |
||
| private Scratch.Services.GitManager git_manager; | ||
|
|
||
| construct { | ||
| var img = new Gtk.Image.from_icon_name ("git-symbolic", SMALL_TOOLBAR); | ||
|
|
@@ -33,10 +36,18 @@ public class Code.ChooseProjectButton : Gtk.Bin { | |
| box.add (label_widget); | ||
| box.add (cloning_spinner); | ||
|
|
||
| git_manager = Scratch.Services.GitManager.get_instance (); | ||
| project_liststore = git_manager.project_liststore; | ||
| project_listbox = new Gtk.ListBox () { | ||
| selection_mode = SINGLE | ||
| }; | ||
|
|
||
| //TODO Use list of objects not widgets | ||
| project_listbox.bind_model (project_liststore, (obj) => { | ||
| var path = ((Scratch.FolderManager.Item) obj).path; | ||
| return new ProjectRow (path); | ||
| }); | ||
|
|
||
| var project_filter = new Gtk.SearchEntry () { | ||
| margin_top = 12, | ||
| margin_bottom = 6, | ||
|
|
@@ -95,36 +106,9 @@ public class Code.ChooseProjectButton : Gtk.Bin { | |
|
|
||
| child = menu_button; | ||
|
|
||
| // Initialise with any pre-existing projects (needed for second and subsequent window) | ||
| var git_manager = Scratch.Services.GitManager.get_instance (); | ||
| var src = git_manager.project_liststore; | ||
| for (int index = 0; index < src.n_items; index++) { | ||
| var item = src.get_object (index); | ||
| if (item is Scratch.FolderManager.ProjectFolderItem) { | ||
| var row = create_project_row ((Scratch.FolderManager.ProjectFolderItem)item); | ||
| project_listbox.insert (row, index); | ||
| } | ||
| } | ||
|
|
||
| git_manager.project_liststore.items_changed.connect ((src, pos, n_removed, n_added) => { | ||
| var rows = project_listbox.get_children (); | ||
| for (int index = (int)pos; index < pos + n_removed; index++) { | ||
| var row = rows.nth_data (index); | ||
| row.destroy (); | ||
| } | ||
|
|
||
| for (int index = (int)pos; index < pos + n_added; index++) { | ||
| var item = src.get_object (index); | ||
| if (item is Scratch.FolderManager.ProjectFolderItem) { | ||
| var row = create_project_row ((Scratch.FolderManager.ProjectFolderItem)item); | ||
| project_listbox.insert (row, index); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| menu_button.toggled.connect (() => { | ||
| if (menu_button.active) { | ||
| unowned var active_path = Scratch.Services.GitManager.get_instance ().active_project_path; | ||
| unowned var active_path = git_manager.active_project_path; | ||
| foreach (var child in project_listbox.get_children ()) { | ||
| var project_row = ((ProjectRow) child); | ||
| // All paths must not end in directory separator so can be compared directly | ||
|
|
@@ -139,7 +123,7 @@ public class Code.ChooseProjectButton : Gtk.Bin { | |
|
|
||
| // Set appearance (only) of project chooser button and list according to active path | ||
| private void update_button () { | ||
| unowned var active_path = Scratch.Services.GitManager.get_instance ().active_project_path; | ||
| unowned var active_path = git_manager.active_project_path; | ||
| if (active_path != "") { | ||
| label_widget.label = Path.get_basename (active_path); | ||
| tooltip_text = _(PROJECT_TOOLTIP).printf (Scratch.Utils.replace_home_with_tilde (active_path)); | ||
|
|
@@ -149,14 +133,6 @@ public class Code.ChooseProjectButton : Gtk.Bin { | |
| } | ||
| } | ||
|
|
||
| private Gtk.Widget create_project_row (Scratch.FolderManager.ProjectFolderItem project_folder) { | ||
| var project_path = project_folder.file.file.get_path (); | ||
| var project_row = new ProjectRow (project_path); | ||
| // Project folder items cannot be renamed in UI, no need to handle | ||
|
|
||
| return project_row; | ||
| } | ||
|
|
||
| public class ProjectRow : Gtk.ListBoxRow { | ||
| private Gtk.CheckButton check_button; | ||
| public bool is_active_project { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never used?