public List <ISegmentPair> GetSegmentPairs(IStudioDocument document, bool exportSelectedSegments) { List <ISegmentPair> segmentPairs; if (exportSelectedSegments) { segmentPairs = document.GetSelectedSegmentPairs().ToList(); if (segmentPairs.Count == 0) { var activeSegmentPair = document.GetActiveSegmentPair(); if (activeSegmentPair != null) { segmentPairs = new List <ISegmentPair> { document.GetActiveSegmentPair() }; } } } else { segmentPairs = document.FilteredSegmentPairs.ToList(); } return(segmentPairs); }
private static void UpdateSegmentHandler(Document doc) #endif { //This method may be fired through docChanged event or through settings change. OpusCatProvider.ClearSegmentHandlers(); OpusCatProvider.activeDocument = doc; var project = doc.Project; var projectInfo = project.GetProjectInfo(); LanguageDirection langDir; //Check whether document contains files if (doc.Files.Any()) { //only files of same language can be merged, so taking the langdir of first file is enough langDir = doc.Files.First().GetLanguageDirection(); } else { return; } var activeOpusCatOptions = OpusCatProvider.GetProjectOpusCatOptions(project, langDir); if (activeOpusCatOptions != null) { if (activeOpusCatOptions.Any(x => x.pregenerateMt)) { //The previous solution for pregeneration was to start translating the //whole document as soon as the doc changes. This has a problem: //if you have a massive document, just opening the document will cause a massive //load on the translation service. //So instead this was changed to add a segment changed handler which order only a certain //amount on new translations for the next n segments whenever segment changes. //Previous solution is provided below, commented out. //Assign the handler to field to make it possible to remove it later if (!OpusCatProvider.activeSegmentHandlers.ContainsKey(doc as Document)) { OpusCatProvider.activeSegmentHandlers[doc as Document] = new List <EventHandler>(); } var handler = new EventHandler((x, y) => segmentChanged(langDir, x, y)); OpusCatProvider.activeSegmentHandlers[doc as Document].Add(handler); doc.ActiveSegmentChanged += handler; } } else { return; } }
public IParagraphUnit GetParagraphUnit(IStudioDocument document, string paragraphUnitId) { foreach (var segmentPair in document.SegmentPairs) { if (paragraphUnitId == segmentPair.GetParagraphUnitProperties().ParagraphUnitId.Id) { return(document.GetParentParagraphUnit(segmentPair)); } } return(null); }
private bool IsTranscreateDocument(IStudioDocument document) { var projectInfo = document?.Project?.GetProjectInfo(); if (projectInfo != null) { return(projectInfo.ProjectOrigin == Constants.ProjectOrigin_TranscreateProject || projectInfo.ProjectOrigin == Constants.ProjectOrigin_BackTranslationProject); } return(false); }
public ISegmentPair GetSegmentPair(IStudioDocument document, string paragraphUnitId, string segmentId) { foreach (var segmentPair in document.SegmentPairs) { if (paragraphUnitId == segmentPair.GetParagraphUnitProperties().ParagraphUnitId.Id && segmentId == segmentPair.Properties.Id.Id) { return(segmentPair); } } return(null); }
public SegmentSearcherViewPartControl() { InitializeComponent(); var toolTip = new ToolTip(); toolTip.AutoPopDelay = 5000; toolTip.InitialDelay = 1000; toolTip.ReshowDelay = 500; toolTip.ShowAlways = true; toolTip.SetToolTip(searchButton, "Execute search."); toolTip.SetToolTip(returnButton, "Return to the segment where you executed search."); _currentDoc = null; _currentSegmentPair = null; searchResultsWebBrowser.ObjectForScripting = this; }
private void SetActiveDocument(IStudioDocument document) { if (_activeDocument != null) { _activeDocument.ActiveSegmentChanged -= ActiveDocument_ActiveSegmentChanged; } _activeDocument = document; if (_activeDocument != null) { _activeDocument.ActiveSegmentChanged += ActiveDocument_ActiveSegmentChanged; UpdateDocumentStructureInformation(); UpdateComments(); } }
private void DocumentChanged(IStudioDocument document) { if (_studioDocument != null) { _studioDocument.ActiveSegmentChanged -= StudioDocumentOnActiveSegmentChanged; } _studioDocument = document; _isTranscreateDocument = IsTranscreateDocument(document); if (_isTranscreateDocument) { _studioDocument.ActiveSegmentChanged += StudioDocumentOnActiveSegmentChanged; } SetEnabled(_studioDocument?.GetActiveSegmentPair()); }
private void InitializeDocumentTrackingEvents(IStudioDocument doc) { doc.ActiveSegmentChanged += (o, eventArgs) => AddListViewEvent("ActiveSegmentChanged"); doc.ContentChanged += (sender, args) => AddListViewEvent("Document changed", args.Segments.First().ToString()); doc.ActiveFileChanged += (o, eventArgs) => AddListViewEvent("Active file changed"); doc.ActiveFilePropertiesChanged += (o, eventArgs) => AddListViewEvent("Active file properties changed"); doc.Selection.Changed += (o, eventArgs) => AddListViewEvent("Document selection changed", doc.Selection.Current.ToString()); doc.Selection.Source.Changed += (o, eventArgs) => AddListViewEvent("Source selection changed.", doc.Selection.Source.ToString()); doc.Selection.Target.Changed += (o, eventArgs) => AddListViewEvent("Target selection changed.", doc.Selection.Target.ToString()); }
public async void RegisterDocument(IStudioDocument document) { try { document.ContentChanged += document_ContentChanged; document.SegmentsConfirmationLevelChanged += document_SegmentsConfirmationLevelChanged; var newTrackInfo = new List <TrackInfo>(); var projectInfo = document.Project.GetProjectInfo(); foreach (var file in document.Files) { _logger.Info(string.Format("Registered file: {0}", file.Name)); var trackInfo = await db.GetTrackInfoByFileIdAsync(file.Id, RavenContext.Current.CurrentSession); if (trackInfo == null) { trackInfo = new TrackInfo { FileId = file.Id, FileName = file.Name, ProjectId = projectInfo.Id, ProjectName = projectInfo.Name, Language = file.Language.CultureInfo.Name, FileType = file.FileTypeId }; newTrackInfo.Add(trackInfo); } _trackingInfos.Add(trackInfo); } ActiveDocument = document; await db.AddTrackInfosAsync(newTrackInfo, RavenContext.Current.CurrentSession); _timer.Change(120000, 60000); } catch (Exception exception) { _logger.Debug(exception, @"Error appeared when RegisterDocument"); } }
private void searchButton_Click(object sender, EventArgs e) { var editorController = GetEditorController(); editorController.Activate(); if (editorController.ActiveDocument == null || string.IsNullOrEmpty(findWhatComboBox.Text) || (!inSourceCheckBox.Checked && !inTargetCheckBox.Checked)) { return; } if (useRegexCheckBox.Checked) { try { Regex.IsMatch("DummyText", findWhatComboBox.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } AddFindWhatHisotry(); _currentDoc = editorController.ActiveDocument; _currentSegmentPair = _currentDoc.GetActiveSegmentPair(); var search = GetSearchSettings(); var xhtml = ExecuteSearch(search); var path = SaveXhtml(xhtml); searchResultsWebBrowser.Url = new Uri(path); }
/// <summary> /// Make sure keys are registered against the segment since last change and saves the information /// on the disk /// </summary> /// <param name="document"></param> public async void UnregisterDocument(IStudioDocument document) { try { var keyStrokes = KeyboardTracking.Instance.GetCount(); if (document.ActiveSegmentPair != null) { SetTrackingElement(document.ActiveFile.Id, document.ActiveSegmentPair.Target, keyStrokes); } EnsureSessionIsNotOld(); lock (lockObject) { db.SaveChangesAsync(RavenContext.Current.CurrentSession); } foreach (var file in document.Files) { _trackingInfos.RemoveAll(x => x.FileId == file.Id); } } catch (Exception exception) { _logger.Debug(exception, @"Error appeared when UnregisterDocument"); } }
public static Structures.TrackerProject GetTrackerProjectFromDocument(IStudioDocument doc) { Structures.TrackerProject trackerProject = null; try { var projectInfo = doc.Project.GetProjectInfo(); if (projectInfo != null) { foreach (var project in Tracked.Preferences.TrackerProjects) { if (project.IdStudio != projectInfo.Id.ToString() && string.Compare(project.PathStudio, projectInfo.LocalProjectFolder.Trim() , StringComparison.OrdinalIgnoreCase) != 0) { continue; } trackerProject = project; break; } if (trackerProject == null) { trackerProject = new Structures.TrackerProject { Id = Guid.NewGuid().ToString(), Name = projectInfo.Name, Path = projectInfo.LocalProjectFolder.Trim(), IdStudio = projectInfo.Id.ToString(), NameStudio = projectInfo.Name.Trim(), PathStudio = projectInfo.LocalProjectFolder.Trim(), ClientId = string.Empty, ProjectActivities = new List <Structures.TrackerProjectActivity>(), ProjectStatus = projectInfo.IsCompleted ? "Completed" : "In progress", Description = projectInfo.Description ?? string.Empty, DateStart = projectInfo.CreatedAt, DateCreated = DateTime.Now, DateDue = projectInfo.DueDate ?? DateTime.Now.AddDays(7) }; if (trackerProject.DateDue < DateTime.Now) { trackerProject.DateDue = DateTime.Now.AddDays(1); } trackerProject.DateCompleted = DateTime.Now; Tracked.Preferences.TrackerProjects.Add(trackerProject); Tracked.TarckerCheckNewProjectAdded = true; Tracked.TarckerCheckNewProjectId = trackerProject.Id; } } } catch (Exception) { // ignored } return(trackerProject); }
private static void UpdateSegmentHandler(IStudioDocument doc)
public EditorService(IStudioDocument document) { _document = document; _segmentMetadata = new Dictionary <int, KeyValuePair <string, string> >(); Initialize(); }
private LanguageMappingModel GetCorrespondingLanguageMappingModel(ProjectInfo currentProject, IStudioDocument activeDocument) { var model = Options.LanguageMappings?.FirstOrDefault(l => l.SourceTradosCode.Equals(currentProject.SourceLanguage.IsoAbbreviation, StringComparison.InvariantCultureIgnoreCase) && l.TargetTradosCode.Equals(activeDocument.ActiveFile.Language.IsoAbbreviation, StringComparison.InvariantCultureIgnoreCase)); return(model); }