예제 #1
0
        public static string ShowDialogList(string title, List <string> list)
        {
            var dialog = new Dialog(title, 50, 22, new Button("Close", true)
            {
                Clicked = () => { Application.RequestStop(); }
            });
            ListViewSelection listView = new ListViewSelection(new Rect(1, 1, 45, 16), list);

            dialog.Add(listView);
            Application.Run(dialog);
            return(listView.Selection);
        }
예제 #2
0
        public static bool ShowDialogFilesNotCommited(string title, Dictionary <string, string> files)
        {
            var dialog = new Dialog(title, 100, 30, new Button("Close", true)
            {
                Clicked = () => { Application.RequestStop(); }
            });
            List <string> list = new List <string>();

            foreach (KeyValuePair <string, string> entry in files)
            {
                list.Add(entry.Key);
            }
            ListViewSelection listView = new ListViewSelection(new Rect(1, 1, 95, 24), list);

            dialog.Add(listView);
            Application.Run(dialog);
            return(false);
        }
예제 #3
0
        /// <summary>
        /// <see cref="SaveListViewSelection"/> によって保存された選択状態を復元します
        /// </summary>
        private void RestoreListViewSelection(DetailsListView listView, TabModel tab, ListViewSelection listSelection)
        {
            // status_id から ListView 上のインデックスに変換
            int[] selectedIndices = null;
            if (listSelection.SelectedStatusIds != null)
                selectedIndices = tab.IndexOf(listSelection.SelectedStatusIds).Where(x => x != -1).ToArray();

            var focusedIndex = -1;
            if (listSelection.FocusedStatusId != null)
                focusedIndex = tab.IndexOf(listSelection.FocusedStatusId.Value);

            var selectionMarkIndex = -1;
            if (listSelection.SelectionMarkStatusId != null)
                selectionMarkIndex = tab.IndexOf(listSelection.SelectionMarkStatusId.Value);

            this.SelectListItem(listView, selectedIndices, focusedIndex, selectionMarkIndex);
        }
예제 #4
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);
        }
예제 #5
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);
        }
예제 #6
0
파일: Tween.cs 프로젝트: nezuku/OpenTween
        /// <summary>
        /// <see cref="SaveListViewStatus"/> によって保存された選択状態を復元します
        /// </summary>
        private void RestoreListViewSelection(DetailsListView listView, TabClass tab, ListViewSelection listSelection)
        {
            // status_id から ListView 上のインデックスに変換
            int[] selectedIndices = null;
            if (listSelection.SelectedStatusIds != null)
                selectedIndices = tab.IndexOf(listSelection.SelectedStatusIds).Where(x => x != -1).ToArray();

            var focusedIndex = -1;
            if (listSelection.FocusedStatusId != null)
                focusedIndex = tab.IndexOf(listSelection.FocusedStatusId.Value);

            var selectionMarkIndex = -1;
            if (listSelection.SelectionMarkStatusId != null)
                selectionMarkIndex = tab.IndexOf(listSelection.SelectionMarkStatusId.Value);

            listView.SelectedIndexChanged -= this.MyList_SelectedIndexChanged;
            try
            {
                this.SelectListItem(listView, selectedIndices, focusedIndex, selectionMarkIndex);
            }
            finally
            {
                listView.SelectedIndexChanged += this.MyList_SelectedIndexChanged;
            }
        }
예제 #7
0
파일: Tween.cs 프로젝트: nezuku/OpenTween
        /// <summary>
        /// <see cref="ListView"/> の選択状態を <see cref="ListViewSelection"/> として返します
        /// </summary>
        private IReadOnlyDictionary<string, ListViewSelection> SaveListViewSelection()
        {
            var listsDict = new Dictionary<string, ListViewSelection>();

            foreach (var tabPage in this.ListTab.TabPages.Cast<TabPage>())
            {
                var listView = (DetailsListView)tabPage.Tag;
                var tab = _statuses.Tabs[tabPage.Text];

                ListViewSelection listStatus;
                if (listView.VirtualListSize != 0)
                {
                    listStatus = new ListViewSelection
                    {
                        SelectedStatusIds = this.GetSelectedStatusIds(listView, tab),
                        FocusedStatusId = this.GetFocusedStatusId(listView, tab),
                        SelectionMarkStatusId = this.GetSelectionMarkStatusId(listView, tab),
                    };
                }
                else
                {
                    listStatus = new ListViewSelection
                    {
                        SelectedStatusIds = new long[0],
                        SelectionMarkStatusId = null,
                        FocusedStatusId = null,
                    };
                }

                listsDict[tab.TabName] = listStatus;
            }

            return listsDict;
        }