[gnome-boxes/wip/snapshot-config-changes: 8/12] properties-toolbar, config-editor: Sync "Save" button state
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes/wip/snapshot-config-changes: 8/12] properties-toolbar, config-editor: Sync "Save" button state
- Date: Mon, 12 Oct 2020 10:57:55 +0000 (UTC)
commit ad5478a94cb2d94f8149d7a70d7309612ccb81a2
Author: Felipe Borges <felipeborges gnome org>
Date: Mon Oct 12 12:06:13 2020 +0200
properties-toolbar, config-editor: Sync "Save" button state
Make it sensitive only where there are changes in the text buffer.
data/ui/properties-toolbar.ui | 1 +
src/config-editor.vala | 17 +++++++++++++++--
src/properties-toolbar.vala | 3 +++
src/properties-window.vala | 2 +-
4 files changed, 20 insertions(+), 3 deletions(-)
---
diff --git a/data/ui/properties-toolbar.ui b/data/ui/properties-toolbar.ui
index 20b3e057..4f44b770 100644
--- a/data/ui/properties-toolbar.ui
+++ b/data/ui/properties-toolbar.ui
@@ -138,6 +138,7 @@
<child>
<object class="GtkButton" id="save_button">
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="valign">center</property>
<property name="use-underline">True</property>
<property name="label" translatable="yes">_Save</property>
diff --git a/src/config-editor.vala b/src/config-editor.vala
index 5d6dc004..f072a7ad 100644
--- a/src/config-editor.vala
+++ b/src/config-editor.vala
@@ -6,19 +6,25 @@
private const string BOXES_NS_URI = "https://wiki.gnome.org/Apps/Boxes/edited";
private const string MANUALLY_EDITED_XML = "<edited>%u</edited>";
+ private Gtk.Button save_button;
[GtkChild]
private Gtk.SourceView view;
private LibvirtMachine machine;
+ private string domain_xml;
- public void setup (LibvirtMachine machine) {
+ public void setup (LibvirtMachine machine, Gtk.Button save_button) {
this.machine = machine;
+ this.save_button = save_button;
var buffer = new Gtk.SourceBuffer (null);
buffer.language = Gtk.SourceLanguageManager.get_default ().get_language ("xml");
view.buffer = buffer;
- buffer.set_text (machine.domain_config.to_xml ());
+ domain_xml = machine.domain_config.to_xml ();
+ buffer.set_text (domain_xml);
+
+ buffer.changed.connect (on_config_changed);
}
private async long create_snapshot () {
@@ -74,6 +80,7 @@ public async void save () {
try {
machine.domain.set_config (custom_config);
+ domain_xml = custom_config.to_xml ();
} catch (GLib.Error error) {
warning ("Failed to save custom VM configuration: %s", error.message);
var msg = _("Boxes failed to save VM configuration changes: %s");
@@ -88,6 +95,12 @@ public async void save () {
machine.restart ();
});
}
+
+ setup (machine, save_button);
}
+ private void on_config_changed () {
+ var config_changed = (view.buffer.text != domain_xml);
+ save_button.sensitive = config_changed;
+ }
}
diff --git a/src/properties-toolbar.vala b/src/properties-toolbar.vala
index abfc1b4a..06bd639a 100644
--- a/src/properties-toolbar.vala
+++ b/src/properties-toolbar.vala
@@ -18,6 +18,8 @@
[GtkChild]
public Gtk.HeaderBar config_editor;
+ [GtkChild]
+ public Gtk.Button save_button;
[GtkChild]
public Gtk.Button troubleshooting_back_button;
@@ -63,6 +65,7 @@ private void on_copy_clipboard_clicked () requires (page == PropsWindowPage.TROU
[GtkCallback]
private void on_config_editor_save_clicked () {
props_window.config_editor.save ();
+ save_button.sensitive = false;
}
[GtkCallback]
diff --git a/src/properties-window.vala b/src/properties-window.vala
index 96d77a7f..fd435c7b 100644
--- a/src/properties-window.vala
+++ b/src/properties-window.vala
@@ -70,7 +70,7 @@ public void show_troubleshoot_log (string log) {
public void show_editor_view (LibvirtMachine machine) {
page = PropsWindowPage.TEXT_EDITOR;
- config_editor.setup (machine);
+ config_editor.setup (machine, topbar.save_button);
topbar.config_editor.set_title (machine.name);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]