GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Apr 24, 2014 11:23 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Prevent multiple instances of the same dialog in same circum
PostPosted: Tue Aug 27, 2013 12:39 am 
Offline
Familiar Face

Joined: Thu Nov 22, 2012 3:46 pm
Posts: 19
I have code to run message dialog and want to prevent to show up if already is showing:

Code:
static void show_message(GtkMessageType type, const char* text, const char* details)
{
   GtkWidget *dialog;
   
   g_assert(text);
   
   dialog = gtk_message_dialog_new (NULL, DIALOG_FLAGS, type, GTK_BUTTONS_CLOSE, "%s", text);
   if (details) {
      gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "%s", details);
   }
   gtk_dialog_run(GTK_DIALOG (dialog));
   gtk_widget_destroy(dialog);
}   

void show_error_message(const char* error, const char* details)
{
   show_message(GTK_MESSAGE_ERROR, error, details);
}   

void show_warning_message(const char* warning, const char* details)
{
   show_message(GTK_MESSAGE_WARNING, warning, details);
}


Thanks for any help


Top
 Profile  
 
 Post subject: Re: Prevent multiple instances of the same dialog in same ci
PostPosted: Wed Aug 28, 2013 8:43 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 709
Location: UK
Hello,

Your code is most of the way there. according to the documentation using gtk_dialog_run()
Quote:
Blocks in a recursive main loop until the dialog either emits the "response" signal, or is destroyed. If the dialog is destroyed during the call to gtk_dialog_run(), gtk_dialog_run() returns GTK_RESPONSE_NONE. Otherwise, it returns the response ID from the ::response signal emission.

Quote:
Note that even though the recursive main loop gives the effect of a modal dialog (it prevents the user from interacting with other windows in the same window group while the dialog is run), callbacks such as timeouts, IO channel watches, DND drops, etc, will be triggered during a gtk_dialog_run() call.


To prevent additional warning/error dialog windows you could use a flag to indicate if you have an existing error/warning dialog window open already.
For example :-
Code:
static void show_message(GtkMessageType type, const char* text, const char* details)
{
   static gboolean is_open = FALSE:
   GtkWidget *dialog;
   
   if (is_open) return;

   g_assert(text);
   is_open = TRUE;
   dialog = gtk_message_dialog_new (NULL, DIALOG_FLAGS, type, GTK_BUTTONS_CLOSE, "%s", text);
   if (details) {
      gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "%s", details);
   }
   gtk_dialog_run(GTK_DIALOG (dialog));
   gtk_widget_destroy(dialog);
   is_open = FALSE;
}   

_________________
E.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group