-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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: Allow plugins to hook into File > Open
#22564
base: master
Are you sure you want to change the base?
Conversation
Hello @jitseniesen! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2024-12-31 18:06:38 UTC |
@spyder-ide/core-developers I took the same approach as the previous PR by Carlos and I moved the code for |
Thanks for working on this @jitseniesen! I opened PR #22576 as a prerequisite of your work because we need to remove some dead code that referenced the open, new, save actions in the Editor. So, please rebase after that PR is merged. |
8a774ef
to
38bcb74
Compare
Thanks, done! |
As discussed in the last Core Team meeting:
|
Hi @jitseniesen. I see you're actively working on this feature at https://github.com/jitseniesen/spyder/tree/plugin-open-tmp if I'm not mistaken. Exciting! Is there a EDIT: I think I've found it: https://github.com/jitseniesen/spyder-notebook/tree/plugin-open. Never mind. |
We want to generalize this action so that it can also be used to open files in other panes, like the Notebook pane. This commit is preparation and it still uses the existing implementation of the action. As a consequence, the shortcut for "Open file" becomes a global shortcut and not restricted to the Editor pane. A side-effect is that the order of the icons in the main toolbar changes (the "Open file" icon now comes before "New file"). This will revert back when the "New file" is also moved to the Application plugin.
As a temporary hack, access the Editor's main widget directly. Following commits will do this properly.
This is a refactoring to simplify the code, in preperation for the next commit in which we also need to trigger application actions in the editor.
The Application plugin owns the shortcut, but does not expose it to the user. Plugins like the Editor plugin that want to expose the shortcut need to do that themselves. This is because making the "Open file" and similar file shortcuts global would be confusing.
On any of the following user actions: * Double clicking a file in the File Explorer plugin, * Double clicking a file in the Projects plugin, * Selecting a file from the current project in the switcher, call the new function open_file_in_plugin() in the Applications plugin. This will allow files to be opened in other plugins.
Keep track of the plugin that has keyboard focus and when this changes, emit a signal to all plugins.
When displaying the Open File dialog, the name of the currently displayed file is used to initialize the dialog. This commit asks the currently focussed plugin first to provide the current filename, and if that fails, the current filename of the Editor is used. The `sig_focused_plugin_changed` signal in the previous commit is used to find which plugin currently has focus.
If the user opens a binary data file with the Open File action, for example a .spydata file, then import the data in the Variable Explorer.
This is the proper way to communicate requests from container to plugin.
It is not clear why one was subtracted from the index, but it seems wrong: `list.insert(index, item)` inserts `item` before the item that is currently in position `index`, which is what we want here.
Also move the shortcut.
Define an attribute `CAN_HANDLE_FILE_ACTIONS` in plugins, set to False by default. If it is set to True, then the plugin's `create_new_file` function is called when the user activates the "New file" action while the plugin has focus.
The Application plugin is in charge of whether file actions are enabled. Other plugins use enable_file_action() to indicate whether the action is enabled for them. The Application plugin stores this information and uses it to enable or disable file actions when focus switches to another plugin.
ade9431
to
e561527
Compare
It is easier to use get_action() to get a reference to the action when needed. This also simplifies the tests.
Since saving files now requires the Application plugin, change the test so that it only tests that the signal for saving a file is emitted.
Put pytest markers for flaky test back in
This should not normally happen, but it does sometimes happen in tests.
This is work in progress, but I want some early feedback on design and stuff.
Description of Changes
This PR revives PR #8798. It provides a mechanism for plugins to register file extensions, so that if a user picks a file with that extension in the dialog window for
File > Open
, the file is opened in that plugin instead of the editor.Here is what it looks like, if the necessary changes are made in the Notebook plugin:
open-notebook.mp4
Issue(s) Resolved
Fixes #22354
Fixes #7794
Affirmation
By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.
I certify the above statement is true and correct:
Jitse Niesen