mirror of
https://github.com/LibreSplit/LibreSplit.git
synced 2026-04-26 13:50:30 +00:00
Ensure dialog windows can only have one instance open (#356)
* Convert help dialog to singleton * Convert settings dialog to singleton
This commit is contained in:
parent
3a4f3e0563
commit
2c18bcbf5e
2 changed files with 20 additions and 0 deletions
|
|
@ -3,15 +3,25 @@
|
|||
#include <gtk/gtk.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static GtkWidget* help_window_singleton = NULL;
|
||||
|
||||
static gboolean on_help_window_delete(GtkWidget* widget, GdkEvent* event, gpointer user_data)
|
||||
{
|
||||
help_window_singleton = NULL;
|
||||
gtk_widget_destroy(widget);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void build_help_dialog(GtkApplication* app, gpointer data)
|
||||
{
|
||||
// Show already open window if another one is called.
|
||||
if (help_window_singleton) {
|
||||
gtk_window_present(GTK_WINDOW(help_window_singleton));
|
||||
return;
|
||||
}
|
||||
|
||||
GtkWidget* window = gtk_application_window_new(app);
|
||||
help_window_singleton = window;
|
||||
gtk_window_set_title(GTK_WINDOW(window), "About LibreSplit");
|
||||
gtk_window_set_default_size(GTK_WINDOW(window), 200, 320);
|
||||
gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
static LSGuiSetting* gui_settings = NULL;
|
||||
|
||||
static GtkWidget* settings_window_singleton = NULL;
|
||||
|
||||
/**
|
||||
* Takes the application config and counts how many settings are available.
|
||||
*
|
||||
|
|
@ -44,6 +46,7 @@ static size_t enumerate_settings(AppConfig cfg)
|
|||
*/
|
||||
static gboolean on_help_window_delete(GtkWidget* widget, GdkEvent* event, gpointer user_data)
|
||||
{
|
||||
settings_window_singleton = NULL;
|
||||
gtk_widget_destroy(widget);
|
||||
free(gui_settings);
|
||||
gui_settings = NULL;
|
||||
|
|
@ -162,6 +165,12 @@ static void set_widget_defaults(GtkWidget* obj)
|
|||
|
||||
static void build_settings_dialog(GtkApplication* app, gpointer data)
|
||||
{
|
||||
// Show already open window if another one is called.
|
||||
if (settings_window_singleton) {
|
||||
gtk_window_present(GTK_WINDOW(settings_window_singleton));
|
||||
return;
|
||||
}
|
||||
|
||||
int settings_number = enumerate_settings(cfg);
|
||||
gui_settings = malloc(settings_number * sizeof(LSGuiSetting));
|
||||
if (gui_settings == NULL) {
|
||||
|
|
@ -170,6 +179,7 @@ static void build_settings_dialog(GtkApplication* app, gpointer data)
|
|||
}
|
||||
|
||||
GtkWidget* window = gtk_application_window_new(app);
|
||||
settings_window_singleton = window;
|
||||
gtk_window_set_title(GTK_WINDOW(window), "LibreSplit Settings");
|
||||
gtk_window_set_default_size(GTK_WINDOW(window), 500, 500);
|
||||
gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue