Skip to content

Commit

Permalink
Present the warning only when the files open in the editor relate to …
Browse files Browse the repository at this point in the history
…the project being worked on for the following actions
  • Loading branch information
Impertatore committed Mar 9, 2021
1 parent 6936118 commit 0141d95
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 23 deletions.
40 changes: 36 additions & 4 deletions SDLTranscreate/SDLTranscreate/Actions/ConvertProjectAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ public class ConvertProjectAction : AbstractAction

protected override void Execute()
{
var selectedProject = _controllers.ProjectsController.SelectedProjects.FirstOrDefault();
if (selectedProject == null)
{
return;
}

var documents = _controllers.EditorController.GetDocuments()?.ToList();
if (documents != null && documents.Count > 0)
{
var documentProjectIds = documents.Select(a => a.Project.GetProjectInfo().Id.ToString()).Distinct();
if (documentProjectIds.Any(a => a == selectedProject.GetProjectInfo().Id.ToString()))
{
MessageBox.Show(PluginResources.Wanring_Message_CloseAllProjectDocumentBeforeProceeding, PluginResources.TranscreateManager_Name, MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
}

// set the default settings for creating the xliff from the sdlxliff
// these should not be taken from the users settings
var settings = GetSettings();
Expand All @@ -54,15 +71,22 @@ protected override void Execute()
var action = Enumerators.Action.Convert;
var workFlow = Enumerators.WorkFlow.Internal;

var selectedProject = _controllers.ProjectsController.SelectedProjects.FirstOrDefault();
var newProjectLocalFolder = selectedProject?.GetProjectInfo().LocalProjectFolder + "-T";

var newProjectLocalFolder = selectedProject.GetProjectInfo().LocalProjectFolder + "-T";
if (Directory.Exists(newProjectLocalFolder))
{
MessageBox.Show(PluginResources.Warning_Message_ProjectFolderAlreadyExists + Environment.NewLine + Environment.NewLine + newProjectLocalFolder,
PluginResources.Plugin_Name, MessageBoxButton.OK, MessageBoxImage.Information);
return;
}

if (selectedProject.GetProjectInfo().ProjectOrigin == Constants.ProjectOrigin_TranscreateProject)
{
MessageBox.Show(PluginResources.Warning_Message_ProjectAlreadyTranscreateProject,
PluginResources.Plugin_Name, MessageBoxButton.OK, MessageBoxImage.Information);
return;
}

var wizardService = new WizardService(action, workFlow, _pathInfo, _customerProvider,
_imageService, _controllers, _segmentBuilder, settings, _dialogService,
_projectAutomationService, _projectSettingsService);
Expand All @@ -73,7 +97,7 @@ protected override void Execute()
MessageBox.Show(message, PluginResources.Plugin_Name, MessageBoxButton.OK, MessageBoxImage.Information);
return;
}

_controllers.TranscreateController.UpdateProjectData(taskContext);
}

Expand Down Expand Up @@ -123,7 +147,15 @@ private void ProjectsController_SelectedProjectsChanged(object sender, System.Ev

private void SetEnabled()
{
Enabled = _controllers.ProjectsController.SelectedProjects.Count() == 1;
if (_controllers.ProjectsController.SelectedProjects.Count() != 1)
{
Enabled = false;
return;
}

var selectedProject = _controllers.ProjectsController.SelectedProjects.FirstOrDefault();

Enabled = selectedProject?.GetProjectInfo().ProjectOrigin != Constants.ProjectOrigin_TranscreateProject;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,25 @@ protected override void Execute()
{
return;
}

var studioProject = _controllers.ProjectsController.GetProjects()
.FirstOrDefault(a => a.GetProjectInfo().Id.ToString() == project.Id);
if (studioProject == null)
{
return;
}

var documents = _controllers.EditorController.GetDocuments()?.ToList();
if (documents != null && documents.Count > 0)
{
var documentProjectIds = documents.Select(a => a.Project.GetProjectInfo().Id.ToString()).Distinct();
if (documentProjectIds.Any(a => a == project.Id))
{
MessageBox.Show(PluginResources.Wanring_Message_CloseAllProjectDocumentBeforeProceeding, PluginResources.TranscreateManager_Name, MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
}

var action = Enumerators.Action.CreateBackTranslation;
var workFlow = Enumerators.WorkFlow.Internal;

Expand Down Expand Up @@ -142,7 +153,7 @@ private void ProjectsController_SelectedProjectsChanged(object sender, ProjectSe
SetEnabled(e.SelectedProject);
}

private void SetEnabled(Interfaces.IProject selectedProject)
private void SetEnabled(IProject selectedProject)
{
Enabled = selectedProject is Project && !(selectedProject is BackTranslationProject);
}
Expand Down
13 changes: 12 additions & 1 deletion SDLTranscreate/SDLTranscreate/Actions/ExportAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ protected override void Execute()
return;
}

var documents = _controllers.EditorController.GetDocuments()?.ToList();
if (documents != null && documents.Count > 0)
{
var documentProjectIds = documents.Select(a => a.Project.GetProjectInfo().Id.ToString()).Distinct();
if (documentProjectIds.Any(a => a == selectedProject.Id))
{
MessageBox.Show(PluginResources.Wanring_Message_CloseAllProjectDocumentBeforeProceeding, PluginResources.TranscreateManager_Name, MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
}

var action = selectedProject is BackTranslationProject
? Enumerators.Action.ExportBackTranslation
: Enumerators.Action.Export;
Expand Down Expand Up @@ -92,7 +103,7 @@ public override void Initialize()
_projectAutomationService = new ProjectAutomationService(
_imageService, _controllers.TranscreateController, _controllers.ProjectsController, _customerProvider, _studioVersionService);
_projectSettingsService = new ProjectSettingsService();

Enabled = false;
}

Expand Down
11 changes: 11 additions & 0 deletions SDLTranscreate/SDLTranscreate/Actions/ImportAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ protected override void Execute()
return;
}

var documents = _controllers.EditorController.GetDocuments()?.ToList();
if (documents != null && documents.Count > 0)
{
var documentProjectIds = documents.Select(a => a.Project.GetProjectInfo().Id.ToString()).Distinct();
if (documentProjectIds.Any(a => a == selectedProject.Id))
{
MessageBox.Show(PluginResources.Wanring_Message_CloseAllProjectDocumentBeforeProceeding, PluginResources.TranscreateManager_Name, MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
}

var action = selectedProject is BackTranslationProject
? Enumerators.Action.ImportBackTranslation
: Enumerators.Action.Import;
Expand Down
1 change: 1 addition & 0 deletions SDLTranscreate/SDLTranscreate/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public class Constants
{
public static string OriginSystem_TranscreateAutomation = "Transcreate Automation";
public static string ProjectOrigin_TranscreateProject = "Transcreate project";
public static string ProjectOrigin_BackTranslationProject = "Back-Translation project";
}
}
20 changes: 19 additions & 1 deletion SDLTranscreate/SDLTranscreate/PluginResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion SDLTranscreate/SDLTranscreate/PluginResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@
<value>Open folder in explorer?</value>
</data>
<data name="Message_TranscreateReportsCreatedSuccessfully" xml:space="preserve">
<value>The transcreate reports have been created successfully.</value>
<value>The Transcreate reports have been created successfully.</value>
</data>
<data name="Warning_Message_ProjectFolderAlreadyExists" xml:space="preserve">
<value>The project folder already exists!</value>
Expand All @@ -748,4 +748,10 @@
<data name="Warning_Message_ProjectNameSuffixCannotBeNull" xml:space="preserve">
<value>The project name suffix cannot be null!</value>
</data>
<data name="Warning_Message_ProjectAlreadyTranscreateProject" xml:space="preserve">
<value>The project has already been converted to a Transcreate project.</value>
</data>
<data name="Wanring_Message_CloseAllProjectDocumentBeforeProceeding" xml:space="preserve">
<value>Close all documents from the editor that are associated with the selected project before proceeding.</value>
</data>
</root>
2 changes: 1 addition & 1 deletion SDLTranscreate/SDLTranscreate/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.4.9")]
[assembly: AssemblyFileVersion("2.0.4.10")]
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public async Task<FileBasedProject> CreateBackTranslationProject(FileBasedProjec
SourceLanguage = newSourceLanguage,
TargetLanguages = new Language[] { newTargetLanguage },
DueDate = projectInfo.DueDate,
ProjectOrigin = "Back-Translation project",
ProjectOrigin = Constants.ProjectOrigin_BackTranslationProject,
IconPath = iconPath
};

Expand Down Expand Up @@ -528,7 +528,7 @@ private bool LanguageExistsIn(List<Language> values, string value, bool ignoreCa

private bool IsBackTranslationProject(string projectOrigin)
{
return string.Compare(projectOrigin, "Back-Translation project",
return string.Compare(projectOrigin, Constants.ProjectOrigin_BackTranslationProject,
StringComparison.CurrentCultureIgnoreCase) == 0;
}

Expand Down
8 changes: 0 additions & 8 deletions SDLTranscreate/SDLTranscreate/Service/WizardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ public TaskContext ShowWizard(AbstractController controller, out string message)
return null;
}

var documents = _controllers.EditorController.GetDocuments();
if (documents.Any())
{
message = PluginResources.WizardMessage_CloseOpenDocumentsInTheEditor;
return null;
}


_isCancelled = false;
_wizardWindow = new WizardWindow();
_wizardWindow.Loaded += WizardWindowLoaded;
Expand Down
7 changes: 5 additions & 2 deletions SDLTranscreate/SDLTranscreate/TranscreateViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ public void UpdateProjectData(TaskContext taskContext)

if (taskContext.Project.Id != _projectsController.CurrentProject?.GetProjectInfo().Id.ToString())
{
_projectAutomationService.ActivateProject(fileBasedProject);
lock (_lockObject)
{
_projectAutomationService.ActivateProject(fileBasedProject);
}
}

var sourceLanguage = taskContext.Project.SourceLanguage.CultureInfo.Name;
Expand Down Expand Up @@ -1016,7 +1019,7 @@ private string GetRelativePath(string projectPath, string path)

private bool IsBackTranslationProject(string projectOrigin)
{
return string.Compare(projectOrigin, "Back-Translation project",
return string.Compare(projectOrigin, Constants.ProjectOrigin_BackTranslationProject,
StringComparison.CurrentCultureIgnoreCase) == 0;
}

Expand Down
2 changes: 1 addition & 1 deletion SDLTranscreate/SDLTranscreate/pluginpackage.manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PluginPackage xmlns="http://www.sdl.com/Plugins/PluginPackage/1.0">
<PlugInName>Trados Transcreate</PlugInName>
<Version>2.0.4.9</Version>
<Version>2.0.4.10</Version>
<Description>Trados Transcreate is a plugin for Trados Studio designed to help manage the Transcreation process.</Description>
<Author>Community Developers</Author>
<RequiredProduct name="SDLTradosStudio" minversion="16.1" />
Expand Down

0 comments on commit 0141d95

Please sign in to comment.