public void MoveItem(ShellNewItem item, bool isUp) { int index = this.GetItemIndex(item); int firstIndex = 0; for (int i = 0; i < this.Controls.Count; i++) { Control ctr = this.Controls[i]; if (ctr.GetType() == typeof(ShellNewItem) && ((ShellNewItem)ctr).CanSort) { firstIndex = i; break; } } if (isUp) { if (index > firstIndex) { this.SetItemIndex(item, index - 1); } } else { if (index < this.Controls.Count - 1) { this.SetItemIndex(item, index + 1); } } this.WriteRegistry(); }
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 LoadItems(List<string> extensions) { foreach(string extension in ShellNewItem.UnableSortExtensions) { if(extensions.Contains(extension, StringComparer.OrdinalIgnoreCase)) { extensions.Remove(extension); extensions.Insert(0, extension); } } using(RegistryKey root = Registry.ClassesRoot) { foreach(string extension in extensions) { using(RegistryKey extKey = root.OpenSubKey(extension)) { string defalutOpenMode = extKey?.GetValue("")?.ToString(); if(string.IsNullOrEmpty(defalutOpenMode)) continue; using(RegistryKey openModeKey = root.OpenSubKey(defalutOpenMode)) { if(openModeKey == null) continue; string value1 = openModeKey.GetValue("FriendlyTypeName")?.ToString(); string value2 = openModeKey.GetValue("")?.ToString(); value1 = ResourceString.GetDirectString(value1); if(value1.IsNullOrWhiteSpace() && value2.IsNullOrWhiteSpace()) continue; } using(RegistryKey tKey = extKey.OpenSubKey(defalutOpenMode)) { foreach(string part in ShellNewItem.SnParts) { string snPart = part; if(tKey != null) snPart = $@"{defalutOpenMode}\{snPart}"; using(RegistryKey snKey = extKey.OpenSubKey(snPart)) { if(ShellNewItem.EffectValueNames.Any(valueName => snKey?.GetValue(valueName) != null)) { ShellNewItem item = new ShellNewItem(this, snKey.Name); if(item.BeforeSeparator) { int index2 = this.GetItemIndex(Separator); this.InsertItem(item, index2); } else { this.AddItem(item); } break; } } } } } } } }
public void MoveItem(ShellNewItem shellNewItem, bool isUp) { int index = this.GetItemIndex(shellNewItem); index += isUp ? -1 : 1; if(index == this.Controls.Count) return; Control ctr = this.Controls[index]; if(ctr is ShellNewItem item && item.CanSort) { this.SetItemIndex(shellNewItem, index); this.SaveSorting(); } }
private void LoadCommonItems() { List <string> extensions = new List <string> { "Folder" }; using (RegistryKey root = Registry.ClassesRoot) { extensions.AddRange(Array.FindAll(root.GetSubKeyNames(), keyName => keyName.StartsWith("."))); if (Environment.OSVersion.Version.Major <= 6 && Environment.OSVersion.Version.Minor <= 1) { extensions.Add("Briefcase"); //Win7公文包 } foreach (string extension in extensions) { string typeName = FileExtensionDialog.GetTypeName(extension, false); if (typeName == null) { continue; } using (RegistryKey extKey = root.OpenSubKey(extension)) using (RegistryKey tKey = extKey.OpenSubKey(typeName)) { foreach (string part in ShellNewItem.SnParts) { string snPart = part; if (tKey != null) { snPart = $@"{typeName}\{snPart}"; } using (RegistryKey snKey = extKey.OpenSubKey(snPart)) { if (ValueNames.Any(valueName => snKey?.GetValue(valueName) != null)) { ShellNewItem item = new ShellNewItem(snKey.Name); if (item.ItemText != null) { this.AddItem(item); break; } else { item.Dispose(); } } } } } } } }
private void LoadItems(List <string> extensions) { foreach (string extension in ShellNewItem.UnableSortExtensions) { string str = extensions.Find(ext => ext.Equals(extension, StringComparison.OrdinalIgnoreCase)); if (str != null) { extensions.Remove(str); extensions.Insert(0, str); } } foreach (string extension in extensions) { using (RegistryKey extKey = Registry.ClassesRoot.OpenSubKey(extension)) { string typeName = extKey.GetValue("")?.ToString(); if (typeName == null) { continue; } using (RegistryKey tKey = extKey.OpenSubKey(typeName)) { foreach (string part in ShellNewItem.SnParts) { string snPart = part; if (tKey != null) { snPart = $@"{typeName}\{snPart}"; } using (RegistryKey snKey = extKey.OpenSubKey(snPart)) { if (ValueNames.Any(valueName => snKey?.GetValue(valueName) != null)) { ShellNewItem item = new ShellNewItem(this, snKey.Name); if (item.ItemText != null) { this.AddItem(item); break; } else { item.Dispose(); } } } } } } } }
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(); } } } }; }