Integrating viewparts
Desktop Integration API provides support for third-party developers to integrate UI view parts inside the Trados Studio desktop applications.
Integrating view parts implies changes, in the way that a view is no longer having one content, but is built by one too many viewparts having at least one main centered viewpart, which is filling its content.
The viewparts can be added to be part of an integrated view (see the sample regarding the integration of a view) or to an existing view (see ProjectsController, FilesController, EditorController).
Integrating view parts inside a custom view
The following example demonstrates how to create a view built by viewparts into a Trados Studio application.
First, create and integrate a view which allows viewparts:
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)
{
}
}
}
Create the main viewpart content of the view.
To define a main content viewpart, 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());
}
}
Define other viewparts and order their relevance by setting the ZIndex
property.
Note
The ZIndex ordering is performed only for the intergrated viewparts and displayed only after Trados Studio viewparts and acts as importance from left to right or top to bottom. The highest ZIndex value is in the left or top and the lowest value is in 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 viewparts inside an existing Trados Studio view
The following example demonstrates how to create a viewpart 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());
}
}
See Also
Reference