Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
[Gtk] Adds EditingFinished event to cell renderers
Browse files Browse the repository at this point in the history
  • Loading branch information
netonjm committed Jan 25, 2019
1 parent 0bb3624 commit 2df379b
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 8 deletions.
23 changes: 18 additions & 5 deletions TestApps/Samples/Samples/ListViewCombos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,33 @@
// THE SOFTWARE.
using System;
using Xwt;
using System.Linq;

namespace Samples
{
public class ListViewCombos: VBox
{
ListStore store;
ListView list;
DataField<int> indexField;
public ListViewCombos ()
{
ListView list = new ListView ();
var indexField = new DataField<int> ();

list = new ListView ();
indexField = new DataField<int> ();
var indexField2 = new DataField<int> ();
var itemsField = new DataField<ItemCollection> ();

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 };
Expand All @@ -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}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Xwt.Gtk/Xwt.GtkBackend.CellViews/CustomCellRendererText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions Xwt.Gtk/Xwt.GtkBackend.CellViews/CustomCellRendererToggle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ void HandleToggled (object o, ToggledArgs args)

CellUtil.SetModelValue (TreeModel, iter, field.Index, type, newValue);
}

view.RaiseEditingFinished ();
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion Xwt/Xwt.Backends/IComboBoxCellViewFrontend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@

namespace Xwt.Backends
{
public interface IComboBoxCellViewFrontend: ICellViewFrontend
public interface IEditableCellViewFrontend
{
void RaiseEditingFinished ();
}

public interface IComboBoxCellViewFrontend: ICellViewFrontend, IEditableCellViewFrontend
{
IDataField<string> SelectedTextField { get; }
IDataField<int> SelectedIndexField { get; }
Expand Down
2 changes: 1 addition & 1 deletion Xwt/Xwt.Backends/ITextCellViewFrontend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace Xwt.Backends
{
public interface ITextCellViewFrontend: ICellViewFrontend
public interface ITextCellViewFrontend: ICellViewFrontend, IEditableCellViewFrontend
{
string Markup { get; }
string Text { get; }
Expand Down
2 changes: 1 addition & 1 deletion Xwt/Xwt.Backends/IToggleCellViewFrontend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
namespace Xwt.Backends
{

public interface IToggleCellViewFrontend : ICellViewFrontend
public interface IToggleCellViewFrontend : ICellViewFrontend, IEditableCellViewFrontend
{
bool Active { get; }
bool Editable { get; }
Expand Down
6 changes: 6 additions & 0 deletions Xwt/Xwt/CheckBoxCellView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public bool AllowMixed {
}

public event EventHandler<WidgetEventArgs> Toggled;
public event EventHandler EditingFinished;

/// <summary>
/// Raises the toggled event
Expand All @@ -115,5 +116,10 @@ public bool RaiseToggled ()
}
return false;
}

public void RaiseEditingFinished ()
{
EditingFinished?.Invoke (this, EventArgs.Empty);
}
}
}
7 changes: 7 additions & 0 deletions Xwt/Xwt/ComboBoxCellView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,12 @@ public bool RaiseSelectionChanged ()
}
return false;
}

public event EventHandler EditingFinished;

public void RaiseEditingFinished ()
{
EditingFinished?.Invoke (this, EventArgs.Empty);
}
}
}
7 changes: 7 additions & 0 deletions Xwt/Xwt/RadioButtonCellView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,12 @@ public bool RaiseToggled ()
}
return false;
}

public event EventHandler EditingFinished;

public void RaiseEditingFinished ()
{
EditingFinished?.Invoke (this, EventArgs.Empty);
}
}
}
7 changes: 7 additions & 0 deletions Xwt/Xwt/TextCellView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,12 @@ bool ITextCellViewFrontend.RaiseTextChanged (string newText)
}
return false;
}

public event EventHandler EditingFinished;

public void RaiseEditingFinished ()
{
EditingFinished?.Invoke (this, EventArgs.Empty);
}
}
}

0 comments on commit 2df379b

Please sign in to comment.