From 9666525b0ce6954eadfd06d00fd4f5d70df42333 Mon Sep 17 00:00:00 2001 From: Jose Medrano Date: Fri, 25 Jan 2019 18:55:16 +0100 Subject: [PATCH] [Gtk] Adds EditingFinished event to cell renderers --- TestApps/Samples/Samples/ListViewCombos.cs | 23 +++++++++++++++---- .../CustomCellRendererComboBox.cs | 2 ++ .../CustomCellRendererText.cs | 1 + .../CustomCellRendererToggle.cs | 2 ++ Xwt/Xwt.Backends/IComboBoxCellViewFrontend.cs | 7 +++++- Xwt/Xwt.Backends/ITextCellViewFrontend.cs | 2 +- Xwt/Xwt.Backends/IToggleCellViewFrontend.cs | 2 +- Xwt/Xwt/CheckBoxCellView.cs | 6 +++++ Xwt/Xwt/ComboBoxCellView.cs | 7 ++++++ Xwt/Xwt/RadioButtonCellView.cs | 7 ++++++ Xwt/Xwt/TextCellView.cs | 7 ++++++ 11 files changed, 58 insertions(+), 8 deletions(-) diff --git a/TestApps/Samples/Samples/ListViewCombos.cs b/TestApps/Samples/Samples/ListViewCombos.cs index 26d03fcf7..cf9e4f0f4 100644 --- a/TestApps/Samples/Samples/ListViewCombos.cs +++ b/TestApps/Samples/Samples/ListViewCombos.cs @@ -25,28 +25,33 @@ // THE SOFTWARE. using System; using Xwt; +using System.Linq; namespace Samples { public class ListViewCombos: VBox { + ListStore store; + ListView list; + DataField indexField; public ListViewCombos () { - ListView list = new ListView (); - var indexField = new DataField (); - + list = new ListView (); + indexField = new DataField (); var indexField2 = new DataField (); var itemsField = new DataField (); - ListStore store = new ListStore (indexField, indexField2, itemsField); + store = new ListStore (indexField, indexField2, itemsField); list.DataSource = store; list.GridLinesVisible = GridLines.Horizontal; - var comboCellView = new ComboBoxCellView { Editable = true, SelectedIndexField = indexField }; + ComboBoxCellView comboCellView = new ComboBoxCellView { Editable = true, SelectedIndexField = indexField }; comboCellView.Items.Add (1, "one"); comboCellView.Items.Add (2, "two"); comboCellView.Items.Add (3, "three"); + comboCellView.EditingFinished += ComboCellView_EditingFinished; + list.Columns.Add (new ListViewColumn ("List 1", comboCellView)); var comboCellView2 = new ComboBoxCellView { Editable = true, SelectedIndexField = indexField2, ItemsField = itemsField }; @@ -65,5 +70,13 @@ public ListViewCombos () } PackStart (list, true); } + + void ComboCellView_EditingFinished (object sender, EventArgs e) + { + var cellView = (ComboBoxCellView)sender; + var cellText = store.GetValue (list.SelectedRow, indexField); + + Console.WriteLine ($"Your real value is : {cellText}"); + } } } diff --git a/Xwt.Gtk/Xwt.GtkBackend.CellViews/CustomCellRendererComboBox.cs b/Xwt.Gtk/Xwt.GtkBackend.CellViews/CustomCellRendererComboBox.cs index 02746b0dc..031e87637 100644 --- a/Xwt.Gtk/Xwt.GtkBackend.CellViews/CustomCellRendererComboBox.cs +++ b/Xwt.Gtk/Xwt.GtkBackend.CellViews/CustomCellRendererComboBox.cs @@ -129,6 +129,8 @@ void HandleEdited (object o, Gtk.EditedArgs args) } if (view.SelectedTextField != null) CellUtil.SetModelValue (TreeModel, CurrentIter, view.SelectedTextField.Index, typeof (string), args.NewText); + + view.RaiseEditingFinished (); } } } diff --git a/Xwt.Gtk/Xwt.GtkBackend.CellViews/CustomCellRendererText.cs b/Xwt.Gtk/Xwt.GtkBackend.CellViews/CustomCellRendererText.cs index 98d2b1a87..0912e4a7a 100644 --- a/Xwt.Gtk/Xwt.GtkBackend.CellViews/CustomCellRendererText.cs +++ b/Xwt.Gtk/Xwt.GtkBackend.CellViews/CustomCellRendererText.cs @@ -72,6 +72,7 @@ void HandleEdited (object o, EditedArgs args) Gtk.TreeIter iter; if (TreeModel.GetIterFromString (out iter, args.Path)) CellUtil.SetModelValue (TreeModel, iter, view.TextField.Index, view.TextField.FieldType, args.NewText); + view.RaiseEditingFinished (); } } } diff --git a/Xwt.Gtk/Xwt.GtkBackend.CellViews/CustomCellRendererToggle.cs b/Xwt.Gtk/Xwt.GtkBackend.CellViews/CustomCellRendererToggle.cs index f935cc54b..86b615879 100644 --- a/Xwt.Gtk/Xwt.GtkBackend.CellViews/CustomCellRendererToggle.cs +++ b/Xwt.Gtk/Xwt.GtkBackend.CellViews/CustomCellRendererToggle.cs @@ -91,6 +91,8 @@ void HandleToggled (object o, ToggledArgs args) CellUtil.SetModelValue (TreeModel, iter, field.Index, type, newValue); } + + view.RaiseEditingFinished (); } } } diff --git a/Xwt/Xwt.Backends/IComboBoxCellViewFrontend.cs b/Xwt/Xwt.Backends/IComboBoxCellViewFrontend.cs index a92994074..23c93f73d 100644 --- a/Xwt/Xwt.Backends/IComboBoxCellViewFrontend.cs +++ b/Xwt/Xwt.Backends/IComboBoxCellViewFrontend.cs @@ -27,7 +27,12 @@ namespace Xwt.Backends { - public interface IComboBoxCellViewFrontend: ICellViewFrontend + public interface IEditableCellViewFrontend + { + void RaiseEditingFinished (); + } + + public interface IComboBoxCellViewFrontend: ICellViewFrontend, IEditableCellViewFrontend { IDataField SelectedTextField { get; } IDataField SelectedIndexField { get; } diff --git a/Xwt/Xwt.Backends/ITextCellViewFrontend.cs b/Xwt/Xwt.Backends/ITextCellViewFrontend.cs index c53577266..da6b61b9b 100644 --- a/Xwt/Xwt.Backends/ITextCellViewFrontend.cs +++ b/Xwt/Xwt.Backends/ITextCellViewFrontend.cs @@ -27,7 +27,7 @@ namespace Xwt.Backends { - public interface ITextCellViewFrontend: ICellViewFrontend + public interface ITextCellViewFrontend: ICellViewFrontend, IEditableCellViewFrontend { string Markup { get; } string Text { get; } diff --git a/Xwt/Xwt.Backends/IToggleCellViewFrontend.cs b/Xwt/Xwt.Backends/IToggleCellViewFrontend.cs index b19f0b6cd..1459baf35 100644 --- a/Xwt/Xwt.Backends/IToggleCellViewFrontend.cs +++ b/Xwt/Xwt.Backends/IToggleCellViewFrontend.cs @@ -27,7 +27,7 @@ namespace Xwt.Backends { - public interface IToggleCellViewFrontend : ICellViewFrontend + public interface IToggleCellViewFrontend : ICellViewFrontend, IEditableCellViewFrontend { bool Active { get; } bool Editable { get; } diff --git a/Xwt/Xwt/CheckBoxCellView.cs b/Xwt/Xwt/CheckBoxCellView.cs index 258b3696c..47ad7dfda 100644 --- a/Xwt/Xwt/CheckBoxCellView.cs +++ b/Xwt/Xwt/CheckBoxCellView.cs @@ -101,6 +101,7 @@ public bool AllowMixed { } public event EventHandler Toggled; + public event EventHandler EditingFinished; /// /// Raises the toggled event @@ -115,5 +116,10 @@ public bool RaiseToggled () } return false; } + + public void RaiseEditingFinished () + { + EditingFinished?.Invoke (this, EventArgs.Empty); + } } } diff --git a/Xwt/Xwt/ComboBoxCellView.cs b/Xwt/Xwt/ComboBoxCellView.cs index 8da60423a..104071156 100644 --- a/Xwt/Xwt/ComboBoxCellView.cs +++ b/Xwt/Xwt/ComboBoxCellView.cs @@ -124,5 +124,12 @@ public bool RaiseSelectionChanged () } return false; } + + public event EventHandler EditingFinished; + + public void RaiseEditingFinished () + { + EditingFinished?.Invoke (this, EventArgs.Empty); + } } } diff --git a/Xwt/Xwt/RadioButtonCellView.cs b/Xwt/Xwt/RadioButtonCellView.cs index 9222fc690..a28697cf2 100644 --- a/Xwt/Xwt/RadioButtonCellView.cs +++ b/Xwt/Xwt/RadioButtonCellView.cs @@ -79,5 +79,12 @@ public bool RaiseToggled () } return false; } + + public event EventHandler EditingFinished; + + public void RaiseEditingFinished () + { + EditingFinished?.Invoke (this, EventArgs.Empty); + } } } diff --git a/Xwt/Xwt/TextCellView.cs b/Xwt/Xwt/TextCellView.cs index 11b94668b..309fa0f1b 100644 --- a/Xwt/Xwt/TextCellView.cs +++ b/Xwt/Xwt/TextCellView.cs @@ -116,5 +116,12 @@ bool ITextCellViewFrontend.RaiseTextChanged (string newText) } return false; } + + public event EventHandler EditingFinished; + + public void RaiseEditingFinished () + { + EditingFinished?.Invoke (this, EventArgs.Empty); + } } }