Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Show all supported text files when opening files with "File > Open" #2973

Merged
merged 11 commits into from
Feb 10, 2016
Merged
26 changes: 18 additions & 8 deletions spyderlib/config/utils.py
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
#==============================================================================
# File extensions supported by Spyder
#==============================================================================
EDIT_FILETYPES = (
EDIT_FILETYPES = [
(_("Python files"), ('.py', '.pyw', '.ipy')),
(_("Cython/Pyrex files"), ('.pyx', '.pxd', '.pxi')),
(_("C files"), ('.c', '.h')),
@@ -44,16 +44,14 @@
(_("Enaml files"), ('.enaml',)),
(_("Configuration files"), ('.properties', '.session', '.ini', '.inf',
'.reg', '.cfg', '.desktop')),
)
]

ALL_FILTER = "%s (*)" % _("All files")

def _create_filter(title, ftypes):
return "%s (*%s)" % (title, " *".join(ftypes))


ALL_FILTER = "%s (*)" % _("All files")


def _get_filters(filetypes):
filters = []
for title, ftypes in filetypes:
@@ -69,7 +67,7 @@ def _get_extensions(filetypes):
return ftype_list


def get_pygments_extensions():
def _get_pygments_extensions():
"""Return all file type extensions supported by Pygments"""
# NOTE: Leave this import here to keep startup process fast!
import pygments.lexers as lexers
@@ -93,7 +91,19 @@ def get_filter(filetypes, ext):
return ''


EDIT_FILTERS = _get_filters(EDIT_FILETYPES)
def get_edit_filetypes():
"""Get all file types supported by the Editor"""
pygments_filetypes = (_("Supported text files"),
_get_pygments_extensions())
return [pygments_filetypes] + EDIT_FILETYPES


def get_edit_filters():
"""Return filters associated with our file types"""
edit_filetypes = get_edit_filetypes()
return _get_filters(edit_filetypes)


EDIT_EXT = _get_extensions(EDIT_FILETYPES)+['']

# Extensions supported by Spyder's Variable explorer
@@ -109,7 +119,7 @@ def get_filter(filetypes, ext):


#==============================================================================
# Detection of OSes specific versions
# Detection of OS specific versions
#==============================================================================
def is_ubuntu():
"Detect if we are running in an Ubuntu-based distribution"
8 changes: 5 additions & 3 deletions spyderlib/plugins/editor.py
Original file line number Diff line number Diff line change
@@ -32,7 +32,8 @@
from spyderlib.utils import encoding, sourcecode, codeanalysis
from spyderlib.config.base import get_conf_path, _
from spyderlib.config.main import CONF
from spyderlib.config.utils import EDIT_FILTERS, EDIT_FILETYPES, get_filter
from spyderlib.config.utils import (get_edit_filters, get_edit_filetypes,
get_filter)
from spyderlib.config.gui import get_color_scheme
from spyderlib.utils import programs
from spyderlib.utils.qthelpers import (create_action, add_actions,
@@ -1653,12 +1654,13 @@ def load(self, filenames=None, goto=None, word='', editorwindow=None,
self.redirect_stdio.emit(False)
parent_widget = self.get_current_editorstack()
if filename0 is not None:
selectedfilter = get_filter(EDIT_FILETYPES,
selectedfilter = get_filter(get_edit_filetypes(),
osp.splitext(filename0)[1])
else:
selectedfilter = ''
filenames, _selfilter = getopenfilenames(parent_widget,
_("Open file"), basedir, EDIT_FILTERS,
_("Open file"), basedir,
get_edit_filters(),
selectedfilter=selectedfilter)
self.redirect_stdio.emit(True)
if filenames:
10 changes: 6 additions & 4 deletions spyderlib/widgets/editor.py
Original file line number Diff line number Diff line change
@@ -31,8 +31,8 @@
from spyderlib.utils import encoding, sourcecode, codeanalysis
from spyderlib.utils import introspection
from spyderlib.config.base import _, DEBUG, STDOUT, STDERR
from spyderlib.config.utils import (EDIT_EXT, EDIT_FILTERS, EDIT_FILETYPES,
get_filter)
from spyderlib.config.utils import (EDIT_EXT, get_edit_filters,
get_edit_filetypes, get_filter)
from spyderlib.config.gui import create_shortcut, new_shortcut
from spyderlib.utils.qthelpers import (create_action, add_actions,
mimedata2url, get_filetype_icon,
@@ -1261,11 +1261,13 @@ def file_saved_in_other_editorstack(self, index, filename):
finfo.lastmodified = QFileInfo(finfo.filename).lastModified()

def select_savename(self, original_filename):
selectedfilter = get_filter(EDIT_FILETYPES,
selectedfilter = get_filter(get_edit_filetypes(),
osp.splitext(original_filename)[1])
self.redirect_stdio.emit(False)
filename, _selfilter = getsavefilename(self, _("Save Python script"),
original_filename, EDIT_FILTERS, selectedfilter)
original_filename,
get_edit_filters(),
selectedfilter)
self.redirect_stdio.emit(True)
if filename:
return osp.normpath(filename)