Exemplo n.º 1
0
        public int OnBeforeSave(uint docCookie)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            try
            {
                string documentPath = GetDocumentInfos();
                string GetDocumentInfos()
                {
                    runningDocumentTable.GetDocumentInfo(docCookie, out uint pgfFlags, out uint pdwReadLocks, out uint pdfEditLocks,
                                                         out string pbstrMkDocument, out IVsHierarchy ppHier, out uint pitemid,
                                                         out IntPtr ppunkDocData);
                    return(pbstrMkDocument);
                }
                DTE                    dte           = Package.GetGlobalService(typeof(DTE)) as DTE;
                ProjectItem            projectItem   = dte.Solution.FindProjectItem(documentPath);
                Project                project       = projectItem.ContainingProject;
                VCProject              p             = project.Object as VCProject;
                VCConfiguration        configuration = p.ActiveConfiguration;
                IVCRulePropertyStorage plcnextRule   = configuration.Rules.Item("PLCnextCommonProperties");
                string                 projectType   = plcnextRule.GetUnevaluatedPropertyValue("ProjectType_");
                if (!string.IsNullOrEmpty(projectType))
                {
                    string name = Path.GetFileName(documentPath);
                    if (name.Equals(fileName))
                    {
                        if (optionPage.AskIncludesUpdate)
                        {
                            UpdateIncludesViewModel  viewModel = new UpdateIncludesViewModel(p.Name);
                            UpdateIncludesDialogView view      = new UpdateIncludesDialogView(viewModel);
                            bool result = (bool)view.ShowModal();

                            optionPage.UpdateIncludes = result;
                            if (viewModel.RememberDecision)
                            {
                                optionPage.AskIncludesUpdate = false;
                            }
                        }
                        if (optionPage.UpdateIncludes)
                        {
                            UpdateIncludesOnBeforeSave(p, p.ProjectDirectory);
                        }
                    }
                    return(VSConstants.S_OK);
                }
            }
            catch (NullReferenceException)
            {
                //do nothing
            }
            return(VSConstants.S_OK);
        }
 public UpdateIncludesDialogView(UpdateIncludesViewModel viewModel)
 {
     InitializeComponent();
     DataContext = viewModel;
 }