private void mnu_rename(object sender, EventArgs e)
 {
     if (this.Folder.Parent != null)
     {
         TreeViewWix tv = this.TreeView as TreeViewWix;
         Form        f  = null;
         if (this.TreeView != null)
         {
             f = this.TreeView.FindForm();
         }
         DlgFolderName dlg = new DlgFolderName();
         dlg.Text = string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                  "Current folder name:{0}", this.Text);
         dlg.LoadData(Folder.Parent.Folders);
         dlg.SetName(Text);
         if (dlg.ShowDialog(f) == DialogResult.OK)
         {
             Text = dlg.NewName;
             Folder.FolderName = dlg.NewName;
             if (tv != null)
             {
                 tv.OnPropertyValueChanged();
             }
         }
     }
 }
        private void mnu_addSourceProject(object sender, EventArgs e)
        {
            TreeViewWix tv = this.TreeView as TreeViewWix;
            Form        f  = null;

            if (this.TreeView != null)
            {
                f = this.TreeView.FindForm();
            }
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = "Limnor Project|*.lrproj";
            dlg.Title  = "Select Limnor Project File";
            if (dlg.ShowDialog(f) == DialogResult.OK)
            {
                Folder.AddProject(dlg.FileName);
                if (tv != null)
                {
                    tv.OnPropertyValueChanged();
                }
                UserControlSetupProperties ucp = getHolder();
                if (ucp != null)
                {
                    ucp.OnSelectTreeNode(this);
                }
            }
        }
        private void mnu_delFolder(object sender, EventArgs e)
        {
            IWixFolder wf = Folder.Parent;

            if (wf != null)
            {
                TreeViewWix tv = this.TreeView as TreeViewWix;
                Form        f  = null;
                if (this.TreeView != null)
                {
                    f = this.TreeView.FindForm();
                }
                if (MessageBox.Show(f, "Do you want to remove this folder?", Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    TreeNode tnp = this.Parent;
                    XmlNode  p   = Folder.XmlData.ParentNode;
                    this.Remove();
                    p.RemoveChild(Folder.XmlData);
                    wf.ResetSubFolders();
                    if (tv != null)
                    {
                        tv.OnPropertyValueChanged();
                    }
                }
            }
        }
        private void mnu_removeCulture(object sender, EventArgs e)
        {
            TreeNode pn = this.Parent;

            if (pn.Nodes.Count > 1)
            {
                TreeViewWix tv = this.TreeView as TreeViewWix;
                Form        f  = null;
                if (this.TreeView != null)
                {
                    f = this.TreeView.FindForm();
                }
                if (MessageBox.Show(f, "Do you want to remove this culture from the setup?", "Remove Culture", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    WixCultureNode         cn  = this.CultureNode;
                    TreeNodeWixCultureList tcl = pn as TreeNodeWixCultureList;
                    if (tcl != null)
                    {
                        tcl.Cultures.CultureList.Remove(cn);
                    }
                    XmlNode wp = cn.XmlData.ParentNode;
                    wp.RemoveChild(cn.XmlData);
                    this.Remove();
                    if (tv != null)
                    {
                        tv.OnPropertyValueChanged();
                    }
                }
            }
        }
        private void mnu_addFolder(object sender, EventArgs e)
        {
            TreeViewWix tv = this.TreeView as TreeViewWix;
            Form        f  = null;

            if (this.TreeView != null)
            {
                f = this.TreeView.FindForm();
            }
            DlgFolderName dlg = new DlgFolderName();

            dlg.LoadData(Folder.Folders);
            if (dlg.ShowDialog(f) == DialogResult.OK)
            {
                this.Expand();
                WixFolderNode     fo = Folder.AddFolder(dlg.NewName);
                TreeNodeWixFolder tn = new TreeNodeWixFolder(fo);
                tn.SelectFile += new EventHandler(tn_SelectFile);
                Nodes.Add(tn);
                if (this.TreeView != null)
                {
                    this.TreeView.SelectedNode = tn;
                }
                if (tv != null)
                {
                    tv.OnPropertyValueChanged();
                    UserControlSetupProperties ucp = getHolder();
                    if (ucp != null)
                    {
                        ucp.OnSelectTreeNode(tn);
                    }
                }
            }
        }
        public void mnu_removeUncheckedFiles(object sender, EventArgs e)
        {
            WixFolderNode             app    = Folder;
            IList <WixSourceFileNode> unused = app.RemoveUnusedFiles();
            TreeViewWix tv = this.TreeView as TreeViewWix;

            tv.OnFilesRemoved(unused);
        }
        void General_VersionChanged(object sender, EventArgs e)
        {
            TreeViewWix tv = this.TreeView as TreeViewWix;

            if (tv != null)
            {
                EventArgsNameChange en = e as EventArgsNameChange;
                if (en != null)
                {
                    tv.OnVersionChanged(en.OldName, en.NewName);
                }
            }
        }
        void node_IdChanged(object sender, EventArgs e)
        {
            Text = IconNode.ToString();
            TreeViewWix tv = this.TreeView as TreeViewWix;

            if (tv != null)
            {
                EventArgsNameChange en = e as EventArgsNameChange;
                if (en != null)
                {
                    tv.OnIconIdChanged(en.OldName, en.NewName);
                }
            }
        }
        private void mnu_addShortcut(object sender, EventArgs e)
        {
            this.Expand();
            WixShortcut         st = this.ShortcutNodes.AddShortcut();
            TreeNodeWixShortcut ts = new TreeNodeWixShortcut(st);

            Nodes.Add(ts);
            if (this.TreeView != null)
            {
                this.TreeView.SelectedNode = ts;
            }
            TreeViewWix tv = this.TreeView as TreeViewWix;

            if (tv != null)
            {
                tv.OnPropertyValueChanged();
            }
        }
        public void mnu_addFiles(object sender, EventArgs e)
        {
            TreeViewWix tv = this.TreeView as TreeViewWix;
            Form        f  = null;

            if (this.TreeView != null)
            {
                f = this.TreeView.FindForm();
            }
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Multiselect = true;
            if (dlg.ShowDialog(f) == DialogResult.OK)
            {
                string[] ss = dlg.FileNames;
                if (ss != null && ss.Length > 0)
                {
                    bool          b   = false;
                    WixFolderNode app = Folder;
                    for (int i = 0; i < ss.Length; i++)
                    {
                        WixSourceFileNode existFile = app.GetWixNodeByName(ss[i]);
                        if (existFile == null)
                        {
                            existFile = app.AddFile(ss[i]);
                            b         = true;
                        }
                        if (SelectFile != null)
                        {
                            SelectFile(existFile, EventArgs.Empty);
                        }
                    }
                    if (b && tv != null)
                    {
                        tv.OnPropertyValueChanged();
                        UserControlSetupProperties ucp = getHolder();
                        if (ucp != null)
                        {
                            ucp.OnSelectTreeNode(this);
                        }
                    }
                }
            }
        }
        public void mnu_addSourceFolder(object sender, EventArgs e)
        {
            TreeViewWix tv = this.TreeView as TreeViewWix;
            Form        f  = null;

            if (this.TreeView != null)
            {
                f = this.TreeView.FindForm();
            }
            FolderBrowserDialog dlg = new FolderBrowserDialog();

            dlg.Description = "All files in the selected folder will be included in the setup";
            if (dlg.ShowDialog(f) == DialogResult.OK)
            {
                bool b = true;
                WixSourceFileNode fn = Folder.GetWixNodeByName(dlg.SelectedPath);
                if (fn != null)
                {
                    MessageBox.Show(f, "Source folder is already included", "Add Source Folder", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    b = false;
                }
                else
                {
                    fn = Folder.AddFile(dlg.SelectedPath);
                }
                if (SelectFile != null)
                {
                    SelectFile(fn, EventArgs.Empty);
                }
                if (b && tv != null)
                {
                    tv.OnPropertyValueChanged();
                    UserControlSetupProperties ucp = getHolder();
                    if (ucp != null)
                    {
                        ucp.OnSelectTreeNode(this);
                    }
                }
            }
        }
        private void mnu_removeShortcut(object sender, EventArgs e)
        {
            TreeViewWix tv = this.TreeView as TreeViewWix;
            Form        f  = null;

            if (this.TreeView != null)
            {
                f = this.TreeView.FindForm();
            }
            if (MessageBox.Show(f, "Do you want to remove this shortcut from the setup?", "Remove Shortcut", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                TreeNodeWixShortcutCollection ip = this.Parent as TreeNodeWixShortcutCollection;
                WixShortcut ico = ShortcutNode;
                XmlNode     p   = ico.XmlData.ParentNode;
                p.RemoveChild(ico.XmlData);
                ip.ShortcutNodes.Shortcuts.Remove(ico);
                this.Remove();
                if (tv != null)
                {
                    tv.OnPropertyValueChanged();
                }
            }
        }
        private void mnu_addIcon(object sender, EventArgs e)
        {
            WixIconNode ico = this.IconNodes.AddIcon();

            if (_nextLevelLoaded)
            {
                TreeNodeWixIcon iconNode = new TreeNodeWixIcon(ico, -1);
                Nodes.Add(iconNode);
                this.TreeView.SelectedNode = iconNode;
            }
            else
            {
                this.Expand();
                if (this.TreeView != null)
                {
                    for (int i = 0; i < this.Nodes.Count; i++)
                    {
                        TreeNodeWixIcon iconNode = this.Nodes[i] as TreeNodeWixIcon;
                        if (iconNode != null)
                        {
                            if (string.CompareOrdinal(iconNode.IconNode.Id, ico.Id) == 0)
                            {
                                this.TreeView.SelectedNode = iconNode;
                                break;
                            }
                        }
                    }
                }
            }
            TreeViewWix tv = this.TreeView as TreeViewWix;

            if (tv != null)
            {
                tv.OnPropertyValueChanged();
            }
        }
        private void mnu_addCulture(object sender, EventArgs e)
        {
            TreeViewWix tv = this.TreeView as TreeViewWix;

            if (tv != null)
            {
                WixCultureCollection cc = this.Cultures;
                StringCollection     ss = new StringCollection();
                foreach (WixCultureNode cn in cc.CultureList)
                {
                    ss.Add(cn.CultureNode.Culture);
                }
                DlgLanguages dlg = new DlgLanguages();
                dlg.SetUseSpecificCulture();
                dlg.LoadData(ss);
                Form f = null;
                if (this.TreeView != null)
                {
                    f = this.TreeView.FindForm();
                }
                if (dlg.ShowDialog(f) == DialogResult.OK)
                {
                    ss = dlg.SelectedLanguages;
                    if (ss.Count > 0)
                    {
                        this.Expand();
                        bool      added = false;
                        ImageList imgs  = null;
                        if (this.TreeView != null)
                        {
                            imgs = this.TreeView.ImageList;
                        }
                        foreach (string s in ss)
                        {
                            if (!cc.CultureExists(s))
                            {
                                int idx = -1;
                                if (imgs != null)
                                {
                                    Image img = VPLUtil.GetLanguageImageByName(s);
                                    if (img != null)
                                    {
                                        idx = imgs.Images.Add(img, Color.White);
                                    }
                                }
                                XmlNode        xn  = tv.createCultureXmlNode(s, false);
                                WixCultureNode wcn = new WixCultureNode(xn);
                                cc.CultureList.Add(wcn);
                                TreeNodeWixCulture twc = new TreeNodeWixCulture(wcn, idx);
                                this.Nodes.Add(twc);
                                added = true;
                            }
                        }
                        if (added)
                        {
                            tv.OnPropertyValueChanged();
                        }
                    }
                }
            }
        }