コード例 #1
0
        /// <summary>
        /// Creates a Dialog that allow user to view and edit API settings
        /// </summary>
        private static void CreateSettingEditDialog()
        {
            var editSettingDialog = new Dialog("Edit Settings", 100, 100)
            {
                Height = Dim.Percent(50)
            };

            List <string> sourceList       = new List <string>();
            var           settingsListView = new ListViewSelection(sourceList)
            {
                X      = 1,
                Y      = 2,
                Width  = Dim.Fill(6),
                Height = Dim.Fill() - 4
            };

            if (settings == null)
            {
                sourceList.Add("No Settings Added Yet");
                settingsListView.SetSource(sourceList);
            }
            else
            {
                sourceList.Add($"URI: {settings.BaseUrl}");
                sourceList.Add($"Key: {settings.ApiKey}");
                settingsListView.SetSource(sourceList);
            }

            var add = new Button("Edit Settings")
            {
                X       = Pos.Center() - 20,
                Y       = Pos.AnchorEnd(2),
                Clicked = () =>
                {
                    if (settings != null)
                    {
                        CreateInputDialog("Api", "Key", settings.BaseUrl, settings.ApiKey);
                    }
                    else
                    {
                        CreateInputDialog("Api", "Key");
                    }
                    if (settings != null)
                    {
                        sourceList.Clear();
                        sourceList.Add($"URI: {settings.BaseUrl}");
                        sourceList.Add($"Key: {settings.ApiKey}");
                        settingsListView.SetSource(sourceList);
                    }
                }
            };

            Button retrn = new Button("Return")
            {
                X       = Pos.Center() + 10,
                Y       = Pos.AnchorEnd(2),
                Clicked = () =>
                {
                    Application.RequestStop();
                }
            };

            editSettingDialog.Add(settingsListView, add, retrn);
            Application.Run(editSettingDialog);
        }
コード例 #2
0
        /// <summary>
        /// Creates a Dialog that allow user to view, add, edit organiazations and tokens
        /// </summary>
        private static void CreateOrgEditDialog()
        {
            var editOrgDialog = new Dialog("Edit Organization/Token", 100, 100)
            {
                Height = Dim.Percent(90)
            };
            var sourceList = new List <string>();
            ListViewSelection orgViewList = new ListViewSelection(sourceList)
            {
                X             = 1,
                Y             = 4,
                Width         = Dim.Fill() - 4,
                Height        = Dim.Fill() - 4,
                AllowsMarking = true
            };

            var myColor = Application.Driver.MakeAttribute(Color.Blue, Color.White);

            if (orgTokList != null && orgTokList.Count != 0)
            {
                sourceList = orgTokList.Select(o => o.Key + "/" + o.Value).ToList();
                Label msg = new Label("Use space bar or control-t to toggle selection")
                {
                    X         = 1,
                    Y         = 1,
                    Width     = Dim.Percent(50),
                    Height    = 1,
                    TextColor = myColor
                };
                orgViewList.SetSource(sourceList);
                editOrgDialog.Add(orgViewList);
                editOrgDialog.Add(msg);
            }
            else
            {
                sourceList.Add("No Organizations saved");
                orgViewList.AllowsMarking = false;
                orgViewList.SetSource(sourceList);
                editOrgDialog.Add(orgViewList);
            }

            var add = new Button("Add new Org")
            {
                X       = 5,
                Y       = Pos.AnchorEnd(2),
                Clicked = () =>
                {
                    CreateInputDialog("Org", "Token");

                    if (sourceList.Count != 0)
                    {
                        sourceList.Clear();
                    }
                    if (orgTokList != null)
                    {
                        sourceList = orgTokList.Select(o => o.Key + "/" + o.Value).ToList();
                        orgViewList.Clear();
                        orgViewList.AllowsMarking = true;
                        orgViewList.SetSource(sourceList);
                        editOrgDialog.SetFocus(orgViewList);
                    }
                }
            };

            var edit = new Button("Edit Selected")
            {
                X       = Pos.Right(add) + 10,
                Y       = Pos.AnchorEnd(2),
                Clicked = () =>
                {
                    int index = 0;
                    for (int i = 0; i < sourceList.Count; i++)
                    {
                        if (orgViewList.Source.IsMarked(i))
                        {
                            int lengthBeforeEditing = orgTokList.Count;
                            index = sourceList[i].IndexOf('/');
                            string key   = sourceList[i].Substring(0, index);
                            string value = sourceList[i].Substring(index + 1, (sourceList[i].Length - 1) - (index));
                            orgTokList.Remove(sourceList[i].Substring(0, index));
                            CreateInputDialog("Org", "Token", key, value);
                            if (orgTokList.Count == lengthBeforeEditing)
                            {
                                sourceList = orgTokList.Select(o => o.Key + "/" + o.Value).ToList();
                            }
                            else
                            {
                                orgTokList.Add(key, value);
                            }
                        }
                    }

                    orgViewList.Clear();
                    orgViewList.SetSource(sourceList);
                    editOrgDialog.SetFocus(orgViewList);
                }
            };

            var delete = new Button("Delete Selected")
            {
                X       = Pos.Right(edit) + 30,
                Y       = Pos.AnchorEnd(2),
                Clicked = () =>
                {
                    int index = 0;
                    for (int i = 0; i < sourceList.Count; i++)
                    {
                        if (orgViewList.Source.IsMarked(i))
                        {
                            index = sourceList[i].IndexOf('/');
                            orgTokList.Remove(sourceList[i].Substring(0, index));
                            sourceList.Remove(sourceList[i]);
                        }
                    }

                    if (orgTokList.Count == 0)
                    {
                        sourceList.Clear();
                        sourceList.Add("No Organizations Saved");
                        orgViewList.AllowsMarking = false;
                    }
                    _readWriteOps.SaveOrgTok(orgTokList);
                    orgViewList.Clear();
                    orgViewList.SetSource(sourceList);
                    editOrgDialog.SetFocus(orgViewList);
                }
            };

            Button retrn = new Button("Return")
            {
                X       = Pos.Right(delete) + 50,
                Y       = Pos.AnchorEnd(2),
                Clicked = () =>
                {
                    Application.RequestStop();
                }
            };

            editOrgDialog.Add(add, edit, delete, retrn, orgViewList);

            Application.Run(editOrgDialog);
        }