예제 #1
0
        /// <summary>Show the actual dialog to allow the user to select a file.</summary>
        /// <example>
        /// <code source='examples\vbnet\ex_addbackgroundbitmap.vb' lang='vbnet'/>
        /// <code source='examples\cs\ex_addbackgroundbitmap.cs' lang='cs'/>
        /// <code source='examples\py\ex_addbackgroundbitmap.py' lang='py'/>
        /// </example>
        /// <returns>true if a file was selected. false if the dialog was canceled</returns>
        /// <since>5.10</since>
        public bool ShowOpenDialog()
        {
            var def_ext      = DefaultExt;
            var filename     = FileName;
            var filter       = Filter;
            var init_dir     = InitialDirectory;
            var title        = Title;
            var ptr_dialog   = UnsafeNativeMethods.CRhinoUiFileDialog_NewOpen(def_ext, filename, filter, init_dir, title, MultiSelect);
            var rc           = UnsafeNativeMethods.CRhinoUiFileDialog_Show(ptr_dialog);
            var ptr_filename = UnsafeNativeMethods.CRhinoUiFileDialog_Filename(ptr_dialog);

            FileName = Marshal.PtrToStringUni(ptr_filename);
            if (MultiSelect)
            {
                using (var array = new Runtime.InteropWrappers.ClassArrayString())
                {
                    var ptr_array = array.NonConstPointer();
                    var count     = UnsafeNativeMethods.CRhinoUiFileDialog_Filenames(ptr_dialog, ptr_array);
                    FileNames = count < 1 ? new string[0] : array.ToArray();
                }
            }
            else
            {
                FileNames = new[] { FileName };
            }
            UnsafeNativeMethods.CRhinoUiFileDialog_Delete(ptr_dialog);
            const int idok = 1;

            return(rc == idok);
        }
예제 #2
0
        /// <summary>Show the actual dialog to allow the user to select a file.</summary>
        /// <example>
        /// <code source='examples\vbnet\ex_addbackgroundbitmap.vb' lang='vbnet'/>
        /// <code source='examples\cs\ex_addbackgroundbitmap.cs' lang='cs'/>
        /// <code source='examples\py\ex_addbackgroundbitmap.py' lang='py'/>
        /// </example>
        /// <returns>true if a file was selected. false if the dialog was canceled</returns>
        /// <since>5.10</since>
        public bool ShowOpenDialog()
        {
            var def_ext      = DefaultExt;
            var filename     = FileName;
            var filter       = Filter;
            var init_dir     = InitialDirectory;
            var title        = Title;
            var ptr_dialog   = UnsafeNativeMethods.CRhinoUiFileDialog_NewOpen(def_ext, filename, filter, init_dir, title, MultiSelect);
            var rc           = UnsafeNativeMethods.CRhinoUiFileDialog_Show(ptr_dialog);
            var ptr_filename = UnsafeNativeMethods.CRhinoUiFileDialog_Filename(ptr_dialog);

            FileName = Marshal.PtrToStringUni(ptr_filename);
            const int idok = 1;

            if (MultiSelect)
            {
                // 1 February 2021 John Morse
                // https://mcneel.myjetbrains.com/youtrack/issue/RH-62568
                // Don't ask for file list when the dialog is canceled otherwise an ASSERT is triggered.
                if (rc == idok)
                {
                    using (var array = new Runtime.InteropWrappers.ClassArrayString())
                    {
                        var ptr_array = array.NonConstPointer();
                        var count     = UnsafeNativeMethods.CRhinoUiFileDialog_Filenames(ptr_dialog, ptr_array);
                        FileNames = count < 1 ? new string[0] : array.ToArray();
                    }
                }
                else
                {
                    FileNames = new string[0];
                }
            }
            else
            {
                FileNames = new[] { FileName };
            }
            UnsafeNativeMethods.CRhinoUiFileDialog_Delete(ptr_dialog);
            return(rc == idok);
        }