Ejemplo n.º 1
0
        public async Task EnterFile(string f)
        {
            if (preloaded.TryGetValue(f, out var result))
            {
                if (result is LoadSuccess || result is LoadNonexistent)
                {
                    mode.Enter(this, f);
                    AddRecentFile(f);
                }
                else
                {
                    Handle(f, result);
                }
            }
            else
            {
                await Load(f);

                EnterFile(f);
            }
        }
Ejemplo n.º 2
0
        public FileMenu(int width, int height, FileMode mode) : base(width, height)
        {
            DefaultBackground = Color.Black;


            this.recentFiles   = File.Exists(RECENTFILES) ? ASECIILoader.DeserializeObject <HashSet <string> >(File.ReadAllText(RECENTFILES)).Where(f => File.Exists(f)).ToHashSet() : new HashSet <string>();
            this.preloaded     = new Dictionary <string, ILoadResult>();
            this.recentListing = new List <LabelButton>();
            int n = 3;

            if (recentFiles.Any())
            {
                folderListingX = 32;
                foreach (var f in recentFiles)
                {
                    var p = Path.GetFileName(f);
                    var b = new LabelButton(p, Load, () => textbox.text = f)
                    {
                        Position = new Point(4, n),
                    };

                    b.MouseEnter += (e, args) => {
                        ShowPreview(f);
                    };

                    this.Children.Add(b);
                    recentListing.Add(b);
                    n++;

                    void Load()
                    {
                        mode.Enter(this, f);
                        //AddRecentFile(f);
                    }
                }
            }
            else
            {
                folderListingX = 8;
            }


            this.mode         = mode;
            UseMouse          = true;
            UseKeyboard       = true;
            IsFocused         = true;
            FocusOnMouseClick = true;
            folderListing     = new List <LabelButton>();

            textbox = new TextField(width - folderListingX)
            {
                Position = new Point(folderListingX, 1),

                UseKeyboard = true,
                UseMouse    = true,
                IsFocused   = true,
                text        = mode.InitialPath,
            };
            textbox.TextChanged  += tf => UpdateListing(textbox.text);
            textbox.EnterPressed += tf => EnterFile();
            this.Children.Add(textbox);
            UpdateListing(textbox.text);
        }