Compare commits
6 Commits
quick-keyb
...
wip/tingpi
Author | SHA1 | Date | |
---|---|---|---|
|
d0b6ca30c2 | ||
|
dea8012e21 | ||
|
14c45dbf10 | ||
|
3a60a29346 | ||
|
84d9bacd29 | ||
|
a947cb986c |
@@ -185,7 +185,7 @@ void gtk_dialog_response (GtkDialog *dialog,
|
|||||||
gint response_id);
|
gint response_id);
|
||||||
|
|
||||||
/* Returns response_id */
|
/* Returns response_id */
|
||||||
GDK_AVAILABLE_IN_ALL
|
GDK_DEPRECATED
|
||||||
gint gtk_dialog_run (GtkDialog *dialog);
|
gint gtk_dialog_run (GtkDialog *dialog);
|
||||||
|
|
||||||
GDK_AVAILABLE_IN_ALL
|
GDK_AVAILABLE_IN_ALL
|
||||||
|
@@ -67,6 +67,22 @@
|
|||||||
* #GtkFileChooserDialog to select a file for opening:
|
* #GtkFileChooserDialog to select a file for opening:
|
||||||
*
|
*
|
||||||
* |[
|
* |[
|
||||||
|
* static void
|
||||||
|
* on_response (GtkNativeDialog *dialog, guint response, gpointer user_data)
|
||||||
|
* {
|
||||||
|
* if (res == GTK_RESPONSE_ACCEPT)
|
||||||
|
* {
|
||||||
|
* char *filename;
|
||||||
|
* GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
|
||||||
|
* filename = gtk_file_chooser_get_filename (chooser);
|
||||||
|
* open_file (filename);
|
||||||
|
* g_free (filename);
|
||||||
|
* }
|
||||||
|
* g_object_unref (dialog);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* ...
|
||||||
|
*
|
||||||
* GtkFileChooserNative *native;
|
* GtkFileChooserNative *native;
|
||||||
* GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
|
* GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
|
||||||
* gint res;
|
* gint res;
|
||||||
@@ -77,22 +93,29 @@
|
|||||||
* "_Open",
|
* "_Open",
|
||||||
* "_Cancel");
|
* "_Cancel");
|
||||||
*
|
*
|
||||||
* res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (native));
|
* g_signal_connect (native, "response", G_CALLBACK(on_response), NULL);
|
||||||
* if (res == GTK_RESPONSE_ACCEPT)
|
* gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));
|
||||||
* {
|
|
||||||
* char *filename;
|
|
||||||
* GtkFileChooser *chooser = GTK_FILE_CHOOSER (native);
|
|
||||||
* filename = gtk_file_chooser_get_filename (chooser);
|
|
||||||
* open_file (filename);
|
|
||||||
* g_free (filename);
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* g_object_unref (native);
|
|
||||||
* ]|
|
* ]|
|
||||||
*
|
*
|
||||||
* To use a dialog for saving, you can use this:
|
* To use a dialog for saving, you can use this:
|
||||||
*
|
*
|
||||||
* |[
|
* |[
|
||||||
|
* static void
|
||||||
|
* on_response (GtkNativeDialog *dialog, guint response, gpointer user_data)
|
||||||
|
* {
|
||||||
|
* if (res == GTK_RESPONSE_ACCEPT)
|
||||||
|
* {
|
||||||
|
* char *filename;
|
||||||
|
* GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
|
||||||
|
* filename = gtk_file_chooser_get_filename (chooser);
|
||||||
|
* save_to_file (filename);
|
||||||
|
* g_free (filename);
|
||||||
|
* }
|
||||||
|
* g_object_unref (dialog);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* ...
|
||||||
|
*
|
||||||
* GtkFileChooserNative *native;
|
* GtkFileChooserNative *native;
|
||||||
* GtkFileChooser *chooser;
|
* GtkFileChooser *chooser;
|
||||||
* GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
|
* GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
|
||||||
@@ -114,17 +137,8 @@
|
|||||||
* gtk_file_chooser_set_filename (chooser,
|
* gtk_file_chooser_set_filename (chooser,
|
||||||
* existing_filename);
|
* existing_filename);
|
||||||
*
|
*
|
||||||
* res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (native));
|
* g_signal_connect (native, "response", G_CALLBACK(on_response), NULL);
|
||||||
* if (res == GTK_RESPONSE_ACCEPT)
|
* gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));
|
||||||
* {
|
|
||||||
* char *filename;
|
|
||||||
*
|
|
||||||
* filename = gtk_file_chooser_get_filename (chooser);
|
|
||||||
* save_to_file (filename);
|
|
||||||
* g_free (filename);
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* g_object_unref (native);
|
|
||||||
* ]|
|
* ]|
|
||||||
*
|
*
|
||||||
* For more information on how to best set up a file dialog, see #GtkFileChooserDialog.
|
* For more information on how to best set up a file dialog, see #GtkFileChooserDialog.
|
||||||
|
@@ -744,8 +744,8 @@ error_message_with_parent (GtkWindow *parent,
|
|||||||
gtk_window_group_add_window (gtk_window_get_group (parent),
|
gtk_window_group_add_window (gtk_window_get_group (parent),
|
||||||
GTK_WINDOW (dialog));
|
GTK_WINDOW (dialog));
|
||||||
|
|
||||||
gtk_dialog_run (GTK_DIALOG (dialog));
|
g_signal_connect (dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL);
|
||||||
gtk_widget_destroy (dialog);
|
gtk_widget_show (dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns a toplevel GtkWindow, or NULL if none */
|
/* Returns a toplevel GtkWindow, or NULL if none */
|
||||||
@@ -1456,14 +1456,45 @@ add_to_shortcuts_cb (GSimpleAction *action,
|
|||||||
impl);
|
impl);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
struct FileTuple {
|
||||||
confirm_delete (GtkFileChooserWidget *impl,
|
GtkFileChooserWidget *widget;
|
||||||
GFileInfo *info)
|
GFile *file;
|
||||||
|
GFileInfo *info;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
file_tuple_free (gpointer data, GClosure *closure)
|
||||||
|
{
|
||||||
|
struct FileTuple *t = data;
|
||||||
|
|
||||||
|
g_object_unref (t->file);
|
||||||
|
g_object_unref (t->info);
|
||||||
|
g_object_unref (t->widget);
|
||||||
|
g_free (t);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_confirm_delete (GtkDialog *dialog, guint response_id, struct FileTuple *data)
|
||||||
|
{
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
if (response_id == GTK_RESPONSE_ACCEPT)
|
||||||
|
{
|
||||||
|
if (!g_file_delete (data->file, NULL, &error))
|
||||||
|
error_deleting_file (data->widget, data->file, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_widget_destroy (GTK_WIDGET(dialog));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
show_confirm_delete_dialog (GtkFileChooserWidget *impl,
|
||||||
|
struct FileTuple *data)
|
||||||
{
|
{
|
||||||
GtkWindow *toplevel;
|
GtkWindow *toplevel;
|
||||||
GtkWidget *dialog;
|
GtkWidget *dialog;
|
||||||
gint response;
|
|
||||||
const gchar *name;
|
const gchar *name;
|
||||||
|
GFileInfo *info = data->info;
|
||||||
|
|
||||||
name = g_file_info_get_display_name (info);
|
name = g_file_info_get_display_name (info);
|
||||||
|
|
||||||
@@ -1484,11 +1515,9 @@ confirm_delete (GtkFileChooserWidget *impl,
|
|||||||
if (gtk_window_has_group (toplevel))
|
if (gtk_window_has_group (toplevel))
|
||||||
gtk_window_group_add_window (gtk_window_get_group (toplevel), GTK_WINDOW (dialog));
|
gtk_window_group_add_window (gtk_window_get_group (toplevel), GTK_WINDOW (dialog));
|
||||||
|
|
||||||
response = gtk_dialog_run (GTK_DIALOG (dialog));
|
g_signal_connect_data (dialog, "response", G_CALLBACK(on_confirm_delete),
|
||||||
|
data, file_tuple_free, 0);
|
||||||
gtk_widget_destroy (dialog);
|
gtk_widget_show (dialog);
|
||||||
|
|
||||||
return (response == GTK_RESPONSE_ACCEPT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -1500,16 +1529,17 @@ delete_selected_cb (GtkTreeModel *model,
|
|||||||
GtkFileChooserWidget *impl = data;
|
GtkFileChooserWidget *impl = data;
|
||||||
GFile *file;
|
GFile *file;
|
||||||
GFileInfo *info;
|
GFileInfo *info;
|
||||||
GError *error = NULL;
|
struct FileTuple *file_data;
|
||||||
|
|
||||||
file = _gtk_file_system_model_get_file (GTK_FILE_SYSTEM_MODEL (model), iter);
|
file = _gtk_file_system_model_get_file (GTK_FILE_SYSTEM_MODEL (model), iter);
|
||||||
info = _gtk_file_system_model_get_info (GTK_FILE_SYSTEM_MODEL (model), iter);
|
info = _gtk_file_system_model_get_info (GTK_FILE_SYSTEM_MODEL (model), iter);
|
||||||
|
|
||||||
if (confirm_delete (impl, info))
|
file_data = g_new (struct FileTuple, 1);
|
||||||
{
|
file_data->file = g_object_ref (file);
|
||||||
if (!g_file_delete (file, NULL, &error))
|
file_data->info = g_object_ref (info);
|
||||||
error_deleting_file (impl, file, error);
|
file_data->widget = g_object_ref (impl);
|
||||||
}
|
|
||||||
|
show_confirm_delete_dialog (impl, file_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@@ -1250,7 +1250,6 @@ on_end_process_activated (GtkMenuItem *item,
|
|||||||
if (!_gtk_mount_operation_kill_process (pid_to_kill, &error))
|
if (!_gtk_mount_operation_kill_process (pid_to_kill, &error))
|
||||||
{
|
{
|
||||||
GtkWidget *dialog;
|
GtkWidget *dialog;
|
||||||
gint response;
|
|
||||||
|
|
||||||
/* Use GTK_DIALOG_DESTROY_WITH_PARENT here since the parent dialog can be
|
/* Use GTK_DIALOG_DESTROY_WITH_PARENT here since the parent dialog can be
|
||||||
* indeed be destroyed via the GMountOperation::abort signal... for example,
|
* indeed be destroyed via the GMountOperation::abort signal... for example,
|
||||||
@@ -1266,16 +1265,8 @@ on_end_process_activated (GtkMenuItem *item,
|
|||||||
"%s",
|
"%s",
|
||||||
error->message);
|
error->message);
|
||||||
|
|
||||||
|
g_signal_connect (dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL);
|
||||||
gtk_widget_show (dialog);
|
gtk_widget_show (dialog);
|
||||||
response = gtk_dialog_run (GTK_DIALOG (dialog));
|
|
||||||
|
|
||||||
/* GTK_RESPONSE_NONE means the dialog were programmatically destroy, e.g. that
|
|
||||||
* GTK_DIALOG_DESTROY_WITH_PARENT kicked in - so it would trigger a warning to
|
|
||||||
* destroy the dialog in that case
|
|
||||||
*/
|
|
||||||
if (response != GTK_RESPONSE_NONE)
|
|
||||||
gtk_widget_destroy (dialog);
|
|
||||||
|
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -56,10 +56,6 @@
|
|||||||
* various common properties on the dialog, as well as show and hide
|
* various common properties on the dialog, as well as show and hide
|
||||||
* it and get a #GtkNativeDialog::response signal when the user finished
|
* it and get a #GtkNativeDialog::response signal when the user finished
|
||||||
* with the dialog.
|
* with the dialog.
|
||||||
*
|
|
||||||
* There is also a gtk_native_dialog_run() helper that makes it easy
|
|
||||||
* to run any native dialog in a modal way with a recursive mainloop,
|
|
||||||
* similar to gtk_dialog_run().
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct _GtkNativeDialogPrivate GtkNativeDialogPrivate;
|
typedef struct _GtkNativeDialogPrivate GtkNativeDialogPrivate;
|
||||||
@@ -71,10 +67,6 @@ struct _GtkNativeDialogPrivate
|
|||||||
|
|
||||||
guint visible : 1;
|
guint visible : 1;
|
||||||
guint modal : 1;
|
guint modal : 1;
|
||||||
|
|
||||||
/* Run state */
|
|
||||||
gint run_response_id;
|
|
||||||
GMainLoop *run_loop; /* Non-NULL when in run */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@@ -355,9 +347,6 @@ gtk_native_dialog_hide (GtkNativeDialog *self)
|
|||||||
|
|
||||||
klass->hide (self);
|
klass->hide (self);
|
||||||
|
|
||||||
if (priv->run_loop && g_main_loop_is_running (priv->run_loop))
|
|
||||||
g_main_loop_quit (priv->run_loop);
|
|
||||||
|
|
||||||
g_object_notify_by_pspec (G_OBJECT (self), native_props[PROP_VISIBLE]);
|
g_object_notify_by_pspec (G_OBJECT (self), native_props[PROP_VISIBLE]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -560,100 +549,3 @@ gtk_native_dialog_get_transient_for (GtkNativeDialog *self)
|
|||||||
|
|
||||||
return priv->transient_for;
|
return priv->transient_for;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
run_response_cb (GtkNativeDialog *self,
|
|
||||||
gint response_id,
|
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
GtkNativeDialogPrivate *priv = gtk_native_dialog_get_instance_private (self);
|
|
||||||
|
|
||||||
priv->run_response_id = response_id;
|
|
||||||
if (priv->run_loop && g_main_loop_is_running (priv->run_loop))
|
|
||||||
g_main_loop_quit (priv->run_loop);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gtk_native_dialog_run:
|
|
||||||
* @self: a #GtkNativeDialog
|
|
||||||
*
|
|
||||||
* Blocks in a recursive main loop until @self emits the
|
|
||||||
* #GtkNativeDialog::response signal. It then returns the response ID
|
|
||||||
* from the ::response signal emission.
|
|
||||||
*
|
|
||||||
* Before entering the recursive main loop, gtk_native_dialog_run()
|
|
||||||
* calls gtk_native_dialog_show() on the dialog for you.
|
|
||||||
*
|
|
||||||
* After gtk_native_dialog_run() returns, then dialog will be hidden.
|
|
||||||
*
|
|
||||||
* Typical usage of this function might be:
|
|
||||||
* |[<!-- language="C" -->
|
|
||||||
* gint result = gtk_native_dialog_run (GTK_NATIVE_DIALOG (dialog));
|
|
||||||
* switch (result)
|
|
||||||
* {
|
|
||||||
* case GTK_RESPONSE_ACCEPT:
|
|
||||||
* do_application_specific_something ();
|
|
||||||
* break;
|
|
||||||
* default:
|
|
||||||
* do_nothing_since_dialog_was_cancelled ();
|
|
||||||
* break;
|
|
||||||
* }
|
|
||||||
* g_object_unref (dialog);
|
|
||||||
* ]|
|
|
||||||
*
|
|
||||||
* 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_nautilus_dialog_run() call.
|
|
||||||
*
|
|
||||||
* Returns: response ID
|
|
||||||
*
|
|
||||||
* Since: 3.20
|
|
||||||
**/
|
|
||||||
gint
|
|
||||||
gtk_native_dialog_run (GtkNativeDialog *self)
|
|
||||||
{
|
|
||||||
GtkNativeDialogPrivate *priv = gtk_native_dialog_get_instance_private (self);
|
|
||||||
gboolean was_modal;
|
|
||||||
guint response_handler;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GTK_IS_NATIVE_DIALOG (self), -1);
|
|
||||||
g_return_val_if_fail (!priv->visible, -1);
|
|
||||||
g_return_val_if_fail (priv->run_loop == NULL, -1);
|
|
||||||
|
|
||||||
if (priv->visible || priv->run_loop != NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
g_object_ref (self);
|
|
||||||
|
|
||||||
priv->run_response_id = GTK_RESPONSE_NONE;
|
|
||||||
priv->run_loop = g_main_loop_new (NULL, FALSE);
|
|
||||||
|
|
||||||
was_modal = priv->modal;
|
|
||||||
gtk_native_dialog_set_modal (self, TRUE);
|
|
||||||
|
|
||||||
response_handler =
|
|
||||||
g_signal_connect (self,
|
|
||||||
"response",
|
|
||||||
G_CALLBACK (run_response_cb),
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
gtk_native_dialog_show (self);
|
|
||||||
|
|
||||||
gdk_threads_leave ();
|
|
||||||
g_main_loop_run (priv->run_loop);
|
|
||||||
gdk_threads_enter ();
|
|
||||||
|
|
||||||
g_signal_handler_disconnect (self, response_handler);
|
|
||||||
|
|
||||||
g_main_loop_unref (priv->run_loop);
|
|
||||||
priv->run_loop = NULL;
|
|
||||||
|
|
||||||
if (!was_modal)
|
|
||||||
gtk_native_dialog_set_modal (self, FALSE);
|
|
||||||
|
|
||||||
g_object_unref (self);
|
|
||||||
|
|
||||||
return priv->run_response_id;
|
|
||||||
}
|
|
||||||
|
@@ -73,9 +73,6 @@ void gtk_native_dialog_set_transient_for (GtkNativeDialog *self
|
|||||||
GDK_AVAILABLE_IN_3_20
|
GDK_AVAILABLE_IN_3_20
|
||||||
GtkWindow * gtk_native_dialog_get_transient_for (GtkNativeDialog *self);
|
GtkWindow * gtk_native_dialog_get_transient_for (GtkNativeDialog *self);
|
||||||
|
|
||||||
GDK_AVAILABLE_IN_3_20
|
|
||||||
gint gtk_native_dialog_run (GtkNativeDialog *self);
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GTK_NATIVE_DIALOG_H__ */
|
#endif /* __GTK_NATIVE_DIALOG_H__ */
|
||||||
|
@@ -596,8 +596,8 @@ error_message_with_parent (GtkWindow *parent,
|
|||||||
gtk_window_group_add_window (gtk_window_get_group (parent),
|
gtk_window_group_add_window (gtk_window_get_group (parent),
|
||||||
GTK_WINDOW (dialog));
|
GTK_WINDOW (dialog));
|
||||||
|
|
||||||
gtk_dialog_run (GTK_DIALOG (dialog));
|
g_signal_connect (dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL);
|
||||||
gtk_widget_destroy (dialog);
|
gtk_widget_show (dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns a toplevel GtkWindow, or NULL if none */
|
/* Returns a toplevel GtkWindow, or NULL if none */
|
||||||
|
Reference in New Issue
Block a user