public static void AddHierarchyItem(this ErrorTask task) { IVsHierarchy hierarchyItem = null; IVsSolution solution = WebEssentialsPackage.GetGlobalService <IVsSolution>(typeof(SVsSolution)); Project project = ProjectHelpers.GetActiveProject(); if (solution != null && project != null) { int flag = -1; try { flag = solution.GetProjectOfUniqueName(project.FullName, out hierarchyItem); } catch (COMException ex) { if ((uint)ex.ErrorCode != DISP_E_MEMBERNOTFOUND) { throw; } } if (0 == flag) { task.HierarchyItem = hierarchyItem; } } }
protected override bool Execute(MinifyCommandId commandId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { if (_spansTuple == null) { return(false); } var source = _spansTuple.Item2.GetText(); string result = Mef.GetImport <IFileMinifier>(_spansTuple.Item2.Snapshot.TextBuffer.ContentType) .MinifyString(source); if (result == null) { return(false); // IFileMinifier already displayed an error } if (result == source) { WebEssentialsPackage.DTE.StatusBar.Text = "The selection is already minified"; return(false); } using (WebEssentialsPackage.UndoContext("Minify")) TextView.TextBuffer.Replace(_spansTuple.Item1, result); return(true); }
private void UpdateTextBuffer(SnapshotSpan span, string text) { using (WebEssentialsPackage.UndoContext("Comment/Uncomment")) { TextView.TextBuffer.Replace(span.Span, text); } }
protected async override void Initialize() { base.Initialize(); Instance = this; SettingsStore.Load(); OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != mcs) { TransformMenu transform = new TransformMenu(DTE, mcs); DiffMenu diffMenu = new DiffMenu(mcs); //MinifyFileMenu minifyMenu = new MinifyFileMenu(mcs); //BundleFilesMenu bundleMenu = new BundleFilesMenu(DTE, mcs); ProjectSettingsMenu projectSettingsMenu = new ProjectSettingsMenu(DTE, mcs); SolutionColorsMenu solutionColorsMenu = new SolutionColorsMenu(mcs); //BuildMenu buildMenu = new BuildMenu(DTE, mcs); MarkdownMenu markdownMenu = new MarkdownMenu(DTE, mcs); AddIntellisenseFileMenu intellisenseFile = new AddIntellisenseFileMenu(DTE, mcs); //UnusedCssMenu unusedCssMenu = new UnusedCssMenu(mcs); PixelPushingMenu pixelPushingMenu = new PixelPushingMenu(mcs); ReferenceJsMenu referenceJsMenu = new ReferenceJsMenu(mcs); CompressImageMenu compressImageMenu = new CompressImageMenu(mcs); //SpriteImageMenu spriteImageMenu = new SpriteImageMenu(DTE, mcs); UnminifyMenu unMinifyMenu = new UnminifyMenu(mcs); AddGruntToProject grunt = new AddGruntToProject(DTE, mcs); HandleMenuVisibility(mcs); referenceJsMenu.SetupCommands(); pixelPushingMenu.SetupCommands(); //unusedCssMenu.SetupCommands(); intellisenseFile.SetupCommands(); markdownMenu.SetupCommands(); //buildMenu.SetupCommands(); solutionColorsMenu.SetupCommands(); projectSettingsMenu.SetupCommands(); //bundleMenu.SetupCommands(); //minifyMenu.SetupCommands(); diffMenu.SetupCommands(); transform.SetupCommands(); compressImageMenu.SetupCommands(); //spriteImageMenu.SetupCommands(); unMinifyMenu.SetupCommands(); grunt.SetupCommands(); } IconRegistration.RegisterIcons(); // Hook up event handlers await Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { DTE.Events.BuildEvents.OnBuildDone += BuildEvents_OnBuildDone; DTE.Events.SolutionEvents.Opened += delegate { SettingsStore.Load(); ShowTopMenu(); }; DTE.Events.SolutionEvents.AfterClosing += delegate { DTE.StatusBar.Clear(); ShowTopMenu(); }; }), DispatcherPriority.ApplicationIdle, null); }
private bool Replace(Replacement callback) { TextDocument document = GetTextDocument(); string replacement = callback(document.Selection.Text); using (WebEssentialsPackage.UndoContext((callback.Method.Name))) document.Selection.Insert(replacement, 0); return(true); }
public void Redo() { try { WebEssentialsPackage.ExecuteCommand("Edit.Redo"); WebEssentialsPackage.DTE.ActiveDocument.Save(); } catch { // Do nothing } }
private bool HandleStartLines(int position, string indentation) { string result = Environment.NewLine + indentation + "* "; using (WebEssentialsPackage.UndoContext("Smart Indent")) { TextView.TextBuffer.Insert(position, result); SnapshotPoint point = new SnapshotPoint(TextView.TextBuffer.CurrentSnapshot, position + result.Length); TextView.Caret.MoveTo(point); } return(true); }
private void Replace(Replacement callback) { TextDocument document = GetTextDocument(); if (document == null) { return; } string replacement = callback(document.Selection.Text); using (WebEssentialsPackage.UndoContext((callback.Method.Name))) document.Selection.Insert(replacement, 0); }
private static void UpdateBuffer(string innerHTML, HtmlEditorDocument html, Span span) { using (WebEssentialsPackage.UndoContext("Design Mode changes")) { try { html.TextBuffer.Replace(span, innerHTML); WebEssentialsPackage.DTE.ActiveDocument.Save(); } catch { // Do nothing } } }
protected override bool Execute(ExtractCommandId commandId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { if (TextView == null) { return(false); } string content = TextView.Selection.SelectedSpans[0].GetText(); string extension = Path.GetExtension(_dte.ActiveDocument.FullName).ToLowerInvariant(); if (!_possible.Contains(extension.ToUpperInvariant())) { extension = ".css"; } string name = Interaction.InputBox("Specify the name of the file", "Web Essentials", "file1" + extension).Trim(); if (!string.IsNullOrEmpty(name)) { if (string.IsNullOrEmpty(Path.GetExtension(name))) { name = name + extension; } string fileName = Path.Combine(Path.GetDirectoryName(_dte.ActiveDocument.FullName), name); if (!File.Exists(fileName)) { using (WebEssentialsPackage.UndoContext("Extract to file...")) { using (StreamWriter writer = new StreamWriter(fileName, false, new UTF8Encoding(true))) { writer.Write(content); } ProjectHelpers.AddFileToActiveProject(fileName); TextView.TextBuffer.Replace(TextView.Selection.SelectedSpans[0].Span, string.Format(CultureInfo.CurrentCulture, "@import \"{0}\";", name)); _dte.ItemOperations.OpenFile(fileName); } } else { Logger.ShowMessage("The file already exists."); } } return(true); }
protected override bool Execute(LinesCommandId commandId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { var span = GetSpan(); var lines = span.GetText().Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); if (lines.Length == 0) { return(false); } string result = SortLines(commandId, lines); using (WebEssentialsPackage.UndoContext(("Sort Selected Lines"))) TextView.TextBuffer.Replace(span.Span, result); return(true); }
private static void AddMetaTag(int index) { Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { var view = ProjectHelpers.GetCurentTextView(); var buffer = view.TextBuffer; using (WebEssentialsPackage.UndoContext("Adding <meta> viewport")) { buffer.Insert(index, "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />" + Environment.NewLine); view.Caret.MoveTo(new SnapshotPoint(buffer.CurrentSnapshot, index + 31 + 37)); view.Selection.Select(new SnapshotSpan(buffer.CurrentSnapshot, 31 + index, 37), false); WebEssentialsPackage.ExecuteCommand("Edit.FormatSelection"); } WebEssentialsPackage.DTE.ActiveDocument.Save(); }), DispatcherPriority.ApplicationIdle, null); }
private static void AddMetaTag(int index) { Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { var view = ProjectHelpers.GetCurentTextView(); var buffer = view.TextBuffer; using (WebEssentialsPackage.UndoContext("Adding <meta> description")) { buffer.Insert(index, "<meta name=\"description\" content=\"The description of my page\" />" + Environment.NewLine); view.Caret.MoveTo(new SnapshotPoint(buffer.CurrentSnapshot, index + 34 + 26)); view.Selection.Select(new SnapshotSpan(buffer.CurrentSnapshot, 34 + index, 26), false); WebEssentialsPackage.ExecuteCommand("Edit.FormatSelection"); } WebEssentialsPackage.DTE.ActiveDocument.Save(); view.ViewScroller.EnsureSpanVisible(new SnapshotSpan(buffer.CurrentSnapshot, index, 1), EnsureSpanVisibleOptions.AlwaysCenter); }), DispatcherPriority.ApplicationIdle, null); }
protected async override void Initialize() { base.Initialize(); Instance = this; Telemetry.Initialize(DTE, Version, "4739999f-47f2-408d-8931-0fd899885bb7"); SettingsStore.Load(); OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != mcs) { TransformMenu transform = new TransformMenu(DTE, mcs); DiffMenu diffMenu = new DiffMenu(mcs); ProjectSettingsMenu projectSettingsMenu = new ProjectSettingsMenu(DTE, mcs); SolutionColorsMenu solutionColorsMenu = new SolutionColorsMenu(mcs); MarkdownMenu markdownMenu = new MarkdownMenu(DTE, mcs); AddIntellisenseFileMenu intellisenseFile = new AddIntellisenseFileMenu(DTE, mcs); PixelPushingMenu pixelPushingMenu = new PixelPushingMenu(mcs); ReferenceJsMenu referenceJsMenu = new ReferenceJsMenu(mcs); UnminifyMenu unMinifyMenu = new UnminifyMenu(mcs); HandleMenuVisibility(mcs); referenceJsMenu.SetupCommands(); pixelPushingMenu.SetupCommands(); intellisenseFile.SetupCommands(); markdownMenu.SetupCommands(); solutionColorsMenu.SetupCommands(); projectSettingsMenu.SetupCommands(); diffMenu.SetupCommands(); transform.SetupCommands(); unMinifyMenu.SetupCommands(); } // Hook up event handlers await Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { DTE.Events.BuildEvents.OnBuildDone += BuildEvents_OnBuildDone; DTE.Events.SolutionEvents.Opened += delegate { SettingsStore.Load(); ShowTopMenu(); }; DTE.Events.SolutionEvents.AfterClosing += delegate { DTE.StatusBar.Clear(); ShowTopMenu(); }; }), DispatcherPriority.ApplicationIdle, null); }
private bool CompleteComment() { int position = TextView.Caret.Position.BufferPosition.Position; if (position < 1) { return(false); } SnapshotSpan span = new SnapshotSpan(TextView.TextBuffer.CurrentSnapshot, position - 1, 1); bool isComment = _classifier.GetClassificationSpans(span).Any(c => c.ClassificationType.IsOfType("comment")); bool isString = IsString(span); if (isComment || isString) { return(false); } char prevChar = TextView.TextBuffer.CurrentSnapshot.ToCharArray(position - 1, 1)[0]; // Abort if the previous characters isn't a forward-slash if (prevChar != '/' || isComment) { return(false); } // Insert the typed character TextView.TextBuffer.Insert(position, "*"); using (WebEssentialsPackage.UndoContext("Comment completion")) { // Use separate undo context for this, so it can be undone separately. TextView.TextBuffer.Insert(position + 1, "*/"); } // Move the caret to the correct point SnapshotPoint point = new SnapshotPoint(TextView.TextBuffer.CurrentSnapshot, position + 1); TextView.Caret.MoveTo(point); return(true); }
public void AddHierarchyItem(ErrorTask task) { if (task == null || Connection == null || Connection.Project == null || string.IsNullOrEmpty(Connection.Project.FullName)) { return; } IVsHierarchy HierarchyItem; IVsSolution solution = WebEssentialsPackage.GetGlobalService <IVsSolution>(typeof(SVsSolution)); if (solution != null) { int flag = solution.GetProjectOfUniqueName(Connection.Project.FullName, out HierarchyItem); if (0 == flag) { task.HierarchyItem = HierarchyItem; } } }
private bool HandleBlockComment(int position, string text, string indentation, int index) { int start = text.IndexOf("/*", StringComparison.Ordinal) + 2; int end = text.IndexOf("*/", StringComparison.Ordinal); if (start == 1 || end == -1 || index < start || index > end) { return(false); } string result = Environment.NewLine + indentation + " * " + Environment.NewLine + indentation + " "; using (WebEssentialsPackage.UndoContext("Smart Indent")) { TextView.TextBuffer.Insert(position, result); SnapshotPoint point = new SnapshotPoint(TextView.TextBuffer.CurrentSnapshot, position + indentation.Length + 5); TextView.Caret.MoveTo(point); } return(true); }
public static void OpenFileInPreviewTab(string file) { IVsNewDocumentStateContext newDocumentStateContext = null; try { IVsUIShellOpenDocument3 openDoc3 = WebEssentialsPackage.GetGlobalService <SVsUIShellOpenDocument>() as IVsUIShellOpenDocument3; Guid reason = VSConstants.NewDocumentStateReason.Navigation; newDocumentStateContext = openDoc3.SetNewDocumentState((uint)__VSNEWDOCUMENTSTATE.NDS_Provisional, ref reason); WebEssentialsPackage.DTE.ItemOperations.OpenFile(file); } finally { if (newDocumentStateContext != null) { newDocumentStateContext.Restore(); } } }
protected override bool Execute(VSConstants.VSStd2KCmdID commandId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { int position = TextView.Caret.Position.BufferPosition.Position; SnapshotPoint point = new SnapshotPoint(TextView.TextBuffer.CurrentSnapshot, position); IWpfTextViewLine line = TextView.GetTextViewLineContainingBufferPosition(point); string text = TextView.TextBuffer.CurrentSnapshot.GetText(line.Start, line.Length); Match match = _indent.Match(text); if (match.Success) { using (WebEssentialsPackage.UndoContext("Smart Indent")) { TextView.TextBuffer.Insert(position, Environment.NewLine + match.Value); } return(true); } return(false); }
private static void GetSize() { try { IVsFontAndColorStorage storage = (IVsFontAndColorStorage)WebEssentialsPackage.GetGlobalService(typeof(IVsFontAndColorStorage)); var guid = new Guid("A27B4E24-A735-4d1d-B8E7-9716E1E3D8E0"); if (storage != null && storage.OpenCategory(ref guid, (uint)(__FCSTORAGEFLAGS.FCSF_READONLY | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) == VS.VSConstants.S_OK) { LOGFONTW[] Fnt = new LOGFONTW[] { new LOGFONTW() }; FontInfo[] Info = new FontInfo[] { new FontInfo() }; storage.GetFont(Fnt, Info); _fontSize = (int)Info[0].wPointSize; } if (storage != null && storage.OpenCategory(ref guid, (uint)(__FCSTORAGEFLAGS.FCSF_NOAUTOCOLORS | __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS)) == VS.VSConstants.S_OK) { var info = new ColorableItemInfo[1]; storage.GetItem("Plain Text", info); _backgroundColor = ConvertFromWin32Color((int)info[0].crBackground); } } catch { } }
static ImageHelper() { _imageService = WebEssentialsPackage.GetGlobalService(typeof(SVsImageService)) as IVsImageService2; }
private void PerformDiff() { WebEssentialsPackage.ExecuteCommand("Tools.DiffFiles", $"\"{files[0]}\" \"{files[1]}\""); }
public static IComponentModel GetComponentModel() { return((IComponentModel)WebEssentialsPackage.GetGlobalService(typeof(SComponentModel))); }
protected async override void Initialize() { base.Initialize(); Instance = this; await NodeServer.Up(); SettingsStore.Load(); JavaScriptIntellisense.Register(); OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != mcs) { TransformMenu transform = new TransformMenu(DTE, mcs); DiffMenu diffMenu = new DiffMenu(mcs); MinifyFileMenu minifyMenu = new MinifyFileMenu(mcs); BundleFilesMenu bundleMenu = new BundleFilesMenu(DTE, mcs); JsHintMenu jsHintMenu = new JsHintMenu(DTE, mcs); TsLintMenu tsLintMenu = new TsLintMenu(DTE, mcs); HubsT4Menu hubsT4Menu = new HubsT4Menu(DTE, mcs); CoffeeLintMenu coffeeLintMenu = new CoffeeLintMenu(DTE, mcs); JsCodeStyle jsCodeStyleMenu = new JsCodeStyle(DTE, mcs); RtlCssMenu rtlCssMenu = new RtlCssMenu(DTE, mcs); CsonMenu cson = new CsonMenu(mcs); ProjectSettingsMenu projectSettingsMenu = new ProjectSettingsMenu(DTE, mcs); SolutionColorsMenu solutionColorsMenu = new SolutionColorsMenu(mcs); BuildMenu buildMenu = new BuildMenu(DTE, mcs); MarkdownMenu markdownMenu = new MarkdownMenu(DTE, mcs); HandlebarsMenu handlebarsMenu = new HandlebarsMenu(DTE, mcs); AddIntellisenseFileMenu intellisenseFile = new AddIntellisenseFileMenu(DTE, mcs); UnusedCssMenu unusedCssMenu = new UnusedCssMenu(mcs); PixelPushingMenu pixelPushingMenu = new PixelPushingMenu(mcs); ReferenceJsMenu referenceJsMenu = new ReferenceJsMenu(mcs); CompressImageMenu compressImageMenu = new CompressImageMenu(mcs); SpriteImageMenu spriteImageMenu = new SpriteImageMenu(DTE, mcs); UnminifyMenu unMinifyMenu = new UnminifyMenu(mcs); //ChainCompilationMenu chainCompilationMenu = new ChainCompilationMenu(DTE, mcs); HandleMenuVisibility(mcs); referenceJsMenu.SetupCommands(); pixelPushingMenu.SetupCommands(); unusedCssMenu.SetupCommands(); intellisenseFile.SetupCommands(); markdownMenu.SetupCommands(); handlebarsMenu.SetupCommands(); buildMenu.SetupCommands(); solutionColorsMenu.SetupCommands(); projectSettingsMenu.SetupCommands(); jsHintMenu.SetupCommands(); tsLintMenu.SetupCommands(); hubsT4Menu.SetupCommands(); coffeeLintMenu.SetupCommands(); jsCodeStyleMenu.SetupCommands(); rtlCssMenu.SetupCommands(); cson.SetupCommands(); bundleMenu.SetupCommands(); minifyMenu.SetupCommands(); diffMenu.SetupCommands(); transform.SetupCommands(); compressImageMenu.SetupCommands(); spriteImageMenu.SetupCommands(); unMinifyMenu.SetupCommands(); //chainCompilationMenu.SetupCommands(); } IconRegistration.RegisterIcons(); // Hook up event handlers await Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { DTE.Events.BuildEvents.OnBuildDone += BuildEvents_OnBuildDone; DTE.Events.SolutionEvents.Opened += delegate { SettingsStore.Load(); ShowTopMenu(); }; DTE.Events.SolutionEvents.AfterClosing += delegate { DTE.StatusBar.Clear(); ShowTopMenu(); }; }), DispatcherPriority.ApplicationIdle, null); }