Merge pull request #112 from JosephMcc/inhibit-fix1
Use GtkApplication inhibit API
This commit is contained in:
commit
ed6eb520b6
|
@ -1138,7 +1138,7 @@ _xed_cmd_file_revert (GtkAction *action,
|
||||||
/* If we are already displaying a notification
|
/* If we are already displaying a notification
|
||||||
* reverting will drop local modifications, do
|
* reverting will drop local modifications, do
|
||||||
* not bug the user further */
|
* not bug the user further */
|
||||||
if (xed_tab_get_state (tab) == XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION)
|
if (xed_tab_get_state (tab) == XED_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION || _xed_tab_get_can_close (tab))
|
||||||
{
|
{
|
||||||
do_revert (window, tab);
|
do_revert (window, tab);
|
||||||
return;
|
return;
|
||||||
|
@ -1532,7 +1532,7 @@ tab_can_close (XedTab *tab,
|
||||||
|
|
||||||
doc = xed_tab_get_document (tab);
|
doc = xed_tab_get_document (tab);
|
||||||
|
|
||||||
if (!_xed_tab_can_close (tab))
|
if (!_xed_tab_get_can_close (tab))
|
||||||
{
|
{
|
||||||
GtkWidget *dlg;
|
GtkWidget *dlg;
|
||||||
|
|
||||||
|
|
|
@ -969,6 +969,18 @@ xed_notebook_remove_all_tabs (XedNotebook *nb)
|
||||||
gtk_container_foreach (GTK_CONTAINER (nb), (GtkCallback)remove_tab, nb);
|
gtk_container_foreach (GTK_CONTAINER (nb), (GtkCallback)remove_tab, nb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GList *
|
||||||
|
xed_notebook_get_all_tabs (XedNotebook *nb)
|
||||||
|
{
|
||||||
|
GList *children = NULL;
|
||||||
|
|
||||||
|
g_return_val_if_fail (XED_IS_NOTEBOOK (nb), NULL);
|
||||||
|
|
||||||
|
children = gtk_container_get_children (GTK_CONTAINER (nb));
|
||||||
|
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_close_buttons_sensitivity (XedTab *tab,
|
set_close_buttons_sensitivity (XedTab *tab,
|
||||||
XedNotebook *nb)
|
XedNotebook *nb)
|
||||||
|
|
|
@ -110,6 +110,8 @@ void xed_notebook_remove_tab (XedNotebook *nb,
|
||||||
|
|
||||||
void xed_notebook_remove_all_tabs (XedNotebook *nb);
|
void xed_notebook_remove_all_tabs (XedNotebook *nb);
|
||||||
|
|
||||||
|
GList *xed_notebook_get_all_tabs (XedNotebook *nb);
|
||||||
|
|
||||||
void xed_notebook_reorder_tab (XedNotebook *src,
|
void xed_notebook_reorder_tab (XedNotebook *src,
|
||||||
XedTab *tab,
|
XedTab *tab,
|
||||||
gint dest_position);
|
gint dest_position);
|
||||||
|
|
|
@ -123,7 +123,8 @@ enum
|
||||||
PROP_NAME,
|
PROP_NAME,
|
||||||
PROP_STATE,
|
PROP_STATE,
|
||||||
PROP_AUTO_SAVE,
|
PROP_AUTO_SAVE,
|
||||||
PROP_AUTO_SAVE_INTERVAL
|
PROP_AUTO_SAVE_INTERVAL,
|
||||||
|
PROP_CAN_CLOSE
|
||||||
};
|
};
|
||||||
|
|
||||||
static gboolean xed_tab_auto_save (XedTab *tab);
|
static gboolean xed_tab_auto_save (XedTab *tab);
|
||||||
|
@ -227,6 +228,8 @@ xed_tab_get_property (GObject *object,
|
||||||
case PROP_AUTO_SAVE_INTERVAL:
|
case PROP_AUTO_SAVE_INTERVAL:
|
||||||
g_value_set_int (value, xed_tab_get_auto_save_interval (tab));
|
g_value_set_int (value, xed_tab_get_auto_save_interval (tab));
|
||||||
break;
|
break;
|
||||||
|
case PROP_CAN_CLOSE:
|
||||||
|
g_value_set_boolean (value, _xed_tab_get_can_close (tab));
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
|
@ -345,6 +348,15 @@ xed_tab_class_init (XedTabClass *klass)
|
||||||
G_PARAM_READWRITE |
|
G_PARAM_READWRITE |
|
||||||
G_PARAM_STATIC_STRINGS));
|
G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
|
g_object_class_install_property (object_class,
|
||||||
|
PROP_CAN_CLOSE,
|
||||||
|
g_param_spec_boolean ("can-close",
|
||||||
|
"Can close",
|
||||||
|
"Wheather the tab can be closed",
|
||||||
|
TRUE,
|
||||||
|
G_PARAM_READABLE |
|
||||||
|
G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
g_type_class_add_private (object_class, sizeof (XedTabPrivate));
|
g_type_class_add_private (object_class, sizeof (XedTabPrivate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,6 +487,7 @@ xed_tab_set_state (XedTab *tab,
|
||||||
update_auto_save_timeout (tab);
|
update_auto_save_timeout (tab);
|
||||||
|
|
||||||
g_object_notify (G_OBJECT (tab), "state");
|
g_object_notify (G_OBJECT (tab), "state");
|
||||||
|
g_object_notify (G_OBJECT (tab), "can-close");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -504,6 +517,7 @@ document_modified_changed (GtkTextBuffer *document,
|
||||||
XedTab *tab)
|
XedTab *tab)
|
||||||
{
|
{
|
||||||
g_object_notify (G_OBJECT (tab), "name");
|
g_object_notify (G_OBJECT (tab), "name");
|
||||||
|
g_object_notify (G_OBJECT (tab), "can-close");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -2830,7 +2844,7 @@ _xed_tab_mark_for_closing (XedTab *tab)
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
_xed_tab_can_close (XedTab *tab)
|
_xed_tab_get_can_close (XedTab *tab)
|
||||||
{
|
{
|
||||||
XedDocument *doc;
|
XedDocument *doc;
|
||||||
XedTabState ts;
|
XedTabState ts;
|
||||||
|
|
|
@ -156,7 +156,7 @@ void _xed_tab_save_as_async (XedTab *tab,
|
||||||
void _xed_tab_print (XedTab *tab);
|
void _xed_tab_print (XedTab *tab);
|
||||||
void _xed_tab_print_preview (XedTab *tab);
|
void _xed_tab_print_preview (XedTab *tab);
|
||||||
void _xed_tab_mark_for_closing (XedTab *tab);
|
void _xed_tab_mark_for_closing (XedTab *tab);
|
||||||
gboolean _xed_tab_can_close (XedTab *tab);
|
gboolean _xed_tab_get_can_close (XedTab *tab);
|
||||||
GtkWidget *_xed_tab_get_view_frame (XedTab *tab);
|
GtkWidget *_xed_tab_get_view_frame (XedTab *tab);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
|
@ -107,6 +107,8 @@ struct _XedWindowPrivate
|
||||||
gint height;
|
gint height;
|
||||||
GdkWindowState window_state;
|
GdkWindowState window_state;
|
||||||
|
|
||||||
|
guint inhibition_cookie;
|
||||||
|
|
||||||
gint side_panel_size;
|
gint side_panel_size;
|
||||||
gint bottom_panel_size;
|
gint bottom_panel_size;
|
||||||
|
|
||||||
|
|
|
@ -2406,6 +2406,43 @@ update_window_state (XedWindow *window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
update_can_close (XedWindow *window)
|
||||||
|
{
|
||||||
|
XedWindowPrivate *priv = window->priv;
|
||||||
|
GList *tabs;
|
||||||
|
GList *l;
|
||||||
|
gboolean can_close = TRUE;
|
||||||
|
|
||||||
|
tabs = xed_notebook_get_all_tabs (priv->notebook);
|
||||||
|
|
||||||
|
for (l = tabs; l != NULL; l = g_list_next (l))
|
||||||
|
{
|
||||||
|
XedTab *tab = l->data;
|
||||||
|
|
||||||
|
if (!_xed_tab_get_can_close (tab))
|
||||||
|
{
|
||||||
|
can_close = FALSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (can_close && (priv->inhibition_cookie != 0))
|
||||||
|
{
|
||||||
|
gtk_application_uninhibit (GTK_APPLICATION (g_application_get_default ()), priv->inhibition_cookie);
|
||||||
|
priv->inhibition_cookie = 0;
|
||||||
|
}
|
||||||
|
else if (!can_close && (priv->inhibition_cookie == 0))
|
||||||
|
{
|
||||||
|
priv->inhibition_cookie = gtk_application_inhibit (GTK_APPLICATION (g_application_get_default ()),
|
||||||
|
GTK_WINDOW (window),
|
||||||
|
GTK_APPLICATION_INHIBIT_LOGOUT,
|
||||||
|
_("There are unsaved documents"));
|
||||||
|
}
|
||||||
|
|
||||||
|
g_list_free (tabs);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sync_state (XedTab *tab,
|
sync_state (XedTab *tab,
|
||||||
GParamSpec *pspec,
|
GParamSpec *pspec,
|
||||||
|
@ -2463,6 +2500,14 @@ sync_name (XedTab *tab,
|
||||||
peas_extension_set_call (window->priv->extensions, "update_state");
|
peas_extension_set_call (window->priv->extensions, "update_state");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sync_can_close (XedTab *tab,
|
||||||
|
GParamSpec *pspec,
|
||||||
|
XedWindow *window)
|
||||||
|
{
|
||||||
|
update_can_close (window);
|
||||||
|
}
|
||||||
|
|
||||||
static XedWindow *
|
static XedWindow *
|
||||||
get_drop_window (GtkWidget *widget)
|
get_drop_window (GtkWidget *widget)
|
||||||
{
|
{
|
||||||
|
@ -2944,6 +2989,7 @@ notebook_tab_added (XedNotebook *notebook,
|
||||||
|
|
||||||
g_signal_connect (tab, "notify::name", G_CALLBACK (sync_name), window);
|
g_signal_connect (tab, "notify::name", G_CALLBACK (sync_name), window);
|
||||||
g_signal_connect (tab, "notify::state", G_CALLBACK (sync_state), window);
|
g_signal_connect (tab, "notify::state", G_CALLBACK (sync_state), window);
|
||||||
|
g_signal_connect (tab, "notify::can-close", G_CALLBACK (sync_can_close), window);
|
||||||
|
|
||||||
g_signal_connect (doc, "cursor-moved", G_CALLBACK (update_cursor_position_statusbar), window);
|
g_signal_connect (doc, "cursor-moved", G_CALLBACK (update_cursor_position_statusbar), window);
|
||||||
g_signal_connect (doc, "notify::search-text", G_CALLBACK (search_text_notify_cb), window);
|
g_signal_connect (doc, "notify::search-text", G_CALLBACK (search_text_notify_cb), window);
|
||||||
|
@ -2960,6 +3006,7 @@ notebook_tab_added (XedNotebook *notebook,
|
||||||
g_signal_connect(view, "drop_uris", G_CALLBACK (drop_uris_cb), NULL);
|
g_signal_connect(view, "drop_uris", G_CALLBACK (drop_uris_cb), NULL);
|
||||||
|
|
||||||
update_window_state (window);
|
update_window_state (window);
|
||||||
|
update_can_close (window);
|
||||||
|
|
||||||
g_signal_emit (G_OBJECT(window), signals[TAB_ADDED], 0, tab);
|
g_signal_emit (G_OBJECT(window), signals[TAB_ADDED], 0, tab);
|
||||||
}
|
}
|
||||||
|
@ -2983,6 +3030,7 @@ notebook_tab_removed (XedNotebook *notebook,
|
||||||
|
|
||||||
g_signal_handlers_disconnect_by_func (tab, G_CALLBACK (sync_name), window);
|
g_signal_handlers_disconnect_by_func (tab, G_CALLBACK (sync_name), window);
|
||||||
g_signal_handlers_disconnect_by_func (tab, G_CALLBACK (sync_state), window);
|
g_signal_handlers_disconnect_by_func (tab, G_CALLBACK (sync_state), window);
|
||||||
|
g_signal_handlers_disconnect_by_func (tab, G_CALLBACK (sync_can_close), window);
|
||||||
g_signal_handlers_disconnect_by_func (doc, G_CALLBACK (update_cursor_position_statusbar), window);
|
g_signal_handlers_disconnect_by_func (doc, G_CALLBACK (update_cursor_position_statusbar), window);
|
||||||
g_signal_handlers_disconnect_by_func (doc, G_CALLBACK (search_text_notify_cb), window);
|
g_signal_handlers_disconnect_by_func (doc, G_CALLBACK (search_text_notify_cb), window);
|
||||||
g_signal_handlers_disconnect_by_func (doc, G_CALLBACK (can_undo), window);
|
g_signal_handlers_disconnect_by_func (doc, G_CALLBACK (can_undo), window);
|
||||||
|
@ -3056,6 +3104,7 @@ notebook_tab_removed (XedNotebook *notebook,
|
||||||
}
|
}
|
||||||
|
|
||||||
update_window_state (window);
|
update_window_state (window);
|
||||||
|
update_can_close (window);
|
||||||
|
|
||||||
g_signal_emit (G_OBJECT(window), signals[TAB_REMOVED], 0, tab);
|
g_signal_emit (G_OBJECT(window), signals[TAB_REMOVED], 0, tab);
|
||||||
}
|
}
|
||||||
|
@ -3502,6 +3551,7 @@ xed_window_init (XedWindow *window)
|
||||||
window->priv->num_tabs = 0;
|
window->priv->num_tabs = 0;
|
||||||
window->priv->removing_tabs = FALSE;
|
window->priv->removing_tabs = FALSE;
|
||||||
window->priv->state = XED_WINDOW_STATE_NORMAL;
|
window->priv->state = XED_WINDOW_STATE_NORMAL;
|
||||||
|
window->priv->inhibition_cookie = 0;
|
||||||
window->priv->dispose_has_run = FALSE;
|
window->priv->dispose_has_run = FALSE;
|
||||||
window->priv->fullscreen_controls = NULL;
|
window->priv->fullscreen_controls = NULL;
|
||||||
window->priv->fullscreen_animation_timeout_id = 0;
|
window->priv->fullscreen_animation_timeout_id = 0;
|
||||||
|
@ -4152,7 +4202,7 @@ xed_window_get_unsaved_documents (XedWindow *window)
|
||||||
{
|
{
|
||||||
XedTab *tab;
|
XedTab *tab;
|
||||||
tab = XED_TAB(l->data);
|
tab = XED_TAB(l->data);
|
||||||
if (!_xed_tab_can_close (tab))
|
if (!_xed_tab_get_can_close (tab))
|
||||||
{
|
{
|
||||||
XedDocument *doc;
|
XedDocument *doc;
|
||||||
doc = xed_tab_get_document (tab);
|
doc = xed_tab_get_document (tab);
|
||||||
|
|
Loading…
Reference in New Issue