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: Fix location of newly created file and directory in Files #14831

Merged
merged 6 commits into from
Mar 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions spyder/plugins/explorer/widgets/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1156,11 +1156,21 @@ def create_new_folder(self, current_path, title, subtitle, is_package):
"<br><br>Error message:<br>%s"
) % (fname, str(error)))

def get_selected_dir(self):
""" Get selected dir
If file is selected the directory containing file is returned.
If multiple items are selected, first item is chosen.
"""
selected_path = self.get_selected_filenames()[0]
if osp.isfile(selected_path):
selected_path = osp.dirname(selected_path)
return fixpath(selected_path)

def new_folder(self, basedir=None):
"""New folder."""

if basedir is None:
fnames = self.get_selected_filenames()
basedir = fixpath(osp.dirname(fnames[0]))
basedir = self.get_selected_dir()

title = _('New folder')
subtitle = _('Folder name:')
Expand Down Expand Up @@ -1189,9 +1199,9 @@ def create_new_file(self, current_path, title, filters, create_func):

def new_file(self, basedir=None):
"""New file"""

if basedir is None:
fnames = self.get_selected_filenames()
basedir = fixpath(osp.dirname(fnames[0]))
basedir = self.get_selected_dir()

title = _("New file")
filters = _("All files")+" (*)"
Expand Down Expand Up @@ -1602,19 +1612,19 @@ def convert_notebooks(self):

def new_package(self, basedir=None):
"""New package"""

if basedir is None:
fnames = self.get_selected_filenames()
basedir = fixpath(osp.dirname(fnames[0]))
basedir = self.get_selected_dir()

title = _('New package')
subtitle = _('Package name:')
self.create_new_folder(basedir, title, subtitle, is_package=True)

def new_module(self, basedir=None):
"""New module"""

if basedir is None:
fnames = self.get_selected_filenames()
basedir = fixpath(osp.dirname(fnames[0]))
basedir = self.get_selected_dir()

title = _("New module")
filters = _("Python files")+" (*.py *.pyw *.ipy)"
Expand Down