예제 #1
0
        private void InitModules()
        {
            QtVersionManager versionManager = QtVersionManager.The();
            string           qtVersion      = qtProject.GetQtVersion();
            string           install_path   = versionManager.GetInstallPath(qtVersion);

            for (int i = 0; i < moduleMap.Count; ++i)
            {
                ModuleMapItem item = moduleMap[i];
                item.initialValue     = qtProject.HasModule(item.moduleId);
                item.checkbox.Checked = item.initialValue;
                moduleMap[i]          = item;

                // Disable if module not installed
                QtModuleInfo info          = QtModules.Instance.ModuleInformation(item.moduleId);
                string       libraryPrefix = info.LibraryPrefix;
                if (libraryPrefix.StartsWith("Qt"))
                {
                    libraryPrefix = "Qt5" + libraryPrefix.Substring(2);
                }
                string             full_path = install_path + "\\lib\\" + libraryPrefix + ".lib";
                System.IO.FileInfo fi        = new System.IO.FileInfo(full_path);
                item.checkbox.Enabled = fi.Exists;
                if (fi.Exists == false)
                {
                    // Don't disable item if qtVersion not available
                    if (qtVersion != null)
                    {
                        item.checkbox.Checked = false;
                    }
                }
            }
        }
예제 #2
0
 private void OnLoaded(object sender, RoutedEventArgs e)
 {
     Loaded -= OnLoaded;
     try {
         foreach (var checkBox in ModuleCheckBoxes)
         {
             if (QtModuleInfo.IsInstalled(checkBox.Tag))
             {
                 checkBox.IsEnabled = true;
             }
             if (Data.DefaultModules.Contains(checkBox.Tag))
             {
                 checkBox.IsEnabled = false;
                 checkBox.IsChecked = QtModuleInfo.IsInstalled(checkBox.Tag);
             }
         }
     } catch {
         // Ignore if we can't find out if the library is installed.
         // We either disable and or un-check the button in the UI.
     }
 }
예제 #3
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            Loaded -= OnLoaded;
            try {
                foreach (var checkBox in Children <CheckBox>(ModuleGrid))
                {
                    checkBox.IsEnabled = QtModuleInfo.IsInstalled(checkBox.Name);
                }

                foreach (var module in Data.DefaultModules)
                {
                    var checkbox = ModuleGrid.FindName(module) as CheckBox;
                    if (checkbox == null)
                    {
                        continue;
                    }
                    checkbox.IsChecked = QtModuleInfo.IsInstalled(module);
                    checkbox.IsEnabled = false; // Required module, always disabled.
                }
            } catch {
                // Ignore if we can't find out if the library is installed.
                // We either disable and or un-check the button in the UI.
            }
        }
예제 #4
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 wizard = new WizardWindow(new List <WizardPage> {
                        new IntroPage {
                            Data    = data,
                            Header  = @"Welcome to the Qt Console Application Wizard",
                            Message = @"This wizard generates a Qt console application "
                                      + @"project. The application derives from QCoreApplication "
                                      + @"and does not present a GUI." + 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 Console 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     = false,
                            FinishButtonEnabled   = QtModuleInfo.IsInstalled(@"QtCore"),
                            CancelButtonEnabled   = true
                        }
                    })
                    {
                        Title = @"Qt Console 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$"] = version.Replace(".", string.Empty);
            } catch {
                try {
                    Directory.Delete(replacements["$destinationdirectory$"]);
                    Directory.Delete(replacements["$solutiondirectory$"]);
                } catch { }

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

            iVsUIShell.EnableModeless(1);
        }
예제 #5
0
 public ModuleCheckBox(QtModuleInfo module)
 {
     this.module = module;
     isChecked   = isEnabled = false;
 }
예제 #6
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);

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

                try {
                    data.ClassName       = safeprojectname;
                    data.ClassHeaderFile = safeprojectname + @".h";
                    data.ClassSourceFile = safeprojectname + @".cpp";

                    var wizard = new WizardWindow(new List <WizardPage> {
                        new IntroPage {
                            Data    = data,
                            Header  = @"Welcome to the Qt Class Library Wizard",
                            Message = @"This wizard generates a Qt Class Library project. The "
                                      + @"resulting library is linked dynamically with Qt."
                                      + 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 Class Library 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 LibraryClassPage {
                            Data    = data,
                            Header  = @"Welcome to the Qt Class Library Wizard",
                            Message = @"This wizard generates a Qt Class Library project. The "
                                      + @"resulting library is linked dynamically with Qt.",
                            PreviousButtonEnabled = true,
                            NextButtonEnabled     = false,
                            FinishButtonEnabled   = QtModuleInfo.IsInstalled(@"QtCore"),
                            CancelButtonEnabled   = true
                        }
                    })
                    {
                        Title = @"Qt Class Library 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["$sourcefilename$"] = data.ClassSourceFile;
                replacements["$headerfilename$"] = data.ClassHeaderFile;

                replacements["$precompiledheader$"] = string.Empty;
                replacements["$precompiledsource$"] = 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["$saveglobal$"] = safeprojectname.ToLower();

                projectDefine = safeprojectname.ToUpper() + @"_LIB";
                replacements["$pro_lib_define$"] = projectDefine;
                replacements["$pro_lib_export$"] = safeprojectname.ToUpper() + @"_EXPORT";

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

#if (VS2017 || VS2015)
                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);
        }
예제 #7
0
        public WizardResult Run(EnvDTE.DTE dte, string name, string location)
        {
            var serviceProvider = new ServiceProvider(dte as IServiceProvider);
            var iVsUIShell      = serviceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell;

            iVsUIShell.EnableModeless(0);

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

                try {
                    if (string.IsNullOrEmpty(name))
                    {
                        name = @"QtClass";
                    }

                    data.ClassName            = name;
                    data.BaseClass            = @"QObject";
                    data.ConstructorSignature = "QObject *parent";
                    data.InsertQObjectMacro   = true;
                    data.ClassHeaderFile      = name + @".h";
                    data.ClassSourceFile      = name + @".cpp";

                    var wizard = new WizardWindow(new List <WizardPage> {
                        new IntroPage {
                            Data    = data,
                            Header  = @"Welcome to the Qt Class Wizard",
                            Message = @"This wizard will add a new Qt5 class to your project. The "
                                      + @"wizard creates a .h and .cpp file." + System.Environment.NewLine
                                      + System.Environment.NewLine + "To continue, click Next.",
                            PreviousButtonEnabled = false,
                            NextButtonEnabled     = true,
                            FinishButtonEnabled   = false,
                            CancelButtonEnabled   = true
                        },
                        new CoreClassPage {
                            Data    = data,
                            Header  = @"Welcome to the Qt Class Wizard",
                            Message = @"This wizard will add a new Qt5 class to your project. The "
                                      + @"wizard creates a .h and .cpp file.",
                            PreviousButtonEnabled = true,
                            NextButtonEnabled     = false,
                            FinishButtonEnabled   = QtModuleInfo.IsInstalled(@"QtCore"),
                            CancelButtonEnabled   = true
                        }
                    })
                    {
                        Title = @"Qt Class Wizard"
                    };
                    WindowHelper.ShowModal(wizard, hwnd);
                    if (!wizard.DialogResult.HasValue || !wizard.DialogResult.Value)
                    {
                        throw new System.Exception("Unexpected wizard return value.");
                    }

                    var array = data.ClassName.Split(new[] { "::" }, System
                                                     .StringSplitOptions.RemoveEmptyEntries);
                    data.ClassName = array.LastOrDefault();

                    string nsBegin = string.Empty, nsEnd = string.Empty;
                    for (var i = 0; i < array.Length - 1; ++i)
                    {
                        nsBegin += "namespace " + array[i] + " {\r\n";
                        nsEnd    = "} // namespace " + array[i] + "\r\n" + nsEnd;
                    }

                    var pro = HelperFunctions.GetSelectedQtProject(dte);
                    if (pro == null)
                    {
                        throw new QtVSException("Can't find a selected project");
                    }

                    var qtProject = QtProject.Create(pro);

                    var hppFile = AddProjectItemHpp(location);
                    ReplaceNamespaceToken(hppFile, nsBegin, nsEnd);

                    qtProject.AdjustWhitespace(hppFile);
                    qtProject.AddFileToProject(hppFile, Filters.HeaderFiles());
                    VsShellUtilities.OpenDocument(serviceProvider, hppFile);

                    var pch = string.Empty;
                    if (qtProject.UsesPrecompiledHeaders())
                    {
                        pch = qtProject.GetPrecompiledHeaderThrough();
                    }

                    var cppFile = AddProjectItemCpp(location, pch);
                    ReplaceNamespaceToken(cppFile, nsBegin, nsEnd);

                    qtProject.AdjustWhitespace(cppFile);
                    qtProject.AddFileToProject(cppFile, Filters.SourceFiles());
                    VsShellUtilities.OpenDocument(serviceProvider, cppFile);
                } catch (QtVSException exception) {
                    Messages.DisplayErrorMessage(exception.Message);
                    throw; // re-throw, but keep the original exception stack intact
                }
            } catch {
                throw new WizardBackoutException();
            } finally {
                iVsUIShell.EnableModeless(1);
            }

            return(WizardResult.Finished);
        }