Commit e747b35b authored by Matthew Leeds's avatar Matthew Leeds
Browse files

configuration: Mark config as dirty when IdeEnvironment changes

This commit makes the IdeConfiguration mark itself as dirty when an environment
variable (or its value) is changed by the user, rather than just when an
env var is added or removed. That way such changes can be written back
to the disk (almost) immediately.

https://bugzilla.gnome.org/show_bug.cgi?id=777959
parent 83faa36b
......@@ -209,9 +209,6 @@ ide_configuration_runtime_manager_items_changed (IdeConfiguration *self,
static void
ide_configuration_environment_changed (IdeConfiguration *self,
guint position,
guint added,
guint removed,
IdeEnvironment *environment)
{
IDE_ENTRY;
......@@ -540,7 +537,7 @@ ide_configuration_init (IdeConfiguration *self)
priv->internal = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, _value_free);
g_signal_connect_object (priv->environment,
"items-changed",
"changed",
G_CALLBACK (ide_configuration_environment_changed),
self,
G_CONNECT_SWAPPED);
......@@ -1031,6 +1028,11 @@ ide_configuration_set_environment (IdeConfiguration *self,
g_clear_object (&priv->environment);
priv->environment = g_object_ref (environment);
g_signal_connect_object (priv->environment,
"changed",
G_CALLBACK (ide_configuration_environment_changed),
self,
G_CONNECT_SWAPPED);
}
const gchar *
......
......@@ -30,6 +30,13 @@ static void list_model_iface_init (GListModelInterface *iface);
G_DEFINE_TYPE_EXTENDED (IdeEnvironment, ide_environment, G_TYPE_OBJECT, 0,
G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, list_model_iface_init))
enum {
CHANGED,
LAST_SIGNAL
};
static guint signals [LAST_SIGNAL];
static void
ide_environment_finalize (GObject *object)
{
......@@ -46,12 +53,31 @@ ide_environment_class_init (IdeEnvironmentClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = ide_environment_finalize;
signals [CHANGED] =
g_signal_new ("changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL, G_TYPE_NONE, 0);
}
static void
ide_environment_items_changed (IdeEnvironment *self)
{
g_assert (IDE_IS_ENVIRONMENT (self));
g_signal_emit (self, signals [CHANGED], 0);
}
static void
ide_environment_init (IdeEnvironment *self)
{
self->variables = g_ptr_array_new_with_free_func (g_object_unref);
g_signal_connect (self,
"items-changed",
G_CALLBACK (ide_environment_items_changed),
NULL);
}
static GType
......@@ -90,6 +116,16 @@ list_model_iface_init (GListModelInterface *iface)
iface->get_item_type = ide_environment_get_item_type;
}
static void
ide_environment_variable_notify (IdeEnvironment *self,
GParamSpec *pspec,
IdeEnvironmentVariable *variable)
{
g_assert (IDE_IS_ENVIRONMENT (self));
g_signal_emit (self, signals [CHANGED], 0);
}
void
ide_environment_setenv (IdeEnvironment *self,
const gchar *key,
......@@ -128,6 +164,11 @@ ide_environment_setenv (IdeEnvironment *self,
"key", key,
"value", value,
NULL);
g_signal_connect_object (var,
"notify",
G_CALLBACK (ide_environment_variable_notify),
self,
G_CONNECT_SWAPPED);
g_ptr_array_add (self->variables, var);
g_list_model_items_changed (G_LIST_MODEL (self), position, 0, 1);
}
......@@ -230,6 +271,11 @@ ide_environment_append (IdeEnvironment *self,
position = self->variables->len;
g_signal_connect_object (variable,
"notify",
G_CALLBACK (ide_environment_variable_notify),
self,
G_CONNECT_SWAPPED);
g_ptr_array_add (self->variables, g_object_ref (variable));
g_list_model_items_changed (G_LIST_MODEL (self), position, 0, 1);
}
......
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