-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add context menu to table view, remove popover arrow
- Loading branch information
Showing
11 changed files
with
153 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -35,6 +35,7 @@ template $PsequelDataCell: Adw.Bin { | |
|
||
PopoverMenu popover { | ||
menu-model: menu; | ||
has-arrow: false; | ||
} | ||
} | ||
|
||
|
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,19 +1,8 @@ | ||
using Gtk 4.0; | ||
|
||
template ListItem { | ||
child: Box { | ||
orientation: horizontal; | ||
spacing: 12; | ||
|
||
Image { | ||
icon-name: "table-symbolic"; | ||
} | ||
|
||
Label { | ||
label: bind template.item as <$PsequelTable>.name; | ||
halign: start; | ||
ellipsize: end; | ||
single-line-mode: true; | ||
} | ||
}; | ||
child: $PsequelTableRow { | ||
icon-name: "table-symbolic"; | ||
content: bind template.item as <$PsequelTable>.name; | ||
}; | ||
} |
This file contains 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 |
---|---|---|
@@ -1 +1,49 @@ | ||
using Gtk 4.0; | ||
using Gtk 4.0; | ||
using Adw 1; | ||
|
||
menu menu { | ||
section { | ||
item { | ||
icon: "category-search-symbolic"; | ||
label: _("_Copy"); | ||
action: "sidebar.copy"; | ||
} | ||
} | ||
|
||
section { | ||
item { | ||
label: _("_Refresh"); | ||
action: "sidebar.refresh"; | ||
} | ||
} | ||
} | ||
|
||
template $PsequelTableRow: Box { | ||
orientation: horizontal; | ||
spacing: 12; | ||
|
||
Image icon_image { | ||
icon-name: bind template.icon-name; | ||
} | ||
|
||
Box { | ||
Label label { | ||
label: bind template.content; | ||
halign: start; | ||
ellipsize: end; | ||
single-line-mode: true; | ||
extra-menu: menu; | ||
} | ||
|
||
PopoverMenu popover { | ||
menu-model: menu; | ||
has-arrow: false; | ||
} | ||
} | ||
|
||
GestureClick { | ||
button: 3; // right clicked | ||
released => $on_right_clicked(); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,84 @@ | ||
using Gtk; | ||
|
||
namespace Psequel { | ||
[GtkTemplate(ui = "/me/ppvan/psequel/gtk/table-row.ui")] | ||
class TableRow : Gtk.Box { | ||
public string content { get; set; default = ""; } | ||
public string icon_name { get; set; default = ""; } | ||
|
||
private TableDataViewModel tabledata_viewmodel { get; set; } | ||
|
||
|
||
const ActionEntry[] ACTION_ENTRIES = { | ||
{ "copy", on_row_copy }, | ||
{ "refresh", on_row_refresh }, | ||
}; | ||
|
||
public TableRow() { | ||
Object(); | ||
} | ||
|
||
construct { | ||
var action_group = new SimpleActionGroup(); | ||
action_group.add_action_entries(ACTION_ENTRIES, this); | ||
this.insert_action_group("sidebar", action_group); | ||
tabledata_viewmodel = autowire <TableDataViewModel> (); | ||
} | ||
|
||
|
||
[GtkCallback] | ||
public void on_right_clicked() { | ||
popover.popup(); | ||
} | ||
|
||
// [GtkAction] | ||
private void on_row_copy() { | ||
clipboard_push(this.content); | ||
|
||
var window = get_parrent_window(this); | ||
Adw.Toast toast = new Adw.Toast("Table name copied") { | ||
timeout = 1, | ||
}; | ||
window.add_toast(toast); | ||
} | ||
|
||
private void on_row_refresh() { | ||
// General idea: Loop throught the single selection model | ||
// Assume the content of the label item is the same as the model-item.name | ||
// and the list view is a single selection. | ||
|
||
var listview_type = GLib.Type.from_name("GtkListView"); | ||
Gtk.ListView view = this.get_ancestor(listview_type) as Gtk.ListView; | ||
Gtk.SingleSelection model = view.model as Gtk.SingleSelection; | ||
|
||
uint n = model.get_n_items(); | ||
|
||
for (uint i = 0; i < n; i++) { | ||
Object obj = model.model.get_item(i); | ||
Value v = {}; | ||
obj.get_property("name", ref v); | ||
string key = v.get_string(); | ||
|
||
if (key == this.content) { | ||
model.select_item(i, true); | ||
view.activate(i); | ||
break; | ||
} | ||
} | ||
|
||
|
||
|
||
// view.activate(); | ||
} | ||
|
||
private void clipboard_push(string text) { | ||
var primary = Gdk.Display.get_default(); | ||
var clipboard = primary.get_clipboard(); | ||
|
||
clipboard.set_text(text); | ||
} | ||
|
||
[GtkChild] | ||
private unowned Gtk.Popover popover; | ||
} | ||
} |