In this release of Studio, public API were improved to make interaction with Studio more easy and more robust.
Based on the feedback we received in the Community we exposed couple of events for: Segment Split action, Segment Merged action. The full list of events will be presented in a separate section of this wiki.
To promote:
- Automation Testing we expose interfaces which will allow users to write Integration Tests by mocking common objects from the Integration API.
- Windows Presentation Foundation (WPF), plugins which have View Parts written using WPF now are recognized by Studio whithout using an Windows Forms Element Host.
Before starting to update your pluginsto support API Changes, please make sure the plugin is migrated correctly to Studio 2021. More information can be found here.
View Parts Changes
How to update plugins which have View Parts
In the bellow example we'll update the DSI VIewer plugin to support the latest chages in the Integration API. The view part of this plugin is written using WPF and is a great example which ilustrates how easy the View Parts can be recognized by Studio.
The source code of this plugin is open Source on our GitHub Repository.
Plugin architecture
Before the API Changes we had to create an Windows Forms Control which had an ElementHost control in which we added our WPF View.
After
After you change the references to point to Studio16 folder you'll see in Visual Studio following error:
Why this error appeared and how to fix it
- First thing we need to do is to make the WPF View to Implement the IUIControl interface exposed by Studio.
- Second we need to remove the reference to WindowsForms control and use the WPF control instead.
In our plugin we use MVVM design pattern, that means we need to add the data context to the view. Before it was added in the WindowsForms Control before settings the WPF control to the Element Host.
As we mentioned before we can delete the Windows Froms control and return the WPF instead. In the class which inherits from AbstractViewPartController we can set the data context of the view.
At this point the error form Visual Studio console should dissapear and the plugin will be successfully be displayed in Studio.
IStudioDocument and IDisplayFilterRowInfo interfaces
We exposed two new interfaces in the Integration API that promotes a testable environment for developers integrating with the Document object.
How to update plugins which have references to Studio Document
If a plugin have a reference to Document this error will appear in Visual Studio:
How to fix it
To fix it is quite simple, you only need to change the type of the object and use the new interface exposed in the API (IStudioDocument)
The same fix applies to the plugins which have references to DisplayFilterRowInfo, we need to use the interface instead IDisplayFilterRowInfo.
New events exposed using IStudioEventAggregator
Based on the feedback we received on the Community we exposed couple of events using Event Aggregator.
Open project for selected language event
This event allows user using the API to open the Files View for a specific target language.
Code sample:
Change source content settings event
This event allows to change the source settings for following properties for a Project:
- Allow source editing
- Allow merge across paragraphs
- Enable Icu Tokenization
Code sample:
Segment split event
User can subscribe to SegmentSplit event and it will be notified every time a segment is split in Studio Editor. Following details are received in the event arguments:
- Document name
- The original segment id which was split
- The ID of the first new segment
- The ID of the second new id
Source code
Segments merged event
SegmentsMergedEvent notifies the user when multiple segments are merged. Following details are received in the event arguments:
- Document name
- Paragraph Unit Id
- The ID of the new segment which resulted after merge operation
- The IDs of the segments which were merged
Source code