示例#1
0
        public void RunStarted(object automation, Dictionary <string, string> replacements,
                               WizardRunKind runKind, object[] customParams)
        {
            var serviceProvider = new ServiceProvider(automation as IServiceProvider);
            var iVsUIShell      = serviceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell;

            iVsUIShell.EnableModeless(0);

            try {
                System.IntPtr hwnd;
                iVsUIShell.GetDialogOwnerHwnd(out hwnd);

                try {
                    var className = replacements["$safeprojectname$"];
                    className = Regex.Replace(className, @"[^a-zA-Z0-9_]", string.Empty);
                    className = Regex.Replace(className, @"^[\d-]*\s*", string.Empty);
                    var result = new ClassNameValidationRule().Validate(className, null);
                    if (result != ValidationResult.ValidResult)
                    {
                        className = @"QtGuiApplication";
                    }

                    data.ClassName       = className;
                    data.BaseClass       = @"QMainWindow";
                    data.ClassHeaderFile = className + @".h";
                    data.ClassSourceFile = className + @".cpp";
                    data.UiFile          = data.ClassName + @".ui";
                    data.QrcFile         = data.ClassName + @".qrc";

                    var wizard = new WizardWindow(new List <WizardPage> {
                        new IntroPage {
                            Data    = data,
                            Header  = @"Welcome to the Qt GUI Application Wizard",
                            Message = @"This wizard generates a Qt GUI application project. The "
                                      + @"application derives from QApplication and includes an empty "
                                      + @"widget." + System.Environment.NewLine
                                      + System.Environment.NewLine + "To continue, click Next.",
                            PreviousButtonEnabled = false,
                            NextButtonEnabled     = true,
                            FinishButtonEnabled   = false,
                            CancelButtonEnabled   = true
                        },
                        new ModulePage {
                            Data    = data,
                            Header  = @"Welcome to the Qt GUI Application Wizard",
                            Message = @"Select the modules you want to include in your project. The "
                                      + @"recommended modules for this project are selected by default.",
                            PreviousButtonEnabled = true,
                            NextButtonEnabled     = true,
                            FinishButtonEnabled   = false,
                            CancelButtonEnabled   = true
                        },
                        new GuiPage {
                            Data    = data,
                            Header  = @"Welcome to the Qt GUI Application Wizard",
                            Message = @"This wizard generates a Qt GUI application project. The "
                                      + @"application derives from QApplication and includes an empty "
                                      + @"widget.",
                            PreviousButtonEnabled = true,
                            NextButtonEnabled     = false,
                            FinishButtonEnabled   = data.DefaultModules.All(QtModuleInfo.IsInstalled),
                            CancelButtonEnabled   = true
                        }
                    })
                    {
                        Title = @"Qt GUI Application Wizard"
                    };
                    WindowHelper.ShowModal(wizard, hwnd);
                    if (!wizard.DialogResult.HasValue || !wizard.DialogResult.Value)
                    {
                        throw new System.Exception("Unexpected wizard return value.");
                    }
                } catch (QtVSException exception) {
                    Messages.DisplayErrorMessage(exception.Message);
                    throw; // re-throw, but keep the original exception stack intact
                }

                var version = (automation as DTE).Version;
                replacements["$ToolsVersion$"] = version;

                var vm = QtVersionManager.The();
                var vi = VersionInformation.Get(vm.GetInstallPath(vm.GetDefaultVersion()));
                replacements["$Platform$"] = vi.GetVSPlatformName();

                replacements["$Keyword$"]         = Resources.qtProjectKeyword;
                replacements["$ProjectGuid$"]     = @"{B12702AD-ABFB-343A-A199-8E24837244A3}";
                replacements["$PlatformToolset$"] = BuildConfig.PlatformToolset(version);

                replacements["$classname$"]      = data.ClassName;
                replacements["$baseclass$"]      = data.BaseClass;
                replacements["$sourcefilename$"] = data.ClassSourceFile;
                replacements["$headerfilename$"] = data.ClassHeaderFile;
                replacements["$uifilename$"]     = data.UiFile;

                replacements["$precompiledheader$"]      = string.Empty;
                replacements["$precompiledsource$"]      = string.Empty;
                replacements["$DefaultApplicationIcon$"] = string.Empty;
                replacements["$centralwidget$"]          = string.Empty;

                var strHeaderInclude = data.ClassHeaderFile;
                if (data.UsePrecompiledHeader)
                {
                    strHeaderInclude = "stdafx.h\"\r\n#include \"" + data.ClassHeaderFile;
                    replacements["$precompiledheader$"] = "<None Include=\"stdafx.h\" />";
                    replacements["$precompiledsource$"] = "<None Include=\"stdafx.cpp\" />";
                }

                replacements["$include$"] = strHeaderInclude;
                replacements["$ui_hdr$"]  = "ui_" + Path.GetFileNameWithoutExtension(data.UiFile)
                                            + ".h";
                replacements["$qrcfilename$"] = data.QrcFile;

                if (data.BaseClass == "QMainWindow")
                {
                    replacements["$centralwidget$"] =
                        "\r\n  <widget class=\"QMenuBar\" name=\"menuBar\" />"
                        + "\r\n  <widget class=\"QToolBar\" name=\"mainToolBar\" />"
                        + "\r\n  <widget class=\"QWidget\" name=\"centralWidget\" />"
                        + "\r\n  <widget class=\"QStatusBar\" name=\"statusBar\" />";
                }

                if (data.AddDefaultAppIcon)
                {
                    replacements["$DefaultApplicationIcon$"] = "<None Include=\"gui.ico\" />";
                }

                if (vi.isWinRT())
                {
                    replacements["$QtWinRT$"] = "true";

                    var projDir = replacements["$destinationdirectory$"];

                    var qmakeTmpDir = Path.Combine(projDir, "qmake_tmp");
                    Directory.CreateDirectory(qmakeTmpDir);

                    var dummyPro = Path.Combine(qmakeTmpDir,
                                                string.Format("{0}.pro", replacements["$projectname$"]));
                    File.WriteAllText(dummyPro, "SOURCES = main.cpp\r\n");

                    var qmake = new QMake(null, dummyPro, false, vi);
                    qmake.RunQMake();

                    var assetsDir = Path.Combine(qmakeTmpDir, "assets");
                    if (Directory.Exists(assetsDir))
                    {
                        Directory.Move(assetsDir, Path.Combine(projDir, "assets"));
                    }

                    var manifestFile = Path.Combine(qmakeTmpDir, "Package.appxmanifest");
                    if (File.Exists(manifestFile))
                    {
                        File.Move(manifestFile, Path.Combine(projDir, "Package.appxmanifest"));
                    }

                    var projFile = Path.Combine(qmakeTmpDir,
                                                string.Format("{0}.vcxproj", replacements["$projectname$"]));

                    var proj = MsBuildProject.Load(projFile);
                    replacements["$MinimumVisualStudioVersion$"] =
                        proj.GetProperty("MinimumVisualStudioVersion");
                    replacements["$ApplicationTypeRevision$"] =
                        proj.GetProperty("ApplicationTypeRevision");
                    replacements["$WindowsTargetPlatformVersion$"] =
                        proj.GetProperty("WindowsTargetPlatformVersion");
                    replacements["$isSet_WindowsTargetPlatformVersion$"] = "true";
                    replacements["$WindowsTargetPlatformMinVersion$"]    =
                        proj.GetProperty("WindowsTargetPlatformMinVersion");
                    replacements["$Link_TargetMachine$"] =
                        proj.GetProperty("Link", "TargetMachine");

                    Directory.Delete(qmakeTmpDir, true);
                }
#if (VS2017 || VS2015)
                else
                {
                    string versionWin10SDK = HelperFunctions.GetWindows10SDKVersion();
                    if (!string.IsNullOrEmpty(versionWin10SDK))
                    {
                        replacements["$WindowsTargetPlatformVersion$"]       = versionWin10SDK;
                        replacements["$isSet_WindowsTargetPlatformVersion$"] = "true";
                    }
                }
#endif
            } catch {
                try {
                    Directory.Delete(replacements["$destinationdirectory$"]);
                    Directory.Delete(replacements["$solutiondirectory$"]);
                } catch { }

                iVsUIShell.EnableModeless(1);
                throw new WizardBackoutException();
            }

            iVsUIShell.EnableModeless(1);
        }
示例#2
0
        private FileInfo RunQmake(FileInfo mainInfo, string ext, bool recursive, VersionInformation vi)
        {
            string name = mainInfo.Name.Remove(mainInfo.Name.IndexOf('.'));

            FileInfo VCInfo = new FileInfo(mainInfo.DirectoryName + "\\" + name + ext);

            if (!VCInfo.Exists || DialogResult.Yes == MessageBox.Show(SR.GetString("ExportProject_ProjectExistsRegenerateOrReuse", VCInfo.Name),
                SR.GetString("ProjectExists"), MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {
                Messages.PaneMessage(dteObject, "--- (Import): Generating new project of " + mainInfo.Name + " file");

                InfoDialog dialog = new InfoDialog(mainInfo.Name);
                QMake qmake = new QMake(dteObject, mainInfo.FullName, recursive, vi);

                qmake.CloseEvent += new QMake.ProcessEventHandler(dialog.CloseEventHandler);
                qmake.PaneMessageDataEvent += new QMake.ProcessEventHandlerArg(this.PaneMessageDataReceived);

                System.Threading.Thread qmakeThread = new System.Threading.Thread(new ThreadStart(qmake.RunQMake));
                qmakeThread.Start();
                dialog.ShowDialog();
                qmakeThread.Join();

                if (qmake.ErrorValue == 0)
                    return VCInfo;
            }

            return null;
        }