public ListViewAction() { add.Clicked += delegate { var dialogo = new Dialog { Title = string.Format(Application.TranslationCatalog.GetString("New {0}"), Title), }; dialogo.Buttons.Add(Command.Cancel, Command.Add); var item = new T(); ItemUI.ValuesClean(); ItemUI.Item = item; OnBeforeAdd(item); ItemUI.ValuesRefresh(); ItemUI.Editable(true); var w = (Widget)ItemUI; var box = new HBox(); box.PackStart(w, true, true); dialogo.Content = box; if (dialogo.Run() == Command.Add) { ItemUI.ValuesTake(); if (OnPreventAdd(ItemUI.Item)) { MessageDialog.ShowWarning(Application.TranslationCatalog.GetString("A validation rule prevents you from add the item")); } else if (OnSimilarity(List, ItemUI.Item)) { MessageDialog.ShowWarning(Application.TranslationCatalog.GetString("A similar element already exists in the list. Try to modify the existing one")); } else { listView.Add(item); listView.SelectedItem = item; ScrollTo(item); OnItemEdited(ItemUI.Item); OnChanged(); } } box.Remove(w); dialogo.Close(); }; edit.Clicked += delegate { var dialogo = new Dialog { Title = string.Format(Application.TranslationCatalog.GetString("Edit {0}"), Title), }; dialogo.Buttons.Add(Command.Cancel, Command.Apply); var row = listView.SelectedRow; if (row == -1) { MessageDialog.ShowMessage(string.Format(Application.TranslationCatalog.GetString("Select a {0} to edit"), Title)); } else { ItemUI.ValuesClean(); ItemUI.Item = listView.SelectedItem; ItemUI.ValuesRefresh(); ItemUI.Editable(true); var widget = (Widget)ItemUI; var box = new HBox(); box.PackStart(widget, true, true); dialogo.Content = box; if (dialogo.Run() == Command.Apply) { ItemUI.ValuesTake(); if (OnSimilarity(List, ItemUI.Item)) { MessageDialog.ShowWarning(Application.TranslationCatalog.GetString("A similar element already exists in the list. Try to modify the existing one")); } else { listView.FillRow(row, listView.SelectedItem); OnItemEdited(ItemUI.Item); OnChanged(); } } box.Remove(widget); dialogo.Close(); } }; remove.Clicked += delegate { var row = listView.SelectedRow; if (row == -1) { MessageDialog.ShowMessage(string.Format(Application.TranslationCatalog.GetString("Select a {0} to remove"), Title)); } else { if (OnPreventRemove(listView.SelectedItem)) { MessageDialog.ShowWarning(Application.TranslationCatalog.GetString("A validation rule prevents you from deleting the selected item")); } else { listView.Remove(); OnChanged(); } } }; listView.RowActivated += delegate(object sender, ListViewRowEventArgs e) { OnRowActivated(); if (ShowOnRowActivated) { var dialogo = new Dialog { Title = Title, }; if (e.RowIndex == -1) { MessageDialog.ShowMessage(string.Format(Application.TranslationCatalog.GetString("Select a {0} to show"), Title)); } else { ItemUI.ValuesClean(); ItemUI.Item = listView.SelectedItem; ItemUI.ValuesRefresh(); ItemUI.Editable(false); var widget = (Widget)ItemUI; var box = new HBox(); box.PackStart(widget, true, true); dialogo.Content = box; dialogo.Run(); box.Remove(widget); dialogo.Close(); } } }; actions.PackStart(add); actions.PackStart(edit); actions.PackStart(remove); PackStart(listView, true, true); PackEnd(actions, false, true); }