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: Adjust calls to use has_filenames return value of None #5777

Merged
merged 1 commit into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions spyder/plugins/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,7 @@ def new(self, fname=None, editorstack=None, text=None):
# QString when triggered by a Qt signal
fname = osp.abspath(to_text_string(fname))
index = current_es.has_filename(fname)
if index and not current_es.close_file(index):
if index is not None and not current_es.close_file(index):
return

# Creating the editor widget in the first editorstack (the one that
Expand All @@ -1788,7 +1788,7 @@ def update_recent_file_menu(self):
"""Update recent file menu"""
recent_files = []
for fname in self.recent_files:
if not self.is_file_opened(fname) and osp.isfile(fname):
if self.is_file_opened(fname) is None and osp.isfile(fname):
recent_files.append(fname)
self.recent_file_menu.clear()
if recent_files:
Expand Down
26 changes: 24 additions & 2 deletions spyder/widgets/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1319,10 +1319,20 @@ def get_current_filename(self):
return self.data[self.get_stack_index()].filename

def has_filename(self, filename):
"""Return the self.data index position for the filename.

Args:
filename: Name of the file to search for in self.data.

Returns:
The self.data index for the filename. Returns None
if the filename is not found in self.data.
"""
fixpath = lambda path: osp.normcase(osp.realpath(path))
for index, finfo in enumerate(self.data):
if fixpath(filename) == fixpath(finfo.filename):
return index
return None

def set_current_filename(self, filename):
"""Set current filename and return the associated editor instance"""
Expand All @@ -1334,6 +1344,18 @@ def set_current_filename(self, filename):
return editor

def is_file_opened(self, filename=None):
"""Return if filename is in the editor stack.

Args:
filename: Name of the file to search for. If filename is None,
then checks if any file is open.

Returns:
True: If filename is None and a file is open.
False: If filename is None and no files are open.
None: If filename is not None and the file isn't found.
integer: Index of file name in editor stack.
"""
if filename is None:
# Is there any file opened?
return len(self.data) > 0
Expand Down Expand Up @@ -1629,7 +1651,7 @@ def save_as(self, index=None):
if filename:
ao_index = self.has_filename(filename)
# Note: ao_index == index --> saving an untitled file
if ao_index and ao_index != index:
if ao_index is not None and ao_index != index:
if not self.close_file(ao_index):
return
if ao_index < index:
Expand Down Expand Up @@ -1660,7 +1682,7 @@ def save_copy_as(self, index=None):
if filename:
ao_index = self.has_filename(filename)
# Note: ao_index == index --> saving an untitled file
if ao_index and ao_index != index:
if ao_index is not None and ao_index != index:
if not self.close_file(ao_index):
return
if ao_index < index:
Expand Down