diff --git a/Client.Config/Config.cs b/Client.Config/Config.cs index 7a40da5b..4ba4f35d 100644 --- a/Client.Config/Config.cs +++ b/Client.Config/Config.cs @@ -14,6 +14,7 @@ namespace Client.Config public static SubModels.Connection ConnectionConfig; public static SubModels.VendorHmi VendorHmiConfig; public static SubModels.ProdSoftware ProdSoftwareConfig { get; set; } + public static string TextEditorPath { get; set; } public static SubModels.Software[] ExtSoftwaresConfig { get; set; } } diff --git a/Client.Config/SubModels/ServerConfigModel.cs b/Client.Config/SubModels/ServerConfigModel.cs index 09b28e2f..b95597e2 100644 --- a/Client.Config/SubModels/ServerConfigModel.cs +++ b/Client.Config/SubModels/ServerConfigModel.cs @@ -15,6 +15,8 @@ namespace Client.Config.SubModels public string ProdEnabled { get; set; } public string ProdPath { get; set; } public string Autorun { get; set; } + public string EditorPath { get; set; } + public List ExtSoftwares { get; set; } } } diff --git a/Client/Browser_Tools/BrowserJSObject.cs b/Client/Browser_Tools/BrowserJSObject.cs index da2d9bd7..82b812ef 100644 --- a/Client/Browser_Tools/BrowserJSObject.cs +++ b/Client/Browser_Tools/BrowserJSObject.cs @@ -26,7 +26,7 @@ namespace Active_Client.Browser_Tools { public class BrowserJSObject : JSObject { - private struct editorVar + private struct EditorVar { public CfrV8Value func; public CfrV8Context context; @@ -45,6 +45,7 @@ namespace Active_Client.Browser_Tools private static readonly int editorH = 873; private static string jobPath = ""; private static Dictionary editorOpened = new Dictionary(); + private static EditorVar CurrentEditorObject = new EditorVar(); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -659,62 +660,72 @@ namespace Active_Client.Browser_Tools // launch FIle editor public void editProgram(object sender, CfrV8HandlerExecuteEventArgs e) { - if (e.Arguments.Count() < 2) { e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("error_arguments_not_ok"))); return; } - String p = e.Arguments[0].StringValue; + string p = e.Arguments[0].StringValue; if (!System.IO.File.Exists(p)) { e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("file_not_found"))); return; } - - editorVar ev = new editorVar(); - ev.context = CfrV8Context.GetCurrentContext(); - ev.func = e.Arguments[1]; - ev.file = p; - IntPtr handleFound; - if (editorOpened.TryGetValue(p,out handleFound)) - NcWindow.ForceExtFocus(handleFound,0,0,0,0); + if(!System.IO.File.Exists(Config.TextEditorPath)) + { + e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("editor_not_configured"))); + return; + } + + CurrentEditorObject = new EditorVar + { + context = CfrV8Context.GetCurrentContext(), + func = e.Arguments[1], + file = p + }; + + if (editorOpened.TryGetValue(p, out IntPtr handleFound)) + NcWindow.ForceExtFocus(handleFound, 0, 0, 0, 0); else { - Thread t = new Thread(new ParameterizedThreadStart(startNewEditor)); - t.Start(ev); + Thread t = new Thread(startNewEditor); + t.Start(); } } - public void startNewEditor(object obj) + public void startNewEditor() { - //Setup editor Variable - editorVar ev = (editorVar)obj; + Process proc = new Process + { + StartInfo = new ProcessStartInfo() + { + FileName = Config.TextEditorPath, + Arguments = CurrentEditorObject.file + } + }; + + proc.Start(); - //Start Ext editor - ProcessStartInfo PS = new ProcessStartInfo(editorPath, ev.file); - PS.WorkingDirectory = new FileInfo(editorPath).Directory.FullName; - Process proc = Process.Start(PS); proc.WaitForInputIdle(); NcWindow.ForceExtFocus(proc.MainWindowHandle, editorX, editorY, editorW, editorH); - //Add it to dictionary - editorOpened.Add(ev.file, proc.MainWindowHandle); + // Add it to dictionary + editorOpened.Add(CurrentEditorObject.file, proc.MainWindowHandle); - //Wait for Editor Exit + // Wait for Editor Exit proc.WaitForExit(); + + // Remove from dictionary + editorOpened.Remove(CurrentEditorObject.file); - //Remove from dictionary - editorOpened.Remove(ev.file); - - //Force Focus Active + // Force Focus Active NcWindow.ForceStepFocus(); - //call JS return function - callJSFunction(ev.func, null, ev.context); + // Call JS return function + callJSFunction(CurrentEditorObject.func, null, CurrentEditorObject.context); } // Private functions diff --git a/Client/View/OpeningForm.cs b/Client/View/OpeningForm.cs index a609e501..9fa1a0f3 100644 --- a/Client/View/OpeningForm.cs +++ b/Client/View/OpeningForm.cs @@ -283,11 +283,13 @@ namespace Active_Client.View else Config.ProdSoftwareConfig.Enabled = false; + // Paths Config.ProdSoftwareConfig.Path = ProdPath; + Config.TextEditorPath = ConfigResponse.EditorPath; - if(ConfigResponse.ExtSoftwares != null) + if (ConfigResponse.ExtSoftwares != null) Config.ExtSoftwaresConfig = ConfigResponse.ExtSoftwares.ToArray(); - + return true; } diff --git a/Step.Config/Config/serverConfig.xml b/Step.Config/Config/serverConfig.xml index 2ae275c9..ba99af4a 100644 --- a/Step.Config/Config/serverConfig.xml +++ b/Step.Config/Config/serverConfig.xml @@ -22,6 +22,7 @@ true localhost false + C:\Windows\System32\notepad.exe C:\CMS\MTC\ADAPTER\ SCMA true diff --git a/Step.Config/Config/serverConfigValidator.xsd b/Step.Config/Config/serverConfigValidator.xsd index bb2e14ef..ad613015 100644 --- a/Step.Config/Config/serverConfigValidator.xsd +++ b/Step.Config/Config/serverConfigValidator.xsd @@ -35,6 +35,7 @@ + diff --git a/Step.Config/ServerConfigController.cs b/Step.Config/ServerConfigController.cs index 34cd2e42..63369e0e 100644 --- a/Step.Config/ServerConfigController.cs +++ b/Step.Config/ServerConfigController.cs @@ -304,6 +304,7 @@ namespace Step.Config EnableDirectoryBrowsing = Convert.ToBoolean(x.Element("enableDirectoryBrowsing").Value), DatabaseAddress = x.Element("databaseAddress").Value, AutoOpenCmsClient = Convert.ToBoolean(x.Element("autoOpenCmsClient").Value), + TextEditorPath = x.Element("textEditorPath").Value, MTCFolderPath = x.Element("MTCFolderPath").Value, MTCApplicationName = x.Element("MTCApplicationName").Value, MaxAlarmsRows = Convert.ToInt32(x.Element("maxAlarmsRows").Value), diff --git a/Step.Model/ConfigModels/ServerConfigModel.cs b/Step.Model/ConfigModels/ServerConfigModel.cs index a2f5dbb7..9a567482 100644 --- a/Step.Model/ConfigModels/ServerConfigModel.cs +++ b/Step.Model/ConfigModels/ServerConfigModel.cs @@ -15,12 +15,12 @@ namespace Step.Model.ConfigModels public bool EnableDirectoryBrowsing { get; set; } public string DatabaseAddress { get; set; } public bool AutoOpenCmsClient { get; set; } + public string TextEditorPath { get; set; } public string MTCFolderPath { get; set; } public string MTCApplicationName { get; set; } - public Boolean CMSConnectReady { get; set; } + public bool CMSConnectReady { get; set; } public int MaxAlarmsRows { get; set; } public int AlarmToDelete { get; set; } - } } \ No newline at end of file diff --git a/Step.Model/DTOModels/DTOClientConfigurationModel.cs b/Step.Model/DTOModels/DTOClientConfigurationModel.cs index ec11a196..7fddd062 100644 --- a/Step.Model/DTOModels/DTOClientConfigurationModel.cs +++ b/Step.Model/DTOModels/DTOClientConfigurationModel.cs @@ -13,6 +13,7 @@ namespace Step.Model.DTOModels public ushort NcPort { get; set; } public bool ProdEnabled { get; set; } public string ProdPath { get; set; } + public string EditorPath { get; set; } public bool Autorun { get; set; } public bool MgiOption { get; set; } public List ExtSoftwares { get; set; } diff --git a/Step/Controllers/WebApi/ConfigurationController.cs b/Step/Controllers/WebApi/ConfigurationController.cs index 84644f68..473065b8 100644 --- a/Step/Controllers/WebApi/ConfigurationController.cs +++ b/Step/Controllers/WebApi/ConfigurationController.cs @@ -46,6 +46,7 @@ namespace Step.Controllers.WebApi ProdPath = SoftwareProdConfig.Path, ExtSoftwares = ExtSoftwaresConfig, Autorun = ServerStartupConfig.AutoOpenCmsClient, + EditorPath = ServerStartupConfig.TextEditorPath, MgiOption = NcConfig.MgiOption }; diff --git a/Step/wwwroot/src/modules/base-components/modal-load-program.ts b/Step/wwwroot/src/modules/base-components/modal-load-program.ts index 303876ca..13159735 100644 --- a/Step/wwwroot/src/modules/base-components/modal-load-program.ts +++ b/Step/wwwroot/src/modules/base-components/modal-load-program.ts @@ -356,8 +356,9 @@ export default class ModalLoadProgram extends Vue { }) } } - else + else { this.externalEditorOpened = true; + } } endEditor(){