示例#1
0
        protected override bool Execute(VSConstants.VSStd97CmdID commandId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (!string.IsNullOrEmpty(_path))
            {
                _path = _path.TrimStart('~').Trim();
                string absolute           = ProjectHelpers.ToAbsoluteFilePathFromActiveFile(_path);
                string dotnetcoreabsolute = ProjectHelpers.ToAbsoluteFilePathFromActiveFile("/wwwroot" + _path);

                if (File.Exists(absolute))
                {
                    ProjectHelpers.OpenFileInPreviewTab(absolute);
                    return(true);
                }
                else if (File.Exists(dotnetcoreabsolute))
                {
                    ProjectHelpers.OpenFileInPreviewTab(dotnetcoreabsolute);
                    return(true);
                }

                ProjectHelpers.DTE.StatusBar.Text = "Couldn't find " + _path;
            }
            else if (!string.IsNullOrEmpty(_className))
            {
                string file = FindFile(new[] { ".less", ".scss", ".css" }, out int position);

                if (!string.IsNullOrEmpty(file))
                {
                    ProjectHelpers.OpenFileInPreviewTab(file);

                    Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
                    {
                        try
                        {
                            IWpfTextView view      = ProjectHelpers.GetCurentTextView();
                            ITextSnapshot snapshot = view.TextBuffer.CurrentSnapshot;
                            view.Caret.MoveTo(new SnapshotPoint(snapshot, position));
                            view.ViewScroller.EnsureSpanVisible(new SnapshotSpan(snapshot, position, 1), EnsureSpanVisibleOptions.AlwaysCenter);
                        }
                        catch
                        { }
                    }), DispatcherPriority.ApplicationIdle, null);

                    return(true);
                }

                ProjectHelpers.DTE.StatusBar.Text = "Couldn't find " + _className;
            }

            return(false);
        }