How can I tell which project is active?

Hi all -

I have a need to find out something about the active project, which I define as either:

- the project I'm currently creating, if I'm in the "New Project" dialog

- the project that I edit if I press the "Project Settings" button on the top ribbon, if I'm anywhere else

How do I find this out reliably in the API? My first idea was to retrieve the ProjectsController as follows:

ProjectsController c = SdlTradosStudio.Application.GetController<ProjectsController>();

and then grab the CurrentProject; but this is not necessarily the project that I'm lookin at in the project settings window. My next idea was to grab the first element from the SelectedProjects list; but this may be empty if no project is selected in the projects list. And if it IS selected, it's not the project in the New Project dialog, for obvious reasons.

If it's not possible to find the active project as I define it above, is it possible to figure out what view or dialog is active? That is, can I tell whether I'm in the New Project dialog, or in the Projects or Files views?

Thanks in advance -

Sam Bayer

Parents
  • Hi there,

    I just did a quick check by simply adding a little code to one of my plugins like this:

    var controller = SdlTradosStudio.Application.GetController<ProjectsController>();
    var cur = controller.CurrentProject;
    var sel = controller.SelectedProjects.FirstOrDefault();
    var curname = cur != null ? cur.GetProjectInfo().Name : "NULL";
    var selname = sel != null ? sel.GetProjectInfo().Name : "NULL";

    MessageBox.Show($"Current project: {curname}\r\nSelected: {selname}");

     

    Then I double clicked one project in the projects list to make it bold and current. I double clicked to open files view, then opened that file in editor.

    Then I triggered my code from projects view, from files view, and from editor. In all cases it always showed me the one bold formatted project, whose file is displayed in the files view as well as in the editor as "Current" and any project that I had selected by single clicking it in the projects view as the "Selected". When I had not selected any (click in an empty area in projectlist to clear selection) it displayed my current project as usual and NULL for selected project.

    So, yes, there is a clear distinction, and yes, you can rely on it pretty well.

     

    Hope this helps.
    Andreas

  • I've been playing with these various ways of accessing the dialog, and I think you may have missed a crucial case.

    If you double-click in the projects view, you'll make a project active. But that's not the only action you can take in the projects view; you can also single click on a project to make it selected. In that case, the selected project and the active/current project are different. Now, if you press "Project Settings" in the projects view, you edit the selected (not active/current) project, and if you press "Project Settings" while you're in the file view, you edit the active/current (not selected) project. But when you're in the Browse() method, there seems to be no way of programmatically distinguishing between the two cases.
  • Former Member
    0 Former Member in reply to Sam Bayer
    Let me try with my own fingers.
    Can you post your 'Browse()' part ?
Reply Children
No Data