예제 #1
0
        static void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var doc = CodistPackage.DTE.ActiveDocument;

            if (doc == null)
            {
                return;
            }
            var docWindow = TextEditorHelper.GetActiveWpfDocumentView();

            if (docWindow == null)
            {
                return;
            }
            using (var f = new System.Windows.Forms.SaveFileDialog {
                Filter = "PNG images (*.png)|*.png",
                AddExtension = true,
                Title = "Please specify the location of the screenshot file",
                FileName = System.IO.Path.GetFileNameWithoutExtension(doc.Name) + ".png"
            }) {
                if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    try {
                        var g = docWindow.VisualElement.GetParent <System.Windows.Controls.Grid>();
                        WpfHelper.ScreenShot(g, f.FileName, (int)g.ActualWidth, (int)g.ActualHeight);
                    }
                    catch (Exception ex) {
                        CodistPackage.ShowErrorMessageBox("Failed to save screenshot for " + doc.Name + "\n" + ex.Message, null, true);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Shows the tool window when the menu item is clicked.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        internal static void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (_Window == null || _Window.IsVisible == false)
            {
                var v = TextEditorHelper.GetActiveWpfDocumentView();
                if (v == null)
                {
                    CodistPackage.ShowErrorMessageBox(R.T_CustomizeSyntaxHighlightNote, R.CMD_ConfigureSyntaxHighlight, true);
                    return;
                }
                CreateWindow(v);
            }
            _Window.Show();

            //// Get the instance number 0 of this tool window. This window is single instance so this instance
            //// is actually the only one.
            //// The last flag is set to true so that if the tool window does not exists it will be created.
            //var window = CodistPackage.Instance.FindToolWindow(typeof(SyntaxCustomizerWindow), 0, true);
            //if ((null == window) || (null == window.Frame)) {
            //	throw new NotSupportedException("Cannot create SyntaxCustomizerWindow");
            //}

            //var windowFrame = (IVsWindowFrame)window.Frame;
            //Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
        }
예제 #3
0
        static void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var doc = CodistPackage.DTE.ActiveDocument;

            if (doc == null)
            {
                return;
            }
            var docWindow = TextEditorHelper.GetActiveWpfDocumentView();

            if (docWindow == null)
            {
                return;
            }
            using (var f = new System.Windows.Forms.SaveFileDialog {
                Filter = R.T_PngFileFilter,
                AddExtension = true,
                Title = R.T_SpecifyScreenshotLocation,
                FileName = System.IO.Path.GetFileNameWithoutExtension(doc.Name) + ".png"
            }) {
                if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    try {
                        var g = docWindow.VisualElement.GetParent <System.Windows.Controls.Grid>();
                        WpfHelper.ScreenShot(g, f.FileName, (int)g.ActualWidth, (int)g.ActualHeight);
                    }
                    catch (Exception ex) {
                        CodistPackage.ShowErrorMessageBox(R.T_FailedToSaveScreenshot.Replace("<NAME>", doc.Name) + Environment.NewLine + ex.Message, null, true);
                    }
                }
            }
        }
        static void Execute(object sender, EventArgs e)
        {
            var item = GetSelectedProjectItem();

            if (item == null)
            {
                return;
            }
            const int YesButton = 6;

            if (item.Saved == false && YesButton == VsShellUtilities.ShowMessageBox(CodistPackage.Instance, item.Name + " is not saved.\nDiscard its changes?", "Increment Version", OLEMSGICON.OLEMSGICON_QUERY, OLEMSGBUTTON.OLEMSGBUTTON_YESNO, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_SECOND))
            {
                return;
            }
            string message;
            bool   error = IncrementVersion(item, out message) == false;

            CodistPackage.ShowErrorMessageBox(message, "Increment Version", error);
        }
예제 #5
0
        static void Execute(object sender, EventArgs e)
        {
            var item = GetSelectedProjectItem();

            if (item == null)
            {
                return;
            }
            const int YesButton = 6;

            if (item.Saved == false && YesButton == VsShellUtilities.ShowMessageBox(CodistPackage.Instance, item.Name + " is not saved.\nDiscard its changes?", "Increment Version", OLEMSGICON.OLEMSGICON_QUERY, OLEMSGBUTTON.OLEMSGBUTTON_YESNO, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_SECOND))
            {
                return;
            }
            string       message;
            bool         error     = false;
            const string Namespace = "http://schemas.microsoft.com/developer/vsx-schema/2011";

            try {
                var fileName = item.FileNames[0];
                var doc      = XDocument.Load(fileName);
                var v        = doc.Root.Element(XName.Get("Metadata", Namespace))?.Element(XName.Get("Identity", Namespace))?.Attribute("Version");
                if (v != null && Version.TryParse(v.Value, out var ver))
                {
                    v.Value = new Version(Math.Max(ver.Major, 1), Math.Max(ver.Minor, 0), Math.Max(ver.Build, 0), Math.Max(ver.Revision, 0) + 1).ToString();
                    doc.Save(fileName);
                    message = "Incremented version to " + v.Value;
                }
                else
                {
                    message = "Version not found or verion number invalid in file " + fileName;
                    error   = true;
                }
            }
            catch (Exception ex) {
                message = ex.Message;
                error   = true;
            }

            CodistPackage.ShowErrorMessageBox(message, "Increment Version", error);
        }
예제 #6
0
        protected override void AddCommands(CancellationToken cancellationToken)
        {
            base.AddCommands(cancellationToken);
            string t = TryGetPath(View);

            if (t == null)
            {
                return;
            }
            if (File.Exists(t))
            {
                AddCommand(MyToolBar, IconIds.Open, R.CMD_OpenOrExecuteFile, ctx => {
                    TryRun(TryGetPath(View));
                });
                AddCommand(MyToolBar, IconIds.OpenFolder, R.CMD_OpenFolder, ctx => {
                    var s = TryGetPath(View);
                    if (s != null)
                    {
                        Process.Start("Explorer.exe", "/select,\"" + s + "\"");
                    }
                });
                if (IsFileTypeRegisteredInVS(t))
                {
                    AddCommand(MyToolBar, IconIds.OpenWithVisualStudio, R.CMD_OpenWithVS, ctx => {
                        var s = TryGetPath(View);
                        if (s != null && IsFileTypeRegisteredInVS(s))
                        {
                            CodistPackage.DTE.OpenFile(s, 1, 1);
                        }
                    });
                }
            }
            else if (Directory.Exists(t))
            {
                AddCommand(MyToolBar, IconIds.OpenFolder, R.CMD_OpenFolder, ctx => {
                    TryRun(TryGetPath(View));
                });
            }

            string TryGetPath(ITextView view)
            {
                if (view.TryGetFirstSelectionSpan(out var span) && span.Length < 255)
                {
                    var text = view.TextSnapshot.GetText(span).TrimStart();
                    try {
                        if (Path.IsPathRooted(text))
                        {
                            return(text.Replace(@"\\", @"\"));
                        }
                    }
                    catch (ArgumentException) {
                        // ignore
                    }
                }
                return(null);
            }

            void TryRun(string path)
            {
                if (path == null)
                {
                    return;
                }
                try {
                    Process.Start(path);
                }
                catch (System.ComponentModel.Win32Exception ex) {
                    CodistPackage.ShowErrorMessageBox(ex.Message, null, true);
                }
                catch (FileNotFoundException) {
                    // ignore
                }
            }

            bool IsFileTypeRegisteredInVS(string fileName)
            {
                try {
                    return(ServicesHelper.Instance.FileExtensionRegistry.GetContentTypeForExtension(Path.GetExtension(fileName)).TypeName != "UNKNOWN");
                }
                catch (ArgumentException) {
                    return(false);
                }
            }
        }