| 5 | |
| 6 | |
| 7 | class FileList: |
| 8 | |
| 9 | # N.B. this import overridden in PyShellFileList. |
| 10 | from idlelib.editor import EditorWindow |
| 11 | |
| 12 | def __init__(self, root): |
| 13 | self.root = root |
| 14 | self.dict = {} |
| 15 | self.inversedict = {} |
| 16 | self.vars = {} # For EditorWindow.getrawvar (shared Tcl variables) |
| 17 | |
| 18 | def open(self, filename, action=None): |
| 19 | assert filename |
| 20 | filename = self.canonize(filename) |
| 21 | if os.path.isdir(filename): |
| 22 | # This can happen when bad filename is passed on command line: |
| 23 | messagebox.showerror( |
| 24 | "File Error", |
| 25 | f"{filename!r} is a directory.", |
| 26 | master=self.root) |
| 27 | return None |
| 28 | key = os.path.normcase(filename) |
| 29 | if key in self.dict: |
| 30 | edit = self.dict[key] |
| 31 | edit.top.wakeup() |
| 32 | return edit |
| 33 | if action: |
| 34 | # Don't create window, perform 'action', e.g. open in same window |
| 35 | return action(filename) |
| 36 | else: |
| 37 | edit = self.EditorWindow(self, filename, key) |
| 38 | if edit.good_load: |
| 39 | return edit |
| 40 | else: |
| 41 | edit._close() |
| 42 | return None |
| 43 | |
| 44 | def gotofileline(self, filename, lineno=None): |
| 45 | edit = self.open(filename) |
| 46 | if edit is not None and lineno is not None: |
| 47 | edit.gotoline(lineno) |
| 48 | |
| 49 | def new(self, filename=None): |
| 50 | return self.EditorWindow(self, filename) |
| 51 | |
| 52 | def close_all_callback(self, *args, **kwds): |
| 53 | for edit in list(self.inversedict): |
| 54 | reply = edit.close() |
| 55 | if reply == "cancel": |
| 56 | break |
| 57 | return "break" |
| 58 | |
| 59 | def unregister_maybe_terminate(self, edit): |
| 60 | try: |
| 61 | key = self.inversedict[edit] |
| 62 | except KeyError: |
| 63 | print("Don't know this EditorWindow object. (close)") |
| 64 | return |
no outgoing calls
searching dependent graphs…