Esempio n. 1
0
        public override int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (pguidCmdGroup == _commandGroup && nCmdID == _commandId)
            {
                _vsTextView.GetCaretPos(out int line, out int column);
                string curLine = _view.TextSnapshot.GetLineFromLineNumber(line).GetText();

                var pattern = new Regex(@"([\w .]+)=");
                if (pattern.IsMatch(curLine))
                {
                    GroupCollection groups   = pattern.Match(curLine).Groups;
                    string          ruleName = groups[1].Value.ToString().Trim();

                    SchemaCatalog.TryGetKeyword(ruleName, out Keyword keyword);
                    if (keyword != null && keyword.DocumentationLink != null)
                    {
                        VsShellUtilities.OpenSystemBrowser(keyword.DocumentationLink);
                    }
                    else
                    {
                        VsShellUtilities.OpenSystemBrowser(Constants.Homepage);
                    }
                }
                else
                {
                    VsShellUtilities.OpenSystemBrowser(Constants.Homepage);
                }
                return(VSConstants.S_OK);
            }

            ThreadHelper.ThrowIfNotOnUIThread();

            return(Next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
Esempio n. 2
0
        private void NavigateHyperlink(Uri uri)
        {
            string page = uri.AbsoluteUri;

            VsShellUtilities.OpenSystemBrowser(page);

            // TODO: add telemetry for clicks
        }
 private void OnNavigateRequested(object sender, RequestNavigateEventArgs e)
 {
     if (string.IsNullOrEmpty(e.Uri.ToString()))
     {
         return;
     }
     VsShellUtilities.OpenSystemBrowser(e.Uri.ToString());
 }
Esempio n. 4
0
        public void NavigateHyperlink(Uri uri)
        {
            string page = uri.AbsoluteUri;

            VsShellUtilities.OpenSystemBrowser(page);

            this.Wizard.TelemetryHelper.TrackLinkClickedEvent(page);
        }
 /// <summary>
 /// Handles click on each sites
 /// </summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event args.</param>
 private void OnSiteClick(object sender, RoutedEventArgs e)
 {
     //object { System.Windows.Controls.Stackpanel }
     //var query = sender.InheritanceParent.CacheModeChangedHandler.Target.Content.Name + ' ' + sender.InheritanceParent.CacheModeChangedHandler.Target.Content.Address;
     //var uri = "https://www.bing.com/maps?q=" + Regex.Replace(query, @"\s+", "+");
     //var name = e.OriginalSource.Inlines.FirstInline.Text;
     VsShellUtilities.OpenSystemBrowser("https://www.bing.com/maps");
 }
Esempio n. 6
0
        public override int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (pguidCmdGroup == _commandGroup && nCmdID == _commandId)
            {
                VsShellUtilities.OpenSystemBrowser(Constants.Homepage);
                return(VSConstants.S_OK);
            }

            return(Next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
Esempio n. 7
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 Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            /*string message = string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.GetType().FullName);*/
            string message = "Hello Yokim! Now Kimy.";
            string title   = "Now Custom Command";

            // Show a message box to prove we were here
            VsShellUtilities.ShowMessageBox(
                this.package,
                message,
                title,
                OLEMSGICON.OLEMSGICON_INFO,
                OLEMSGBUTTON.OLEMSGBUTTON_OK,
                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

            // Open web page!!
            VsShellUtilities.OpenSystemBrowser("https://docs.microsoft.com/en-us/visualstudio/extensibility/internals/command-design?view=vs-2019");
        }
Esempio n. 8
0
 public static void StartBrowser(Uri uri)
 {
     VsShellUtilities.OpenSystemBrowser(uri.AbsoluteUri);
 }
Esempio n. 9
0
 public static void StartBrowser(string uri)
 => VsShellUtilities.OpenSystemBrowser(uri);
Esempio n. 10
0
        async void F1QtHelpCallback(object sender, EventArgs args)
        {
            try {
                var dte             = ServiceProvider.GetService(typeof(SDTE)) as DTE;
                var objTextDocument = dte.ActiveDocument.Object() as TextDocument;

                var keyword   = string.Empty;
                var selection = objTextDocument.Selection;
                if (selection.IsEmpty)                                 // no selection inside the document
                {
                    var line   = selection.ActivePoint.Line;           // current line
                    var offset = selection.ActivePoint.LineCharOffset; // current char offset

                    selection.CharLeft(true);                          // try the character before the cursor
                    if (!selection.IsEmpty)
                    {
                        keyword = selection.Text;  // something in front of the cursor
                        selection.CharRight(true); // reset to origin
                        if (!IsSuperfluousCharacter(keyword))
                        {
                            // move the selection to the start of the word
                            selection.WordLeft(true);
                            selection.MoveToPoint(selection.TopPoint);
                        }
                    }
                    selection.WordRight(true);                   // select the word
                    keyword = selection.Text;                    // get the selected text
                    selection.MoveToLineAndOffset(line, offset); // reset
                }
                else
                {
                    keyword = selection.Text;
                }

                keyword = keyword.Trim();
                if (keyword.Length <= 1 || IsSuperfluousCharacter(keyword))
                {
                    return; // suppress single character, operators etc...
                }
                var qtVersion = "$(DefaultQtVersion)";
                var project   = HelperFunctions.GetSelectedQtProject(dte);
                if (project == null)
                {
                    project = HelperFunctions.GetSelectedProject(dte);
                    if (project != null && HelperFunctions.IsQMakeProject(project))
                    {
                        var qmakeQtDir = HelperFunctions.GetQtDirFromQMakeProject(project);
                        qtVersion = QtVersionManager.The().GetQtVersionFromInstallDir(qmakeQtDir);
                    }
                }
                else
                {
                    qtVersion = QtVersionManager.The().GetProjectQtVersion(project);
                }

                var docPath = QtVersionManager.The().GetVersionInfo(qtVersion).QtInstallDocs;
                if (string.IsNullOrEmpty(docPath) || !Directory.Exists(docPath))
                {
                    return;
                }

                var qchFiles = Directory.GetFiles(docPath, "*?.qch");
                if (qchFiles.Length == 0)
                {
                    return;
                }

                var settingsManager = new ShellSettingsManager(Instance.ServiceProvider);
                var store           = settingsManager.GetReadOnlySettingsStore(SettingsScope.UserSettings);
                var offline         =
                    store.GetBoolean(Statics.HelpPreferencePath, Statics.HelpPreferenceKey, true);

                var linksForKeyword = string.Format("SELECT d.Title, f.Name, e.Name, "
                                                    + "d.Name, a.Anchor FROM IndexTable a, FileNameTable d, FolderTable e, "
                                                    + "NamespaceTable f WHERE a.FileId=d.FileId AND d.FolderId=e.Id AND "
                                                    + "a.NamespaceId=f.Id AND a.Name='{0}'", keyword);

                var links   = new Dictionary <string, string>();
                var builder = new SQLiteConnectionStringBuilder
                {
                    ReadOnly = true
                };
                foreach (var file in qchFiles)
                {
                    builder.DataSource = file;
                    using (var connection = new SQLiteConnection(builder.ToString())) {
                        connection.Open();
                        using (var command = new SQLiteCommand(linksForKeyword, connection)) {
                            using (var reader = await command.ExecuteReaderAsync()) {
                                while (reader.Read())
                                {
                                    var title = GetString(reader, 0);
                                    if (string.IsNullOrWhiteSpace(title))
                                    {
                                        title = keyword + ':' + GetString(reader, 3);
                                    }
                                    var path = string.Empty;
                                    if (offline)
                                    {
                                        path = "file:///" + Path.Combine(docPath,
                                                                         GetString(reader, 2), GetString(reader, 3));
                                    }
                                    else
                                    {
                                        path = "https://" + Path.Combine("doc.qt.io", "qt-5",
                                                                         GetString(reader, 3));
                                    }
                                    if (!string.IsNullOrWhiteSpace(GetString(reader, 4)))
                                    {
                                        path += "#" + GetString(reader, 4);
                                    }
                                    links.Add(title, path);
                                }
                            }
                        }
                    }
                }

                var uri = string.Empty;
                switch (links.Values.Count)
                {
                case 0:
                    if (!offline)
                    {
                        uri = new UriBuilder("https://doc.qt.io/qt-5/search-results.html")
                        {
                            Query = "q=" + keyword
                        }.ToString();
                    }
                    break;

                case 1:
                    uri = links.First().Value;
                    break;

                default:
                    var dialog = new QtHelpLinkChooser
                    {
                        Links         = links,
                        Keyword       = keyword,
                        ShowInTaskbar = false
                    };
                    if (!dialog.ShowModal().GetValueOrDefault())
                    {
                        return;
                    }
                    uri = dialog.Link;
                    break;
                }

                if (string.IsNullOrEmpty(uri))   // offline mode without a single search hit
                {
                    VsShellUtilities.ShowMessageBox(Instance.ServiceProvider,
                                                    "Your search - " + keyword + " - did not match any documents.",
                                                    string.Empty, OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                }
                else
                {
                    if (uri.StartsWith("file:///", StringComparison.Ordinal) &&
                        !File.Exists(uri.Substring("file:///".Length)))
                    {
                        VsShellUtilities.ShowMessageBox(Instance.ServiceProvider,
                                                        "Your search - " + keyword + " - did match a document, but it could "
                                                        + "not be found on disk. To use the online help, select: "
                                                        + "Help | Set Qt Help Preference | Use Online Documentation",
                                                        string.Empty, OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                        OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                    }
                    else
                    {
                        VsShellUtilities.OpenSystemBrowser(HelperFunctions.ChangePathFormat(uri));
                    }
                }
            } catch { }
        }
Esempio n. 11
0
 void ViewQtHelpCallback(object sender, EventArgs args)
 {
     VsShellUtilities.OpenSystemBrowser("https://www.qt.io/developers");
 }
Esempio n. 12
0
        public static bool QueryEditorContextHelp(bool defaultTryOnline = false)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            try {
                var dte             = VsServiceProvider.GetService <SDTE, DTE>();
                var objTextDocument = dte?.ActiveDocument?.Object() as TextDocument;
                if (objTextDocument == null)
                {
                    return(false);
                }

                var keyword   = string.Empty;
                var selection = objTextDocument.Selection;
                if (selection.IsEmpty)                                 // no selection inside the document
                {
                    var line   = selection.ActivePoint.Line;           // current line
                    var offset = selection.ActivePoint.LineCharOffset; // current char offset

                    selection.CharLeft(true);                          // try the character before the cursor
                    if (!selection.IsEmpty)
                    {
                        keyword = selection.Text;  // something in front of the cursor
                        selection.CharRight(true); // reset to origin
                        if (!IsSuperfluousCharacter(keyword))
                        {
                            // move the selection to the start of the word
                            selection.WordLeft(true);
                            selection.MoveToPoint(selection.TopPoint);
                        }
                    }
                    selection.WordRight(true);                   // select the word
                    keyword = selection.Text;                    // get the selected text
                    selection.MoveToLineAndOffset(line, offset); // reset
                }
                else
                {
                    keyword = selection.Text;
                }

                keyword = keyword.Trim();
                if (keyword.Length <= 1 || IsSuperfluousCharacter(keyword))
                {
                    return(false); // suppress single character, operators etc...
                }
                var qtVersion = "$(DefaultQtVersion)";
                var project   = HelperFunctions.GetSelectedQtProject(dte);
                if (project == null)
                {
                    project = HelperFunctions.GetSelectedProject(dte);
                    if (project != null && HelperFunctions.IsQMakeProject(project))
                    {
                        var qmakeQtDir = HelperFunctions.GetQtDirFromQMakeProject(project);
                        qtVersion = QtVersionManager.The().GetQtVersionFromInstallDir(qmakeQtDir);
                    }
                }
                else
                {
                    qtVersion = QtVersionManager.The().GetProjectQtVersion(project);
                }

                var info    = QtVersionManager.The().GetVersionInfo(qtVersion);
                var docPath = info?.QtInstallDocs;
                if (string.IsNullOrEmpty(docPath) || !Directory.Exists(docPath))
                {
                    return(false);
                }

                var qchFiles = Directory.GetFiles(docPath, "*?.qch");
                if (qchFiles.Length == 0)
                {
                    return(false);
                }

                var offline = QtVsToolsPackage.Instance.Options.HelpPreference == SourcePreference.Offline;

                var linksForKeyword = string.Format("SELECT d.Title, f.Name, e.Name, "
                                                    + "d.Name, a.Anchor FROM IndexTable a, FileNameTable d, FolderTable e, "
                                                    + "NamespaceTable f WHERE a.FileId=d.FileId AND d.FolderId=e.Id AND "
                                                    + "a.NamespaceId=f.Id AND a.Name='{0}'", keyword);

                var links   = new Dictionary <string, string>();
                var builder = new SQLiteConnectionStringBuilder
                {
                    ReadOnly = true
                };
                foreach (var file in qchFiles)
                {
                    builder.DataSource = file;
                    using (var connection = new SQLiteConnection(builder.ToString())) {
                        connection.Open();
                        using (var command = new SQLiteCommand(linksForKeyword, connection)) {
                            var reader = QtVsToolsPackage.Instance.JoinableTaskFactory
                                         .Run(async() => await command.ExecuteReaderAsync());
                            using (reader) {
                                while (reader.Read())
                                {
                                    var title = GetString(reader, 0);
                                    if (string.IsNullOrWhiteSpace(title))
                                    {
                                        title = keyword + ':' + GetString(reader, 3);
                                    }
                                    var path = string.Empty;
                                    if (offline)
                                    {
                                        path = "file:///" + Path.Combine(docPath,
                                                                         GetString(reader, 2), GetString(reader, 3));
                                    }
                                    else
                                    {
                                        path = "https://" + Path.Combine("doc.qt.io",
                                                                         $"qt-{info.qtMajor}", GetString(reader, 3));
                                    }
                                    if (!string.IsNullOrWhiteSpace(GetString(reader, 4)))
                                    {
                                        path += "#" + GetString(reader, 4);
                                    }
                                    links.Add(title, path);
                                }
                            }
                        }
                    }
                }

                var uri = string.Empty;
                switch (links.Values.Count)
                {
                case 0:
                    if (!offline && defaultTryOnline)
                    {
                        uri = new UriBuilder($"https://doc.qt.io/qt-{info.qtMajor}/search-results.html")
                        {
                            Query = "q=" + keyword
                        }.ToString();
                    }
                    else
                    {
                        return(false);
                    }
                    break;

                case 1:
                    uri = links.First().Value;
                    break;

                default:
                    var dialog = new QtHelpLinkChooser
                    {
                        Links         = links,
                        Keyword       = keyword,
                        ShowInTaskbar = false
                    };
                    if (!dialog.ShowModal().GetValueOrDefault())
                    {
                        return(false);
                    }
                    uri = dialog.Link
                          .Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
                    break;
                }

                if (string.IsNullOrEmpty(uri))   // offline mode without a single search hit
                {
                    VsShellUtilities.ShowMessageBox(QtVsToolsPackage.Instance,
                                                    "Your search - " + keyword + " - did not match any documents.",
                                                    string.Empty, OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                }
                else
                {
                    var helpUri = new Uri(uri.Replace('\\', '/'));
                    if (helpUri.IsFile && !File.Exists(helpUri.LocalPath))
                    {
                        VsShellUtilities.ShowMessageBox(QtVsToolsPackage.Instance,
                                                        "Your search - " + keyword + " - did match a document, but it could "
                                                        + "not be found on disk. To use the online help, select: "
                                                        + "Help | Set Qt Help Preference | Use Online Documentation",
                                                        string.Empty, OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                        OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                    }
                    else
                    {
                        VsShellUtilities.OpenSystemBrowser(HelperFunctions.ChangePathFormat(uri));
                    }
                }
            } catch (Exception e) {
                Messages.Print(
                    e.Message + "\r\n\r\nStacktrace:\r\n" + e.StackTrace);
            }
            return(true);
        }
Esempio n. 13
0
 public void Navigate(string url)
 {
     VsShellUtilities.OpenSystemBrowser(url);
 }
Esempio n. 14
0
        private void execHandler(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var command = sender as OleMenuCommand;

            if (command == null)
            {
                return;
            }

            switch ((CommandId)command.CommandID.ID)
            {
            case CommandId.ViewQtHelpId:
                VsShellUtilities.OpenSystemBrowser("https://www.qt.io/developers");
                break;

            case CommandId.LaunchDesignerId:
                QtVsToolsPackage.Instance.QtDesigner.Start(hideWindow: false);
                break;

            case CommandId.LaunchLinguistId:
                QtVsToolsPackage.Instance.QtLinguist.Start(hideWindow: false);
                break;

            case CommandId.OpenProFileId:
                ExtLoader.ImportProFile();
                break;

            case CommandId.ImportPriFileId:
                ExtLoader.ImportPriFile(HelperFunctions.GetSelectedQtProject(QtVsToolsPackage.Instance.Dte));
                break;

            case CommandId.ExportPriFileId:
                ExtLoader.ExportPriFile();
                break;

            case CommandId.ExportProFileId:
                ExtLoader.ExportProFile();
                break;

            case CommandId.ConvertToQtId:
            case CommandId.ConvertToQmakeId: {
                var caption = SR.GetString("ConvertTitle");
                var text    = SR.GetString("ConvertConfirmation");
                if (MessageBox.Show(text, caption, MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    HelperFunctions.ToggleProjectKind(HelperFunctions.GetSelectedProject(QtVsToolsPackage
                                                                                         .Instance.Dte));
                }
            }
            break;

            case CommandId.ConvertToQtMsBuild: {
                QtMsBuildConverter.SolutionToQtMsBuild();
            }
            break;

            case CommandId.QtProjectSettingsId: {
                var pro            = HelperFunctions.GetSelectedQtProject(QtVsToolsPackage.Instance.Dte);
                int projectVersion = QtProject.GetFormatVersion(pro);
                if (projectVersion >= Resources.qtMinFormatVersion_Settings)
                {
                    QtVsToolsPackage.Instance.Dte.ExecuteCommand("Project.Properties");
                }
                else if (pro != null)
                {
                    using (var formProjectQtSettings = new FormProjectQtSettings()) {
                        formProjectQtSettings.SetProject(pro);
                        formProjectQtSettings.StartPosition = FormStartPosition.CenterParent;
                        var ww = new MainWinWrapper(QtVsToolsPackage.Instance.Dte);
                        formProjectQtSettings.ShowDialog(ww);
                    }
                }
                else
                {
                    MessageBox.Show(SR.GetString("NoProjectOpened"));
                }
            }
            break;

            case CommandId.ChangeProjectQtVersionId: {
                var pro = HelperFunctions.GetSelectedQtProject(QtVsToolsPackage.Instance.Dte);
                if (HelperFunctions.IsQMakeProject(pro))
                {
                    using (var formChangeQtVersion = new FormChangeQtVersion()) {
                        formChangeQtVersion.UpdateContent(ChangeFor.Project);
                        var ww = new MainWinWrapper(QtVsToolsPackage.Instance.Dte);
                        if (formChangeQtVersion.ShowDialog(ww) == DialogResult.OK)
                        {
                            var qtVersion = formChangeQtVersion.GetSelectedQtVersion();
                            HelperFunctions.SetDebuggingEnvironment(pro, "PATH=" + QtVersionManager
                                                                    .The().GetInstallPath(qtVersion) + @"\bin;$(PATH)", true);
                        }
                    }
                }
            }
            break;

            case CommandId.QtOptionsId:
                QtVsToolsPackage.Instance.ShowOptionPage(typeof(Options.QtOptionsPage));
                break;

            case CommandId.QtVersionsId:
                QtVsToolsPackage.Instance.ShowOptionPage(typeof(Options.QtVersionsPage));
                break;
            }
        }