private void AddNewItem() { NewItem newItem = new NewItem(); this.AddItem(newItem); newItem.NewItemAdd += (sender, e) => { using (FileExtensionDialog dlg = new FileExtensionDialog()) { if (dlg.ShowDialog() != DialogResult.OK) { return; } string extension = dlg.Extension; string typeName = FileExtensionDialog.GetTypeName(extension, false); using (RegistryKey exKey = Registry.ClassesRoot.OpenSubKey(extension, true)) { exKey.SetValue("", typeName); using (RegistryKey snKey = exKey.CreateSubKey("ShellNew", true)) { snKey.SetValue("NullFile", string.Empty); this.InsertItem(new ShellNewItem(snKey.Name), GetItemIndex(newItem) + 1); } } } }; }
private void AddNewItem() { NewItem newItem = new NewItem(); this.AddItem(newItem); newItem.AddNewItem += (sender, e) => { using (FileExtensionDialog dlg = new FileExtensionDialog()) { if (dlg.ShowDialog() != DialogResult.OK) { return; } string extension = dlg.Extension; string openMode = FileExtension.GetOpenMode(extension); if (string.IsNullOrEmpty(openMode)) { MessageBoxEx.Show(AppString.MessageBox.NoOpenModeExtension); return; } foreach (Control ctr in this.Controls) { if (ctr is ShellNewItem item) { if (item.Extension.Equals(extension, StringComparison.OrdinalIgnoreCase)) { MessageBoxEx.Show(AppString.MessageBox.HasBeenAdded); return; } } } using (RegistryKey exKey = Registry.ClassesRoot.OpenSubKey(extension, true)) using (RegistryKey snKey = exKey.CreateSubKey("ShellNew", true)) { string defaultOpenMode = exKey.GetValue("")?.ToString(); if (string.IsNullOrEmpty(defaultOpenMode)) { exKey.SetValue("", openMode); } snKey.SetValue("NullFile", string.Empty); ShellNewItem item = new ShellNewItem(this, snKey.Name); this.AddItem(item); item.Focus(); if (item.ItemText.IsNullOrWhiteSpace()) { item.ItemText = $"{extension.Substring(1)} file"; } if (ShellNewLockItem.IsLocked) { this.SaveSorting(); } } } }; }
private void AddNewItem() { NewItem newItem = new NewItem(); this.AddItem(newItem); newItem.AddNewItem += (sender, e) => { using (FileExtensionDialog dlg = new FileExtensionDialog()) { if (dlg.ShowDialog() != DialogResult.OK) { return; } string extension = dlg.Extension; foreach (Control ctr in this.Controls) { if (ctr.GetType() == typeof(ShellNewItem)) { if (((ShellNewItem)ctr).Extension.Equals(extension, StringComparison.OrdinalIgnoreCase)) { MessageBoxEx.Show(AppString.MessageBox.HasBeenAdded); return; } } } string typeName = FileExtensionDialog.GetTypeName(extension, false); using (RegistryKey exKey = Registry.ClassesRoot.OpenSubKey(extension, true)) { exKey.SetValue("", typeName); using (RegistryKey snKey = exKey.CreateSubKey("ShellNew", true)) { snKey.SetValue("NullFile", string.Empty); this.AddItem(new ShellNewItem(this, snKey.Name)); if (LockNewItem.IsLocked()) { this.WriteRegistry(); } } } } }; }
private void AddNewItem() { NewItem newItem = new NewItem(); this.AddItem(newItem); newItem.AddNewItem += () => { using (FileExtensionDialog dlg = new FileExtensionDialog()) { if (dlg.ShowDialog() != DialogResult.OK) { return; } string extension = dlg.Extension; if (extension == ".") { return; } string openMode = FileExtension.GetOpenMode(extension); if (string.IsNullOrEmpty(openMode)) { if (AppMessageBox.Show(AppString.Message.NoOpenModeExtension, MessageBoxButtons.OKCancel) == DialogResult.OK) { ExternalProgram.ShowOpenWithDialog(extension); } return; } foreach (Control ctr in this.Controls) { if (ctr is ShellNewItem item) { if (item.Extension.Equals(extension, StringComparison.OrdinalIgnoreCase)) { AppMessageBox.Show(AppString.Message.HasBeenAdded); return; } } } using (RegistryKey root = Registry.ClassesRoot) using (RegistryKey exKey = root.OpenSubKey(extension, true)) using (RegistryKey snKey = exKey.CreateSubKey("ShellNew", true)) { string defaultOpenMode = exKey.GetValue("")?.ToString(); if (string.IsNullOrEmpty(defaultOpenMode)) { exKey.SetValue("", openMode); } byte[] bytes = GetWebShellNewData(extension); if (bytes != null) { snKey.SetValue("Data", bytes, RegistryValueKind.Binary); } else { snKey.SetValue("NullFile", "", RegistryValueKind.String); } ShellNewItem item = new ShellNewItem(this, snKey.Name); this.AddItem(item); item.Focus(); if (item.ItemText.IsNullOrWhiteSpace()) { item.ItemText = FileExtension.GetExtentionInfo(FileExtension.AssocStr.FriendlyDocName, extension); } if (ShellNewLockItem.IsLocked) { this.SaveSorting(); } } } }; }