Search Results for

    Show / Hide Table of Contents

    Using Trados Studio FilesController

    The TranslationStudioAutomation API enables you to access the Trados Studio files view and perform file operations.

    Create a custom file list in a viewpart

    This sample demonstrates how to create a custom file list using the FilesController and add it to the files view as a custom viewpart.

    The custom list includes:

    • Two columns: the file name and the total word count from the file
    • Selection synchronization between the custom list and the files view

    Step 1: Implement the user control

    Create a Windows Forms user control to display the file list:

    • C#
    • C#
    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    using Sdl.Desktop.IntegrationApi.Interfaces;
    using Sdl.ProjectAutomation.Core;
    using Sdl.TranslationStudioAutomation.IntegrationApi;
    
    namespace FilesOperations.Sample
    {
        public partial class MyFilesViewPartControl : UserControl, IUIControl
        {
            public MyFilesViewPartControl()
            {
                InitializeComponent();
                GetFilesController().SelectedFilesChanged += OnSelectedFilesChanged;
            }    
    
            private FilesController GetFilesController()
            {
                return SdlTradosStudio.Application.GetController<FilesController>();
            }
    
            private void OnSelectedFilesChanged(object sender, EventArgs eventArgs)
            {
                RepopulateFilesList();
                OpenFileButton.Enabled = false;
            }
    
            private void RepopulateFilesList()
            {
                FilesListView.Items.Clear();
                FilesController filesController = GetFilesController();   
                foreach (ProjectFile file in filesController.SelectedFiles)
                {
                    var item = new ListViewItem(file.Name)
                                   {
                                       Tag = file
                                   };
                    item.SubItems.Add(file.AnalysisStatistics.Total.Words.ToString());
    
                    FilesListView.Items.Add(item);
                }            
            }
    
            private void FilesListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
            {
                OpenFileButton.Enabled = FilesListView.SelectedItems.Count > 0;
            }
    
            private void FilesListView_ItemActivate(object sender, EventArgs e)
            {
                if (FilesListView.SelectedItems.Count == 0)
                {
                    return;
                }
    
                SdlTradosStudio.Application.GetController<EditorController>().Open((ProjectFile)FilesListView.SelectedItems[0].Tag, EditingMode.Translation);
            }
    
            private void OpenFileButton_Click(object sender, EventArgs e)
            {
                var selectedProjectFiles = new List<ProjectFile>();
                for (int i = 0; i < FilesListView.SelectedItems.Count; i++)
                {
                    selectedProjectFiles.Add((ProjectFile)FilesListView.SelectedItems[i].Tag);
                }
    
                if (selectedProjectFiles.Count == 0)
                {
                    return;
                }
    
                try
                {
                    SdlTradosStudio.Application.GetController<EditorController>()
                                   .Open(selectedProjectFiles, EditingMode.Translation);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("Cannot open the project file: \n{0}", ex.Message));
                }
            }
    
            private void AddFileButton_Click(object sender, EventArgs e)
            {
                GetFilesController().AddFiles();
            }        
        }
    }
    

    Step 2: Integrate the viewpart into the files view

    Register the viewpart with the files view:

    using System;
    using System.Windows.Forms;
    using Sdl.Desktop.IntegrationApi;
    using Sdl.Desktop.IntegrationApi.Extensions;
    using Sdl.Desktop.IntegrationApi.Interfaces;
    using Sdl.TranslationStudioAutomation.IntegrationApi;
    
    namespace FilesOperations.Sample
    {
        [ViewPart(
            Id = "MyFilesViewPart", 
            Name = "My Files View Part", 
            Description = "Integrating a view part inside the files view"        
            )]
        [ViewPartLayout(typeof(FilesController), Dock = DockType.Bottom)]
        class MyFilesViewPart : AbstractViewPartController
        {
            protected override IUIControl GetContentControl()
            {
                return _control.Value;
            }
    
            protected override void Initialize()
            {            
            }
    
            private FilesController FilesController
            {
                get { return SdlTradosStudio.Application.GetController<FilesController>(); }
            }
    
            private static readonly Lazy<MyFilesViewPartControl> _control = new Lazy<MyFilesViewPartControl>(() => new MyFilesViewPartControl());                        
        }
    }
    
    • Improve this Doc
    In this article
    Back to top Generated by DocFX