Exemple #1
0
        private unsafe Task <string> OpenFileNfd(FileDialogFilters filters)
        {
            // Have to run it in the thread pool to avoid blocking the main thread.
            return(RunAsyncMaybe(() =>
            {
                var filterPtr = IntPtr.Zero;
                byte *outPath;

                if (filters != null)
                {
                    var filterString = string.Join(';', filters.Groups.Select(f => string.Join(',', f.Extensions)));

                    filterPtr = Marshal.StringToCoTaskMemUTF8(filterString);
                }

                sw_nfdresult result;

                try
                {
                    result = sw_NFD_OpenDialog((byte *)filterPtr, null, &outPath);
                }
                finally
                {
                    if (filterPtr != IntPtr.Zero)
                    {
                        Marshal.FreeCoTaskMem(filterPtr);
                    }
                }

                return HandleNfdResult(result, outPath);
            }));
        }
Exemple #2
0
        public async Task <string> OpenFile(FileDialogFilters filters = null)
        {
#if LINUX
            if (await IsKDialogAvailable())
            {
                return(await OpenFileKDialog(filters));
            }
#endif
            return(await OpenFileNfd(filters));
        }
Exemple #3
0
        private static Task <string> OpenFileKDialog(FileDialogFilters filters)
        {
            var sb = new StringBuilder();

            if (filters != null && filters.Groups.Count != 0)
            {
                var first = true;
                foreach (var group in filters.Groups)
                {
                    if (!first)
                    {
                        sb.Append('|');
                    }

                    foreach (var extension in group.Extensions)
                    {
                        sb.AppendFormat(".{0} ", extension);
                    }

                    sb.Append('(');

                    foreach (var extension in group.Extensions)
                    {
                        sb.AppendFormat("*.{0} ", extension);
                    }

                    sb.Append(')');

                    first = false;
                }

                sb.Append("| All Files (*)");
            }

            return(RunKDialog("--getopenfilename", Environment.GetEnvironmentVariable("HOME"), sb.ToString()));
        }
 public Task <string> OpenFile(FileDialogFilters filters = null)
 {
     return(Task.FromResult <string>(null));
 }