clapper-app: Add "New Window" menu option

Allow creating new windows from within the app
This commit is contained in:
Rafał Dzięgiel
2024-05-13 19:15:31 +02:00
parent 71142ab0c6
commit cc5c2b2403
2 changed files with 22 additions and 0 deletions

View File

@@ -217,6 +217,21 @@ add_uri (GSimpleAction *action, GVariant *param, gpointer user_data)
clapper_app_uri_dialog_open_uri (gtk_app);
}
static void
new_window (GSimpleAction *action, GVariant *param, gpointer user_data)
{
GtkApplication *gtk_app = GTK_APPLICATION (user_data);
GtkWidget *stack = gtk_window_get_child (gtk_application_get_active_window (gtk_app));
const gchar *child_name = gtk_stack_get_visible_child_name (GTK_STACK (stack));
/* Do not allow to open new windows during initial state,
* there already is a free one to use */
if (g_strcmp0 (child_name, "initial_state") != 0) {
GtkWidget *window = clapper_app_window_new (gtk_app);
gtk_window_present (GTK_WINDOW (window));
}
}
static void
show_preferences (GSimpleAction *action, GVariant *param, gpointer user_data)
{
@@ -648,6 +663,7 @@ clapper_app_application_constructed (GObject *object)
static const GActionEntry app_actions[] = {
{ "add-files", add_files, NULL, NULL, NULL },
{ "add-uri", add_uri, NULL, NULL, NULL },
{ "new-window", new_window, NULL, NULL, NULL },
{ "info", show_info, NULL, NULL, NULL },
{ "preferences", show_preferences, NULL, NULL, NULL },
{ "about", show_about, NULL, NULL, NULL },

View File

@@ -178,6 +178,12 @@
</child>
</template>
<menu id="app_menu">
<section>
<item>
<attribute name="label" translatable="yes">New Window</attribute>
<attribute name="action">app.new-window</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">Preferences</attribute>