Ejemplo n.º 1
0
        public ListBoxAll()
        {
            label = new Label {
                Text    = Application.TranslationCatalog.GetString("List description"),
                Visible = false,
            };

            listBoxFilter = new ListBoxFilter <T> {
                ExpandHorizontal    = true,
                ExpandVertical      = true,
                HorizontalPlacement = WidgetPlacement.Fill,
                VerticalPlacement   = WidgetPlacement.Fill,
            };
            listBoxFilter.SelectionItemChanged += (sender, e) => OnSelectionItemChanged(e);

            allCheckBox = new CheckBox {
                Label      = Application.TranslationCatalog.GetString("All"),
                AllowMixed = false,
                State      = CheckBoxState.Off,
                Active     = false,
                Visible    = false,
            };
            allCheckBox.Clicked += AllCheckBoxClicked;

            PackStart(label);
            PackStart(listBoxFilter);
            PackStart(allCheckBox);

            listBoxFilter.ExpandVertical = true;
        }
Ejemplo n.º 2
0
        public ListBoxAction(IController <T> controller = null)
        {
            add.Clicked += delegate {
                var dialogo = new Dialog {
                    Title = string.Format(Application.TranslationCatalog.GetString("Add {0}"), Title),
                };

                dialogo.Buttons.Add(Command.Cancel, Command.Add);

                var w = new ListBoxFilter <T> {
                    List      = ListAvailable.Except(List).ToList() ?? controller.List.Except(List).ToList(),
                    MinHeight = 200,
                    MinWidth  = 300
                };
                var box = new HBox();
                box.PackStart(w, true, true);
                dialogo.Content = box;
                if (dialogo.Run() == Command.Add)
                {
                    if (w.SelectedItems.Count == 0)
                    {
                        MessageDialog.ShowWarning(Application.TranslationCatalog.GetString("Must select a item."));
                    }
                    else if (List.Contains(w.SelectedItem))
                    {
                        MessageDialog.ShowWarning(Application.TranslationCatalog.GetString("The item already exists in the list."));
                    }
                    else
                    {
                        OnAddItem(w.SelectedItem);
                        listBox.List.Add(w.SelectedItem);
                        listBox.Items.Add(w.SelectedItem);
                        OnChanged();
                    }
                }

                box.Remove(w);
                dialogo.Close();
            };

            remove.Clicked += delegate {
                var row = listBox.SelectedRow;
                if (row == -1)
                {
                    MessageDialog.ShowMessage(string.Format(Application.TranslationCatalog.GetString("Select a {0} to remove"), typeof(T).Name.Humanize()));
                }
                else
                {
                    if (OnPreventRemove(listBox.SelectedItem))
                    {
                        MessageDialog.ShowWarning(Application.TranslationCatalog.GetString("A validation rule prevents you from deleting the selected item"));
                    }
                    else
                    {
                        OnRemoveItem(listBox.SelectedItem);
                        listBox.List.Remove(listBox.SelectedItem);
                        listBox.Items.Remove(listBox.SelectedItem);
                        OnChanged();
                    }
                }
            };

            actions.PackStart(add);
            actions.PackStart(remove);
            PackStart(listBox, true, true);
            PackEnd(actions, false, true);
        }