Integrating View Parts
The Desktop Integration API allows third-party developers to integrate custom UI view parts into Trados Studio desktop applications.
View parts allow you to build a view from multiple parts instead of a single content area. A view typically has one main content view part (with Dock set to Fill) and one or more additional view parts.
You can add view parts to a custom view or to existing Trados Studio views such as ProjectsController, FilesController, or EditorController.
Integrating View Parts in a Custom View
The following example demonstrates how to create a view built from view parts in a Trados Studio application.
Step 1: Create a View That Allows View Parts
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sdl.Desktop.IntegrationApi;
using Sdl.Desktop.IntegrationApi.Extensions;
using Sdl.TranslationStudioAutomation.IntegrationApi.Presentation;
using Sdl.TranslationStudioAutomation.IntegrationApi.Presentation.DefaultLocations;
namespace ViewParts.Sample
{
[View(
Id ="MyViewWithViewParts",
Name = "My View with ViewParts",
Description = "Sample of a view which allows view parts",
LocationByType = typeof(TranslationStudioDefaultViews.TradosStudioViewsLocation),
AllowViewParts = true)]
class MyViewWithParts: AbstractViewController
{
protected override void Initialize(IViewContext context)
{
}
}
}
Step 2: Create the Main View Part Content
To define the main content view part, set the Dock property of the ViewPartLayoutAttribute attribute to Fill.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sdl.Desktop.IntegrationApi;
using Sdl.Desktop.IntegrationApi.Extensions;
using Sdl.Desktop.IntegrationApi.Interfaces;
namespace ViewParts.Sample
{
[ViewPart(
Id = "MyCustomViewPartContent",
Name = "My Custom ViewPart Content",
Description = "This is a sample of viewpart content.")]
[ViewPartLayout(Dock = DockType.Fill, LocationByType = typeof(MyViewWithParts))]
public class MyCustomViewPartContent: AbstractViewPartController
{
protected override IUIControl GetContentControl()
{
return _control.Value;
}
protected override void Initialize()
{
}
private readonly Lazy<MyCustomViewPartContentControl> _control = new Lazy<MyCustomViewPartContentControl>(() => new MyCustomViewPartContentControl());
}
}
Step 3: Create Additional View Parts
Define other view parts and order them by setting the ZIndex property.
Note
The ZIndex ordering applies only to integrated view parts and displays after Trados Studio's default view parts. Higher ZIndex values appear on the left or top; lower values appear on the right or bottom.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sdl.Desktop.IntegrationApi;
using Sdl.Desktop.IntegrationApi.Extensions;
using Sdl.Desktop.IntegrationApi.Interfaces;
using Sdl.TranslationStudioAutomation.IntegrationApi;
namespace ViewParts.Sample
{
[ViewPart(
Id = "MyCustomViewPart1",
Name = "My Custom ViewPart 1",
Description = "This is a sample of viewpart.")]
[ViewPartLayout(LocationByType = typeof(MyViewWithParts), ZIndex = 2, Dock = DockType.Bottom)]
public class MyCustomViewPart1 : AbstractViewPartController
{
protected override IUIControl GetContentControl()
{
return _control.Value;
}
protected override void Initialize()
{
}
private readonly Lazy<MyCustomViewPart1Control> _control = new Lazy<MyCustomViewPart1Control>(() => new MyCustomViewPart1Control());
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sdl.Desktop.IntegrationApi;
using Sdl.Desktop.IntegrationApi.Extensions;
using Sdl.Desktop.IntegrationApi.Interfaces;
namespace ViewParts.Sample
{
[ViewPart(
Id = "MyCustomViewPart2",
Name = "My Custom ViewPart 2",
Description = "This is a sample of viewpart.")]
[ViewPartLayout(Dock = DockType.Bottom,LocationByType = typeof(MyViewWithParts), ZIndex = 1)]
public class MyCustomViewPart2 : AbstractViewPartController
{
protected override IUIControl GetContentControl()
{
return _control.Value;
}
protected override void Initialize()
{
}
private readonly Lazy<MyCustomViewPart2Control> _control = new Lazy<MyCustomViewPart2Control>(() => new MyCustomViewPart2Control());
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sdl.Desktop.IntegrationApi;
using Sdl.Desktop.IntegrationApi.Extensions;
using Sdl.Desktop.IntegrationApi.Interfaces;
namespace ViewParts.Sample
{
[ViewPart(
Id = "MyCustomViewPart3",
Name = "My Custom ViewPart 3",
Description = "This is a sample of viewpart.")]
[ViewPartLayout(Dock = DockType.Bottom, LocationByType = typeof(MyViewWithParts), ZIndex = 3)]
public class MyCustomViewPart3 : AbstractViewPartController
{
protected override IUIControl GetContentControl()
{
return _control.Value;
}
protected override void Initialize()
{
}
private readonly Lazy<MyCustomViewPart3Control> _control = new Lazy<MyCustomViewPart3Control>(() => new MyCustomViewPart3Control());
}
}
Integrating View Parts in Existing Trados Studio Views
The following example demonstrates how to create a view part and integrate it into the Trados Studio Projects View.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Sdl.Desktop.IntegrationApi;
using Sdl.Desktop.IntegrationApi.Extensions;
using Sdl.Desktop.IntegrationApi.Interfaces;
using Sdl.TranslationStudioAutomation.IntegrationApi;
namespace ViewParts.Sample
{
[ViewPart(
Id = "MyProjectViewPart",
Name = "My Project View Part",
Description = "Integrationg a view part inside the project view")]
[ViewPartLayout(Dock = DockType.Bottom, LocationByType = typeof(ProjectsController))]
class MyProjectViewPart : AbstractViewPartController
{
protected override IUIControl GetContentControl()
{
return _control.Value;
}
protected override void Initialize()
{
var projectController = SdlTradosStudio.Application.GetController<ProjectsController>();
projectController.CurrentProjectChanged += (s, e) =>
{
if (projectController.CurrentProject == null)
return;
_control.Value.CurrentProject = projectController.CurrentProject.FilePath;
};
projectController.SelectedProjectsChanged += (s, e) =>
{
_control.Value.SelectedProjectsCount = projectController.SelectedProjects.Count();
};
}
private static readonly Lazy<MyProjectViewPartControl> _control = new Lazy<MyProjectViewPartControl>(() => new MyProjectViewPartControl());
}
}