@@ -157,35 +157,32 @@ def set_filename(self, filename):
157157
158158 def open (self , event = None , editFile = None ):
159159 flist = self .editwin .flist
160+ # Save in case parent window is closed (ie, during askopenfile()).
160161 if flist :
161162 if not editFile :
162163 filename = self .askopenfile ()
163164 else :
164165 filename = editFile
165166 if filename :
166- # If the current window has no filename and hasn't been
167- # modified, we replace its contents (no loss). Otherwise
168- # we open a new window. But we won't replace the
169- # shell window (which has an interp(reter) attribute), which
170- # gets set to "not modified" at every new prompt.
171- # Also, make sure the current window has not been closed,
172- # since it can be closed during the Open File dialog.
173- try :
174- interp = self .editwin .interp
175- except AttributeError :
176- interp = None
177-
178- if self .editwin and not self .filename and \
179- self .get_saved () and not interp :
167+ # If editFile is valid and already open, flist.open will
168+ # shift focus to its existing window.
169+ # If the current window exists and is a fresh unnamed,
170+ # unmodified editor window (not an interpreter shell),
171+ # pass self.loadfile to flist.open so it will load the file
172+ # in the current window (if the file is not already open)
173+ # instead of a new window.
174+ if (self .editwin and
175+ not getattr (self .editwin , 'interp' , None ) and
176+ not self .filename and
177+ self .get_saved ()):
180178 flist .open (filename , self .loadfile )
181179 else :
182180 flist .open (filename )
183181 else :
184182 if self .text :
185183 self .text .focus_set ()
186-
187184 return "break"
188- #
185+
189186 # Code for use outside IDLE:
190187 if self .get_saved ():
191188 reply = self .maybesave ()
0 commit comments