예제 #1
0
        internal void Init(TvDialog dialog, IComponentTree owner)
        {
            _myDialog = dialog;
            _buttons.AddOkButton();
            _buttons.AddCancelButton();
            var viewport = _myDialog.AsComponent().Viewport.Layer(ViewportLayer.Top);

            _mainPanel = new TvStackPanel(owner, $"{_prefixNames}_MainPanel");
            _mainPanel.Layout.Add("1", "*");
            _mainPanel.AsComponent().AddViewport(new Viewport(viewport.Position + new TvPoint(1, 1), viewport.Columns - 2, viewport.Rows - 2, viewport.ZIndex));
            _bottomGrid = new TvGrid(owner, new GridState(1, 2), $"{_prefixNames}_BottomGrid");
            _bottomGrid.Use(0, 0).Add(_buttons.OkButton);
            _bottomGrid.Use(0, 1).Add(_buttons.CancelButton);
            _mainCanvas = new TvCanvas(owner, $"{_prefixNames}_BodyCanvas");
            _mainCanvas.AsComponent().AddViewport(Viewport.NullViewport);

            _mainPanel.At(0).Add(_mainCanvas);
            _mainPanel.At(1).Add(_bottomGrid);

            IsDirty = true;
        }
예제 #2
0
        Task ITvisionAppStartup.Startup(ITuiEngine tui)
        {
            var skin = _skinManager.CurrentSkin;
            var dvpf = _layoutManager.DynamicViewportFactory;

            var mainStackPanel = new TvStackPanel(tui.UI, "mainStackPanel");

            mainStackPanel.AsComponent().AddViewport(dvpf.Create(vpf => vpf.FullViewport().Translate(new TvPoint(0, 1)).Grow(0, -3)));
            mainStackPanel.Layout.Add("*", "3");
            var listFilesGrid = new TvGrid(tui.UI, new GridState(1, 2));

            mainStackPanel.At(0).Add(listFilesGrid);

            tui.UI.Add(mainStackPanel);

            // TODO: Implement BorderedPanel
            // mainStackPanel.At(1).Add(new BorderedPanel());

            var textbox = new TvTextbox(skin, null, new TextboxState());
            //var left = new TvList<FileItem>(skin, new Viewport(new TvPoint(0, 0), 10, 1, 0),
            //    new ListState<FileItem>(Enumerable.Empty<FileItem>(), f => new TvListItem() { Text = f.Name }));

            var actind = new TvActivityIndicator(skin, new Viewport(new TvPoint(0, 22), 1, 1, 0)
                                                 , new ActivityIndicatorState());

            tui.UI.Add(actind);


            var left = new TvList <FileItem>(skin, new Viewport(new TvPoint(0, 0), 10, 1, 0),
                                             ListState <FileItem>
                                             .From(Enumerable.Empty <FileItem>())
                                             .AddFixedColumn(fi => fi.IsDirectory ? "*" : " ", width: 2)
                                             .AddColumn(fi => fi.Name)
                                             .Build());


            left.StyleProvider
            .Use(Core.Colors.TvColor.Red, Core.Colors.TvColor.Blue)
            .When(f => (f.FileAttributes & System.IO.FileAttributes.Hidden) == System.IO.FileAttributes.Hidden)
            .AppliesToColumn(1);

            var right = new TvList <FileItem>(skin, new Viewport(new TvPoint(0, 0), 10, 1, 0),
                                              new ListState <FileItem>(Enumerable.Empty <FileItem>(), new TvListColumnSpec <FileItem>()
            {
                Transformer = f => f.Name
            }));

            right.StyleProvider
            .Use(Core.Colors.TvColor.Red, Core.Colors.TvColor.Blue)
            .When(f => (f.FileAttributes & System.IO.FileAttributes.Hidden) == System.IO.FileAttributes.Hidden)
            .AppliesToColumn(1);

            var menu = new TvMenuBar(skin, dvpf.Create(vpf => vpf.FullViewport().TakeRows(1, 0)),
                                     new MenuBarState(new[] { "Left", "Edit", "Command", "Options", "Help", "Right" }), opt =>
            {
                opt.ItemsSpacedBy(4);
            });

            //var window = new TvWindow(skin, vpf.FullViewport().CreateCentered(20, 10), new WindowState(tui.UI));
            //var label = new TvLabel(skin, new Viewport(new TvPoint(0, 0), 9, 1, 0), new LabelState() { Text = "In Window" });
            //window.State.UI.Add(label);

            var label = new TvLabel(skin, new Viewport(new TvPoint(0, 0), 9, 1, 0),
                                    new LabelState()
            {
                Text = "In Window"
            });


            var dialog = _dialogManager.CreateDialog(dvpf.Create(vpf => vpf.FullViewport().CreateCentered(20, 10)),
                                                     d => { d.State.UI.Add(label); });



            var sleft = TvStatexControl.Wrap <TvList <FileItem>, ListState <FileItem>, FileList>(left, opt =>
            {
                opt.UseStore("left");
                opt.UseStatexTransformation((fl, cs) =>
                {
                    cs.Clear();
                    cs.AddRange(fl.Items);
                });
                opt.On(c => c.OnItemClicked)
                .Dispatch((s, args) => new TvAction <string>("FETCH_DIR", args.FullName))
                .When(f => f.IsDirectory);

                opt.OnKeyEvent(e => e.AsConsoleKeyInfo().Key == System.ConsoleKey.Enter)
                .Dispatch(s => new TvAction <FileItem>("FETCH_INFO", s[s.SelectedIndex]));

                opt.OnKeyEvent(e => e.AsConsoleKeyInfo().Key == System.ConsoleKey.Backspace)
                .Dispatch(s => new TvAction("FETCH_BACK"));
            });
            var sright = TvStatexControl.Wrap <TvList <FileItem>, ListState <FileItem>, FileList>(right, opt =>
            {
                opt.UseStore("right");
                opt.UseStatexTransformation((fl, cs) =>
                {
                    cs.Clear();
                    cs.AddRange(fl.Items);
                });
                opt.On(c => c.OnItemClicked)
                .Dispatch((s, args) => new TvAction <string>("FETCH_DIR", args.FullName))
                .When(f => f.IsDirectory);
            });

            listFilesGrid.Use(0, 0).Add(left);
            listFilesGrid.Use(0, 1).Add(right);
            var bottom = new TvStackPanel(tui.UI, "BottomContainer");

            bottom.Layout.Add(new LayoutSize());
            bottom.AsComponent().AddViewport(dvpf.Create(vpf => vpf.BottomViewport(2)));
            bottom.At(0).Add(textbox);
            tui.UI.Add(bottom);
            tui.UI.Add(menu);

            //tui.UI.Add(window);

            _dialogManager.ShowDialog(dialog);

            if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                _storeSelector.GetStore <FileList>("left").Dispatch(new TvAction <string>("FETCH_DIR", "/"));
                _storeSelector.GetStore <FileList>("right").Dispatch(new TvAction <string>("FETCH_DIR", "/home/eiximenis"));
            }
            else
            {
                _storeSelector.GetStore <FileList>("left").Dispatch(new TvAction <string>("FETCH_DIR", "C:\\"));
                _storeSelector.GetStore <FileList>("right").Dispatch(new TvAction <string>("FETCH_DIR", "D:\\"));
            }


            return(Task.CompletedTask);
        }