private void tsddWindow_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
 {
     if (e.ClickedItem == tsmiWebresourcesExplorer)
     {
         tv.ShowDocked();
     }
     else if (e.ClickedItem == tsmiPendingUpdates)
     {
         pud.ShowDocked();
     }
     else if (e.ClickedItem == tsmiMainProperties)
     {
         rpd.ShowDocked();
     }
     else if (e.ClickedItem == tsmiSettings)
     {
         sd.ShowDocked();
     }
 }
        private void cmsWebresourceTreeview_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (e.ClickedItem != tsmiAddNewResource)
            {
                cmsWebresourceTreeview.Hide();
            }

            if (e.ClickedItem == tsmiProperties)
            {
                if (rpd.IsDisposed)
                {
                    rpd = new ResourcePropertiesDialog();
                }

                rpd.Resource = contextStripResource;
                rpd.ShowDocked();
            }
            else if (e.ClickedItem == tsmiSetDependencies)
            {
                var dialog = new DependencyDialog(contextStripResource, this);
                if (dialog.ShowDialog(this) == DialogResult.OK)
                {
                    contextStripResource.DependencyXml = dialog.UpdatedDependencyXml;
                }
            }
            else if (e.ClickedItem == tsmiCopyNameToClipboard)
            {
                Clipboard.SetData(DataFormats.StringFormat, contextStripResource.Name);
            }
            else if (e.ClickedItem == tsmiOpenInCrm)
            {
                if (contextStripResource.Id == Guid.Empty)
                {
                    MessageBox.Show(this, @"This web resource does not exist on the CRM organization or is not synced", @"Warning",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                Process.Start($"{ConnectionDetail.WebApplicationUrl}/main.aspx?id={contextStripResource.Id}&etc=9333&pagetype=webresourceedit");
            }
            else if (e.ClickedItem == tsmiDelete)
            {
                ExecuteMethod(DeleteWebresource, contextStripResource);
            }
            else if (e.ClickedItem == tsmiUpdate)
            {
                var us = new UpdateResourcesSettings
                {
                    Webresources = new List <Webresource> {
                        contextStripResource
                    },
                };

                ExecuteMethod(UpdateWebResources, us);
            }
            else if (e.ClickedItem == tsmiUpdatePublish)
            {
                var us = new UpdateResourcesSettings
                {
                    Webresources = new List <Webresource> {
                        contextStripResource
                    },
                    Publish = true
                };

                ExecuteMethod(UpdateWebResources, us);
            }
            else if (e.ClickedItem == tsmiUpdatePublishAdd)
            {
                var us = new UpdateResourcesSettings
                {
                    Webresources = new List <Webresource> {
                        contextStripResource
                    },
                    Publish       = true,
                    AddToSolution = true
                };

                ExecuteMethod(UpdateWebResources, us);
            }
            else if (e.ClickedItem == tsmiGetLatest)
            {
                try
                {
                    contextStripResource.GetLatestVersion();
                }
                catch (Exception error)
                {
                    MessageBox.Show(this, error.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else if (e.ClickedItem == tsmiRefreshFileFromDisk)
            {
                if (string.IsNullOrEmpty(contextStripResource.FilePath))
                {
                    MessageBox.Show(this, @"This webresource is not synced with a local file", @"Warning",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                contextStripResource.RefreshFromDisk();
            }
            else if (e.ClickedItem == tsmiUpdateFolderFromDisk)
            {
                if (string.IsNullOrEmpty(contextFolderNode.FolderPath))
                {
                    MessageBox.Show(this,
                                    @"This folder node is not synced with a local folder. Cannot refresh from disk", @"Warning",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                var invalidFileNames = new List <string>();
                tv.RefreshFolderNodeContent(contextFolderNode, invalidFileNames, null);

                if (invalidFileNames.Any())
                {
                    if (ifnd == null || ifnd.IsDisposed)
                    {
                        ifnd = new InvalidFilenamesDialog();
                    }

                    ifnd.InvalidFiles = invalidFileNames;
                    ifnd.ShowDocked(DockState.DockBottom);
                }
            }
            else if (e.ClickedItem == tsmiRenameWebresource)
            {
                var renameDialog = new RenameWebResourceDialog(contextStripResource.Name, ConnectionDetail?.OrganizationMajorVersion ?? -1);

                if (renameDialog.ShowDialog(this) == DialogResult.OK)
                {
                    if (contextStripResource.Name != renameDialog.WebResourceName)
                    {
                        ExecuteMethod(RenameWebresource, renameDialog.WebResourceName);
                    }
                }
            }
            else if (e.ClickedItem == tsmiAddNewFolder)
            {
                var newFolderDialog = new NewFolderDialog(ConnectionDetail?.OrganizationMajorVersion ?? -1);
                if (newFolderDialog.ShowDialog(this) == DialogResult.OK)
                {
                    tv.AddSingleFolder(contextFolderNode, newFolderDialog.FolderName);
                }
            }
            else if (e.ClickedItem == tsmiAddExistingFile)
            {
                var ofd = new OpenFileDialog {
                    Multiselect = true, Title = @"Select file(s) to add as webresource(s)"
                };

                if (ofd.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    var invalidFileNames = new List <string>();
                    tv.AddFilesAsNodes(contextFolderNode, ofd.FileNames.ToList(), invalidFileNames);

                    if (invalidFileNames.Any())
                    {
                        if (ifnd == null || ifnd.IsDisposed)
                        {
                            ifnd = new InvalidFilenamesDialog();
                        }

                        ifnd.InvalidFiles = invalidFileNames;
                        ifnd.ShowDocked(DockState.DockBottom);
                    }
                }
            }
            else if (e.ClickedItem == tsmiNewCss)
            {
                tv.AddNewWebresource(contextFolderNode, WebresourceType.Css);
            }
            else if (e.ClickedItem == tsmiNewData)
            {
                tv.AddNewWebresource(contextFolderNode, WebresourceType.Data);
            }
            else if (e.ClickedItem == tsmiNewHtml)
            {
                tv.AddNewWebresource(contextFolderNode, WebresourceType.WebPage);
            }
            else if (e.ClickedItem == tsmiNewResx)
            {
                tv.AddNewWebresource(contextFolderNode, WebresourceType.Resx);
            }
            else if (e.ClickedItem == tsmiNewScript)
            {
                tv.AddNewWebresource(contextFolderNode, WebresourceType.Script);
            }
            else if (e.ClickedItem == tsmiNewXsl)
            {
                tv.AddNewWebresource(contextFolderNode, WebresourceType.Xsl);
            }
            else if (e.ClickedItem == tsmiExpand)
            {
                contextFolderNode.ExpandAll();
            }
            else if (e.ClickedItem == tsmiCollapse)
            {
                contextFolderNode.Collapse(false);
            }
        }