Ejemplo n.º 1
0
        public ScriptInputGroupsPage(Script script)
        {
            Title = "Input Groups";

            ListView groupsList = new ListView(ListViewCachingStrategy.RecycleElement);

            groupsList.ItemTemplate = new DataTemplate(typeof(TextCell));
            groupsList.ItemTemplate.SetBinding(TextCell.TextProperty, nameof(InputGroup.Name));
            groupsList.ItemsSource = script.InputGroups;
            groupsList.ItemTapped += async(o, e) =>
            {
                if (groupsList.SelectedItem == null)
                {
                    return;
                }

                InputGroup selectedInputGroup = groupsList.SelectedItem as InputGroup;
                int        selectedIndex      = script.InputGroups.IndexOf(selectedInputGroup);

                List <string> actions = new string[] { "Edit", "Copy", "Delete" }.ToList();

                if (selectedIndex < script.InputGroups.Count - 1)
                {
                    actions.Insert(0, "Move Down");
                }

                if (selectedIndex > 0)
                {
                    actions.Insert(0, "Move Up");
                }

                string selectedAction = await DisplayActionSheet(selectedInputGroup.Name, "Cancel", null, actions.ToArray());

                if (selectedAction == "Move Up")
                {
                    script.InputGroups.Move(selectedIndex, selectedIndex - 1);
                }
                else if (selectedAction == "Move Down")
                {
                    script.InputGroups.Move(selectedIndex, selectedIndex + 1);
                }
                else if (selectedAction == "Edit")
                {
                    List <InputGroup>    previousInputGroups = script.InputGroups.Where((inputGroup, index) => index < selectedIndex).ToList();
                    ScriptInputGroupPage inputGroupPage      = new ScriptInputGroupPage(selectedInputGroup, previousInputGroups);
                    await Navigation.PushAsync(inputGroupPage);

                    groupsList.SelectedItem = null;
                }
                else if (selectedAction == "Copy")
                {
                    script.InputGroups.Add(selectedInputGroup.Copy(true));
                }
                else if (selectedAction == "Delete")
                {
                    if (await DisplayAlert("Delete " + selectedInputGroup.Name + "?", "This action cannot be undone.", "Delete", "Cancel"))
                    {
                        script.InputGroups.Remove(selectedInputGroup);
                        groupsList.SelectedItem = null;
                    }
                }
            };

            ToolbarItems.Add(new ToolbarItem(null, "plus.png", () =>
            {
                script.InputGroups.Add(new InputGroup {
                    Name = "New Input Group"
                });
            }));

            Content = groupsList;
        }
Ejemplo n.º 2
0
        public ScriptInputGroupsPage(Script script)
        {
            _script = script;

            Title = "Input Groups";

            _groupsList = new ListView();
            _groupsList.ItemTemplate = new DataTemplate(typeof(TextCell));
            _groupsList.ItemTemplate.SetBinding(TextCell.TextProperty, new Binding(".", stringFormat: "{0}"));
            _groupsList.ItemTapped += async(o, e) =>
            {
                if (_groupsList.SelectedItem == null)
                {
                    return;
                }

                InputGroup selectedInputGroup = _groupsList.SelectedItem as InputGroup;
                int        selectedIndex      = script.InputGroups.IndexOf(selectedInputGroup);

                List <string> actions = new string[] { "Edit", "Copy", "Delete" }.ToList();

                if (selectedIndex < script.InputGroups.Count - 1)
                {
                    actions.Insert(0, "Move Down");
                }

                if (selectedIndex > 0)
                {
                    actions.Insert(0, "Move Up");
                }

                string selectedAction = await DisplayActionSheet(selectedInputGroup.Name, "Cancel", null, actions.ToArray());

                if (selectedAction == "Move Up")
                {
                    script.InputGroups.Move(selectedIndex, selectedIndex - 1);
                }
                else if (selectedAction == "Move Down")
                {
                    script.InputGroups.Move(selectedIndex, selectedIndex + 1);
                }
                else if (selectedAction == "Edit")
                {
                    List <InputGroup>    previousInputGroups = _script.InputGroups.Where((inputGroup, index) => index < selectedIndex).ToList();
                    ScriptInputGroupPage inputGroupPage      = new ScriptInputGroupPage(selectedInputGroup, previousInputGroups);
                    inputGroupPage.Disappearing += (oo, ee) =>
                    {
                        Bind();
                    };

                    await Navigation.PushAsync(inputGroupPage);

                    _groupsList.SelectedItem = null;
                }
                else if (selectedAction == "Copy")
                {
                    script.InputGroups.Add(new InputGroup(selectedInputGroup));
                }
                else if (selectedAction == "Delete")
                {
                    if (await DisplayAlert("Delete " + selectedInputGroup.Name + "?", "This action cannot be undone.", "Delete", "Cancel"))
                    {
                        _script.InputGroups.Remove(selectedInputGroup);
                        _groupsList.SelectedItem = null;  // manually reset, since it isn't done automatically.
                    }
                }
            };

            ToolbarItems.Add(new ToolbarItem(null, "plus.png", () => { _script.InputGroups.Add(new InputGroup {
                    Name = "New Input Group"
                }); }));

            Bind();
            Content = _groupsList;
        }