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

  • Thanks for responding. I meant my definition of "active" quite precisely. Changing my definition of "active", sadly, does not answer my question. I still need to know how to get access to the properties of the "active" project, as defined in my original question.
  • Also, active is not the same as current. E.g., if you're in the Projects view, and you select a project in the list that is not active, and summon the Project Settings dialog, the project whose settings you're editing is the selected project, but not the active one.

    Let's leave aside the "New project" case for a moment (although I do need it). I've continued to poke around the API and I can't find any way to distinguish between the following two cases:

    - Project A is the current project, Project B is the project that's currently highlighted in the Projects list. In the Projects view, press "Project Settings".

    - Project A is the current project, Project B is the project that's currently highlighted in the Projects list. In the Files view, press "Project Settings".

    In the first case, you're editing Project B's settings; in the second case, Project A's. When I'm in the Browse() method of a ITranslationProviderWinFormsUI, how can I distinguish between these two cases?
  • I think I asked a very clear question. How do I distinguish between the two cases I described in my second response? Does the API give me any way of doing it, or not.

    If you can't answer the question, please don't reply.
  • First, I said "please", and I meant it. I didn't intend to be rude, and I don't think I was. You've spent multiple replies correcting my terminology and not answering my question.

    As you say, the project that Trados judges to be "active" is the CurrentProject in the ProjectsController, and those projects which are selected in the Projects view are the SelectedProjects.

    When I'm in the Browse() method of a ITranslationProviderWinFormsUI, I can get access to the ProjectsController, and there are frequently both a CurrentProject and a single item in the SelectedProjects list. However, depending on how the user got to the Browse() method, the user may be editing the settings for either the CurrentProject or the single item in the SelectedProjects list (or, as I said originally, the settings for a new project which, as you say, is not yet an actual project object). Does the Trados API permit me to distinguish between these cases?

    At the moment, I can find only one method: use reflection to digest the title of the project settings window and match its name to the known projects. But I have a hard time believing that's the right way to do it.
  • 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.