Example #1
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void OnExportSSOCommand(object sender, EventArgs e)
        {
            IVsHierarchy hierarchy = null;
            uint         itemid    = VSConstants.VSITEMID_NIL;

            if (!ImportSSO.IsSingleProjectItemSelection(out hierarchy, out itemid))
            {
                return;
            }

            var vsProject = (IVsProject)hierarchy;

            // get the name of the item
            string itemFullPath = null;

            if (ErrorHandler.Failed(vsProject.GetMkDocument(itemid, out itemFullPath)))
            {
                return;
            }

            // Save the project file
            var solution = (IVsSolution)Package.GetGlobalService(typeof(SVsSolution));
            int hr       = solution.SaveSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_SaveIfDirty, hierarchy, 0);

            if (hr < 0)
            {
                throw new COMException(string.Format("Failed to add project item", itemFullPath, ImportSSO.GetErrorInfo()), hr);
            }

            var selectedProjectItem = ImportSSO.GetProjectItemFromHierarchy(hierarchy, itemid);

            if (selectedProjectItem != null)
            {
                string itemFolder    = Path.GetDirectoryName(itemFullPath);
                string itemFilename  = Path.GetFileNameWithoutExtension(itemFullPath);
                string itemExtension = Path.GetExtension(itemFullPath);

                var dialog = new Dialogs.ExportSSO(itemFilename, itemFullPath);
                dialog.ShowDialog();
                if (!dialog.OK)
                {
                    return;
                }

                // Export the SSO application
                ExportSSOApplication(itemFilename, itemFullPath);
            }
        }
Example #2
0
        private void menuCommand_BeforeQueryStatus(object sender, EventArgs e)
        {
            // get the menu that fired the event
            var menuCommand = sender as OleMenuCommand;

            if (menuCommand != null)
            {
                // start by assuming that the menu will not be shown
                menuCommand.Visible = false;
                menuCommand.Enabled = false;

                IVsHierarchy hierarchy = null;
                uint         itemid    = VSConstants.VSITEMID_NIL;
                if (!ImportSSO.IsSingleProjectItemSelection(out hierarchy, out itemid))
                {
                    return;
                }

                // Get the file path
                string itemFullPath = null;
                ((IVsProject)hierarchy).GetMkDocument(itemid, out itemFullPath);
                var transformFileInfo = new FileInfo(itemFullPath);

                // then check if the file is a SSO file
                // if not leave the menu hidden
                if (transformFileInfo.Extension == ".sso")
                {
                    menuCommand.Visible = true;
                    menuCommand.Enabled = true;
                    return;
                }
                if (transformFileInfo.Extension != ".xml")
                {
                    return;
                }
                if (!ImportSSO.IsSSOXmlFile(transformFileInfo))
                {
                    return;
                }

                menuCommand.Visible = true;
                menuCommand.Enabled = true;
            }
        }