ubsicap / paratext_demo_plugins

Sample code to demonstrate how to create a Paratext plugin
2 stars 4 forks source link

Programmatically Changing Projects #10

Closed GeoDirk closed 2 years ago

GeoDirk commented 2 years ago

We have a use case for when a user is creating a new Dashboard Project to have our plugin be able to switch from the currently connected Paratext project to a different one. Your PluginN example shows how we can open up a closed project which is handy. But now we would like to be able to programmatically from within our Plugin switch the current m_Project to another one that is open.

You have parent.ProjectChanged += ProjectChanged; this in every OnAddedToParent method, but I've never seen the ProjectChanged actually be called. So I'm guessing that you have a way to do this in there somewhere.

Thanks!

FoolRunning commented 2 years ago

I'm going to guess that the question in there is "How does ProjectChanged ever fire?". It should fire whenever the user changes the project for the plugin window via the project dropdown on the Paratext main window.

GeoDirk commented 2 years ago

@FoolRunning I think you will need to give me a screenshot or video of what you are describing. I'm not seeing what you are describing.

But mostly I'm interested in switching projects programmatically from within our plugin if that is possible. Such as, I'm currently connected to the Dedua project and want to switch to CARS both of which are loaded on my machine.

tombogle commented 2 years ago

This is not currently possible. The only way a plugin can open a window for a different project is to call IWindowPluginHost.ShowEmbeddedUi, but that results in the opening of a new embedded child window. it does not change the project of an existing window. This is by design since the ability to select a project is something that is under user control (i.e., even in built-in Paratext child windows). It is possible to retrieve data from a different project and display that in any way you like inside a plugin window, but that window would continue to be associated (as far as Paratext is concerned) with the project selected in the dropdown when that project is active.

On Mon, Aug 15, 2022 at 2:26 PM GeoDirk @.***> wrote:

@FoolRunning https://github.com/FoolRunning I think you will need to give me a screenshot or video of what you are describing. I'm not seeing what you are describing.

But mostly I'm interested in switching projects programmatically from within our plugin if that is possible. Such as, I'm currently connected to the Dedua project and want to switch to CARS both of which are loaded on my machine.

— Reply to this email directly, view it on GitHub https://github.com/ubsicap/paratext_demo_plugins/issues/10#issuecomment-1215579149, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABAITXW6CD7S6QA2ZYG2LOTVZKDUHANCNFSM56S7JEWA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

FoolRunning commented 2 years ago

@GeoDirk, Here is a screenshot of the dropdown that fires the ProjectChanged event when the user changes the value: image

EDIT: As Tom says, there is currently no way for a plugin to change the project associated with a window, that is up to the user (via the dropdown highlighted above). I'm not sure we want to add this functionality since that's not the way that Paratext usually works (i.e. the user controls the project associated with a window, not the application/plugin/Paratext). Maybe it would help to know what you are trying to do (and maybe why?).

GeoDirk commented 2 years ago

@FoolRunning Thanks for the image. Now at least I know what you were talking about. I was looking in the menus.

OK...I don't think anything needs to change on your end because as you all mentioned, we can grab the data from any project through our plugin. We probably need to rewrite some of our code because we had a wrong assumption that we could programmatically change it.

Thanks for the quick responses!