-
-
Notifications
You must be signed in to change notification settings - Fork 90
library: Adds columnview entry #437
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d2e36ef
Add columnview
SoNiC-HeRE a40a5be
test
SoNiC-HeRE 8258b64
Update
SoNiC-HeRE 2c78601
Clean Up and implement colview
SoNiC-HeRE 5156e47
Refactoring and applied suggested changes
SoNiC-HeRE 99ae852
Applied changes
SoNiC-HeRE bf6ea43
Progress
SoNiC-HeRE 99c0eff
Updated
SoNiC-HeRE 07b0621
Update
SoNiC-HeRE b63cf3b
Update
SoNiC-HeRE 297d709
Reverse
SoNiC-HeRE 6eacdbe
Applied Suggested Changes
SoNiC-HeRE 8dff295
Minor Change
SoNiC-HeRE 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 |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| using Gtk 4.0; | ||
| using Adw 1; | ||
|
|
||
| Adw.StatusPage { | ||
| title: _("Column View"); | ||
| description: _("Presents a large dynamic list of items using multiple columns with headers"); | ||
| valign: start; | ||
|
|
||
| Adw.Clamp { | ||
| maximum-size: 240; | ||
|
|
||
| Box { | ||
| orientation: vertical; | ||
| spacing: 12; | ||
|
|
||
| LinkButton { | ||
| label: _("Documentation"); | ||
| uri: "https://docs.gtk.org/gtk4/class.ColumnView.html"; | ||
| } | ||
|
|
||
| Frame { | ||
| ColumnView column_view { | ||
| show-column-separators: true; | ||
| show-row-separators: true; | ||
|
|
||
| ColumnViewColumn col1 { | ||
| title: _("Name"); | ||
| factory: SignalListItemFactory{}; | ||
| } | ||
|
|
||
| ColumnViewColumn col2 { | ||
| title: _("Size"); | ||
| factory: SignalListItemFactory {}; | ||
| } | ||
|
|
||
| ColumnViewColumn col3 { | ||
| title: _("Date"); | ||
| factory: SignalListItemFactory {}; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import Gtk from "gi://Gtk"; | ||
| import Gio from "gi://Gio"; | ||
| import GObject from "gi://GObject"; | ||
|
|
||
| const column_view = workbench.builder.get_object("column_view"); | ||
| const col1 = workbench.builder.get_object("col1"); | ||
| const col2 = workbench.builder.get_object("col2"); | ||
| const col3 = workbench.builder.get_object("col3"); | ||
|
|
||
| //Model | ||
| const dir = Gio.File.new_for_path(pkg.pkgdatadir).resolve_relative_path( | ||
| "Library/demos", | ||
| ); | ||
|
|
||
| const data_model = new Gtk.DirectoryList({ | ||
| file: dir, | ||
| attributes: "standard::*,time::modified", | ||
| }); | ||
|
|
||
| const sort_model = new Gtk.SortListModel({ | ||
| model: data_model, | ||
| sorter: column_view.sorter, | ||
| }); | ||
|
|
||
| column_view.model = new Gtk.SingleSelection({ | ||
| model: sort_model, | ||
| }); | ||
|
|
||
| col1.sorter = new Gtk.StringSorter({ | ||
| expression: new Gtk.ClosureExpression( | ||
| GObject.TYPE_STRING, | ||
| (fileInfo) => fileInfo.get_display_name(), | ||
| null, | ||
| ), | ||
| }); | ||
|
|
||
| col2.sorter = new Gtk.NumericSorter({ | ||
| expression: new Gtk.ClosureExpression( | ||
| GObject.TYPE_INT, | ||
| (fileInfo) => fileInfo.get_size(), | ||
| null, | ||
| ), | ||
| }); | ||
|
|
||
| col3.sorter = new Gtk.NumericSorter({ | ||
| expression: new Gtk.ClosureExpression( | ||
| GObject.TYPE_INT64, | ||
| (fileInfo) => fileInfo.get_modification_date_time().to_unix(), | ||
| null, | ||
| ), | ||
| }); | ||
SoNiC-HeRE marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| //View | ||
| //Column 1 | ||
| const factory_col1 = col1.factory; | ||
| factory_col1.connect("setup", (factory, list_item) => { | ||
| const label = new Gtk.Label({ | ||
| margin_start: 12, | ||
| margin_end: 12, | ||
| }); | ||
| list_item.set_child(label); | ||
| }); | ||
| factory_col1.connect("bind", (factory, list_item) => { | ||
| const label_widget = list_item.get_child(); | ||
| const model_item = list_item.get_item(); | ||
| label_widget.label = model_item.get_display_name(); | ||
| }); | ||
|
|
||
| //Column 2 | ||
| const factory_col2 = col2.factory; | ||
| factory_col2.connect("setup", (factory, list_item) => { | ||
| const label = new Gtk.Label({ | ||
| margin_start: 12, | ||
| margin_end: 12, | ||
| }); | ||
| list_item.set_child(label); | ||
| }); | ||
| factory_col2.connect("bind", (factory, list_item) => { | ||
| const label_widget = list_item.get_child(); | ||
| const model_item = list_item.get_item(); | ||
| const size = model_item.get_size(); | ||
| if (Math.floor(size / 1_000_000_000) > 0) | ||
| label_widget.label = `${(size / 1_000_000_000).toFixed(1)} GB`; | ||
| else if (Math.floor(size / 1_000_000) > 0) | ||
| label_widget.label = `${(size / 1_000_000).toFixed(1)} MB`; | ||
| else if (Math.floor(size / 1000) > 0) | ||
| label_widget.label = `${(size / 1000).toFixed(1)} kB`; | ||
| else label_widget.label = `${size / 1000} bytes`; | ||
| }); | ||
|
|
||
| //Column 3 | ||
| const factory_col3 = col3.factory; | ||
| factory_col3.connect("setup", (factory, list_item) => { | ||
| const label = new Gtk.Label({ | ||
| margin_start: 12, | ||
| margin_end: 12, | ||
| }); | ||
| list_item.set_child(label); | ||
| }); | ||
| factory_col3.connect("bind", (factory, list_item) => { | ||
| const label_widget = list_item.get_child(); | ||
| const model_item = list_item.get_item(); | ||
| const date = model_item.get_modification_date_time(); | ||
| label_widget.label = date.format("%F"); | ||
| }); | ||
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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "name": "Column View", | ||
| "category": "layout", | ||
| "description": "Presents a large dynamic list of items using multiple columns with headers", | ||
| "panels": ["ui", "preview"], | ||
| "autorun": true | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.