Commit 05918e07 authored by Paolo Borelli's avatar Paolo Borelli

Use GtkApplication inhibit api

Introduce a can-save property on GeditTab in order to bubble up this
information to GeditWindow... GtkApplication api requires us
to inhibit session shutdown preemptively instead of checking lazily
when shutdown is requested.
parent 8bc593ff
......@@ -1335,7 +1335,7 @@ _gedit_cmd_file_revert (GtkAction *action,
* if the document has not been modified, do
* not bug the user further */
if (gedit_tab_get_state (tab) == GEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION ||
_gedit_tab_can_close (tab))
_gedit_tab_get_can_close (tab))
{
do_revert (window, tab);
return;
......@@ -1766,7 +1766,7 @@ tab_can_close (GeditTab *tab,
doc = gedit_tab_get_document (tab);
if (!_gedit_tab_can_close (tab))
if (!_gedit_tab_get_can_close (tab))
{
GtkWidget *dlg;
......
......@@ -92,7 +92,8 @@ enum
PROP_NAME,
PROP_STATE,
PROP_AUTO_SAVE,
PROP_AUTO_SAVE_INTERVAL
PROP_AUTO_SAVE_INTERVAL,
PROP_CAN_CLOSE
};
/* Signals */
......@@ -206,6 +207,10 @@ gedit_tab_get_property (GObject *object,
g_value_set_int (value,
gedit_tab_get_auto_save_interval (tab));
break;
case PROP_CAN_CLOSE:
g_value_set_boolean (value,
_gedit_tab_get_can_close (tab));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -339,6 +344,15 @@ gedit_tab_class_init (GeditTabClass *klass)
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class,
PROP_CAN_CLOSE,
g_param_spec_boolean ("can-close",
"Can close",
"Whether the tab can be closed",
TRUE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
signals[DROP_URIS] =
g_signal_new ("drop-uris",
G_TYPE_FROM_CLASS (object_class),
......@@ -477,6 +491,7 @@ gedit_tab_set_state (GeditTab *tab,
state);
g_object_notify (G_OBJECT (tab), "state");
g_object_notify (G_OBJECT (tab), "can-close");
}
static void
......@@ -506,6 +521,7 @@ document_modified_changed (GtkTextBuffer *document,
GeditTab *tab)
{
g_object_notify (G_OBJECT (tab), "name");
g_object_notify (G_OBJECT (tab), "can-close");
}
static void
......@@ -2204,7 +2220,6 @@ _gedit_tab_load_stream (GeditTab *tab,
encoding,
line_pos,
column_pos);
}
void
......@@ -2825,7 +2840,7 @@ _gedit_tab_mark_for_closing (GeditTab *tab)
}
gboolean
_gedit_tab_can_close (GeditTab *tab)
_gedit_tab_get_can_close (GeditTab *tab)
{
GeditDocument *doc;
GeditTabState ts;
......@@ -2845,15 +2860,25 @@ _gedit_tab_can_close (GeditTab *tab)
/* Do not close tab with saving errors */
if (ts == GEDIT_TAB_STATE_SAVING_ERROR)
{
return FALSE;
}
doc = gedit_tab_get_document (tab);
/* TODO: we need to save the file also if it has been externally
modified - Paolo (Oct 10, 2005) */
if (gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc)))
{
return FALSE;
}
if (gedit_document_is_local (doc) &&
(gedit_document_get_deleted (doc) ||
_gedit_document_check_externally_modified (doc)))
{
return FALSE;
}
return (!gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc)) &&
!gedit_document_get_deleted (doc));
return TRUE;
}
/**
......
......@@ -173,7 +173,7 @@ void _gedit_tab_print_preview (GeditTab *tab);
void _gedit_tab_mark_for_closing (GeditTab *tab);
gboolean _gedit_tab_can_close (GeditTab *tab);
gboolean _gedit_tab_get_can_close (GeditTab *tab);
GtkWidget *_gedit_tab_get_view_frame (GeditTab *tab);
......
......@@ -113,6 +113,8 @@ struct _GeditWindowPrivate
GeditWindowState state;
guint inhibition_cookie;
gint bottom_panel_item_removed_handler_id;
GtkWindowGroup *window_group;
......
......@@ -114,7 +114,7 @@ gedit_window_get_property (GObject *object,
case PROP_STATE:
g_value_set_enum (value,
gedit_window_get_state (window));
break;
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -2802,6 +2802,44 @@ update_window_state (GeditWindow *window)
}
}
static void
update_can_close (GeditWindow *window)
{
GeditWindowPrivate *priv = window->priv;
GList *tabs;
GList *l;
gboolean can_close = TRUE;
gedit_debug (DEBUG_WINDOW);
tabs = gedit_multi_notebook_get_all_tabs (priv->multi_notebook);
for (l = tabs; l != NULL; l = g_list_next (l))
{
GeditTab *tab = l->data;
if (!_gedit_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"));
}
}
static void
sync_state (GeditTab *tab,
GParamSpec *pspec,
......@@ -2890,6 +2928,14 @@ sync_name (GeditTab *tab,
window);
}
static void
sync_can_close (GeditTab *tab,
GParamSpec *pspec,
GeditWindow *window)
{
update_can_close (window);
}
static GeditWindow *
get_drop_window (GtkWidget *widget)
{
......@@ -3379,11 +3425,14 @@ on_tab_added (GeditMultiNotebook *multi,
"notify::state",
G_CALLBACK (sync_state),
window);
g_signal_connect (tab,
"notify::can-close",
G_CALLBACK (sync_can_close),
window);
g_signal_connect (tab,
"drop_uris",
G_CALLBACK (drop_uris_cb),
window);
g_signal_connect (doc,
"bracket-matched",
G_CALLBACK (bracket_matched_cb),
......@@ -3428,6 +3477,7 @@ on_tab_added (GeditMultiNotebook *multi,
update_documents_list_menu (window);
update_window_state (window);
update_can_close (window);
g_signal_emit (G_OBJECT (window), signals[TAB_ADDED], 0, tab);
}
......@@ -3457,6 +3507,9 @@ on_tab_removed (GeditMultiNotebook *multi,
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 (tab,
G_CALLBACK (drop_uris_cb),
window);
......@@ -3550,6 +3603,7 @@ on_tab_removed (GeditMultiNotebook *multi,
}
update_window_state (window);
update_can_close (window);
g_signal_emit (G_OBJECT (window), signals[TAB_REMOVED], 0, tab);
}
......@@ -3985,8 +4039,10 @@ gedit_window_init (GeditWindow *window)
gedit_debug (DEBUG_WINDOW);
window->priv = GEDIT_WINDOW_GET_PRIVATE (window);
window->priv->removing_tabs = FALSE;
window->priv->state = GEDIT_WINDOW_STATE_NORMAL;
window->priv->inhibition_cookie = 0;
window->priv->dispose_has_run = FALSE;
window->priv->fullscreen_controls = NULL;
window->priv->fullscreen_animation_timeout_id = 0;
......@@ -4713,7 +4769,7 @@ static void
add_unsaved_doc (GeditTab *tab,
GList **res)
{
if (!_gedit_tab_can_close (tab))
if (!_gedit_tab_get_can_close (tab))
{
GeditDocument *doc;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment