internal static int AddExtension(Extensions form, ExtensionObjectList extensionObjectList, int newExtensionIdentity) { TreeView extensionTreeView = form.extensionTreeView; if (newExtensionIdentity < extensionTreeView.Nodes.Count) { newExtensionIdentity = extensionTreeView.Nodes.Count; } newExtensionIdentity++; String description = String.Format("{0} ({1})", LanguageUtil.GetCurrentLanguageString("New", className), newExtensionIdentity); while (CheckIdentityExists(form, extensionObjectList, description)) { newExtensionIdentity++; description = String.Format("{0} ({1})", LanguageUtil.GetCurrentLanguageString("New", className), newExtensionIdentity); } ExtensionObject extensionObject = new ExtensionObject(description, String.Empty, false); extensionObjectList.Add(extensionObject); extensionTreeView.Focus(); extensionTreeView.Nodes.Add(description); extensionTreeView.SelectedNode = extensionTreeView.Nodes[extensionTreeView.Nodes.Count - 1]; return(newExtensionIdentity); }
internal static void LoadExtension(Extensions form, ExtensionObjectList extensionObjectList) { TreeView extensionTreeView = form.extensionTreeView; TextBox descriptionTextBox = form.descriptionTextBox; TextBox extensionTextBox = form.extensionTextBox; CheckBox defaultCheckBox = form.defaultCheckBox; Button removeButton = form.removeButton; foreach (ExtensionObject extensionObject in extensionObjectList) { if (extensionObject.Description != extensionTreeView.SelectedNode.Text) { continue; } descriptionTextBox.Text = extensionObject.Description; //Text document extensionTextBox.Text = extensionObject.Extension; //txt defaultCheckBox.Checked = Convert.ToBoolean(extensionObject.DefaultExtension); //True break; } if (extensionTreeView.SelectedNode.Index == 0) { descriptionTextBox.Enabled = true; extensionTextBox.Enabled = false; removeButton.Enabled = false; } else { descriptionTextBox.Enabled = true; extensionTextBox.Enabled = true; removeButton.Enabled = true; } }
internal void InitializeForm() { InitializeComponent(); SetLanguage(); ControlUtil.SetContextMenuStrip(this, new[] { descriptionTextBox, extensionTextBox }); extensionObjectList = ExtensionManager.LoadExtensionsList(this); ExtensionManager.LoadExtension(this, extensionObjectList); }
internal static void SetListExtensions(Options form) { ListBox extensionListBox = form.extensionListBox; ExtensionObjectList extensionObjectList = ExtensionManager.GetExtensionObjectListFromExFile(); extensionListBox.Items.Clear(); foreach (ExtensionObject extensionObject in extensionObjectList) { extensionListBox.Items.Add(String.Format("{0} (*.{1})", extensionObject.Description, extensionObject.Extension)); } }
private static bool CheckIdentityExists(Extensions form, ExtensionObjectList extensionObjectList, String descriptionToSearch) { TreeView extensionTreeView = form.extensionTreeView; //foreach (ExtensionObject extensionObject in extensionObjectList) //{ // if (extensionObject.Description != extensionTreeView.SelectedNode.Text && extensionObject.Description == descriptionToSearch) // { // return true; // } //} return(extensionObjectList.Cast <ExtensionObject>().Any(extensionObject => extensionObject.Description != extensionTreeView.SelectedNode.Text && extensionObject.Description == descriptionToSearch)); }
internal static void SaveExtension(Extensions form, ExtensionObjectList extensionObjectList) { TreeView extensionTreeView = form.extensionTreeView; TextBox extensionTextBox = form.extensionTextBox; foreach (ExtensionObject extensionObject in extensionObjectList) { if (extensionObject.Description != extensionTreeView.SelectedNode.Text) { continue; } extensionObject.Extension = CheckExtension(extensionTextBox.Text); return; } }
private static ExtensionObjectList LoadExtensionsListPrivate(Extensions form, bool suppressMessageBox) { TreeView extensionTreeView = form.extensionTreeView; ExtensionObjectList extensionObjectList = new ExtensionObjectList(); String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.exFile)); String[] separator = { Environment.NewLine }; String[] splittedFileContent = fileContent.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (splittedFileContent.Length > 0) { extensionTreeView.BeginUpdate(); } foreach (String extensionString in splittedFileContent) { separator[0] = "|"; String[] splittedExtensionContent = extensionString.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (splittedExtensionContent.Length != 3) { if (!suppressMessageBox) { WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("Reading", className)); } FileListManager.SaveFileList(ConstantUtil.exFile, ConstantUtil.defaultExtensionFileContent); return(LoadExtensionsList(form)); } extensionTreeView.Nodes.Add(splittedExtensionContent[0]); //Text document ExtensionObject extensionObject = new ExtensionObject(splittedExtensionContent[0], splittedExtensionContent[1], Convert.ToBoolean(splittedExtensionContent[2])); extensionObjectList.Add(extensionObject); } if (splittedFileContent.Length > 0) { extensionTreeView.EndUpdate(); } extensionTreeView.Focus(); extensionTreeView.SelectedNode = extensionTreeView.Nodes[0]; return(extensionObjectList); }
internal static bool SaveDescription(Extensions form, ExtensionObjectList extensionObjectList) { TreeView extensionTreeView = form.extensionTreeView; TextBox descriptionTextBox = form.descriptionTextBox; if (String.IsNullOrEmpty(descriptionTextBox.Text)) { WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("ExtensionNameNotEmpty", className)); descriptionTextBox.Focus(); return(true); } ExtensionObject selectedExtensionObject = null; foreach (ExtensionObject extensionObject in extensionObjectList) { if (extensionObject.Description != extensionTreeView.SelectedNode.Text && extensionObject.Description == descriptionTextBox.Text) { WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("AlreadyExists", className)); descriptionTextBox.Focus(); return(true); } if (extensionObject.Description == extensionTreeView.SelectedNode.Text) { selectedExtensionObject = extensionObject; } } if (selectedExtensionObject == null) { String error = LanguageUtil.GetCurrentLanguageString("Saving", className); ExtensionException exception = new ExtensionException(error); WindowManager.ShowErrorBox(form, error, exception); return(false); } selectedExtensionObject.Description = descriptionTextBox.Text; extensionTreeView.SelectedNode.Text = selectedExtensionObject.Description; return(true); }
internal static ExtensionObjectList GetExtensionObjectListFromExFile() { ExtensionObjectList extensionObjectList = new ExtensionObjectList(); String fileContent = FileUtil.ReadToEndWithStandardEncoding(Path.Combine(ConstantUtil.ApplicationExecutionPath(), ConstantUtil.exFile)); String[] separator = { Environment.NewLine }; String[] splittedFileContent = fileContent.Split(separator, StringSplitOptions.RemoveEmptyEntries); foreach (String extensionString in splittedFileContent) { separator[0] = "|"; String[] splittedExtensionContent = extensionString.Split(separator, StringSplitOptions.RemoveEmptyEntries); ExtensionObject extensionObject = new ExtensionObject(splittedExtensionContent[0], splittedExtensionContent[1], Convert.ToBoolean(splittedExtensionContent[2])); extensionObjectList.Add(extensionObject); } return(extensionObjectList); }
private static bool SaveExtensionsIntoFilePrivate(Form form, ExtensionObjectList extensionObjectList, bool suppressMessageBox) { String fileContent = String.Empty; foreach (ExtensionObject extensionObject in extensionObjectList) { if (String.IsNullOrEmpty(extensionObject.Extension) || String.IsNullOrEmpty(extensionObject.Description)) { if (!suppressMessageBox) { WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("Unvalorized", className)); } return(false); } fileContent += String.Format("{0}|{1}|{2}{3}", extensionObject.Description, extensionObject.Extension, extensionObject.DefaultExtension, Environment.NewLine); } FileListManager.SaveFileList(ConstantUtil.exFile, fileContent); return(true); }
internal static void SaveDefault(Extensions form, ExtensionObjectList extensionObjectList) { TreeView extensionTreeView = form.extensionTreeView; CheckBox defaultCheckBox = form.defaultCheckBox; if (!defaultCheckBox.Checked) { return; } foreach (ExtensionObject extensionObject in extensionObjectList) { if (extensionObject.Description != extensionTreeView.SelectedNode.Text && extensionObject.DefaultExtension) { extensionObject.DefaultExtension = false; } else if (extensionObject.Description == extensionTreeView.SelectedNode.Text) { extensionObject.DefaultExtension = true; } } }
internal static bool RemoveExtension(Extensions form, ExtensionObjectList extensionObjectList) { TreeView extensionTreeView = form.extensionTreeView; TextBox descriptionTextBox = form.descriptionTextBox; int indexNodeToRemove = extensionTreeView.SelectedNode.Index; int extensionPositionInList = GetExtensionPositionInList(extensionObjectList, descriptionTextBox.Text); if (extensionPositionInList == -1) { String error = LanguageUtil.GetCurrentLanguageString("Removing", className); ExtensionException exception = new ExtensionException(error); WindowManager.ShowErrorBox(form, error, exception); return(false); } extensionObjectList.RemoveAt(extensionPositionInList); extensionTreeView.Focus(); extensionTreeView.Nodes.Remove(extensionTreeView.SelectedNode); extensionTreeView.SelectedNode = extensionTreeView.Nodes.Count > indexNodeToRemove ? extensionTreeView.Nodes[indexNodeToRemove] : extensionTreeView.Nodes[indexNodeToRemove - 1]; return(true); }
private void moveUpButton_Click(object sender, EventArgs e) { extensionObjectList = ExtensionManager.MoveExtension(this, ObjectListUtil.Movement.Up, extensionObjectList); }
internal static bool SaveExtensionsIntoFile(Form form, ExtensionObjectList extensionObjectList) { return(SaveExtensionsIntoFilePrivate(form, extensionObjectList, false)); }
internal static ExtensionObjectList MoveExtension(Extensions form, ObjectListUtil.Movement move, ExtensionObjectList extensionObjectList) { TreeView extensionTreeView = form.extensionTreeView; TreeNode selectedNode = extensionTreeView.SelectedNode; int selectedNodeIndex = extensionTreeView.SelectedNode.Index; ExtensionObject extensionObject = (ExtensionObject)extensionObjectList[selectedNodeIndex]; return((ExtensionObjectList)ObjectListUtil.MoveObject(move, extensionObjectList, extensionObject, extensionTreeView, selectedNode, selectedNodeIndex)); }