Ejemplo n.º 1
0
        public void Scan(string folder)
        {
            if (new DirectoryInfo(folder).Exists == false)
            {
                return;
            }

            DirBox.Text = new DirectoryInfo(folder).FullName;
            // LastPath.Add(folder);
            CurPath = folder;
            DirectoryInfo di = new DirectoryInfo(folder);

            foreach (DirectoryInfo fold in di.GetDirectories())
            {
                ItemForm ni = Files.AddItem(fold.Name, FolderPic);
                void DoubleClickFunc(int b)
                {
                    Console.WriteLine("Scanning:" + fold.FullName);
                    Forms.Remove(Files);
                    Files = new ListForm().Set(10, 60, 370, 350, "") as ListForm;
                    Add(Files);
                    Scan(fold.FullName);
                    // Files.Changed?.Invoke();
                }

                ni.DoubleClick = DoubleClickFunc;
            }
            if (!Folder)
            {
                foreach (FileInfo file in di.GetFiles())
                {
                    ItemForm newi = Files.AddItem(file.Name, FilePic);
                    void ClickFunc(int b)
                    {
                        FileBox.Text = file.Name;
                    }

                    void DoubleClickFunc(int b)
                    {
                        Selected?.Invoke(DirBox.Text + "/" + newi.Text);
                    }

                    newi.DoubleClick = DoubleClickFunc;
                    newi.Click       = ClickFunc;
                }
                Files.Changed?.Invoke();
            }
            else
            {
                Files.Changed?.Invoke();
            }
        }
Ejemplo n.º 2
0
        public RequestFileForm(string title = "", string defdir = "")
        {
            if (FolderPic == null)
            {
                FolderPic = new Texture2D("data/UI/folder1.png", LoadMethod.Single, true);
                FilePic   = new Texture2D("data/UI/file1.png", LoadMethod.Single, true);
                BackPic   = new Texture2D("data/ui/backbut1.png", LoadMethod.Single, true);
            }

            LockedSize = true;
            DirBox     = new TextBoxForm().Set(55, 35, 300, 20) as TextBoxForm;
            FileBox    = new TextBoxForm().Set(10, 415, 300, 20) as TextBoxForm;
            Add(DirBox);
            Add(FileBox);

            UIForm cancel = new ButtonForm().Set(10, 450, 120, 20, "Cancel");
            UIForm ok     = new ButtonForm().Set(180, 450, 120, 20, "Select");

            cancel.Click = (b) =>
            {
                if (UI.CurUI.Top == this)
                {
                    UI.CurUI.Top = null;
                }
            };

            void SelectFunc(int b)
            {
                Selected?.Invoke(DirBox.Text + "/" + FileBox.Text);
            }

            ok.Click = SelectFunc;

            Add(cancel);
            Add(ok);

            if (defdir == "")
            {
                defdir = DefDir; // System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            }

            if (title == "")
            {
                title = "Select file";
            }

            Set(VividApp.W / 2 - 200, VividApp.H / 2 - 250, 400, 500, title);

            Files = new ListForm().Set(10, 60, 370, 350, "") as ListForm;
            Add(Files);
            Scan(defdir);
            BackFolder = new ButtonForm().Set(2, 30, 54, 22, "").SetImage(BackPic) as ButtonForm;

            void BackFunc(int b)
            {
                if (new DirectoryInfo(CurPath).Parent == null)
                {
                    return;
                }

                string curPath = new DirectoryInfo(CurPath).Parent.FullName;

                Forms.Remove(Files);
                Files = new ListForm().Set(10, 60, 370, 350, "") as ListForm;

                Add(Files);

                Scan(curPath);
            }

            BackFolder.Click = BackFunc;
            Add(BackFolder);
        }