|
21 | 21 |
|
22 | 22 | # Third party imports |
23 | 23 | from qtpy.compat import from_qvariant, getopenfilenames, to_qvariant |
24 | | -from qtpy.QtCore import QByteArray, Qt, Signal, Slot |
| 24 | +from qtpy.QtCore import QByteArray, Qt, Signal, Slot, QDir |
25 | 25 | from qtpy.QtPrintSupport import QAbstractPrintDialog, QPrintDialog, QPrinter |
26 | 26 | from qtpy.QtWidgets import (QAction, QActionGroup, QApplication, QDialog, |
27 | 27 | QFileDialog, QInputDialog, QMenu, QSplitter, |
@@ -1916,27 +1916,49 @@ def load(self, filenames=None, goto=None, word='', |
1916 | 1916 | c_fname = self.get_current_filename() |
1917 | 1917 | if c_fname is not None and c_fname != self.TEMPFILE_PATH: |
1918 | 1918 | basedir = osp.dirname(c_fname) |
| 1919 | + |
1919 | 1920 | self.redirect_stdio.emit(False) |
1920 | 1921 | parent_widget = self.get_current_editorstack() |
1921 | 1922 | if filename0 is not None: |
1922 | 1923 | selectedfilter = get_filter(self.edit_filetypes, |
1923 | 1924 | osp.splitext(filename0)[1]) |
1924 | 1925 | else: |
1925 | 1926 | selectedfilter = '' |
| 1927 | + |
1926 | 1928 | if not running_under_pytest(): |
1927 | | - filenames, _sf = getopenfilenames( |
1928 | | - parent_widget, |
1929 | | - _("Open file"), basedir, |
1930 | | - self.edit_filters, |
1931 | | - selectedfilter=selectedfilter, |
1932 | | - options=QFileDialog.HideNameFilterDetails) |
| 1929 | + # See: spyder-ide/spyder#3291 |
| 1930 | + if sys.platform == 'darwin': |
| 1931 | + dialog = QFileDialog( |
| 1932 | + parent=parent_widget, |
| 1933 | + caption=_("Open file"), |
| 1934 | + directory=basedir, |
| 1935 | + ) |
| 1936 | + dialog.setNameFilters(self.edit_filters.split(';;')) |
| 1937 | + dialog.setOption(QFileDialog.HideNameFilterDetails, True) |
| 1938 | + dialog.setFilter(QDir.AllDirs | QDir.Files | QDir.Drives |
| 1939 | + | QDir.Hidden) |
| 1940 | + dialog.setFileMode(QFileDialog.ExistingFiles) |
| 1941 | + |
| 1942 | + if dialog.exec_(): |
| 1943 | + filenames = dialog.selectedFiles() |
| 1944 | + else: |
| 1945 | + filenames, _sf = getopenfilenames( |
| 1946 | + parent_widget, |
| 1947 | + _("Open file"), |
| 1948 | + basedir, |
| 1949 | + self.edit_filters, |
| 1950 | + selectedfilter=selectedfilter, |
| 1951 | + options=QFileDialog.HideNameFilterDetails, |
| 1952 | + ) |
1933 | 1953 | else: |
1934 | 1954 | # Use a Qt (i.e. scriptable) dialog for pytest |
1935 | 1955 | dialog = QFileDialog(parent_widget, _("Open file"), |
1936 | 1956 | options=QFileDialog.DontUseNativeDialog) |
1937 | 1957 | if dialog.exec_(): |
1938 | 1958 | filenames = dialog.selectedFiles() |
| 1959 | + |
1939 | 1960 | self.redirect_stdio.emit(True) |
| 1961 | + |
1940 | 1962 | if filenames: |
1941 | 1963 | filenames = [osp.normpath(fname) for fname in filenames] |
1942 | 1964 | else: |
|
0 commit comments