diff --git a/LineSorter.Export/Enums.cs b/LineSorter.Export/Enums.cs new file mode 100644 index 0000000..d978602 --- /dev/null +++ b/LineSorter.Export/Enums.cs @@ -0,0 +1,15 @@ +using System.ComponentModel; + +namespace LineSorter.Export +{ + public enum EmptyLineAction + { + DependsOnSettings, + Remove, + AsLine, + AsMask, + + [Browsable(false)] + AsGroupMarker + } +} diff --git a/LineSorter.Export/IUserSort.cs b/LineSorter.Export/IUserSort.cs index 74e17c3..4298660 100644 --- a/LineSorter.Export/IUserSort.cs +++ b/LineSorter.Export/IUserSort.cs @@ -6,6 +6,7 @@ public interface IUserSort { string Guid { get; } string Name { get; } + EmptyLineAction EmptyLineAction { get; } IEnumerable Sort(IEnumerable Source); } } diff --git a/LineSorter.Export/LineSorter.Export.csproj b/LineSorter.Export/LineSorter.Export.csproj index 1a8bdd4..7cbcc88 100644 --- a/LineSorter.Export/LineSorter.Export.csproj +++ b/LineSorter.Export/LineSorter.Export.csproj @@ -46,6 +46,7 @@ + diff --git a/LineSorter.Export/Properties/AssemblyInfo.cs b/LineSorter.Export/Properties/AssemblyInfo.cs index fa90b82..0ad443c 100644 --- a/LineSorter.Export/Properties/AssemblyInfo.cs +++ b/LineSorter.Export/Properties/AssemblyInfo.cs @@ -2,8 +2,8 @@ using System.Reflection; using System.Runtime.InteropServices; -[assembly: AssemblyVersion("3.0.0.0")] -[assembly: AssemblyFileVersion("3.0.0.0")] +[assembly: AssemblyVersion("3.5.0.0")] +[assembly: AssemblyFileVersion("3.5.0.0")] [assembly: NeutralResourcesLanguage("en", UltimateResourceFallbackLocation.Satellite)] [assembly: AssemblyTitle("LineSorter.Export")] diff --git a/LineSorter/Commands/CommandAlphSort.cs b/LineSorter/Commands/CommandAlphSort.cs index 67b6efa..b2d3488 100644 --- a/LineSorter/Commands/CommandAlphSort.cs +++ b/LineSorter/Commands/CommandAlphSort.cs @@ -18,7 +18,7 @@ static CommandAlphSort() #region Functions protected override void Execute(OleMenuCommand Button) => - TextSelection.GetSelection(Package, out bool newLine).Select(x => (Row)x).OrderBy(x => x.Cleared).ThenBy(x => x.Cleared.Length).Select(x => (string)x).ReplaceSelection(newLine); + TextSelection.GetSelection(Package, out int[] poses, out bool newLine).Select(x => (Row)x).OrderBy(x => x.Cleared).ThenBy(x => x.Cleared.Length).Select(x => (string)x).ReplaceSelection(poses, newLine); #endregion } } diff --git a/LineSorter/Commands/CommandAlphSortDesc.cs b/LineSorter/Commands/CommandAlphSortDesc.cs index edd2e3a..4665367 100644 --- a/LineSorter/Commands/CommandAlphSortDesc.cs +++ b/LineSorter/Commands/CommandAlphSortDesc.cs @@ -18,7 +18,7 @@ static CommandAlphSortDesc() #region Functions protected override void Execute(OleMenuCommand Button) => - TextSelection.GetSelection(Package, out bool newLine).Select(x => (Row)x).OrderByDescending(x => x.Cleared).ThenByDescending(x => x.Cleared.Length).Select(x => (string)x).ReplaceSelection(newLine); + TextSelection.GetSelection(Package, out int[] poses, out bool newLine).Select(x => (Row)x).OrderByDescending(x => x.Cleared).ThenByDescending(x => x.Cleared.Length).Select(x => (string)x).ReplaceSelection(poses, newLine); #endregion } } diff --git a/LineSorter/Commands/CommandAnchor.cs b/LineSorter/Commands/CommandAnchor.cs index 0fe6822..a234664 100644 --- a/LineSorter/Commands/CommandAnchor.cs +++ b/LineSorter/Commands/CommandAnchor.cs @@ -1,11 +1,7 @@ -using EnvDTE; -using System; +using System; using System.Linq; using LineSorter.Export; -using LineSorter.Options; using Microsoft.VisualStudio.Shell; -using Microsoft.VisualStudio.Threading; -using Microsoft.VisualStudio.Shell.Interop; namespace LineSorter.Commands { diff --git a/LineSorter/Commands/CommandLengthSort.cs b/LineSorter/Commands/CommandLengthSort.cs index 62a5d60..b3ad58d 100644 --- a/LineSorter/Commands/CommandLengthSort.cs +++ b/LineSorter/Commands/CommandLengthSort.cs @@ -18,7 +18,7 @@ static CommandLengthSort() #region Functions protected override void Execute(OleMenuCommand Button) => - TextSelection.GetSelection(Package, out bool newLine).Select(x => (Row)x).OrderBy(x => x.Cleared.Length).ThenBy(x => x.Cleared).Select(x => (string)x).ReplaceSelection(newLine); + TextSelection.GetSelection(Package, out int[] poses, out bool newLine).Select(x => (Row)x).OrderBy(x => x.Cleared.Length).ThenBy(x => x.Cleared).Select(x => (string)x).ReplaceSelection(poses, newLine); #endregion } } diff --git a/LineSorter/Commands/CommandLengthSortDesc.cs b/LineSorter/Commands/CommandLengthSortDesc.cs index c3f2771..cdd0e18 100644 --- a/LineSorter/Commands/CommandLengthSortDesc.cs +++ b/LineSorter/Commands/CommandLengthSortDesc.cs @@ -18,7 +18,7 @@ static CommandLengthSortDesc() #region Functions protected override void Execute(OleMenuCommand Button) => - TextSelection.GetSelection(Package, out bool newLine).Select(x => (Row)x).OrderByDescending(x => x.Cleared.Length).ThenByDescending(x => x.Cleared).Select(x => (string)x).ReplaceSelection(newLine); + TextSelection.GetSelection(Package, out int[] poses, out bool newLine).Select(x => (Row)x).OrderByDescending(x => x.Cleared.Length).ThenByDescending(x => x.Cleared).Select(x => (string)x).ReplaceSelection(poses, newLine); #endregion } } diff --git a/LineSorter/Commands/CommandRandomSort.cs b/LineSorter/Commands/CommandRandomSort.cs index 1e474a9..0c98fee 100644 --- a/LineSorter/Commands/CommandRandomSort.cs +++ b/LineSorter/Commands/CommandRandomSort.cs @@ -22,7 +22,7 @@ static CommandRandomSort() #region Functions protected override void Execute(OleMenuCommand Button) => - Shuffle(TextSelection.GetSelection(Package, out bool newLine)).ReplaceSelection(newLine); + Shuffle(TextSelection.GetSelection(Package, out int[] poses, out bool newLine)).ReplaceSelection(poses, newLine); private static IEnumerable Shuffle(IEnumerable Source) { diff --git a/LineSorter/Commands/CommandUserSort.cs b/LineSorter/Commands/CommandUserSort.cs index cede2b4..58d3b46 100644 --- a/LineSorter/Commands/CommandUserSort.cs +++ b/LineSorter/Commands/CommandUserSort.cs @@ -1,10 +1,7 @@ using System; using System.IO; -using System.Linq; using LineSorter.Export; -using System.Reflection; using LineSorter.Helpers; -using LineSorter.Options; using System.Collections.Generic; using LineSorter.Commands.UserSort; using Microsoft.VisualStudio.Shell; @@ -27,7 +24,7 @@ static CommandUserSort() CommandID = 0x0105; CommandSet = new Guid("e9f69e2b-6313-4c2b-9765-1ddd6439d519"); SavePath = Path.Combine(VSPackage.Path, "UserSort\\"); - ExportFile = Path.Combine(SavePath, "LineSorter.Export.dll"); + ExportFile = new Uri(typeof(IUserSort).Assembly.CodeBase, UriKind.Absolute).LocalPath; if (!Directory.Exists(SavePath)) Directory.CreateDirectory(SavePath); } @@ -49,7 +46,7 @@ protected override void Execute(OleMenuCommand Button) public void AddSort(IUserSort Sort) { - MenuCommandWrapper wrapper = Factory.Create(() => Sort.Sort(TextSelection.GetSelection(Package, out bool was)).ReplaceSelection(was), Sort.Name); + MenuCommandWrapper wrapper = Factory.Create(() => Sort.Sort(TextSelection.GetSelection(Package, Sort.EmptyLineAction, out int[] poses, out bool was)).ReplaceSelection(Sort.EmptyLineAction, poses, was), Sort.Name); wrapper.SetParameter("Guid", Sort.Guid); } #endregion diff --git a/LineSorter/Commands/MenuCommandWrapper.cs b/LineSorter/Commands/MenuCommandWrapper.cs index 5cc4a3e..a15c030 100644 --- a/LineSorter/Commands/MenuCommandWrapper.cs +++ b/LineSorter/Commands/MenuCommandWrapper.cs @@ -1,7 +1,11 @@ -using System; +using EnvDTE; +using System; +using System.Windows.Forms; using System.Collections.Generic; using Microsoft.VisualStudio.Shell; using System.ComponentModel.Design; +using Task = System.Threading.Tasks.Task; +using System.Linq; namespace LineSorter.Commands { @@ -77,6 +81,27 @@ public void ChangeCmdID(CommandID NewID) } public void ChangeCmdID(int NewID) => ChangeCmdID(new CommandID(CommandID.Guid, NewID)); + public async Task SetHotkeyAsync(Keys Mod1, Keys Key1, Keys Key2) => await SetBindingsAsync(GetStringBinding(Mod1, Key1, Key2)); + public async Task SetHotkeyAsync(Keys Mod1, Keys Key1, Keys Mod2, Keys Key2) => await SetBindingsAsync(GetStringBinding(Mod1, Key1, Mod2, Key2)); + public async Task RemoveHotkeyAsync() => await SetBindingsAsync(); + private async Task SetBindingsAsync(params string[] Bindings) + { + await VSPackage.Instance.JoinableTaskFactory.SwitchToMainThreadAsync(); + DTE dte = (await VSPackage.Instance.GetServiceAsync(typeof(DTE))) as DTE; + Command cmd = dte.Commands.Item(CommandID.Guid.ToString(), CommandID.ID); + cmd.Bindings = Bindings; + } + private string GetStringBinding(params Keys[] Keys) + { + return $"Global::{string.Join("+", Keys.Select(getKey))}"; + string getKey(Keys key) + { + if ((int)key > 47 && (int)key < 58) + return ((int)key - 48).ToString(); + return key.ToString(); + } + } + public override string ToString() => Text; public override int GetHashCode() => CommandID.GetHashCode(); public override bool Equals(object obj) => obj is MenuCommandWrapper wrapper && wrapper.CommandID == CommandID; diff --git a/LineSorter/Commands/UserSort/FormCreateFunc.Designer.cs b/LineSorter/Commands/UserSort/FormCreateFunc.Designer.cs index e9f51d3..ae0ccb9 100644 --- a/LineSorter/Commands/UserSort/FormCreateFunc.Designer.cs +++ b/LineSorter/Commands/UserSort/FormCreateFunc.Designer.cs @@ -42,6 +42,8 @@ private void InitializeComponent() this.textAfter = new LineSorter.Commands.UserSort.LangBox(); this.textBefore = new LineSorter.Commands.UserSort.LangBox(); this.textMain = new LineSorter.Commands.UserSort.LangBox(); + this.labelEmpty = new System.Windows.Forms.Label(); + this.comboLines = new System.Windows.Forms.ComboBox(); this.SuspendLayout(); // // comboLang @@ -125,7 +127,7 @@ private void InitializeComponent() // buttCancel // this.buttCancel.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttCancel.Location = new System.Drawing.Point(379, 181); + this.buttCancel.Location = new System.Drawing.Point(379, 210); this.buttCancel.Name = "buttCancel"; this.buttCancel.Size = new System.Drawing.Size(121, 23); this.buttCancel.TabIndex = 9; @@ -136,7 +138,7 @@ private void InitializeComponent() // buttCompile // this.buttCompile.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttCompile.Location = new System.Drawing.Point(252, 181); + this.buttCompile.Location = new System.Drawing.Point(252, 210); this.buttCompile.Name = "buttCompile"; this.buttCompile.Size = new System.Drawing.Size(121, 23); this.buttCompile.TabIndex = 10; @@ -148,7 +150,7 @@ private void InitializeComponent() // this.panelBack.BackColor = System.Drawing.Color.White; this.panelBack.Cursor = System.Windows.Forms.Cursors.IBeam; - this.panelBack.Location = new System.Drawing.Point(15, 143); + this.panelBack.Location = new System.Drawing.Point(15, 172); this.panelBack.Name = "panelBack"; this.panelBack.Size = new System.Drawing.Size(485, 17); this.panelBack.TabIndex = 11; @@ -159,7 +161,7 @@ private void InitializeComponent() this.labelName.AutoSize = true; this.labelName.Font = new System.Drawing.Font("Segoe UI", 9F); this.labelName.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.labelName.Location = new System.Drawing.Point(12, 102); + this.labelName.Location = new System.Drawing.Point(12, 131); this.labelName.Name = "labelName"; this.labelName.Size = new System.Drawing.Size(42, 15); this.labelName.TabIndex = 12; @@ -168,7 +170,7 @@ private void InitializeComponent() // textName // this.textName.Font = new System.Drawing.Font("Segoe UI", 9F); - this.textName.Location = new System.Drawing.Point(101, 99); + this.textName.Location = new System.Drawing.Point(101, 128); this.textName.Name = "textName"; this.textName.Size = new System.Drawing.Size(399, 23); this.textName.TabIndex = 13; @@ -182,8 +184,9 @@ private void InitializeComponent() this.textAfter.CommentColor = System.Drawing.Color.YellowGreen; this.textAfter.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.textAfter.Freezed = false; + this.textAfter.Interval = 1000; this.textAfter.KeywordColor = System.Drawing.Color.SteelBlue; - this.textAfter.Location = new System.Drawing.Point(15, 160); + this.textAfter.Location = new System.Drawing.Point(15, 189); this.textAfter.Name = "textAfter"; this.textAfter.NumericColor = System.Drawing.Color.SpringGreen; this.textAfter.ReadOnly = true; @@ -202,8 +205,9 @@ private void InitializeComponent() this.textBefore.CommentColor = System.Drawing.Color.YellowGreen; this.textBefore.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.textBefore.Freezed = false; + this.textBefore.Interval = 1000; this.textBefore.KeywordColor = System.Drawing.Color.SteelBlue; - this.textBefore.Location = new System.Drawing.Point(15, 128); + this.textBefore.Location = new System.Drawing.Point(15, 157); this.textBefore.Name = "textBefore"; this.textBefore.NumericColor = System.Drawing.Color.SpringGreen; this.textBefore.ReadOnly = true; @@ -223,8 +227,9 @@ private void InitializeComponent() this.textMain.CommentColor = System.Drawing.Color.YellowGreen; this.textMain.Font = new System.Drawing.Font("Segoe UI", 9F); this.textMain.Freezed = false; + this.textMain.Interval = 1000; this.textMain.KeywordColor = System.Drawing.Color.SteelBlue; - this.textMain.Location = new System.Drawing.Point(35, 143); + this.textMain.Location = new System.Drawing.Point(35, 172); this.textMain.MaximumSize = new System.Drawing.Size(465, 200); this.textMain.MinimumSize = new System.Drawing.Size(465, 17); this.textMain.Name = "textMain"; @@ -236,12 +241,41 @@ private void InitializeComponent() this.textMain.Text = ""; this.textMain.TextChanged += new System.EventHandler(this.TextMain_TextChanged); // + // labelEmpty + // + this.labelEmpty.AutoSize = true; + this.labelEmpty.Font = new System.Drawing.Font("Segoe UI", 9F); + this.labelEmpty.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.labelEmpty.Location = new System.Drawing.Point(12, 102); + this.labelEmpty.Name = "labelEmpty"; + this.labelEmpty.Size = new System.Drawing.Size(74, 15); + this.labelEmpty.TabIndex = 15; + this.labelEmpty.Text = "Empty Lines:"; + // + // comboLines + // + this.comboLines.DisplayMember = "1"; + this.comboLines.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboLines.Font = new System.Drawing.Font("Segoe UI", 9F); + this.comboLines.FormattingEnabled = true; + this.comboLines.Items.AddRange(new object[] { + "Depends on global settings", + "Remove", + "As ordinary strings", + "As mask"}); + this.comboLines.Location = new System.Drawing.Point(101, 99); + this.comboLines.Name = "comboLines"; + this.comboLines.Size = new System.Drawing.Size(399, 23); + this.comboLines.TabIndex = 14; + // // FormCreateFunc // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(506, 210); + this.ClientSize = new System.Drawing.Size(507, 237); this.ControlBox = false; + this.Controls.Add(this.labelEmpty); + this.Controls.Add(this.comboLines); this.Controls.Add(this.textName); this.Controls.Add(this.labelName); this.Controls.Add(this.buttCompile); @@ -285,5 +319,7 @@ private void InitializeComponent() private System.Windows.Forms.Panel panelBack; private System.Windows.Forms.Label labelName; private System.Windows.Forms.TextBox textName; + private System.Windows.Forms.Label labelEmpty; + private System.Windows.Forms.ComboBox comboLines; } } \ No newline at end of file diff --git a/LineSorter/Commands/UserSort/FormCreateFunc.cs b/LineSorter/Commands/UserSort/FormCreateFunc.cs index e2dae7a..8853d3a 100644 --- a/LineSorter/Commands/UserSort/FormCreateFunc.cs +++ b/LineSorter/Commands/UserSort/FormCreateFunc.cs @@ -55,12 +55,26 @@ static FormCreateFunc() Manager["labelFunc", ru] = "Тип функции:"; Manager["labelT", en] = "`T` is:"; Manager["labelT", ru] = "`T` является:"; + Manager["labelEmpty", en] = "Empty Lines:"; + Manager["labelEmpty", ru] = "Пустые линии:"; Manager["labelName", en] = "Name:"; Manager["labelName", ru] = "Название:"; Manager["buttCompile", en] = "Compile"; Manager["buttCompile", ru] = "Компилировать"; Manager["buttCancel", en] = "Cancel"; Manager["buttCancel", ru] = "Отмена"; + Manager["comboFunc.Items.0", en] = "Comparer (Func)"; + Manager["comboFunc.Items.0", ru] = "Компаратор (Func)"; + Manager["comboFunc.Items.1", en] = "Full implementation (Func, IEnumerable>)"; + Manager["comboFunc.Items.1", ru] = "Полная реализация (Func, IEnumerable>)"; + Manager["comboLines.Items.0", en] = "Depends on global settings"; + Manager["comboLines.Items.0", ru] = "Аналогично глобальным настройкам"; + Manager["comboLines.Items.1", en] = "Remove"; + Manager["comboLines.Items.1", ru] = "Удалять"; + Manager["comboLines.Items.2", en] = "As ordinary strings"; + Manager["comboLines.Items.2", ru] = "Как обычные строки"; + Manager["comboLines.Items.3", en] = "As mask"; + Manager["comboLines.Items.3", ru] = "В качестве маски"; Manager["Error", en] = "Error!"; Manager["Error", ru] = "Ошибка!"; Manager["Error.NoName", en] = "Please specify the function name!"; @@ -86,9 +100,10 @@ public FormCreateFunc(string SavePath) comboLang.SelectedIndex = 0; comboFunc.SelectedIndex = 0; comboType.SelectedIndex = 0; + comboLines.SelectedIndex = 0; Measure = Graphics.FromImage(new Bitmap(textMain.Width, textMain.MaximumSize.Height)); - foreach (Control x in new Control[] { this, labelLang, labelFunc, labelT, labelName, buttCompile, buttCancel }) - x.Text = Manager[x.Name]; + Manager.Localize(this); + } public FormCreateFunc() : this(string.Empty) { } #endregion @@ -105,6 +120,7 @@ private void Compile() bool isCSharp = comboLang.SelectedIndex == 0; bool isString = comboType.SelectedIndex == 0; bool isCompare = comboFunc.SelectedIndex == 0; + string emptyLineAction = ((EmptyLineAction)comboLines.SelectedIndex).ToString(); string userCode = $"{(isCSharp ? textBefore.Text : (isCompare ? $"{textBefore.Text} Implements IComparer(Of {(isString ? "String" : "Row")}).Compare" : (isString ? ($"{textBefore.Text} Implements IUserSort.Sort") : textBefore.Text)))}{Environment.NewLine}{textMain.Text}{Environment.NewLine}{textAfter.Text}"; if (isCSharp) { @@ -161,6 +177,7 @@ public class Wrapper : IUserSort {{ public string Guid {{ get {{ return ""{guid}""; }} }} public string Name {{ get {{ return ""{name}""; }} }} + public EmptyLineAction EmptyLineAction {{ get {{ return EmptyLineAction.{emptyLineAction}; }} }} {userCode} public override string ToString() {{ @@ -183,6 +200,11 @@ Public ReadOnly Property Name As String Implements IUserSort.Name Return ""{name}"" End Get End Property + Public ReadOnly Property EmptyLineAction As EmptyLineAction Implements IUserSort.EmptyLineAction + Get + Return EmptyLineAction.{emptyLineAction} + End Get + End Property {userCode} Public Overrides Function ToString() As String Return Name diff --git a/LineSorter/Commands/UserSort/FormTestFunc.cs b/LineSorter/Commands/UserSort/FormTestFunc.cs index 800d73e..d763ed8 100644 --- a/LineSorter/Commands/UserSort/FormTestFunc.cs +++ b/LineSorter/Commands/UserSort/FormTestFunc.cs @@ -50,8 +50,7 @@ public FormTestFunc(IUserSort Sorter) : this() using Microsoft.CodeAnalysis.Text; using Antlr4.Runtime.Misc;"; this.Sorter = Sorter; - foreach (Control x in new Control[] { this, labelTest, labelResult, buttDone }) - x.Text = Manager[x.Name]; + Manager.Localize(this); Sort(); } #endregion diff --git a/LineSorter/Helpers/ResourceManager.cs b/LineSorter/Helpers/ResourceManager.cs index 7869d03..67a7ea0 100644 --- a/LineSorter/Helpers/ResourceManager.cs +++ b/LineSorter/Helpers/ResourceManager.cs @@ -1,4 +1,5 @@ using System.Globalization; +using System.Windows.Forms; using System.Collections.Generic; namespace LineSorter.Helpers @@ -24,11 +25,53 @@ public string this[string Key] get => Get(Key); set => Set(Key, value); } + public string this[Control Control] + { + get => Get(Control.Name); + set => Set(Control.Name, value); + } public string this[string Key, CultureInfo Culture] { get => Get(Key, Culture); set => Set(Key, value, Culture); } + public string this[Control Control, CultureInfo Culture] + { + get => Get(Control.Name, Culture); + set => Set(Control.Name, value, Culture); + } + + public void Localize(Control Container) + { + string text = Get(Container.Name); + if (text != null) + Container.Text = text; + if (Container.ContextMenuStrip != null) + Localize(Container.ContextMenuStrip); + foreach (Control x in Container.Controls) + Localize(x); + if (Container is ComboBox combo) + LocalizeItems(combo); + } + private void Localize(ToolStrip Container) + { + string text = Get(Container.Name); + if (text != null) + Container.Text = text; + foreach (ToolStripItem x in Container.Items) + { + text = Get(x.Name); + if (text != null) + x.Text = text; + } + } + + public void LocalizeItems(ComboBox Box) + { + int count = Box.Items.Count; + for (int i = 0; i < count; ++i) + Box.Items[i] = Get($"{Box.Name}.Items.{i}") ?? Box.Items[i]; + } public static void Set(string Key, string Value, CultureInfo Culture) { diff --git a/LineSorter/Helpers/SortsLoader.cs b/LineSorter/Helpers/SortsLoader.cs index 52d3267..85e2bd8 100644 --- a/LineSorter/Helpers/SortsLoader.cs +++ b/LineSorter/Helpers/SortsLoader.cs @@ -1,11 +1,8 @@ -using System; -using System.IO; +using System.IO; using System.Linq; -using System.Text; using LineSorter.Export; using LineSorter.Options; using LineSorter.Commands; -using System.Threading.Tasks; using System.Collections.Generic; namespace LineSorter.Helpers diff --git a/LineSorter/Helpers/TextSelection.cs b/LineSorter/Helpers/TextSelection.cs index 2cbd178..f27690b 100644 --- a/LineSorter/Helpers/TextSelection.cs +++ b/LineSorter/Helpers/TextSelection.cs @@ -3,6 +3,7 @@ using Microsoft; using System.Linq; using System.Windows; +using LineSorter.Export; using System.Collections.Generic; using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.TextManager.Interop; @@ -16,26 +17,58 @@ public static class TextSelection #endregion #region Functions - public static IEnumerable GetSelection(out bool WasNewLine) + public static IEnumerable GetSelection(EmptyLineAction Action, out int[] EmptyLinePositions, out bool WasNewLine) { IVsTextManager2 textManager = ServiceProvider.GetService(typeof(SVsTextManager)) as IVsTextManager2; Assumes.Present(textManager); textManager.GetActiveView2(1, null, (uint)_VIEWFRAMETYPE.vftCodeWindow, out IVsTextView view); view.GetSelectedText(out string selectedText); WasNewLine = selectedText.EndsWith("\n"); - return selectedText.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); + IEnumerable result = selectedText.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); + int lastIndex = ((string[])result).Length - 1; + EmptyLinePositions = result.Select((x, i) => new { Line = x, Index = i }).Where(x => string.IsNullOrWhiteSpace(x.Line)).Select(x => x.Index).ToArray(); + if (Action == EmptyLineAction.DependsOnSettings) + Action = VSPackage.Loader.Settings.EmptyLineAction; + result = Action == EmptyLineAction.AsLine ? result.Where((x, i) => !(string.IsNullOrEmpty(x) && i == lastIndex)) : result.Where(x => !string.IsNullOrWhiteSpace(x)); + return result; } - public static IEnumerable GetSelection(IServiceProvider ServiceProvider, out bool WasNewLine) + public static IEnumerable GetSelection(IServiceProvider ServiceProvider, out int[] EmptyLinePositions, out bool WasNewLine) { TextSelection.ServiceProvider = ServiceProvider; - return GetSelection(out WasNewLine); + return GetSelection(VSPackage.Loader.Settings.EmptyLineAction, out EmptyLinePositions, out WasNewLine); + } + public static IEnumerable GetSelection(IServiceProvider ServiceProvider, EmptyLineAction Action, out int[] EmptyLinePositions, out bool WasNewLine) + { + TextSelection.ServiceProvider = ServiceProvider; + return GetSelection(Action, out EmptyLinePositions, out WasNewLine); } - public static void ReplaceSelection(this IEnumerable Selections, bool WasNewLine) + public static void ReplaceSelection(this IEnumerable Selections, EmptyLineAction Action, int[] EmptyLinePositions, bool WasNewLine) { ThreadHelper.ThrowIfNotOnUIThread(); + if (Action == EmptyLineAction.DependsOnSettings) + Action = VSPackage.Loader.Settings.EmptyLineAction; DTE dte = ServiceProvider?.GetService(typeof(DTE)) as DTE; if (dte is null) return; + switch (Action) + { + case EmptyLineAction.AsMask: + int i = 0; + Selections = Selections.SelectMany(x => { + List result = new List(); + while(EmptyLinePositions.Contains(i)) + { + result.Add(string.Empty); + i++; + } + result.Add(x); + i++; + return result; + }); + break; + default: + break; + } // `((EnvDTE.TextSelection)dte.ActiveDocument.Selection).Text = value` is really slow! // So I use this small 'hack': // Saving current clipboard state: @@ -47,12 +80,17 @@ public static void ReplaceSelection(this IEnumerable Selections, bool Wa // Now we return everything as it was) Clipboard.SetDataObject(obj); } - public static void ReplaceSelection(this IEnumerable Selections) => ReplaceSelection(Selections, ServiceProvider, false); - public static void ReplaceSelection(this IEnumerable Selections, IServiceProvider ServiceProvider, bool WasNewLine) + public static void ReplaceSelection(this IEnumerable Selections, IServiceProvider ServiceProvider, int[] EmptyLinePositions, bool WasNewLine) + { + TextSelection.ServiceProvider = ServiceProvider; + ReplaceSelection(Selections, VSPackage.Loader.Settings.EmptyLineAction, EmptyLinePositions, WasNewLine); + } + public static void ReplaceSelection(this IEnumerable Selections, IServiceProvider ServiceProvider, EmptyLineAction Action, int[] EmptyLinePositions, bool WasNewLine) { TextSelection.ServiceProvider = ServiceProvider; - ReplaceSelection(Selections, WasNewLine); + ReplaceSelection(Selections, Action, EmptyLinePositions, WasNewLine); } + public static void ReplaceSelection(this IEnumerable Selections, int[] EmptyLinePositions, bool WasNewLine) => ReplaceSelection(Selections, VSPackage.Loader.Settings.EmptyLineAction, EmptyLinePositions, WasNewLine); #endregion } } diff --git a/LineSorter/LineSorter.Export.dll b/LineSorter/LineSorter.Export.dll new file mode 100644 index 0000000..1c1a77a Binary files /dev/null and b/LineSorter/LineSorter.Export.dll differ diff --git a/LineSorter/LineSorter.csproj b/LineSorter/LineSorter.csproj index c674719..cdd0a0b 100644 --- a/LineSorter/LineSorter.csproj +++ b/LineSorter/LineSorter.csproj @@ -128,8 +128,7 @@ False - UserSort\LineSorter.Export.dll - False + .\LineSorter.Export.dll @@ -238,7 +237,9 @@ + + @@ -279,6 +280,10 @@ Always true + + true + Always + TextTemplatingFileGenerator @@ -286,10 +291,6 @@ - - true - Always - True True diff --git a/LineSorter/Options/OptionControl.Designer.cs b/LineSorter/Options/OptionControl.Designer.cs index aa6a886..bcdcfbe 100644 --- a/LineSorter/Options/OptionControl.Designer.cs +++ b/LineSorter/Options/OptionControl.Designer.cs @@ -37,15 +37,20 @@ private void InitializeComponent() this.checkLoadOnInit = new System.Windows.Forms.CheckBox(); this.groupUserSort = new System.Windows.Forms.GroupBox(); this.gridSorts = new System.Windows.Forms.DataGridView(); + this.ColumnGuid = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnSort = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.gridStrip = new System.Windows.Forms.ContextMenuStrip(this.components); this.buttUse = new System.Windows.Forms.ToolStripMenuItem(); this.buttDelete = new System.Windows.Forms.ToolStripMenuItem(); - this.ColumnGuid = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnSort = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.groupLines = new System.Windows.Forms.GroupBox(); + this.checkRemove = new System.Windows.Forms.RadioButton(); + this.checkAsLine = new System.Windows.Forms.RadioButton(); + this.checkAsMask = new System.Windows.Forms.RadioButton(); this.groupAutoLoad.SuspendLayout(); this.groupUserSort.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.gridSorts)).BeginInit(); this.gridStrip.SuspendLayout(); + this.groupLines.SuspendLayout(); this.SuspendLayout(); // // groupAutoLoad @@ -55,7 +60,7 @@ private void InitializeComponent() this.groupAutoLoad.Controls.Add(this.checkLoadOnCreate); this.groupAutoLoad.Controls.Add(this.checkLoadOnInit); this.groupAutoLoad.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); - this.groupAutoLoad.Location = new System.Drawing.Point(3, 0); + this.groupAutoLoad.Location = new System.Drawing.Point(3, 104); this.groupAutoLoad.Name = "groupAutoLoad"; this.groupAutoLoad.Size = new System.Drawing.Size(332, 79); this.groupAutoLoad.TabIndex = 5; @@ -71,7 +76,7 @@ private void InitializeComponent() this.checkLoadOnCreate.TabIndex = 1; this.checkLoadOnCreate.Text = "Загружать пользовательские сортировки при создании"; this.checkLoadOnCreate.UseVisualStyleBackColor = true; - this.checkLoadOnCreate.CheckedChanged += new System.EventHandler(this.CheckLoadOnCreate_CheckedChanged); + this.checkLoadOnCreate.CheckedChanged += new System.EventHandler(this.StateChanged); // // checkLoadOnInit // @@ -82,14 +87,14 @@ private void InitializeComponent() this.checkLoadOnInit.TabIndex = 0; this.checkLoadOnInit.Text = "Загружать пользовательские сортировки при запуске"; this.checkLoadOnInit.UseVisualStyleBackColor = true; - this.checkLoadOnInit.CheckedChanged += new System.EventHandler(this.CheckLoadOnInit_CheckedChanged); + this.checkLoadOnInit.CheckedChanged += new System.EventHandler(this.StateChanged); // // groupUserSort // this.groupUserSort.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.groupUserSort.Controls.Add(this.gridSorts); - this.groupUserSort.Location = new System.Drawing.Point(3, 82); + this.groupUserSort.Location = new System.Drawing.Point(3, 189); this.groupUserSort.Name = "groupUserSort"; this.groupUserSort.Size = new System.Drawing.Size(332, 64); this.groupUserSort.TabIndex = 6; @@ -151,6 +156,18 @@ private void InitializeComponent() this.gridSorts.Leave += new System.EventHandler(this.GridSorts_Leave); this.gridSorts.MouseDown += new System.Windows.Forms.MouseEventHandler(this.GridSorts_MouseDown); // + // ColumnGuid + // + this.ColumnGuid.HeaderText = "Guid"; + this.ColumnGuid.Name = "ColumnGuid"; + this.ColumnGuid.ReadOnly = true; + // + // ColumnSort + // + this.ColumnSort.HeaderText = "Name"; + this.ColumnSort.Name = "ColumnSort"; + this.ColumnSort.ReadOnly = true; + // // gridStrip // this.gridStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -174,22 +191,62 @@ private void InitializeComponent() this.buttDelete.Text = "Удалить"; this.buttDelete.Click += new System.EventHandler(this.ButtDelete_Click); // - // ColumnGuid + // groupLines // - this.ColumnGuid.HeaderText = "Guid"; - this.ColumnGuid.Name = "ColumnGuid"; - this.ColumnGuid.ReadOnly = true; + this.groupLines.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupLines.Controls.Add(this.checkAsMask); + this.groupLines.Controls.Add(this.checkAsLine); + this.groupLines.Controls.Add(this.checkRemove); + this.groupLines.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.groupLines.Location = new System.Drawing.Point(3, 0); + this.groupLines.Name = "groupLines"; + this.groupLines.Size = new System.Drawing.Size(332, 98); + this.groupLines.TabIndex = 6; + this.groupLines.TabStop = false; + this.groupLines.Text = "Обработка пустых строк"; // - // ColumnSort + // checkRemove // - this.ColumnSort.HeaderText = "Name"; - this.ColumnSort.Name = "ColumnSort"; - this.ColumnSort.ReadOnly = true; + this.checkRemove.AutoSize = true; + this.checkRemove.Location = new System.Drawing.Point(7, 23); + this.checkRemove.Name = "checkRemove"; + this.checkRemove.Size = new System.Drawing.Size(151, 19); + this.checkRemove.TabIndex = 0; + this.checkRemove.TabStop = true; + this.checkRemove.Text = "Удалять пустые строки"; + this.checkRemove.UseVisualStyleBackColor = true; + this.checkRemove.CheckedChanged += new System.EventHandler(this.StateChanged); + // + // checkAsLine + // + this.checkAsLine.AutoSize = true; + this.checkAsLine.Location = new System.Drawing.Point(7, 48); + this.checkAsLine.Name = "checkAsLine"; + this.checkAsLine.Size = new System.Drawing.Size(221, 19); + this.checkAsLine.TabIndex = 1; + this.checkAsLine.TabStop = true; + this.checkAsLine.Text = "Обрабатывать как обычные строки"; + this.checkAsLine.UseVisualStyleBackColor = true; + this.checkAsLine.CheckedChanged += new System.EventHandler(this.StateChanged); + // + // checkAsMask + // + this.checkAsMask.AutoSize = true; + this.checkAsMask.Location = new System.Drawing.Point(7, 73); + this.checkAsMask.Name = "checkAsMask"; + this.checkAsMask.Size = new System.Drawing.Size(283, 19); + this.checkAsMask.TabIndex = 2; + this.checkAsMask.TabStop = true; + this.checkAsMask.Text = "Использовать как маску (неподвижный якорь)"; + this.checkAsMask.UseVisualStyleBackColor = true; + this.checkAsMask.CheckedChanged += new System.EventHandler(this.StateChanged); // // OptionControl // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.groupLines); this.Controls.Add(this.groupUserSort); this.Controls.Add(this.groupAutoLoad); this.Name = "OptionControl"; @@ -200,6 +257,8 @@ private void InitializeComponent() this.groupUserSort.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.gridSorts)).EndInit(); this.gridStrip.ResumeLayout(false); + this.groupLines.ResumeLayout(false); + this.groupLines.PerformLayout(); this.ResumeLayout(false); } @@ -216,5 +275,9 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem buttDelete; private System.Windows.Forms.DataGridViewTextBoxColumn ColumnGuid; private System.Windows.Forms.DataGridViewTextBoxColumn ColumnSort; + private System.Windows.Forms.GroupBox groupLines; + private System.Windows.Forms.RadioButton checkAsMask; + private System.Windows.Forms.RadioButton checkAsLine; + private System.Windows.Forms.RadioButton checkRemove; } } diff --git a/LineSorter/Options/OptionControl.cs b/LineSorter/Options/OptionControl.cs index b63c002..74acf48 100644 --- a/LineSorter/Options/OptionControl.cs +++ b/LineSorter/Options/OptionControl.cs @@ -12,6 +12,7 @@ namespace LineSorter.Options public partial class OptionControl : UserControl { #region Var + private bool Initialized { get; } private List Selected { get; set; } public Color SelectedSort { get; set; } = Color.LightGreen; @@ -29,12 +30,22 @@ static OptionControl() Manager["OptionControl", ru] = "Общие"; Manager["groupAutoLoad", en] = "Autoload"; Manager["groupAutoLoad", ru] = "Автозагрузка"; + Manager["groupLines", en] = "Empty lines processing"; + Manager["groupLines", ru] = "Обработка пустых строк"; Manager["groupUserSort", en] = "Custom sorts"; Manager["groupUserSort", ru] = "Пользовательские сортировки"; Manager["checkLoadOnInit", en] = "Load custom sorts at startup"; Manager["checkLoadOnInit", ru] = "Загружать пользовательские сортировки при запуске"; Manager["checkLoadOnCreate", en] = "Load custom sorts on creating"; Manager["checkLoadOnCreate", ru] = "Загружать пользовательские сортировки при создании"; + Manager["checkRemove", en] = "Delete empty lines"; + Manager["checkRemove", ru] = "Удалять пустые строки"; + Manager["checkAsLine", en] = "Process as ordinary strings"; + Manager["checkAsLine", ru] = "Обрабатывать как обычные строки"; + Manager["checkAsMask", en] = "Use as mask (fixed anchor)"; + Manager["checkAsMask", ru] = "Использовать как маску (неподвижный якорь)"; + Manager["checkAsGroupMarker", en] = "Use as separator"; + Manager["checkAsGroupMarker", ru] = "Использовать как разделитель"; Manager["buttDelete", en] = "Delete"; Manager["buttDelete", ru] = "Удалить"; Manager["buttUse.Use", en] = "Use"; @@ -53,9 +64,9 @@ public OptionControl() Selected = new List(VSPackage.Loader.Settings.Loaded); checkLoadOnInit.Checked = VSPackage.Loader.Settings.LoadOnInit; checkLoadOnCreate.Checked = VSPackage.Loader.Settings.LoadOnCreate; - foreach (Control x in new Control[] { this, groupAutoLoad, groupUserSort, checkLoadOnInit, checkLoadOnCreate }) - x.Text = Manager[x.Name]; - buttDelete.Text = Manager["buttDelete"]; + groupLines.Controls.OfType().First(x => x.Name.EndsWith(VSPackage.Loader.Settings.EmptyLineAction.ToString())).Checked = true; + Manager.Localize(this); + Initialized = true; } #endregion @@ -100,22 +111,30 @@ private void SetBackColor(DataGridViewRow Row, Color Color) foreach (DataGridViewCell cell in Row.Cells) cell.Style.BackColor = Color; } - #endregion - #region Actions - private void CheckLoadOnInit_CheckedChanged(object sender, System.EventArgs e) + private void UpdateSettings() { - VSPackage.Loader.Settings.LoadOnInit = checkLoadOnInit.Checked; - VSPackage.Loader.Settings.Save(SortsLoader.SettingsPath); + if (Initialized) + { + VSPackage.Loader.Settings.LoadOnInit = checkLoadOnInit.Checked; + VSPackage.Loader.Settings.LoadOnCreate = checkLoadOnCreate.Checked; + VSPackage.Loader.Settings.EmptyLineAction = (EmptyLineAction)System.Enum.Parse(typeof(EmptyLineAction), groupLines.Controls.OfType().FirstOrDefault(x => x.Checked)?.Name.Replace("check", string.Empty) ?? "Remove"); + VSPackage.Loader.Settings.Save(SortsLoader.SettingsPath); + } } + #endregion - private void CheckLoadOnCreate_CheckedChanged(object sender, System.EventArgs e) + #region Actions + private void StateChanged(object sender, System.EventArgs e) => UpdateSettings(); + + private void OptionControl_VisibleChanged(object sender, System.EventArgs e) { - VSPackage.Loader.Settings.LoadOnCreate = checkLoadOnCreate.Checked; - VSPackage.Loader.Settings.Save(SortsLoader.SettingsPath); - } + // Refresh sizes + checkLoadOnCreate.AutoSize = checkLoadOnInit.AutoSize = false; + checkLoadOnCreate.AutoSize = checkLoadOnInit.AutoSize = true; - private void OptionControl_VisibleChanged(object sender, System.EventArgs e) => RefreshData(); + RefreshData(); + } private void GridSorts_MouseDown(object sender, MouseEventArgs e) { diff --git a/LineSorter/Options/Settings.cs b/LineSorter/Options/Settings.cs index 5569677..1fb9b7b 100644 --- a/LineSorter/Options/Settings.cs +++ b/LineSorter/Options/Settings.cs @@ -1,4 +1,5 @@ using System.IO; +using LineSorter.Export; using System.Xml.Serialization; namespace LineSorter.Options @@ -9,6 +10,7 @@ public class Settings public string[] Loaded { get; set; } public bool LoadOnInit { get; set; } public bool LoadOnCreate { get; set; } + public EmptyLineAction EmptyLineAction { get; set; } = EmptyLineAction.Remove; #endregion #region Functions diff --git a/LineSorter/Properties/AssemblyInfo.cs b/LineSorter/Properties/AssemblyInfo.cs index 6b7c5c0..e31e509 100644 --- a/LineSorter/Properties/AssemblyInfo.cs +++ b/LineSorter/Properties/AssemblyInfo.cs @@ -3,8 +3,8 @@ using Microsoft.VisualStudio.Shell; using System.Runtime.InteropServices; -[assembly: AssemblyVersion("3.0.0.0")] -[assembly: AssemblyFileVersion("3.0.0.0")] +[assembly: AssemblyVersion("3.5.0.0")] +[assembly: AssemblyFileVersion("3.5.0.0")] [assembly: NeutralResourcesLanguage("en", UltimateResourceFallbackLocation.Satellite)] [assembly: ProvideCodeBase] diff --git a/LineSorter/Templates/VSPackage.tt b/LineSorter/Templates/VSPackage.tt index 4e84eae..b283eb5 100644 --- a/LineSorter/Templates/VSPackage.tt +++ b/LineSorter/Templates/VSPackage.tt @@ -3,24 +3,21 @@ <#@ import namespace="System.Linq" #> <#@ import namespace="System.Text" #> <#@ import namespace="System.Collections.Generic" #> -using EnvDTE; using System; using System.Threading; using LineSorter.Helpers; using LineSorter.Commands; using Microsoft.VisualStudio; -using System.Collections.Generic; using Microsoft.VisualStudio.Shell; using System.Runtime.InteropServices; using System.Diagnostics.CodeAnalysis; using Task = System.Threading.Tasks.Task; -using Microsoft.VisualStudio.Shell.Interop; namespace LineSorter { + [ProvideBindingPath] [Guid(PackageGuidString)] [ProvideMenuResource("Menus.ctmenu", 1)] - [ProvideBindingPath(SubPath = "UserSort")] [InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)] [ProvideOptionPage(typeof(Options.OptionPageGrid), "LineSorter", "General", 0, 0, true, 0)] @@ -42,12 +39,10 @@ namespace LineSorter #region Init static VSPackage() { - string assemblyPath = new Uri(typeof(VSPackage).Assembly.CodeBase, UriKind.Absolute).LocalPath; - int index = assemblyPath.LastIndexOf('\\'); - if (index == -1) - index = assemblyPath.LastIndexOf('/'); - DllLocation = assemblyPath; - Path = assemblyPath.Substring(0, index + 1); + DllLocation = new Uri(typeof(VSPackage).Assembly.CodeBase, UriKind.Absolute).LocalPath; + Path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "LineSorter\\"); + if (!System.IO.Directory.Exists(Path)) + System.IO.Directory.CreateDirectory(Path); Loader = new SortsLoader(); } #endregion @@ -56,7 +51,6 @@ namespace LineSorter protected override async Task InitializeAsync(CancellationToken CancellationToken, IProgress Progress) { await JoinableTaskFactory.SwitchToMainThreadAsync(CancellationToken); - <# for (int i = 0; i < commands.Length; i++) { #> await <#= commands[i].Name #>.InitializeAsync(this); <# } #> diff --git a/LineSorter/UserSort/LineSorter.Export.dll b/LineSorter/UserSort/LineSorter.Export.dll deleted file mode 100644 index fbd6537..0000000 Binary files a/LineSorter/UserSort/LineSorter.Export.dll and /dev/null differ diff --git a/LineSorter/VSPackage.cs b/LineSorter/VSPackage.cs index c46594d..0bc6fd9 100644 --- a/LineSorter/VSPackage.cs +++ b/LineSorter/VSPackage.cs @@ -1,21 +1,18 @@ -using EnvDTE; using System; using System.Threading; using LineSorter.Helpers; using LineSorter.Commands; using Microsoft.VisualStudio; -using System.Collections.Generic; using Microsoft.VisualStudio.Shell; using System.Runtime.InteropServices; using System.Diagnostics.CodeAnalysis; using Task = System.Threading.Tasks.Task; -using Microsoft.VisualStudio.Shell.Interop; namespace LineSorter { + [ProvideBindingPath] [Guid(PackageGuidString)] [ProvideMenuResource("Menus.ctmenu", 1)] - [ProvideBindingPath(SubPath = "UserSort")] [InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)] [ProvideOptionPage(typeof(Options.OptionPageGrid), "LineSorter", "General", 0, 0, true, 0)] @@ -30,6 +27,7 @@ public sealed class VSPackage : AsyncPackage public static string Path { get; } public static SortsLoader Loader { get; } public static string DllLocation { get; } + public static VSPackage Instance { get; private set; } public static Guid Guid { get; } = new Guid(PackageGuidString); public const string PackageGuidString = "7fb18e2a-1a51-4dbb-b676-a3514e44823d"; #endregion @@ -37,12 +35,10 @@ public sealed class VSPackage : AsyncPackage #region Init static VSPackage() { - string assemblyPath = new Uri(typeof(VSPackage).Assembly.CodeBase, UriKind.Absolute).LocalPath; - int index = assemblyPath.LastIndexOf('\\'); - if (index == -1) - index = assemblyPath.LastIndexOf('/'); - DllLocation = assemblyPath; - Path = assemblyPath.Substring(0, index + 1); + DllLocation = new Uri(typeof(VSPackage).Assembly.CodeBase, UriKind.Absolute).LocalPath; + Path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "LineSorter\\"); + if (!System.IO.Directory.Exists(Path)) + System.IO.Directory.CreateDirectory(Path); Loader = new SortsLoader(); } #endregion @@ -59,6 +55,8 @@ protected override async Task InitializeAsync(CancellationToken CancellationToke await CommandRandomSort.InitializeAsync(this); await CommandUserSort.InitializeAsync(this); await CommandAnchor.InitializeAsync(this); + + Instance = this; } #endregion } diff --git a/LineSorter/source.extension.vsixmanifest b/LineSorter/source.extension.vsixmanifest index 9825ad5..4c23516 100644 --- a/LineSorter/source.extension.vsixmanifest +++ b/LineSorter/source.extension.vsixmanifest @@ -1,7 +1,7 @@  - + LineSorter An extension that allows you to sort rows by different criteria Images\VSPackageIcon.ico