Skip to content

Commit 8ac7b84

Browse files
authored
Add demo for Shortcuts Window (#225)
1 parent bc657cb commit 8ac7b84

File tree

6 files changed

+200
-0
lines changed

6 files changed

+200
-0
lines changed

src/Shortcuts Window/code.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use crate::workbench;
2+
use gtk::prelude::*;
3+
4+
pub fn main() {
5+
let shortcuts_window: gtk::ShortcutsWindow =
6+
workbench::builder().object("shortcuts_window").unwrap();
7+
let button: gtk::Button = workbench::builder().object("button").unwrap();
8+
9+
button.connect_clicked(move |_| shortcuts_window.present());
10+
}

src/Shortcuts Window/main.blp

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
using Gtk 4.0;
2+
using Adw 1;
3+
4+
Adw.StatusPage {
5+
title: _("Shortcuts Window");
6+
description: _("A window showing the application's keyboard shortcuts");
7+
8+
Box {
9+
spacing: 50;
10+
halign: center;
11+
orientation: vertical;
12+
13+
Button button {
14+
label: _("Open");
15+
16+
styles [
17+
"suggested-action",
18+
"pill",
19+
]
20+
}
21+
22+
Box {
23+
orientation: vertical;
24+
25+
LinkButton {
26+
label: _("API Reference");
27+
uri: "https://docs.gtk.org/gtk4/class.ShortcutsWindow.html";
28+
}
29+
30+
LinkButton {
31+
label: _("Human Interface Guidelines");
32+
uri: "https://developer.gnome.org/hig/reference/keyboard.html";
33+
}
34+
}
35+
}
36+
}
37+
38+
Gtk.ShortcutsWindow shortcuts_window {
39+
hide-on-close: true;
40+
41+
Gtk.ShortcutsSection {
42+
section-name: _("Shortcuts");
43+
max-height: 18;
44+
45+
Gtk.ShortcutsGroup {
46+
title: _("Application");
47+
48+
Gtk.ShortcutsShortcut {
49+
accelerator: "<Primary>Return";
50+
title: _("Run Code");
51+
}
52+
53+
Gtk.ShortcutsShortcut {
54+
accelerator: "<Shift><Primary>Return";
55+
title: _("Format");
56+
}
57+
58+
Gtk.ShortcutsShortcut {
59+
accelerator: "<Primary>N";
60+
title: _("New Project");
61+
}
62+
63+
Gtk.ShortcutsShortcut {
64+
accelerator: "<Primary>O";
65+
title: _("Open Project");
66+
}
67+
68+
Gtk.ShortcutsShortcut {
69+
accelerator: "<Shift><Primary>O";
70+
title: _("Open Library");
71+
}
72+
73+
Gtk.ShortcutsShortcut {
74+
accelerator: "<Shift><Primary>I";
75+
title: _("Inspector");
76+
}
77+
78+
Gtk.ShortcutsShortcut {
79+
accelerator: "<Primary>W";
80+
title: _("Close Window");
81+
}
82+
83+
Gtk.ShortcutsShortcut {
84+
accelerator: "<Primary>M";
85+
title: _("Reveal in Files");
86+
}
87+
88+
Gtk.ShortcutsShortcut {
89+
accelerator: "<Primary>question";
90+
title: _("Keyboard Shortcuts");
91+
}
92+
93+
Gtk.ShortcutsShortcut {
94+
accelerator: "<Primary>Q";
95+
title: _("Quit");
96+
}
97+
}
98+
99+
Gtk.ShortcutsGroup {
100+
title: _("Editor");
101+
102+
Gtk.ShortcutsShortcut {
103+
accelerator: "<Primary>X";
104+
title: _("Cut");
105+
}
106+
107+
Gtk.ShortcutsShortcut {
108+
accelerator: "<Primary>C";
109+
title: _("Copy");
110+
}
111+
112+
Gtk.ShortcutsShortcut {
113+
accelerator: "<Primary>V";
114+
title: _("Paste");
115+
}
116+
117+
Gtk.ShortcutsShortcut {
118+
accelerator: "<Primary>F";
119+
title: _("Find");
120+
}
121+
122+
Gtk.ShortcutsShortcut {
123+
accelerator: "<Primary>Z";
124+
title: _("Undo");
125+
}
126+
127+
Gtk.ShortcutsShortcut {
128+
accelerator: "<Primary>space";
129+
title: _("Show code suggestions");
130+
}
131+
132+
Gtk.ShortcutsShortcut {
133+
accelerator: "<Shift><Primary>Z";
134+
title: _("Redo");
135+
}
136+
}
137+
138+
Gtk.ShortcutsGroup {
139+
title: _("Console");
140+
141+
Gtk.ShortcutsShortcut {
142+
accelerator: "<Shift><Primary>K";
143+
title: _("Toggle Console");
144+
}
145+
146+
Gtk.ShortcutsShortcut {
147+
accelerator: "<Shift><Primary>C";
148+
title: _("Copy");
149+
}
150+
151+
Gtk.ShortcutsShortcut {
152+
accelerator: "<Shift><Primary>A";
153+
title: _("Select All");
154+
}
155+
156+
Gtk.ShortcutsShortcut {
157+
accelerator: "<Primary>K";
158+
title: _("Clear");
159+
}
160+
}
161+
}
162+
}

src/Shortcuts Window/main.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const shortcuts_window = workbench.builder.get_object("shortcuts_window");
2+
const button = workbench.builder.get_object("button");
3+
4+
button.connect("clicked", () => {
5+
shortcuts_window.present();
6+
});

src/Shortcuts Window/main.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"category": "user_interface",
3+
"description": "A window showing the application's keyboard shortcuts",
4+
"panels": ["ui", "preview"],
5+
"autorun": true
6+
}

src/Shortcuts Window/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import workbench
2+
3+
shortcuts_window = workbench.builder.get_object("shortcuts_window")
4+
button = workbench.builder.get_object("button")
5+
6+
button.connect("clicked", lambda *_: shortcuts_window.present())

src/Shortcuts Window/main.vala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#! /usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1
2+
3+
public void main() {
4+
var shortcuts_window = (Gtk.ShortcutsWindow) workbench.builder.get_object("shortcuts_window");
5+
var button = (Gtk.Button) workbench.builder.get_object("button");
6+
7+
button.clicked.connect(() => {
8+
shortcuts_window.present();
9+
});
10+
}

0 commit comments

Comments
 (0)