-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
gh-44968: Add "Reload from Disk" feature to IDLE #141574
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
Open
ashm-dev
wants to merge
30
commits into
python:main
Choose a base branch
from
ashm-dev:idle
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
39e6187
gh-44968: Add "Reload from Disk" feature to IDLE
ashm-dev 9dacd3d
Use builtins.open for file operations in tests
ashm-dev 884758b
Update Lib/idlelib/iomenu.py
ashm-dev d6f54a2
Simplify file reload by removing cursor restoration
ashm-dev 66ab8ce
Merge branch 'main' into idle
ashm-dev c10c5b9
Fix typo in 'File Not Found' message
ashm-dev 7a88c34
Update error message in test for file reload
ashm-dev 5614c28
fix import
ashm-dev 3ce95d3
Merge remote-tracking branch 'origin/idle' into idle
ashm-dev 545ba86
fix: move local imports to global
ashm-dev 5f5e769
test_iomenu: use unittest.mock.patch and call_args
ashm-dev da37468
IDLE tests: use addCleanup for tempfile removal in test_iomenu
ashm-dev 66e0495
remove comments
ashm-dev a154c9f
refactor(tests): Use mock.patch for messagebox dialogs
ashm-dev bd28bb4
add news
ashm-dev fe997ec
rewrite tests
ashm-dev 0f1795b
Merge branch 'main' into idle
ashm-dev 7421699
Update Doc/whatsnew/3.15.rst
ashm-dev 21c5a9c
Update Misc/NEWS.d/next/IDLE/2025-11-14-20-58-55.gh-issue-44968.rL9dK…
ashm-dev ad17754
Update Doc/whatsnew/3.15.rst
ashm-dev 8672683
Update Doc/whatsnew/3.15.rst
ashm-dev a1e94ca
fix
ashm-dev 9485351
Merge remote-tracking branch 'origin/idle' into idle
ashm-dev 1788b80
fix tsan
ashm-dev 953dc8d
fix tests
ashm-dev a689fd1
Merge branch 'main' into idle
ashm-dev d27c71b
Merge branch 'main' into idle
ashm-dev a77a5c0
Merge branch 'main' into idle
ashm-dev 18a30d2
Update Lib/idlelib/idle_test/test_iomenu.py
ashm-dev 885f2cf
Update Lib/idlelib/idle_test/test_iomenu.py
ashm-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -31,6 +31,7 @@ def __init__(self, editwin): | |||
| self.save_as) | ||||
| self.__id_savecopy = self.text.bind("<<save-copy-of-window-as-file>>", | ||||
| self.save_a_copy) | ||||
| self.__id_reload = self.text.bind("<<reload-window>>", self.reload) | ||||
| self.fileencoding = 'utf-8' | ||||
| self.__id_print = self.text.bind("<<print-window>>", self.print_window) | ||||
|
|
||||
|
|
@@ -40,6 +41,7 @@ def close(self): | |||
| self.text.unbind("<<save-window>>", self.__id_save) | ||||
| self.text.unbind("<<save-window-as-file>>",self.__id_saveas) | ||||
| self.text.unbind("<<save-copy-of-window-as-file>>", self.__id_savecopy) | ||||
| self.text.unbind("<<reload-window>>", self.__id_reload) | ||||
| self.text.unbind("<<print-window>>", self.__id_print) | ||||
| # Break cycles | ||||
| self.editwin = None | ||||
|
|
@@ -237,6 +239,49 @@ def save_a_copy(self, event): | |||
| self.updaterecentfileslist(filename) | ||||
| return "break" | ||||
|
|
||||
| def reload(self, event): | ||||
| """Reload the file from disk, discarding any unsaved changes. | ||||
|
|
||||
| If the file has unsaved changes, ask the user to confirm. | ||||
| """ | ||||
| if not self.filename: | ||||
| messagebox.showinfo( | ||||
| "No File", | ||||
ashm-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
| "This window has no associated file to reload.", | ||||
| parent=self.text) | ||||
| self.text.focus_set() | ||||
| return "break" | ||||
|
|
||||
| if not self.get_saved(): | ||||
| confirm = messagebox.askokcancel( | ||||
| title="Reload File", | ||||
| message=f"Discard changes to {self.filename}?", | ||||
| default=messagebox.CANCEL, | ||||
| parent=self.text) | ||||
| if not confirm: | ||||
| self.text.focus_set() | ||||
| return "break" | ||||
|
|
||||
| # Save cursor position | ||||
| insert_pos = self.text.index("insert") | ||||
| yview_pos = self.text.yview() | ||||
|
|
||||
| # Reload the file | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Trivial comment |
||||
| if self.loadfile(self.filename): | ||||
| # Try to restore cursor position if the file still has that line | ||||
| try: | ||||
| self.text.mark_set("insert", insert_pos) | ||||
| self.text.see("insert") | ||||
| # Restore vertical scroll position | ||||
| self.text.yview_moveto(yview_pos[0]) | ||||
| except Exception: | ||||
| # If position doesn't exist anymore, go to top | ||||
| self.text.mark_set("insert", "1.0") | ||||
| self.text.see("insert") | ||||
|
|
||||
| self.text.focus_set() | ||||
| return "break" | ||||
|
|
||||
| def writefile(self, filename): | ||||
| text = self.fixnewlines() | ||||
| chars = self.encode(text) | ||||
|
|
||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
Misc/NEWS.d/next/IDLE/2025-11-14-20-58-55.gh-issue-44968.rL9dK3.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,4 @@ | ||||||
| Add "Reload from Disk" menu item to IDLE's File menu. This allows users to | ||||||
| easily reload a file from disk, discarding any unsaved changes in the editor. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Remove unnecessary words |
||||||
| The feature is particularly useful when working with version control systems | ||||||
| or when external tools modify files. Patch by ashm-dev. | ||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.