예제 #1
0
        static void Main(string[] args)
        {
            _client = new IpcClient(new DefaultIpcEndpoint());
            var answer = _client.GetRepositories();

            var repositoryCount = answer?.Repositories?.Length ?? 0;

            if (repositoryCount == 0)
            {
                if (!string.IsNullOrEmpty(answer?.Answer))
                {
                    Console.WriteLine(answer.Answer);
                }
                else
                {
                    Console.WriteLine("No repositories yet");
                }

                return;
            }

            _repositoriesView = new RepositoriesView(answer.Repositories);

            Application.Init();

            var filterLabel = new Label(1, 1, "Filter: ");

            _filterField = new TextField("")
            {
                X     = Pos.Right(filterLabel) + 2,
                Y     = Pos.Top(filterLabel),
                Width = Dim.Fill(margin: 1),
            };
            _filterField.Changed += FilterField_Changed;

            _repositoryList = new ListView(_repositoriesView.Repositories)
            {
                X      = Pos.Left(filterLabel),
                Y      = Pos.Bottom(filterLabel) + 1,
                Width  = Dim.Fill(margin: 1),
                Height = Dim.Fill() - 2
            };

            var win = new KeyPreviewWindow("grr: Git repositories of RepoZ")
            {
                filterLabel,
                _filterField,
                _repositoryList
            };

            var buttonX = Pos.Left(filterLabel);

            var navigationButton = new Button("Navigate")
            {
                Clicked  = Navigate,
                X        = buttonX,
                Y        = Pos.AnchorEnd(1),
                CanFocus = false
            };

            if (!CanNavigate)
            {
                navigationButton.Text    = "Copy navigation command";
                navigationButton.Clicked = CopyNavigationCommandAndQuit;
            }

            buttonX = buttonX + navigationButton.Text.Length + BUTTON_BORDER + BUTTON_DISTANCE;
            var browseButton = new Button("Browse")
            {
                Clicked  = Browse,
                X        = buttonX,
                Y        = Pos.AnchorEnd(1),
                CanFocus = false
            };

            var quitButton = new Button("Quit")
            {
                Clicked  = Application.RequestStop,
                X        = Pos.AnchorEnd("Quit".Length + BUTTON_BORDER + BUTTON_DISTANCE),
                Y        = Pos.AnchorEnd(1),
                CanFocus = false
            };

            win.Add(navigationButton, browseButton, quitButton);

            win.DefineKeyAction(Key.Enter, () => win.SetFocus(_repositoryList));
            win.DefineKeyAction(Key.Esc, () =>
            {
                if (_filterField.HasFocus)
                {
                    SetFilterText("");
                }
                else
                {
                    win.SetFocus(_filterField);
                }
            });

            if (args?.Length > 0)
            {
                SetFilterText(String.Join(" ", args));
            }

            Application.Top.Add(win);
            Application.Run();
        }
예제 #2
0
        static void Main(string[] args)
        {
            _client = new RepoZIpcClient();
            var answer = _client.GetRepositories();

            if (answer.Repositories == null)
            {
                Console.WriteLine(answer.Answer);
                return;
            }

            if (answer.Repositories.Length == 0)
            {
                Console.WriteLine("No repositories yet");
                return;
            }

            _repositoriesView = new RepositoriesView(answer.Repositories);

            Application.Init();

            var filterLabel = new Label(1, 1, "Filter: ");
            var filterField = new TextField("")
            {
                X     = Pos.Right(filterLabel) + 2,
                Y     = Pos.Top(filterLabel),
                Width = Dim.Fill(margin: 1),
            };

            filterField.Changed += FilterField_Changed;

            _repositoryList = new ListView(_repositoriesView.Repositories)
            {
                X      = Pos.Left(filterLabel),
                Y      = Pos.Bottom(filterLabel) + 1,
                Width  = Dim.Fill(margin: 1),
                Height = Dim.Fill() - 2
            };

            var win = new KeyPreviewWindow("grr: Git repositories of RepoZ");

            win.Add(filterLabel);
            win.Add(filterField);
            win.Add(_repositoryList);

            var navigationButton = new Button("Navigate")
            {
                Clicked  = Navigate,
                X        = Pos.Left(filterLabel),
                Y        = Pos.AnchorEnd(1),
                CanFocus = false
            };

            var browseButton = new Button("Browse")
            {
                Clicked  = Browse,
                X        = Pos.Right(navigationButton) + 1,
                Y        = Pos.AnchorEnd(1),
                CanFocus = false
            };

            var copyButton = new Button("Copy path")
            {
                Clicked  = CopyPath,
                X        = Pos.Right(browseButton) + 1,
                Y        = Pos.AnchorEnd(1),
                CanFocus = false
            };

            var quitButton = new Button("Quit")
            {
                Clicked  = () => Application.RequestStop(),
                X        = Pos.AnchorEnd(8 + 1),
                Y        = Pos.AnchorEnd(1),
                CanFocus = false
            };

            win.Add(navigationButton, browseButton, copyButton, quitButton);

            win.DefineKeyAction(Key.Enter, () => win.SetFocus(_repositoryList));
            win.DefineKeyAction(Key.Esc, () =>
            {
                if (filterField.HasFocus)
                {
                    filterField.Text = "";
                    FilterField_Changed(filterField, EventArgs.Empty);
                }
                else
                {
                    win.SetFocus(filterField);
                }
            });

            Application.Top.Add(win);
            Application.Run();
        }