| Integrating viewparts |
Desktop Integration Api provides support for the third party developers to integrate UI view parts inside the SDL 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 to many view parts having at least one main centered viewpart which is filling its content.
The view parts 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 ).
The following example demonstrates how to create a view built by viewparts into a Studio application.
First create and integrate a view which 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 Sdl.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 view part content of the view.
To define a 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; namespace Sdl.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 System.Windows.Forms.Control GetContentControl() { return _control.Value; } protected override void Initialize() { } private readonly Lazy<MyCustomViewPartContentControl> _control = new Lazy<MyCustomViewPartContentControl>(() => new MyCustomViewPartContentControl()); } }
Define other view parts and order their relevance by setting the ZIndex property.
The ZIndex ordering is performed only for the intergrated viewparts and displayed only after SDL 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.TranslationStudioAutomation.IntegrationApi; namespace Sdl.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 System.Windows.Forms.Control 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; namespace Sdl.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 System.Windows.Forms.Control 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; namespace Sdl.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 System.Windows.Forms.Control GetContentControl() { return _control.Value; } protected override void Initialize() { } private readonly Lazy<MyCustomViewPart3Control> _control = new Lazy<MyCustomViewPart3Control>(() => new MyCustomViewPart3Control()); } }
The following example demonstrates how to create a view part and integrate it into the SDL 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.TranslationStudioAutomation.IntegrationApi; namespace Sdl.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 Control 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()); } }