diff --git a/OneMore/Commands/Favorites/FavoritesDialog.Designer.cs b/OneMore/Commands/Favorites/FavoritesDialog.Designer.cs index 2e904a24b7..a4578f5eb8 100644 --- a/OneMore/Commands/Favorites/FavoritesDialog.Designer.cs +++ b/OneMore/Commands/Favorites/FavoritesDialog.Designer.cs @@ -41,9 +41,10 @@ private void InitializeComponent() this.searchBox = new System.Windows.Forms.TextBox(); this.searchLabel = new System.Windows.Forms.Label(); this.contextMenu = new System.Windows.Forms.ContextMenuStrip(this.components); + this.addButton = new System.Windows.Forms.ToolStripMenuItem(); this.checkButton = new System.Windows.Forms.ToolStripMenuItem(); this.manageButton = new System.Windows.Forms.ToolStripMenuItem(); - this.addButton = new System.Windows.Forms.ToolStripMenuItem(); + this.sortByNameToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.gridView)).BeginInit(); this.buttonPanel.SuspendLayout(); this.searchPanel.SuspendLayout(); @@ -175,30 +176,42 @@ private void InitializeComponent() this.contextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.addButton, this.checkButton, + this.sortByNameToolStripMenuItem, this.manageButton}); this.contextMenu.Name = "contextMenu"; - this.contextMenu.Size = new System.Drawing.Size(241, 133); + this.contextMenu.Size = new System.Drawing.Size(249, 165); + // + // addButton + // + this.addButton.Image = global::River.OneMoreAddIn.Properties.Resources.Journal; + this.addButton.Name = "addButton"; + this.addButton.Size = new System.Drawing.Size(248, 32); + this.addButton.Text = "Add Current Page"; + this.addButton.Click += new System.EventHandler(this.AddCurrentPage); // // checkButton // + this.checkButton.Image = global::River.OneMoreAddIn.Properties.Resources.CheckMark; this.checkButton.Name = "checkButton"; - this.checkButton.Size = new System.Drawing.Size(240, 32); + this.checkButton.Size = new System.Drawing.Size(248, 32); this.checkButton.Text = "Check Favorites"; this.checkButton.Click += new System.EventHandler(this.CheckFavorites); // // manageButton // + this.manageButton.Image = global::River.OneMoreAddIn.Properties.Resources.Hammer; this.manageButton.Name = "manageButton"; - this.manageButton.Size = new System.Drawing.Size(240, 32); + this.manageButton.Size = new System.Drawing.Size(248, 32); this.manageButton.Text = "Manage Favorites"; this.manageButton.Click += new System.EventHandler(this.ManageFavorites); // - // addButton + // sortByNameToolStripMenuItem // - this.addButton.Name = "addButton"; - this.addButton.Size = new System.Drawing.Size(240, 32); - this.addButton.Text = "Add Current Page"; - this.addButton.Click += new System.EventHandler(this.AddCurrentPage); + this.sortByNameToolStripMenuItem.Image = global::River.OneMoreAddIn.Properties.Resources.DownArrow; + this.sortByNameToolStripMenuItem.Name = "sortByNameToolStripMenuItem"; + this.sortByNameToolStripMenuItem.Size = new System.Drawing.Size(248, 32); + this.sortByNameToolStripMenuItem.Text = "Sort By Name"; + this.sortByNameToolStripMenuItem.Click += new System.EventHandler(this.SortFavorites); // // FavoritesDialog // @@ -243,5 +256,6 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem checkButton; private System.Windows.Forms.ToolStripMenuItem manageButton; private System.Windows.Forms.ToolStripMenuItem addButton; + private System.Windows.Forms.ToolStripMenuItem sortByNameToolStripMenuItem; } } \ No newline at end of file diff --git a/OneMore/Commands/Favorites/FavoritesDialog.cs b/OneMore/Commands/Favorites/FavoritesDialog.cs index ce040eb2f9..b7cd204eab 100644 --- a/OneMore/Commands/Favorites/FavoritesDialog.cs +++ b/OneMore/Commands/Favorites/FavoritesDialog.cs @@ -501,7 +501,6 @@ private async void CheckFavorites(object sender, EventArgs e) var list = ((BindingList)gridView.DataSource).ToList(); await provider.ValidateFavorites(list); gridView.DataSource = new BindingList(list); - } @@ -511,5 +510,13 @@ private void ManageFavorites(object sender, EventArgs e) DialogResult = DialogResult.OK; Close(); } + + + private void SortFavorites(object sender, EventArgs e) + { + using var provider = new FavoritesProvider(null); + var list = provider.SortFavorites(); + gridView.DataSource = new BindingList(list); + } } } diff --git a/OneMore/Commands/Favorites/FavoritesDialog.resx b/OneMore/Commands/Favorites/FavoritesDialog.resx index 04b9ad8626..edb9d8e279 100644 --- a/OneMore/Commands/Favorites/FavoritesDialog.resx +++ b/OneMore/Commands/Favorites/FavoritesDialog.resx @@ -123,6 +123,12 @@ True + + True + + + True + 17, 17 diff --git a/OneMore/Commands/Favorites/FavoritesProvider.cs b/OneMore/Commands/Favorites/FavoritesProvider.cs index d39fae02b3..81197c5ab7 100644 --- a/OneMore/Commands/Favorites/FavoritesProvider.cs +++ b/OneMore/Commands/Favorites/FavoritesProvider.cs @@ -174,6 +174,29 @@ public List LoadFavorites() } + public List SortFavorites() + { + var list = new List(); + if (!File.Exists(path)) + { + return list; + } + + var root = XElement.Load(path, LoadOptions.None); + + var favorites = root.Elements() + .Where(e => e.Attribute("notebookID") != null) + .ToList(); + + favorites.Remove(); + root.Add(favorites.OrderBy(e => e.Attribute("label").Value)); + + SaveFavorites(root); + + return LoadFavorites(); + } + + public async Task ValidateFavorites(List favorites) { one ??= new OneNote();