Ejemplo n.º 1
0
 /// <summary>
 /// Specifies a common dialog box.
 /// </summary>
 /// <param name="hwndOwner">A value that represents the window handle of the owner window for the common dialog box.</param>
 /// <returns><see langword="true"/> if the file could be opened; otherwise, <see langword="false"/>.</returns>
 protected override bool RunDialog(IntPtr hwndOwner)
 {
     if (DownlevelDialog != null)
     {
         return(DownlevelDialog.ShowDialog(hwndOwner == IntPtr.Zero ? null : new Interop.WindowHandleWrapper(hwndOwner)) == DialogResult.OK);
     }
     else
     {
         return(RunFileDialog(hwndOwner));
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Displays the file dialog.
        /// </summary>
        /// <param name="owner">Handle to the window that owns the dialog.</param>
        /// <returns>If the user clicks the OK button of the dialog that is displayed (e.g. <see cref="VistaOpenFileDialog" />, <see cref="VistaSaveFileDialog" />), <see langword="true" /> is returned; otherwise, <see langword="false" />.</returns>
        public bool?ShowDialog(Window owner)
        {
            _owner = owner;
            if (DownlevelDialog != null)
            {
                return(DownlevelDialog.ShowDialog(owner));
            }
            else
            {
                IntPtr ownerHandle = owner == null?NativeMethods.GetActiveWindow() : new WindowInteropHelper(owner).Handle;

                return(ShowDialog(ownerHandle));
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Releases the unmanaged resources used by the <see cref="VistaFileDialog" /> and optionally releases the managed resources.
 /// </summary>
 /// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langword="false"/> to release only unmanaged resources.</param>
 protected override void Dispose(bool disposing)
 {
     try
     {
         if (disposing && DownlevelDialog != null)
         {
             DownlevelDialog.Dispose();
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Resets all properties to their default values.
 /// </summary>
 public virtual void Reset()
 {
     if (DownlevelDialog != null)
     {
         DownlevelDialog.Reset();
     }
     else
     {
         _fileNames      = null;
         _filter         = null;
         _filterIndex    = 1;
         _addExtension   = true;
         _defaultExt     = null;
         _options        = 0;
         _title          = null;
         CheckPathExists = true;
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Resets all properties to their default values.
 /// </summary>
 public override void Reset()
 {
     if (DownlevelDialog != null)
     {
         DownlevelDialog.Reset();
     }
     else
     {
         _fileNames    = null;
         _filter       = null;
         _filterIndex  = 1;
         _addExtension = true;
         _defaultExt   = null;
         _options      = 0;
         _showHelp     = false;
         _title        = null;
         _supportMultiDottedExtensions = false;
         CheckPathExists = true;
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        ///  When overridden in a derived class, displays a particular type of common dialog box.
        /// </summary>
        protected override bool RunDialog(IntPtr hwndOwner)
        {
            Window owner = (Window)HwndSource.FromHwnd(hwndOwner).RootVisual;

            _owner = owner;
            if (DownlevelDialog != null)
            {
                return(DownlevelDialog.ShowDialog(owner) ?? false);
            }

            Ookii.Dialogs.Wpf.Interop.IFileDialog dialog = null;
            try
            {
                dialog = CreateFileDialog();
                SetDialogProperties(dialog);
                int result = dialog.Show(hwndOwner);
                if (result < 0)
                {
                    if (result == (int)HRESULT.ERROR_CANCELLED)
                    {
                        return(false);
                    }
                    else
                    {
                        throw System.Runtime.InteropServices.Marshal.GetExceptionForHR(result);
                    }
                }
                return(true);
            }
            finally
            {
                if (dialog != null)
                {
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(dialog);
                }
            }
        }