コード例 #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);
            }));
        }
コード例 #2
0
        public async Task <string> OpenFile(FileDialogFilters filters = null)
        {
#if LINUX
            if (await IsKDialogAvailable())
            {
                return(await OpenFileKDialog(filters));
            }
#endif
            return(await OpenFileNfd(filters));
        }
コード例 #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()));
        }
コード例 #4
0
 public Task <string> OpenFile(FileDialogFilters filters = null)
 {
     return(Task.FromResult <string>(null));
 }