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

Commit

Permalink
EditableCellViewArgs to Xwt.CellEditingFinishedArgs and work with gen…
Browse files Browse the repository at this point in the history
…erics
  • Loading branch information
netonjm committed Feb 12, 2020
1 parent 8711894 commit 6eb3892
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 43 deletions.
27 changes: 16 additions & 11 deletions TestApps/Samples/Samples/ListView2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public ListView2 ()
list.DataSource = store;
list.GridLinesVisible = GridLines.Horizontal;

var checkCellView = new CheckBoxCellView { Editable = true, ActiveField = editableActiveField };
checkCellView.Toggled += (sender, e) => {
var cellView = new CheckBoxCellView { Editable = true, ActiveField = editableActiveField };
cellView.Toggled += (sender, e) => {

if (list.CurrentEventRow == null) {
MessageDialog.ShowError("CurrentEventRow is null. This is not supposed to happen");
Expand All @@ -30,24 +30,24 @@ public ListView2 ()
store.SetValue(list.CurrentEventRow, textField, "Toggled");
}
};
checkCellView.EditingFinished += CellView_EditingFinished;
cellView.EditingFinished += CellView_EditingFinished;

list.Columns.Add (new ListViewColumn("Editable", checkCellView));
list.Columns.Add (new ListViewColumn("Editable", cellView));

list.Columns.Add (new ListViewColumn("Not Editable", new CheckBoxCellView { Editable = false, ActiveField = nonEditableActiveField }));

Xwt.Backends.IEditableCellViewFrontend cellView = new TextCellView { Editable = true, TextField = textField };
cellView.EditingFinished += CellView_EditingFinished;
list.Columns.Add (new ListViewColumn("Editable",(CellView) cellView));
Xwt.Backends.IEditableCellViewFrontend<string> stringCellView = new TextCellView { Editable = true, TextField = textField };
stringCellView.EditingFinished += StringCellView_EditingFinished;
list.Columns.Add (new ListViewColumn("Editable",(CellView) stringCellView));

cellView = new CheckBoxCellView { EditableField = editableField, ActiveField = somewhatEditableData };
cellView.EditingFinished += CellView_EditingFinished;
list.Columns.Add(new ListViewColumn("Somewhat Editable",(CellView) cellView));

cellView = new TextCellView { EditableField = editableField, TextField = textField2 };
cellView.EditingFinished += CellView_EditingFinished;
stringCellView = new TextCellView { EditableField = editableField, TextField = textField2 };
stringCellView.EditingFinished += StringCellView_EditingFinished;

list.Columns.Add (new ListViewColumn("Somewhat Editable", (CellView)cellView));
list.Columns.Add (new ListViewColumn("Somewhat Editable", (CellView)stringCellView));

Random rand = new Random ();

Expand All @@ -64,7 +64,12 @@ public ListView2 ()
PackStart (list, true);
}

void CellView_EditingFinished(object sender, Xwt.Backends.EditableCellViewArgs e)
void CellView_EditingFinished(object sender, Xwt.Backends.CellEditingFinishedArgs<Xwt.CheckBoxState> e)
{
Console.WriteLine("Your old value was '{0}' and now is '{1}'", e.OldValue, e.NewValue);
}

void StringCellView_EditingFinished(object sender, Xwt.Backends.CellEditingFinishedArgs<string> e)
{
Console.WriteLine("Your old value was '{0}' and now is '{1}'", e.OldValue, e.NewValue);
}
Expand Down
12 changes: 8 additions & 4 deletions TestApps/Samples/Samples/ListViewCombos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ public ListViewCombos ()
comboCellView.Items.Add (1, "one");
comboCellView.Items.Add (2, "two");
comboCellView.Items.Add (3, "three");

comboCellView.EditingFinished += ComboCellView_EditingFinished;

comboCellView.EditingFinished += TextCellView_EditingFinished;
list.Columns.Add (new ListViewColumn ("List 1", comboCellView));

var comboCellView2 = new ComboBoxCellView { Editable = true, SelectedIndexField = indexField2, ItemsField = itemsField };
comboCellView2.EditingFinished += TextCellView_EditingFinished;
list.Columns.Add (new ListViewColumn ("List 2", comboCellView2));

int p = 0;
Expand All @@ -71,7 +70,12 @@ public ListViewCombos ()
PackStart (list, true);
}

void ComboCellView_EditingFinished (object sender, Xwt.Backends.EditableCellViewArgs e)
void ComboCellView_EditingFinished (object sender, Xwt.Backends.CellEditingFinishedArgs<CheckBoxState> e)
{
Console.WriteLine("Your old value was '{0}' and now is '{1}'", e.OldValue, e.NewValue);
}

void TextCellView_EditingFinished(object sender, Xwt.Backends.CellEditingFinishedArgs<string> e)
{
Console.WriteLine("Your old value was '{0}' and now is '{1}'", e.OldValue, e.NewValue);
}
Expand Down
17 changes: 11 additions & 6 deletions TestApps/Samples/Samples/TreeViews.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public TreeViews ()
store.GetNavigatorAt(view.CurrentEventRow).SetValue(text, "TriState Toggled");
}
};
triStateCellView.EditingFinished += CellView_EditingFinished;
triStateCellView.EditingFinished += CheckBoxCellView_EditingFinished;
var checkCellView = new CheckBoxCellView (check) { Editable = true };
checkCellView.Toggled += (object sender, WidgetEventArgs e) => {
if (view.CurrentEventRow == null) {
Expand All @@ -64,7 +64,7 @@ public TreeViews ()
store.GetNavigatorAt(view.CurrentEventRow).SetValue(text, "Toggled " + checkCellView.Active);
}
};
checkCellView.EditingFinished += CellView_EditingFinished;
checkCellView.EditingFinished += CheckBoxCellView_EditingFinished;
var optionCellView1 = new RadioButtonCellView (option1) { Editable = true };
optionCellView1.Toggled += (object sender, WidgetEventArgs e) => {
if (view.CurrentEventRow == null) {
Expand All @@ -73,7 +73,7 @@ public TreeViews ()
store.GetNavigatorAt (view.CurrentEventRow).SetValue (option2, optionCellView1.Active);
}
};
optionCellView1.EditingFinished += CellView_EditingFinished;
optionCellView1.EditingFinished += CheckBoxCellView_EditingFinished;

var optionCellView2 = new RadioButtonCellView (option2) { Editable = true };
optionCellView2.Toggled += (object sender, WidgetEventArgs e) => {
Expand All @@ -83,7 +83,7 @@ public TreeViews ()
store.GetNavigatorAt (view.CurrentEventRow).SetValue (option1, optionCellView2.Active);
}
};
optionCellView2.EditingFinished += CellView_EditingFinished;
optionCellView2.EditingFinished += CheckBoxCellView_EditingFinished;

TreePosition initialActive = null;
var optionCellView3 = new RadioButtonCellView (option3) { Editable = true };
Expand All @@ -96,7 +96,7 @@ public TreeViews ()
initialActive = view.CurrentEventRow;
}
};
optionCellView3.EditingFinished += CellView_EditingFinished;
optionCellView3.EditingFinished += CheckBoxCellView_EditingFinished;
view.Columns.Add ("TriCheck", triStateCellView);
view.Columns.Add ("Check", checkCellView);
view.Columns.Add ("Radio", optionCellView1, optionCellView2, optionCellView3);
Expand Down Expand Up @@ -235,7 +235,12 @@ public TreeViews ()
view.RowExpanded += (sender, e) => label.Text = "Row expanded: " + store.GetNavigatorAt (e.Position).GetValue (text);
}

void CellView_EditingFinished(object sender, Xwt.Backends.EditableCellViewArgs e)
void CheckBoxCellView_EditingFinished (object sender, Xwt.Backends.CellEditingFinishedArgs<Xwt.CheckBoxState> e)
{
Console.WriteLine("Your old value was '{0}' and now is '{1}'", e.OldValue, e.NewValue);
}

void StringCellView_EditingFinished(object sender, Xwt.Backends.CellEditingFinishedArgs<string> e)
{
Console.WriteLine("Your old value was '{0}' and now is '{1}'", e.OldValue, e.NewValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void HandleEdited (object o, Gtk.EditedArgs args)
if (view.SelectedTextField != null)
CellUtil.SetModelValue (TreeModel, CurrentIter, view.SelectedTextField.Index, typeof (string), args.NewText);

view.RaiseEditingFinished (new EditableCellViewArgs (lastValue, args.NewText));
view.RaiseEditingFinished (new CellEditingFinishedArgs<string> (lastValue, args.NewText));
lastValue = args.NewText;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Xwt.Gtk/Xwt.GtkBackend.CellViews/CustomCellRendererText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,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 (new EditableCellViewArgs (lastValue, args.NewText));
view.RaiseEditingFinished (new CellEditingFinishedArgs<string> (lastValue, args.NewText));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Xwt.Gtk/Xwt.GtkBackend.CellViews/CustomCellRendererToggle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ void HandleToggled (object o, ToggledArgs args)
(object) newState : (object) (newState == CheckBoxState.On);

CellUtil.SetModelValue (TreeModel, iter, field.Index, type, newValue);
view.RaiseEditingFinished(new EditableCellViewArgs(lastValue, newState));
view.RaiseEditingFinished(new CellEditingFinishedArgs<CheckBoxState> (lastValue, newState));
lastValue = newState;
return;
}

view.RaiseEditingFinished (new EditableCellViewArgs (lastValue, lastValue));
view.RaiseEditingFinished (new CellEditingFinishedArgs<CheckBoxState> (lastValue, lastValue));
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions Xwt/Xwt.Backends/IComboBoxCellViewFrontend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@

namespace Xwt.Backends
{
public class EditableCellViewArgs : EventArgs
public class CellEditingFinishedArgs<T> : EventArgs
{
public EditableCellViewArgs(object oldValue, object newValue)
public CellEditingFinishedArgs(T oldValue, T newValue)
{
OldValue = oldValue;
NewValue = newValue;
}

public object OldValue { get; set; }
public object NewValue { get; set; }
public T OldValue { get; set; }
public T NewValue { get; set; }
}

public interface IEditableCellViewFrontend
public interface IEditableCellViewFrontend<T>
{
event EventHandler<EditableCellViewArgs> EditingFinished;
void RaiseEditingFinished (EditableCellViewArgs args);
event EventHandler<CellEditingFinishedArgs<T>> EditingFinished;
void RaiseEditingFinished (CellEditingFinishedArgs<T> args);
}

public interface IComboBoxCellViewFrontend: ICellViewFrontend, IEditableCellViewFrontend
public interface IComboBoxCellViewFrontend: ICellViewFrontend, IEditableCellViewFrontend<string>
{
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, IEditableCellViewFrontend
public interface ITextCellViewFrontend: ICellViewFrontend, IEditableCellViewFrontend<string>
{
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, IEditableCellViewFrontend
public interface IToggleCellViewFrontend : ICellViewFrontend, IEditableCellViewFrontend<CheckBoxState>
{
bool Active { get; }
bool Editable { get; }
Expand Down
4 changes: 2 additions & 2 deletions Xwt/Xwt/CheckBoxCellView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public bool AllowMixed {
}

public event EventHandler<WidgetEventArgs> Toggled;
public event EventHandler<EditableCellViewArgs> EditingFinished;
public event EventHandler<CellEditingFinishedArgs<CheckBoxState>> EditingFinished;

/// <summary>
/// Raises the toggled event
Expand All @@ -117,7 +117,7 @@ public bool RaiseToggled ()
return false;
}

public void RaiseEditingFinished (EditableCellViewArgs args)
public void RaiseEditingFinished (CellEditingFinishedArgs<CheckBoxState> args)
{
EditingFinished?.Invoke (this, args);
}
Expand Down
4 changes: 2 additions & 2 deletions Xwt/Xwt/ComboBoxCellView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ public bool RaiseSelectionChanged ()
return false;
}

public event EventHandler<EditableCellViewArgs> EditingFinished;
public event EventHandler<CellEditingFinishedArgs<string>> EditingFinished;

public void RaiseEditingFinished (EditableCellViewArgs args)
public void RaiseEditingFinished (CellEditingFinishedArgs<string> args)
{
EditingFinished?.Invoke (this, args);
}
Expand Down
4 changes: 2 additions & 2 deletions Xwt/Xwt/RadioButtonCellView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public bool RaiseToggled ()
return false;
}

public event EventHandler<EditableCellViewArgs> EditingFinished;
public event EventHandler<CellEditingFinishedArgs<CheckBoxState>> EditingFinished;

public void RaiseEditingFinished (EditableCellViewArgs args)
public void RaiseEditingFinished (CellEditingFinishedArgs<CheckBoxState> args)
{
EditingFinished?.Invoke (this, args);
}
Expand Down
4 changes: 2 additions & 2 deletions Xwt/Xwt/TextCellView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ bool ITextCellViewFrontend.RaiseTextChanged (string newText)
return false;
}

public event EventHandler<EditableCellViewArgs> EditingFinished;
public event EventHandler<CellEditingFinishedArgs<string>> EditingFinished;

public void RaiseEditingFinished (EditableCellViewArgs args)
public void RaiseEditingFinished (CellEditingFinishedArgs<string> args)
{
EditingFinished?.Invoke (this, args);
}
Expand Down

0 comments on commit 6eb3892

Please sign in to comment.