internal static TemplateObjectList GetTemplateObjectListFromTmFile(Form form) { try { TemplateObjectList templateObjectList = new TemplateObjectList(); String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.tmFile)); String[] separator = { Environment.NewLine }; String[] splittedFileContent = fileContent.Split(separator, StringSplitOptions.RemoveEmptyEntries); foreach (String extensionString in splittedFileContent) { separator[0] = "@|-"; String[] splittedExtensionContent = extensionString.Split(separator, StringSplitOptions.None); TemplateObject templateObject = new TemplateObject(splittedExtensionContent[0], splittedExtensionContent[1]); templateObjectList.Add(templateObject); } return(templateObjectList); } catch (Exception) { WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("ErrorReading", className)); FileListManager.SaveFileList(ConstantUtil.tmFile, String.Empty); return(GetTemplateObjectListFromTmFile(form)); } }
internal static int AddTemplate(Templates form, TemplateObjectList templateObjectList, int newTemplateIdentity) { TreeView templateTreeView = form.templateTreeView; TextBox descriptionTextBox = form.descriptionTextBox; TextBox textTextBox = form.textTextBox; Button removeButton = form.removeButton; String newTemplate = LanguageUtil.GetCurrentLanguageString("New", className); newTemplateIdentity++; String description = String.Format("{0} ({1})", newTemplate, newTemplateIdentity); while (CheckIdentityExists(form, templateObjectList, description)) { newTemplateIdentity++; description = String.Format("{0} ({1})", newTemplate, newTemplateIdentity); } TemplateObject extensionObject = new TemplateObject(description, String.Empty); templateObjectList.Add(extensionObject); templateTreeView.Focus(); templateTreeView.Nodes.Add(description); templateTreeView.SelectedNode = templateTreeView.Nodes[templateTreeView.Nodes.Count - 1]; descriptionTextBox.Enabled = true; textTextBox.Enabled = true; removeButton.Enabled = true; return(newTemplateIdentity); }
internal static TemplateObjectList LoadTemplatesList(Templates form) { TreeView templateTreeView = form.templateTreeView; TextBox descriptionTextBox = form.descriptionTextBox; TextBox textTextBox = form.textTextBox; Button removeButton = form.removeButton; TemplateObjectList templateObjectList = new TemplateObjectList(); String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.tmFile)); String[] separator = { Environment.NewLine }; String[] splittedFileContent = fileContent.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (splittedFileContent.Length > 0) { templateTreeView.BeginUpdate(); } foreach (String templateString in splittedFileContent) //HTML@|-<html></html> { separator[0] = "@|-"; String[] splittedExtensionContent = templateString.Split(separator, StringSplitOptions.None); if (splittedExtensionContent.Length != 2) { WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("ErrorReading", className)); FileListManager.SaveFileList(ConstantUtil.tmFile, String.Empty); return(LoadTemplatesList(form)); } templateTreeView.Nodes.Add(splittedExtensionContent[0]); //HTML TemplateObject templateObject = new TemplateObject(splittedExtensionContent[0], splittedExtensionContent[1]); templateObjectList.Add(templateObject); } if (splittedFileContent.Length > 0) { templateTreeView.EndUpdate(); } templateTreeView.Focus(); if (templateTreeView.Nodes.Count > 0) { templateTreeView.SelectedNode = templateTreeView.Nodes[0]; } else { descriptionTextBox.Enabled = false; textTextBox.Enabled = false; removeButton.Enabled = false; } return(templateObjectList); }