예제 #1
0
 public ShellNewItem(ShellNewList list, string regPath)
 {
     this.Owner = list;
     InitializeComponents();
     this.RegPath      = regPath;
     BtnMoveUp.Visible = BtnMoveDown.Visible = this.CanSort && LockNewItem.IsLocked();
 }
예제 #2
0
        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.GetType() == typeof(ShellNewItem))
                        {
                            if (((ShellNewItem)ctr).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 (LockNewItem.IsLocked())
                            {
                                this.WriteRegistry();
                            }
                        }
                }
            };
        }
예제 #3
0
        public void WriteRegistry()
        {
            List <string> extensions = new List <string>();

            for (int i = 2; i < this.Controls.Count; i++)
            {
                extensions.Add(((ShellNewItem)Controls[i]).Extension);
            }
            LockNewItem.UnLock();
            Registry.SetValue(ShellNewPath, "Classes", extensions.ToArray());
            LockNewItem.Lock();
        }
예제 #4
0
 public void LoadItems()
 {
     this.AddNewItem();
     this.AddItem(new LockNewItem(this));
     if (LockNewItem.IsLocked())
     {
         this.LoadLockItems();
     }
     else
     {
         this.LoadUnlockItems();
     }
 }
예제 #5
0
        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();
                            }
                        }
                    }
                }
            };
        }