private int ProcessNotifyMessage(IntPtr hWnd, InteropUtil.OFNOTIFY notifyData)
        {
            switch (notifyData.hdr_code)
            {
            case InteropUtil.CDN_FOLDERCHANGE:
            {
                //CDM_GETFOLDERPATH returns garbage for some standard folders like 'Libraries'
                //var newFolder = GetTextFromCommonDialog(InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd)),
                //                  InteropUtil.CDM_GETFOLDERPATH);
                string newFolder =
                    GetTextFromCommonDialog(InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd)),
                                            InteropUtil.CDM_GETFILEPATH);

                /*
                 * if (m_currentFolder != null && newFolder != null &&
                 *  Util.PathContains(newFolder, m_currentFolder))
                 * {
                 *  m_suppressSelectionChange = true;
                 * }
                 */

                m_currentFolder = newFolder;

                /* #5841 On Windows XP when changing the folder 'newFolder' contains the selected directory twice (e.g. c:\temp\i386\i386)
                 * HACK
                 */
                if (!Directory.Exists(newFolder))
                {
                    try
                    {
                        String lastPart   = System.IO.Path.GetFileName(newFolder);
                        String parent     = Directory.GetParent(newFolder).FullName;
                        String parentFile = System.IO.Path.GetFileName(parent);
                        if (lastPart.Equals(parentFile))
                        {
                            m_currentFolder = parent;
                        }
                    }
                    catch (Exception)
                    {
                        //ignore
                    }
                }
                IntPtr fileNameCombo =
                    InteropUtil.AssumeNonZero(
                        InteropUtil.GetDlgItem(InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd)),
                                               InteropUtil.ID_FileNameCombo));
                if (m_hasDirChangeFired)
                {
                    InteropUtil.SetWindowTextW(fileNameCombo, String.Empty);
                }
                m_hasDirChangeFired = true;

                //refresh the file list to make sure that the extension is shown properly
                IntPtr hParent = InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd));
                SetForegroundWindow(hParent);
                SendKeys.SendWait("{F5}");

                break;
            }

            case InteropUtil.CDN_FILEOK:
            {
                if (!AcceptFiles)
                {
                    return(1);
                }

                IntPtr hParent = InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd));
                ProcessSelection(hParent, false);

                break;
            }

            case InteropUtil.CDN_INITDONE:
            {
                IntPtr hParent = InteropUtil.GetParent(hWnd);
                IntPtr hFile   =
                    InteropUtil.AssumeNonZero(InteropUtil.GetDlgItem(InteropUtil.AssumeNonZero(hParent),
                                                                     InteropUtil.ID_FileNameCombo));
                InteropUtil.SetFocus(hFile);
                break;
            }
            }
            return(0);
        }
Beispiel #2
0
        private int ProcessNotifyMessage(IntPtr hWnd, InteropUtil.OFNOTIFY notifyData)
        {
            switch (notifyData.hdr_code)
            {
            case InteropUtil.CDN_FOLDERCHANGE:
            {
                //CDM_GETFOLDERPATH returns garbage for some standard folders like 'Libraries'
                //var newFolder = GetTextFromCommonDialog(InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd)),
                //                  InteropUtil.CDM_GETFOLDERPATH);
                var newFolder = GetTextFromCommonDialog(InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd)),
                                                        InteropUtil.CDM_GETFILEPATH);

                /*
                 * if (m_currentFolder != null && newFolder != null &&
                 *  Util.PathContains(newFolder, m_currentFolder))
                 * {
                 *  m_suppressSelectionChange = true;
                 * }
                 */

                m_currentFolder = newFolder;
                var fileNameCombo =
                    InteropUtil.AssumeNonZero(
                        InteropUtil.GetDlgItem(InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd)),
                                               InteropUtil.ID_FileNameCombo));
                if (m_hasDirChangeFired)
                {
                    InteropUtil.SetWindowTextW(fileNameCombo, "");
                }
                m_hasDirChangeFired = true;

                //refresh the file list to make sure that the extension is shown properly
                var hParent = InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd));
                SetForegroundWindow(hParent);
                SendKeys.SendWait("{F5}");

                break;
            }

            case InteropUtil.CDN_FILEOK:
            {
                if (!AcceptFiles)
                {
                    return(1);
                }

                var hParent = InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd));
                ProcessSelection(hParent, false);

                break;
            }

            case InteropUtil.CDN_INITDONE:
            {
                var hParent = InteropUtil.GetParent(hWnd);
                var hFile   =
                    InteropUtil.AssumeNonZero(InteropUtil.GetDlgItem(InteropUtil.AssumeNonZero(hParent),
                                                                     InteropUtil.ID_FileNameCombo));
                InteropUtil.SetFocus(hFile);
                break;
            }
            }
            return(0);
        }