Example #1
0
 public FileDialogResult(string title, string filter, FileDialogMode mode, string fileName)
 {
     Mode = mode;
     this.title = title;
     this.filter = filter;
     this.fileName = fileName;
 }
 public FileDialogResult(string title, string filter, FileDialogMode mode, string fileName)
 {
     Mode          = mode;
     this.title    = title;
     this.filter   = filter;
     this.fileName = fileName;
 }
Example #3
0
        public IEnumerator SelectFolder(string path = null, string windowName = "SELECT FOLDER", Sprite windowIcon = null, bool saveLastPath = true)
        {
            mode = FileDialogMode.FolderSelector;
            commit.GetComponentInChildren <Text>().text = "SELECT";
            fileName.text = "";
            fileName.transform.Find("FileText").GetComponent <Text>().text = "FOLDER NAME:";
            workingPath            = "";
            workingFile            = "";
            result                 = null;
            finished               = false;
            fileName.interactable  = false;
            maxSize                = -1;
            this.saveLastPath      = saveLastPath;
            this.allowedExtensions = null;

            if (string.IsNullOrEmpty(path))
            {
                path = saveLastPath ? (string.IsNullOrEmpty(PlayerPrefs.GetString("OxOD.lastPath", null)) ? Application.dataPath + "/../" : PlayerPrefs.GetString("OxOD.lastPath", null)) : Application.dataPath + "/../";
            }

            this.windowName.text = windowName;

            if (windowIcon)
            {
                this.windowIcon.sprite = windowIcon;
            }

            GoTo(path);
            gameObject.SetActive(true);

            while (!finished)
            {
                yield return(new WaitForSeconds(0.1f));
            }
        }
        public FileDialogViewModel(FileDialogMode mode)
        {
            Mode       = mode;
            SourceType = GraphSourceType.Gxml;

            IsOpenMode = mode == FileDialogMode.Open;
        }
Example #5
0
        /// <summary>
        ///     选取文件
        /// </summary>
        /// <param name="mode">模式</param>
        /// <param name="filter">过滤器</param>
        /// <returns></returns>
        public static string PickFile(FileDialogMode mode, string filter = "*.*(All Files)|*.*")
        {
            FileDialog dialog;

            if (mode == FileDialogMode.Open)
            {
                dialog = new OpenFileDialog();
            }
            else
            {
                dialog = new SaveFileDialog();
            }
            dialog.Filter = filter;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                return(dialog.FileName);
            }
            return(string.Empty);
        }
Example #6
0
        public IEnumerator Open(string path = null, string allowedExtensions = null, string windowName = "OPEN FILE", Sprite windowIcon = null, long maxSize = -1, bool saveLastPath = true)
        {
            mode = FileDialogMode.Open;
            commit.GetComponentInChildren <Text>().text = "OPEN";
            fileName.text = "";
            fileName.transform.Find("FileText").GetComponent <Text>().text = "FILE NAME:";
            workingPath           = "";
            workingFile           = "";
            result                = null;
            finished              = false;
            fileName.interactable = true;
            this.maxSize          = maxSize;
            this.saveLastPath     = saveLastPath;

            if (!string.IsNullOrEmpty(allowedExtensions))
            {
                allowedExtensions      = allowedExtensions.ToLower();
                this.allowedExtensions = allowedExtensions.Split('|');
            }

            if (string.IsNullOrEmpty(path))
            {
                path = saveLastPath ? (string.IsNullOrEmpty(PlayerPrefs.GetString("OxOD.lastPath", null))? Application.dataPath + "/../" : PlayerPrefs.GetString("OxOD.lastPath", null)) : Application.dataPath + "/../";
            }

            this.windowName.text = windowName;

            if (windowIcon)
            {
                this.windowIcon.sprite = windowIcon;
            }

            GoTo(path);
            gameObject.SetActive(true);

            while (!finished)
            {
                yield return(new WaitForSeconds(0.1f));
            }
        }
Example #7
0
 public FileDialogResult ShowFileDialog(string title, string filter, FileDialogMode mode, string fileName)
 {
     return(new FileDialogResult(title, filter, mode, fileName));
 }
Example #8
0
 public FileDialogResult ShowFileDialog(string title, string filter, FileDialogMode mode)
 {
     return(ShowFileDialog(title, filter, mode, null));
 }
Example #9
0
        public FileDialog(FileDialogMode mode)
        {
            _mode = mode;

            BuildUI();

            switch (mode)
            {
            case FileDialogMode.OpenFile:
                Title = "Open File...";
                break;

            case FileDialogMode.SaveFile:
                Title = "Save File...";
                break;

            case FileDialogMode.ChooseFolder:
                Title = "Choose Folder...";
                break;
            }

            AutoAddFilterExtension = true;

            if (mode == FileDialogMode.ChooseFolder)
            {
                _textBlockFileName.Visible = false;
                _textFieldFileName.Visible = false;
            }

            _splitPane.SetSplitterPosition(0, 0.3f);

            _buttonBack.Background    = null;
            _buttonForward.Background = null;
            _buttonParent.Background  = null;

            _listBoxPlaces.Background = null;

            _buttonBack.Image    = DefaultAssets.UISpritesheet["icon-arrow-left"];
            _buttonForward.Image = DefaultAssets.UISpritesheet["icon-arrow-right"];
            _buttonParent.Image  = DefaultAssets.UISpritesheet["icon-folder-parent"];

            var homePath = (Environment.OSVersion.Platform == PlatformID.Unix ||
                            Environment.OSVersion.Platform == PlatformID.MacOSX)
                                ? Environment.GetEnvironmentVariable("HOME")
                                : Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");

            var iconFolder = DefaultAssets.UISpritesheet["icon-folder"];

            var places = new List <string>
            {
                homePath
            };

            foreach (var f in Folders)
            {
                places.Add(Path.Combine(homePath, f));
            }

            foreach (var p in places)
            {
                if (!Directory.Exists(p))
                {
                    continue;
                }

                _listBoxPlaces.Items.Add(new ListItem(Path.GetFileName(p), null, p)
                {
                    Image            = iconFolder,
                    ImageTextSpacing = ImageTextSpacing
                });
            }

            if (_listBoxPlaces.Items.Count > 0)
            {
                SetFolder((string)_listBoxPlaces.Items[0].Tag, false);
            }

            _listBoxPlaces.Items.Add(new ListItem
            {
                IsSeparator = true
            });

            var drives = DriveInfo.GetDrives();

            var iconDrive = DefaultAssets.UISpritesheet["icon-drive"];

            foreach (var d in drives)
            {
                if (d.DriveType == DriveType.Ram)
                {
                    continue;
                }

                try
                {
                    var s = d.RootDirectory.Name;

                    if (!string.IsNullOrEmpty(d.VolumeLabel) && d.VolumeLabel != d.RootDirectory.Name)
                    {
                        s += " (" + d.VolumeLabel + ")";
                    }

                    _listBoxPlaces.Items.Add(new ListItem(s, null, d.RootDirectory.Name)
                    {
                        Image            = iconDrive,
                        ImageTextSpacing = ImageTextSpacing
                    });
                }
                catch (Exception)
                {
                }
            }

            _listBoxPlaces.SelectedIndexChanged += OnPlacesSelectedIndexChanged;

            _gridFiles.SelectionBackground      = DefaultAssets.UISpritesheet["tree-selection"];
            _gridFiles.SelectionHoverBackground = DefaultAssets.UISpritesheet["button-over"];
            _gridFiles.SelectedIndexChanged    += OnGridFilesSelectedIndexChanged;
            _gridFiles.TouchDoubleClick        += OnGridFilesDoubleClick;

            _buttonParent.Click += OnButtonParent;

            _textFieldFileName.TextChanged += (s, a) => UpdateEnabled();

            _buttonBack.Click    += OnButtonBack;
            _buttonForward.Click += OnButtonForward;

            UpdateEnabled();
        }
        public static FileDialog GetDialog(InstancedIFormat2 ThisOne, ApplicationState CurrentState, FileDialogMode Mode)
        {
            if (StringResources == null)
            {
                StringResources = new ResourceManager(typeof(StringResources.Localized_GenericDialog));
            }
            FileDialog ret = null;

            if (CurrentState == null)
            {
                throw new ArgumentNullException(nameof(CurrentState));
            }
            if (ThisOne == null)
            {
                throw new ArgumentNullException(nameof(ThisOne));
            }
            else
            {
                if (Mode.HasFlag(FileDialogMode.UseOpenDialog))
                {
                    ret = new OpenFileDialog
                    {
                        Title = StringResources.GetString("WindowFilePlugin_OpenFragment", CultureInfo.CurrentUICulture)
                    };
                }
                else
                {
                    if (Mode.HasFlag(FileDialogMode.UseSaveDialog))
                    {
                        ret = new SaveFileDialog
                        {
                            Title = StringResources.GetString("WindowFilePlugin_SaveFragment", CultureInfo.CurrentUICulture)
                        };
                    }
                }

                if (ret == null)
                {
                    throw new NotImplementedException(StringResources.GetString("WindowFilePlugin_UnsupportedMode", CultureInfo.CurrentUICulture));
                }
                ret.InitialDirectory = CurrentState.UserDocumentLocation;

                ret.Title += ThisOne.GetFriendlyName();
                ret.Filter = ThisOne.GetDialogBoxExt();
                if (ret.Filter.EndsWith("|", StringComparison.InvariantCultureIgnoreCase))
                {
                    ret.Filter += "All Files (*.*)|*.*";
                }
                else
                {
                    ret.Filter += "|All Files (*.*)|*.*";
                }

                return(ret);
            }
        }
Example #11
0
 /// <summary>
 ///     选取文件
 /// </summary>
 /// <param name="mode">模式</param>
 /// <param name="filter">过滤器</param>
 /// <returns></returns>
 public static string PickFile(FileDialogMode mode, string filter = "*.*(All Files)|*.*")
 {
     FileDialog dialog;
     if (mode == FileDialogMode.Open)
     {
         dialog = new OpenFileDialog();
     }
     else
     {
         dialog = new SaveFileDialog();
     }
     dialog.Filter = filter;
     if (dialog.ShowDialog() == DialogResult.OK)
     {
         return dialog.FileName;
     }
     return string.Empty;
 }
Example #12
0
        /// <summary>
        /// Create a new file dialog.
        /// </summary>
        /// <param name="dialogClass">Dialog class, used for re-using the same path.</param>
        /// <param name="mode">Dialog mode.</param>
        /// <param name="filter">File filter.</param>
        /// <param name="defaultFileName">Default file name.</param>
        /// <param name="defaultPath">Default file path.</param>
        public FileDialog(string dialogClass, FileDialogMode mode, string filter, string defaultFileName = "", string defaultPath = "") : base("Blah", ImGuiNET.ImGuiWindowFlags.Modal, modalMode: true, x: 150, y: 150, width: 700, height: 400)
        {
            //Set vars.
            switch (mode)
            {
            case FileDialogMode.OpenFile:
                Name = "Open File:";
                break;

            case FileDialogMode.SaveFile:
                Name = "Save File:";
                break;

            case FileDialogMode.Directory:
                Name = "Select Directory:";
                break;
            }
            Mode     = mode;
            FileName = defaultFileName;
            Ok       = false;

            //Filters if not dir mode.
            if (Mode != FileDialogMode.Directory)
            {
                //Split the filter.
                string[] strs = filter.Split('|');

                //Load the filters.
                Filters     = new List <Tuple <string, string[]> >();
                FilterTexts = new string[strs.Length / 2];

                //Make sure the filter is legal.
                if (strs.Length == 0 || strs.Length % 2 != 0)
                {
                    throw new Exception("Bad File Filter!");
                }

                //Temp values.
                string   filterText  = "";
                string   description = "";
                string[] extensions;

                //Get filters.
                for (int i = 0; i < strs.Length; i++)
                {
                    //Description.
                    if (i % 2 == 0)
                    {
                        description = strs[i];
                        filterText  = description + " (";
                    }

                    //Extensions.
                    else
                    {
                        //Get extensions.
                        extensions = strs[i].Split(';');

                        //Add to filters.
                        Filters.Add(new Tuple <string, string[]>(description, extensions));

                        //Filter text.
                        filterText        += strs[i] + ")";
                        FilterTexts[i / 2] = filterText;
                    }
                }
            }
        }