From 647cf5b88dccc102ff1fd4cef6a72c38ebb6df28 Mon Sep 17 00:00:00 2001 From: HovKlan-DH Date: Wed, 3 Mar 2021 10:49:04 +0100 Subject: [PATCH] 2021-March-3 --- HovText/History.cs | 794 +++++++++++++++++------ HovText/HovText.csproj | 4 +- HovText/Logging.cs | 20 +- HovText/PasteOnHotkey.cs | 4 +- HovText/Program.cs | 4 +- HovText/Properties/AssemblyInfo.cs | 4 +- HovText/Properties/Resources.Designer.cs | 10 + HovText/Properties/Resources.resx | 4 + HovText/Resources/Favorite.png | Bin 0 -> 616 bytes HovText/Resources/favorite.jpg | Bin 0 -> 2562 bytes HovText/Settings.Designer.cs | 140 +++- HovText/Settings.cs | 784 +++++++++++++++++----- HovText/Update.Designer.cs | 1 - 13 files changed, 1358 insertions(+), 411 deletions(-) create mode 100644 HovText/Resources/Favorite.png create mode 100644 HovText/Resources/favorite.jpg diff --git a/HovText/History.cs b/HovText/History.cs index 03885ec..1941ad4 100644 --- a/HovText/History.cs +++ b/HovText/History.cs @@ -1,4 +1,5 @@ -using System.Diagnostics; +using HovText.Properties; +using System.Diagnostics; using System.Drawing; using System.Linq; using System.Threading; @@ -11,9 +12,17 @@ public partial class History : Form // ########################################################################################### // Define "History" class variables - real spaghetti :-) // ########################################################################################### - int firstBox; - int entryIndexLast; - string changeBorderElement = ""; + string changeBorderElement = ""; // the UI name for the element coming to the paint redraw event + private static int entryFirstBox = -1; // 0-indexed array ID for the first box element to show + private static int entryFirst = -1; // 0-indexed array ID for the first element in the full list + private static int entryLast = -1; // 0-indexed array ID for the last element in the full list + private static int entryActive = -1; // 0-indexed array ID for the active entry + private static int entryActiveLast = -1; // 0-indexed array ID for the last active entry (only used to determine if it should "flash") + private static int entryActiveList = -1; // human-readable list number for the active entry (1 => showElements) + private static bool isEntryAtTop = false; // is the active entry at the top position (newest entry) + private static bool isEntryAtBottom = false; // is the active entry at the bottom position (oldest entry) + public static int entriesInList; + private static int entryInList = 0; // this is number X of Y (this stores the "X") // ########################################################################################### @@ -32,90 +41,174 @@ public History() public void SetupForm() { - int entries = Settings.entriesText.Count; - int showElements = Settings.historyListElements; - showElements = showElements > entries ? entries : showElements; - int width; - int nextPosY = 0; + // Get the total amount of entries, depending which view this is + entriesInList = Settings.entriesText.Count; + if (Settings.isEnabledFavorites && Settings.showFavoriteList) + { + int countFavorites = 0; + for (int i = Settings.entriesText.ElementAt(0).Key; i <= Settings.entriesText.ElementAt(Settings.entriesText.Count - 1).Key; i++) + { + if (Settings.entriesText.ContainsKey(i)) + { + bool isFavorite = Settings.entriesIsFavorite[i]; + countFavorites += isFavorite ? 1 : 0; + } + } + entriesInList = countFavorites; + if (Settings.isTroubleshootEnabled) Logging.Log("Opened the history list view [Favorite]"); + } + else + { + if (Settings.isTroubleshootEnabled) Logging.Log("Opened the history list view [All]"); + } - // Set this form width and element heights int headlineHeight = 42; - int workingAreaWidth = Screen.PrimaryScreen.WorkingArea.Width; - int workingAreaHeight = Screen.PrimaryScreen.WorkingArea.Height; - int height = (workingAreaHeight * Settings.historySizeHeight) / 100; - int boxHeight = (height - headlineHeight) / showElements; - width = (workingAreaWidth * Settings.historySizeWidth) / 100; + int resourceWidth = 18; // this is the "Favorite" icon width - optimize this by automatically get the width + Label label; // Setup form width and height + int workingAreaWidth = Screen.AllScreens[Settings.activeScreen].WorkingArea.Width; + int workingAreaHeight = Screen.AllScreens[Settings.activeScreen].WorkingArea.Height; + int width = (workingAreaWidth * Settings.historySizeWidth) / 100; + int height = (workingAreaHeight * Settings.historySizeHeight) / 100; Width = width; - Height = (boxHeight * showElements) + headlineHeight + SystemInformation.FrameBorderSize.Height + SystemInformation.Border3DSize.Height + 4; - // Add the headline, if not already created - if (this.Controls.Count == 0) + // Add the headline and favorite marker + + // Headline + label = new Label(); + label.Name = "uiHistoryHeadline"; + label.Width = width; + label.Height = headlineHeight; + label.Location = new Point(0, 0); + label.BorderStyle = BorderStyle.FixedSingle; + label.Padding = new Padding(5); + label.TextAlign = ContentAlignment.MiddleLeft; + label.Font = new Font(Settings.historyFontFamily, Settings.historyFontSize); + label.BackColor = ColorTranslator.FromHtml(Settings.historyColorsTop[Settings.historyColor]); + label.ForeColor = ColorTranslator.FromHtml(Settings.historyColorsText[Settings.historyColor]); + label.Visible = true; + this.Controls.Add(label); + + // Headline favorite image (PictureBox) + if (Settings.isEnabledFavorites) { - Label label = new Label(); - label.Name = "uiHistoryHeadline"; - label.Width = width; - label.Height = headlineHeight; - label.Location = new Point(0, 0); - label.BorderStyle = BorderStyle.FixedSingle; - label.Padding = new Padding(5); - label.TextAlign = ContentAlignment.MiddleLeft; - label.Font = new Font(Settings.historyFontFamily, Settings.historyFontSize); - label.BackColor = ColorTranslator.FromHtml(Settings.historyColorsTop[Settings.historyColor]); - label.ForeColor = ColorTranslator.FromHtml(Settings.historyColorsText[Settings.historyColor]); - label.Visible = true; - this.Controls.Add(label); - } else - { - // If created then only update the colors etc. - this.Controls["uiHistoryHeadline"].Width = width; - this.Controls["uiHistoryHeadline"].Height = headlineHeight; - this.Controls["uiHistoryHeadline"].Font = new Font(Settings.historyFontFamily, Settings.historyFontSize); - this.Controls["uiHistoryHeadline"].BackColor = ColorTranslator.FromHtml(Settings.historyColorsTop[Settings.historyColor]); - this.Controls["uiHistoryHeadline"].ForeColor = ColorTranslator.FromHtml(Settings.historyColorsText[Settings.historyColor]); + PictureBox pictureBoxFav = new PictureBox(); + pictureBoxFav.Name = "uiHistoryHeadlineFav"; + pictureBoxFav.Width = resourceWidth; + pictureBoxFav.Height = resourceWidth; + pictureBoxFav.Location = new Point(width - resourceWidth - 10, 1); + pictureBoxFav.BorderStyle = BorderStyle.None; + pictureBoxFav.Visible = false; + pictureBoxFav.Image = Resources.Favorite; + this.Controls.Add(pictureBoxFav); } + // Set the next vertical position + int nextPosY = 0; nextPosY += headlineHeight; - // Setup all visible element boxes - int instance = 1; - for (int i = 1; i <= showElements; i++) + // Show a "warning" if we are in the favorite view but has no favorites + if (Settings.isEnabledFavorites && entriesInList == 0 && Settings.showFavoriteList) { - // Label - Label label = new Label(); - label.Name = "historyLabel" + i; + Height = height + SystemInformation.FrameBorderSize.Height + SystemInformation.Border3DSize.Height + 4; + + // Add a new label that will show the warning text + label = new Label(); + label.Name = "uiNoFavorites"; label.Width = width; - label.Height = boxHeight; - label.Location = new Point(0, nextPosY); + label.Height = height - headlineHeight; + label.Location = new Point(0, headlineHeight); label.BorderStyle = BorderStyle.FixedSingle; label.Padding = new Padding(5); + label.TextAlign = ContentAlignment.MiddleCenter; + label.Text = "You have no favorites set"; label.Font = new Font(Settings.historyFontFamily, Settings.historyFontSize); - label.Visible = false; - label.Text = ""; + label.BackColor = Color.WhiteSmoke; + label.ForeColor = Color.Black; + label.Visible = true; this.Controls.Add(label); + } + else + { + // We are now in one of the views, "All" or "Favorite" and it has one or more entries + + // "showElements" determines how many boxes to show + int showElements = Settings.historyListElements; + showElements = showElements > entriesInList ? entriesInList : showElements; + + // Set this form height and element heights + int boxHeight = (height - headlineHeight) / showElements; + Height = (boxHeight * showElements) + headlineHeight + SystemInformation.FrameBorderSize.Height + SystemInformation.Border3DSize.Height + 4; + + // Setup all visible element boxes + for (int i = 1; i <= showElements; i++) + { + // Text entry (Label) + label = new Label(); + label.Name = "historyLabel" + i; + label.Width = width; + label.Height = boxHeight; + label.Location = new Point(0, nextPosY); + label.BorderStyle = BorderStyle.FixedSingle; + label.Padding = new Padding(5); + label.Font = new Font(Settings.historyFontFamily, Settings.historyFontSize); + label.Visible = false; + label.Text = ""; + this.Controls.Add(label); + + // Catch repaint event for this specific element (to draw the border) + this.Controls["historyLabel" + i].Paint += new System.Windows.Forms.PaintEventHandler(this.History_Paint); + + // Image entry (PictureBox) + PictureBox pictureBox = new PictureBox(); + pictureBox.Name = "historyPictureBox" + i; + pictureBox.Width = width; + pictureBox.Height = boxHeight; + pictureBox.Location = new Point(0, nextPosY); + pictureBox.BorderStyle = BorderStyle.FixedSingle; + pictureBox.Padding = new Padding(10); + pictureBox.Visible = false; + pictureBox.Image = null; + this.Controls.Add(pictureBox); + + // Catch repaint event for this specific element (to draw the border) + this.Controls["historyPictureBox" + i].Paint += new System.Windows.Forms.PaintEventHandler(this.History_Paint); + + // Favorite image (PictureBox) + if (Settings.isEnabledFavorites) + { + PictureBox pictureBoxFavEntry = new PictureBox(); + pictureBoxFavEntry.Name = "historyPictureBoxFav" + i; + pictureBoxFavEntry.Width = resourceWidth; + pictureBoxFavEntry.Height = resourceWidth; + pictureBoxFavEntry.Location = new Point(width - resourceWidth - 11, nextPosY + 2); + pictureBoxFavEntry.BorderStyle = BorderStyle.None; + pictureBoxFavEntry.Visible = false; + pictureBoxFavEntry.Image = Resources.Favorite; + this.Controls.Add(pictureBoxFavEntry); + } - // Catch repaint event for this specific element (to draw the border) - this.Controls[instance].Paint += new System.Windows.Forms.PaintEventHandler(this.History_Paint); - instance++; - - // PictureBox - PictureBox pictureBox = new PictureBox(); - pictureBox.Name = "historyPictureBox" + i; - pictureBox.Width = width; - pictureBox.Height = boxHeight; - pictureBox.Location = new Point(0, nextPosY); - pictureBox.BorderStyle = BorderStyle.FixedSingle; - pictureBox.Padding = new Padding(10); - pictureBox.Visible = false; - pictureBox.Image = null; - this.Controls.Add(pictureBox); - - // Catch repaint event for this specific element (to draw the border) - this.Controls[instance].Paint += new System.Windows.Forms.PaintEventHandler(this.History_Paint); - instance++; - - nextPosY += boxHeight; + nextPosY += boxHeight; + } + } + + // If we are in the "favorite" view then show the icon for it in the "headline" + if (Settings.isEnabledFavorites) + { + foreach (Control c in this.Controls.Find("uiHistoryHeadlineFav", true)) + { + if (Settings.showFavoriteList) + { + c.BackColor = this.Controls["uiHistoryHeadline"].BackColor; + c.BringToFront(); + c.Visible = true; + } + else + { + c.Visible = false; + } + } } SetHistoryPosition(); @@ -130,29 +223,25 @@ public void SetupForm() private void ResetForm() { - // remove all form elements, except element [0] which is the "uiHistoryHeadline" - int formElements = this.Controls.Count; - for (int i = 0; i < formElements; i++) - { - if (i != 0) - { - this.Controls.RemoveAt(1); - } - } + // Remove all form elements and hide the form + this.Controls.Clear(); Hide(); } // ########################################################################################### - // Update the form elements - set content and color + // Repaint the entry border // ########################################################################################### private void History_Paint(object sender, PaintEventArgs e) { if (Settings.historyBorder) { - if (changeBorderElement == ((System.Windows.Forms.Control)sender).Name) - { + + // Redraw border with a solid color, if the update source event is larger than 18px (favorite icon) and if we are placed on the active entry + if (changeBorderElement == ((System.Windows.Forms.Control)sender).Name && e.ClipRectangle.Width > 18) + { + Debug.WriteLine("hest=" + changeBorderElement + " + sender=" + (System.Windows.Forms.Control)sender + " + width=" + e.ClipRectangle.Width); ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, ColorTranslator.FromHtml(Settings.historyColorsBorder[Settings.historyColor]), 1, ButtonBorderStyle.Solid, ColorTranslator.FromHtml(Settings.historyColorsBorder[Settings.historyColor]), 1, ButtonBorderStyle.Solid, @@ -177,139 +266,327 @@ private void History_Paint(object sender, PaintEventArgs e) public void UpdateHistory(string direction) { - - int entries = Settings.entriesText.Count; - int showElements = Settings.historyListElements; - showElements = showElements > entries ? entries : showElements; - int entryIndex = Settings.entryCounter; // 1 is the lowest value as a human readable number - firstBox = firstBox == 0 ? entries : firstBox; - int scopeHighest = firstBox; // "showElements" is the lowest value as a human readable number (newest copy on top) - int scopeLowest = scopeHighest - showElements + 1; // 1 is the lowest value as a human readable number (oldest copy at bottom) - scopeLowest = scopeLowest < 1 ? 1 : scopeLowest; - - // Set the "firstBox" depending if we are going down (older) or up (newer) in history - if (direction == "down") - { - firstBox = entryIndex >= scopeLowest ? firstBox : firstBox - 1; - } - if (direction == "up") + // Set the "first" and "last" IDs + entryFirstBox = entryFirstBox == -1 ? GetFirstIndex() : entryFirstBox; + entryFirst = entryFirst == -1 ? GetFirstIndex() : entryFirst; + entryLast = entryLast == -1 ? GetLastIndex() : entryLast; + entryFirstBox = isEntryAtTop && direction == "up" ? GetNextIndex(direction, entryFirstBox) : entryFirstBox; + entryFirstBox = isEntryAtBottom && direction == "down" ? GetNextIndex(direction, entryFirstBox) : entryFirstBox; + + // Set the active entry + entryActive = entryActive == -1 ? entryFirstBox : GetNextIndex(direction, entryActive); + + // Get the amount of total entries in array - overwrite if we are showing the "Favorite" list + entriesInList = Settings.entriesText.Count; + if (Settings.showFavoriteList) { - firstBox = entryIndex <= scopeHighest ? firstBox : firstBox + 1; - } - - // Flash the headline if we are all the way to the top or bottom - if (entryIndex == entryIndexLast && (entryIndex == entries || entryIndex == 1)) - { - Flash(); + int countFavorites = 0; + for (int i = entryFirst; i >= Settings.entriesText.ElementAt(0).Key; i--) + { + if (Settings.entriesText.ContainsKey(i)) + { + bool isFavorite = Settings.entriesIsFavorite[i]; + countFavorites += isFavorite ? 1 : 0; + } + } + entriesInList = countFavorites < entriesInList ? countFavorites : entriesInList; } - entryIndexLast = entryIndex; - // Set the headline bool isTransparent; - string entryApplication = Settings.entriesApplication.ElementAt(entryIndex - 1).Value; - this.Controls["uiHistoryHeadline"].Text = entryIndex + " of " + entries + " from \"" + entryApplication + "\""; - Image entryImage = Settings.entriesImage.ElementAt(entryIndex - 1).Value; - if (entryImage != null) + Image entryImage; + + // Proceed if we have more than one entry in the list (it also comes to here, if we are showing an empty favorite list) + if (entriesInList > 0) { - isTransparent = Settings.entriesImageTransparent.ElementAt(entryIndex - 1).Value; - if(isTransparent) + // "showElements" determines how many boxes to show + int showElements = Settings.historyListElements; + showElements = showElements > entriesInList ? entriesInList : showElements; + int shownElements = 0; + + // Move the first box element if there is only one to show + entryFirstBox = showElements == 1 ? entryActive : entryFirstBox; + + // Build the list of visible entry boxes + for (int i = entryFirstBox; i >= 0 && shownElements < showElements; i--) { - this.Controls["uiHistoryHeadline"].Text += " (transparent image)"; + Color favoriteBackgroundColor = Color.Red; + + // Check if the array ID exists + bool doesKeyExist = Settings.entriesText.ContainsKey(i); + if (doesKeyExist) + { + // Get the array data + string entryText = Settings.entriesText[i]; + entryImage = Settings.entriesImage[i]; + bool isFavorite = Settings.entriesIsFavorite[i]; + + // Proceed if this is a valid entry, depending on the list view + if (!Settings.showFavoriteList || (Settings.showFavoriteList && isFavorite)) + { + shownElements++; + + // Check if it is a TEXT + if (!string.IsNullOrEmpty(entryText)) + { + // Find a form element with a specific name + foreach (Control c in this.Controls.Find("historyLabel" + shownElements, true)) + { + c.Text = entryText; + c.Visible = true; + + // Set the colors + if (i == entryActive && showElements > 1) + { + c.BackColor = ColorTranslator.FromHtml(Settings.historyColorsTop[Settings.historyColor]); + c.ForeColor = ColorTranslator.FromHtml(Settings.historyColorsText[Settings.historyColor]); + changeBorderElement = c.Name; + c.Refresh(); + + isEntryAtTop = shownElements == 1 ? true : false; + isEntryAtBottom = shownElements == showElements ? true : false; + entryActiveList = shownElements; + } + else + { + c.BackColor = ColorTranslator.FromHtml(Settings.historyColorsBottom[Settings.historyColor]); + c.ForeColor = ColorTranslator.FromHtml(Settings.historyColorsText[Settings.historyColor]); + + // Mark this as the active element, if there is only shown one entry + if (i == entryActive && showElements == 1) + { + entryActiveList = shownElements; + } + } + favoriteBackgroundColor = c.BackColor; + } + } + else + { + // Hide the label as it then must be an image + this.Controls["historyLabel" + shownElements].Visible = false; + } + + // Check if it is an IMAGE + if (entryImage != null) + { + // Find a form element with a specific name + foreach (Control c in this.Controls.Find("historyPictureBox" + shownElements, true)) + { + // Check if the image is transparent - if so make the image background transparent + isTransparent = Settings.entriesImageTransparent[i]; + if (isTransparent) + { + Bitmap bmp = new Bitmap(entryImage); + bmp.MakeTransparent(bmp.GetPixel(0, 0)); + ((PictureBox)c).Image = (Image)bmp; + } + else + { + ((PictureBox)c).Image = entryImage; + } + + c.Visible = true; + + // Set the colors + if (i == entryActive && showElements > 1) + { + c.BackColor = ColorTranslator.FromHtml(Settings.historyColorsTop[Settings.historyColor]); + c.ForeColor = ColorTranslator.FromHtml(Settings.historyColorsText[Settings.historyColor]); + changeBorderElement = c.Name; + c.Refresh(); + + isEntryAtTop = shownElements == 1 ? true : false; + isEntryAtBottom = shownElements == showElements ? true : false; + entryActiveList = shownElements; + } + else + { + c.BackColor = ColorTranslator.FromHtml(Settings.historyColorsBottom[Settings.historyColor]); + c.ForeColor = ColorTranslator.FromHtml(Settings.historyColorsText[Settings.historyColor]); + + // Mark this as the active element, if there is only shown one entry + if (i == entryActive && showElements == 1) + { + entryActiveList = shownElements; + } + } + favoriteBackgroundColor = c.BackColor; + } + } + else + { + // Hide the pictureBox as it then must be a text + this.Controls["historyPictureBox" + shownElements].Visible = false; + } + + // Find the "favorite" picture box + if (Settings.isEnabledFavorites) + { + foreach (Control c in this.Controls.Find("historyPictureBoxFav" + shownElements, true)) + { + if (isFavorite) + { + c.BackColor = favoriteBackgroundColor; + c.BringToFront(); + c.Visible = true; + } + else + { + c.Visible = false; + + } + } + } + } + } } - else + + // Set the "this is entry X of Y" number + entryInList += direction == "down" && entryActive != entryLast ? 1 : 0; + entryInList -= direction == "up" && entryActive != entryFirst ? 1 : 0; + entryInList = entryActive == entryLast ? entriesInList : entryInList; + entryInList = entryActive == entryFirst ? 1 : entryInList; + + // Set the headline + string entryApplication = Settings.entriesApplication[entryActive]; + this.Controls["uiHistoryHeadline"].Text = entryInList + " of " + entriesInList + " from \"" + entryApplication + "\""; + entryImage = Settings.entriesImage[entryActive]; + if (entryImage != null) { - this.Controls["uiHistoryHeadline"].Text += " (image)"; + isTransparent = Settings.entriesImageTransparent[entryActive]; + if (isTransparent) + { + this.Controls["uiHistoryHeadline"].Text += " (transparent image)"; + } + else + { + this.Controls["uiHistoryHeadline"].Text += " (image)"; + } } - + + // Flash the headline if we are all the way to the top or bottom + if (entryActive == entryActiveLast) + { + Flash(); + } + entryActiveLast = entryActive; } - this.Controls["uiHistoryHeadline"].Refresh(); - // Update the history list view - for (int i = 1; i <= showElements; i++) + // Set a special headline text, if there is no favorites + if (Settings.showFavoriteList && entriesInList == 0) { - int activeEntryKey = firstBox - i; + this.Controls["uiHistoryHeadline"].Text = "No data - change view"; + } + this.Controls["uiHistoryHeadline"].Refresh(); + + // Make sure that we will catch the key-up event + TopMost = true; + } + - // Get the data from the data arrays - string entryText = Settings.entriesText.ElementAt(activeEntryKey).Value; - entryImage = Settings.entriesImage.ElementAt(activeEntryKey).Value; + // ########################################################################################### + // Get the first (newest) array ID in the full array, depending on the view + // ########################################################################################### - // Check if it is a TEXT - if (!string.IsNullOrEmpty(entryText)) + private int GetFirstIndex () + { + int first = entryFirstBox == -1 ? Settings.entryIndex : entryFirstBox; + for (int i = first; i >= Settings.entriesText.ElementAt(0).Key; i--) + { + // Proceed if the array ID exists + if (Settings.entriesText.ContainsKey(i)) { - // Find a form element with a specific name - foreach (Control c in this.Controls.Find("historyLabel" + i, true)) + if (!Settings.showFavoriteList) { - c.Text = entryText; - c.Visible = true; - - // Set the colors - if (entryIndex == activeEntryKey + 1 && showElements > 1) - { - c.BackColor = ColorTranslator.FromHtml(Settings.historyColorsTop[Settings.historyColor]); - c.ForeColor = ColorTranslator.FromHtml(Settings.historyColorsText[Settings.historyColor]); - changeBorderElement = c.Name; - c.Refresh(); - } - else - { - c.BackColor = ColorTranslator.FromHtml(Settings.historyColorsBottom[Settings.historyColor]); - c.ForeColor = ColorTranslator.FromHtml(Settings.historyColorsText[Settings.historyColor]); - } - + return i; } - } else + if (Settings.showFavoriteList && Settings.entriesIsFavorite[i]) + { + return i; + } + } + } + return 0; + } + + + // ########################################################################################### + // Get the last (oldest) array ID in the full array, depending on the view + // ########################################################################################### + + private int GetLastIndex() + { + int last = entryLast == -1 ? Settings.entriesText.ElementAt(0).Key : entryLast; + for (int i = last; i <= Settings.entriesText.ElementAt(Settings.entriesText.Count - 1).Key; i++) + { + // Proceed if the array ID exists + if (Settings.entriesText.ContainsKey(i)) { - // Hide the label as it then must be an image - this.Controls["historyLabel" + i].Visible = false; + if (!Settings.showFavoriteList) + { + return i; + } + if (Settings.showFavoriteList && Settings.entriesIsFavorite[i]) + { + return i; + } } + } + return 0; + } - // Check if it is an IMAGE - if (entryImage != null) + + // ########################################################################################### + // Get the next entry array ID, depending on the view and the direction, up/down + // ########################################################################################### + + public static int GetNextIndex(string direction, int entryKey) + { + if (direction == "up") + { + for (int i = entryKey + 1; i <= Settings.entriesText.ElementAt(Settings.entriesText.Count - 1).Key; i++) { - // Find a form element with a specific name - foreach (Control c in this.Controls.Find("historyPictureBox" + i, true)) + if (Settings.entriesText.ContainsKey(i)) { - // Check if the image is transparent - if so make the image background transparent - isTransparent = Settings.entriesImageTransparent.ElementAt(activeEntryKey).Value; - if(isTransparent) - { - Bitmap bmp = new Bitmap(entryImage); - bmp.MakeTransparent(bmp.GetPixel(0, 0)); - ((PictureBox)c).Image = (Image)bmp; - } - else + if (!Settings.showFavoriteList) { - ((PictureBox)c).Image = entryImage; + return i; } - c.Visible = true; - - // Set the colors - if (entryIndex == activeEntryKey + 1 && showElements > 1) + if (Settings.showFavoriteList && Settings.entriesIsFavorite[i]) { - c.BackColor = ColorTranslator.FromHtml(Settings.historyColorsTop[Settings.historyColor]); - c.ForeColor = ColorTranslator.FromHtml(Settings.historyColorsText[Settings.historyColor]); - changeBorderElement = c.Name; - c.Refresh(); + return i; } - else + + } + } + } + + if (direction == "down") + { + // Proceed if the active element is not the last element + if (entryActive != entryLast) + { + for (int i = entryKey - 1; i >= Settings.entriesText.ElementAt(0).Key; i--) + { + if (Settings.entriesText.ContainsKey(i)) { - c.BackColor = ColorTranslator.FromHtml(Settings.historyColorsBottom[Settings.historyColor]); - c.ForeColor = ColorTranslator.FromHtml(Settings.historyColorsText[Settings.historyColor]); + if (!Settings.showFavoriteList) + { + return i; + } + if (Settings.showFavoriteList && Settings.entriesIsFavorite[i]) + { + return i; + } } } - } else - { - // Hide the pictureBox as it then must be a text - this.Controls["historyPictureBox" + i].Visible = false; } } - // Make sure that we will catch the key-up event - TopMost = true; + return entryKey; } - // ########################################################################################### // Catch keyboard input to react on modifier KEY UP @@ -322,14 +599,22 @@ private void History_KeyUp(object sender, KeyEventArgs e) bool isAlt = e.Alt; bool isControl = e.Control; - // Proceed if no modifier keys are pressed down + // Proceed if no modifier keys are pressed down - this equals that we have selected the entry if (!isShift && !isAlt && !isControl) { - // Reset if the entry is selected - firstBox = 0; - entryIndexLast = 0; - - if (Settings.isTroubleshootEnabled) Logging.Log("Selected history entry"); + // Insert log depending if list is empty or not + if (entriesInList == 0) + { + if (Settings.isTroubleshootEnabled) Logging.Log("Selected history entry element [none, as list is empty]"); + } + else + { + if (Settings.isTroubleshootEnabled) Logging.Log("Selected history entry list element [" + entryActiveList + "] of ["+ entriesInList +"] with key [" + entryActive + "]"); + } + + // Reset some stuff + Settings.entryIndex = entryActive; // set the new "entryIndex" variable as it is now selected + ResetVariables(); Settings.settings.SelectHistoryEntry(); if (Settings.isEnabledPasteOnSelection) @@ -344,17 +629,132 @@ private void History_KeyUp(object sender, KeyEventArgs e) } ResetForm(); + } else + { + // Check for other key combinations + + // For conversion from text to keys + KeysConverter cvt = new KeysConverter(); + Keys key; + + // Proceed if we should toggle the list view + string hotkey6 = Settings.GetRegistryKey(Settings.registryPath, "Hotkey6"); + if (Settings.isEnabledFavorites && hotkey6 != "Not set") + { + key = (Keys)cvt.ConvertFrom(hotkey6); + if (e.KeyCode == key) + { + if (Settings.showFavoriteList) + { + Settings.showFavoriteList = false; + if (Settings.isTroubleshootEnabled) Logging.Log("History list changed to [All]"); + } + else + { + Settings.showFavoriteList = true; + if (Settings.isTroubleshootEnabled) Logging.Log("History list changed to [Favorite]"); + } + + // Reset some stuff + ResetVariables(); + ResetForm(); + SetupForm(); + UpdateHistory("down"); + } + } + + // Proceed if we should toggle a favorite entry + string hotkey5 = Settings.GetRegistryKey(Settings.registryPath, "Hotkey5"); + if (Settings.isEnabledFavorites && hotkey5 != "Not set") + { + key = (Keys)cvt.ConvertFrom(hotkey5); + if (e.KeyCode == key) + { + // Only relevant when we are in the "favorite" view + bool isFavoriteEmpty = false; + foreach (Control c in this.Controls.Find("uiNoFavorites", true)) + { + isFavoriteEmpty = true; // if this label exists then we know the favorite is empty + } + + // Proceed if there is at least one entry in the favorite list + if (!Settings.showFavoriteList || !isFavoriteEmpty) + { + + // Procced if the entry already is marked as a favorite + if (Settings.entriesIsFavorite[entryActive]) + { + Settings.entriesIsFavorite[entryActive] = false; + foreach (Control c in this.Controls.Find("historyPictureBoxFav" + entryActiveList, true)) + { + c.Visible = false; + } + if (Settings.isTroubleshootEnabled) Logging.Log("History favorite toggled [Off] on entry key [" + entryActive + "]"); + } + else + { + // Get the background color for the active entry (this is either a "label" or a "pictureBox") + Color favoriteBackgroundColor = Color.Red; + foreach (Control c in this.Controls.Find("historyLabel" + entryActiveList, true)) + { + if (c.Visible) + { + favoriteBackgroundColor = c.BackColor; + } + } + foreach (Control c in this.Controls.Find("historyPictureBox" + entryActiveList, true)) + { + if (c.Visible) + { + favoriteBackgroundColor = c.BackColor; + } + } + + // Show the entry with a favorite marking + Settings.entriesIsFavorite[entryActive] = true; + foreach (Control c in this.Controls.Find("historyPictureBoxFav" + entryActiveList, true)) + { + c.BackColor = favoriteBackgroundColor; + c.BringToFront(); + c.Visible = true; + } + if (Settings.isTroubleshootEnabled) Logging.Log("History favorite toggled [On] on entry key [" + entryActive + "]"); + } + + if (Settings.showFavoriteList) + { + // Reset some stuff + ResetVariables(); + ResetForm(); + SetupForm(); + UpdateHistory("down"); + } + } + } + } } } + private void ResetVariables () + { + entryFirstBox = -1; + entryFirst = -1; + entryLast = -1; + entryActive = -1; + entryActiveList = -1; + isEntryAtTop = false; + isEntryAtBottom = false; + entryInList = 0; + } + // ########################################################################################### // Set the position for the history area + // Contributor: FNI // ########################################################################################### private void SetHistoryPosition() { - // Set history location int x; int y; @@ -362,32 +762,32 @@ private void SetHistoryPosition() switch (Settings.historyLocation) { case "Left Top": - x = Screen.PrimaryScreen.WorkingArea.Left; - y = Screen.PrimaryScreen.WorkingArea.Top; + x = Screen.AllScreens[Settings.activeScreen].WorkingArea.Left; + y = Screen.AllScreens[Settings.activeScreen].WorkingArea.Top; this.Left = x + airgab; this.Top = y + airgab; break; case "Left Bottom": - x = Screen.PrimaryScreen.WorkingArea.Left; - y = Screen.PrimaryScreen.WorkingArea.Bottom - this.Height; + x = Screen.AllScreens[Settings.activeScreen].WorkingArea.Left; + y = Screen.AllScreens[Settings.activeScreen].WorkingArea.Bottom - this.Height; this.Left = x + airgab; this.Top = y - airgab; break; case "Center": - x = (Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2; - y = (Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2; + x = Screen.AllScreens[Settings.activeScreen].WorkingArea.Left + ((Screen.AllScreens[Settings.activeScreen].WorkingArea.Width - this.Width) / 2); + y = Screen.AllScreens[Settings.activeScreen].WorkingArea.Top + ((Screen.AllScreens[Settings.activeScreen].WorkingArea.Height - this.Height) / 2); this.Left = x; this.Top = y; break; case "Right Top": - x = Screen.PrimaryScreen.WorkingArea.Right - this.Width; - y = Screen.PrimaryScreen.WorkingArea.Top; + x = Screen.AllScreens[Settings.activeScreen].WorkingArea.Right - this.Width; + y = Screen.AllScreens[Settings.activeScreen].WorkingArea.Top; this.Left = x - airgab; this.Top = y + airgab; break; default: // Right Bottom - x = Screen.PrimaryScreen.WorkingArea.Right - this.Width; - y = Screen.PrimaryScreen.WorkingArea.Bottom - this.Height; + x = Screen.AllScreens[Settings.activeScreen].WorkingArea.Right - this.Width; + y = Screen.AllScreens[Settings.activeScreen].WorkingArea.Bottom - this.Height; this.Left = x - airgab; this.Top = y - airgab; break; diff --git a/HovText/HovText.csproj b/HovText/HovText.csproj index 10c9056..1ff169f 100644 --- a/HovText/HovText.csproj +++ b/HovText/HovText.csproj @@ -50,6 +50,7 @@ false true false + true AnyCPU @@ -158,7 +159,6 @@ Update.cs - SettingsSingleFileGenerator @@ -174,6 +174,8 @@ + + diff --git a/HovText/Logging.cs b/HovText/Logging.cs index ec22b11..f915b45 100644 --- a/HovText/Logging.cs +++ b/HovText/Logging.cs @@ -6,7 +6,6 @@ using System.Management; using Microsoft.Win32; - namespace HovText { @@ -64,15 +63,18 @@ public static void EndLogging() public static void Log(string logMessage) { - if (logMessage == "") - { - File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + Settings.troubleshootLogfile, Environment.NewLine); - } - else + if (Settings.isTroubleshootEnabled) { - File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + Settings.troubleshootLogfile, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " " + logMessage + Environment.NewLine); + if (logMessage == "") + { + File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + Settings.troubleshootLogfile, Environment.NewLine); + } + else + { + File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + Settings.troubleshootLogfile, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " " + logMessage + Environment.NewLine); + } } - + Debug.WriteLine(logMessage); } @@ -148,7 +150,7 @@ private static string CheckFor45DotVersion(int releaseKey) return "newer than 4.8"; } else { - return "4 or older"; + return "older than 4.5"; } break; } diff --git a/HovText/PasteOnHotkey.cs b/HovText/PasteOnHotkey.cs index e9f0f48..1a8a010 100644 --- a/HovText/PasteOnHotkey.cs +++ b/HovText/PasteOnHotkey.cs @@ -53,7 +53,7 @@ private void PasteOnHotkey_KeyUp(object sender, KeyEventArgs e) SendKeys.SendWait("^v"); // send "CTRL + v" (paste from clipboard) StartTimerToRestoreOriginal(); - if (Settings.isTroubleshootEnabled) Logging.Log("Pasted cleartext clipboard"); + Logging.Log("Pasted cleartext clipboard"); } } @@ -82,7 +82,7 @@ private void OnTimedEvent(object source, ElapsedEventArgs e) // We do no longer need to paste cleartext Settings.pasteOnHotkeySetCleartext = false; - if (Settings.isTroubleshootEnabled) Logging.Log("Pasted original clipboard"); + Logging.Log("Pasted original clipboard"); } diff --git a/HovText/Program.cs b/HovText/Program.cs index ce65022..3707371 100644 --- a/HovText/Program.cs +++ b/HovText/Program.cs @@ -45,8 +45,8 @@ static int Main(string[] args) { string txt = "HovText is already running and cannot startup one more instance"; - if (Settings.isTroubleshootEnabled) Logging.Log("Exception #1 (Program):"); - if (Settings.isTroubleshootEnabled) Logging.Log(" "+ txt); + Logging.Log("Exception #1 (Program):"); + Logging.Log(" "+ txt); MessageBox.Show(txt,"HovText is already running", MessageBoxButtons.OK, MessageBoxIcon.Information); } diff --git a/HovText/Properties/AssemblyInfo.cs b/HovText/Properties/AssemblyInfo.cs index 92dffa8..9f4c6f4 100644 --- a/HovText/Properties/AssemblyInfo.cs +++ b/HovText/Properties/AssemblyInfo.cs @@ -6,7 +6,7 @@ // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("HovText")] -[assembly: AssemblyDescription("An advanced Windows .NET open source clipboard manager")] +[assembly: AssemblyDescription("A simple Windows .NET open source clipboard manager")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCompany("The Hovgaard Klan")] [assembly: AssemblyProduct("HovText")] @@ -17,7 +17,7 @@ // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("03fbad69-cd44-4a0c-b4bf-90406561f14f")] //[assembly: AssemblyVersion("2021.01.23.1")] -[assembly: AssemblyFileVersion("2021.01.27.0")] +[assembly: AssemblyFileVersion("2021.03.03.1")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from diff --git a/HovText/Properties/Resources.Designer.cs b/HovText/Properties/Resources.Designer.cs index c6501e8..5e10f56 100644 --- a/HovText/Properties/Resources.Designer.cs +++ b/HovText/Properties/Resources.Designer.cs @@ -70,6 +70,16 @@ internal static System.Drawing.Icon Active { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Favorite { + get { + object obj = ResourceManager.GetObject("Favorite", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). /// diff --git a/HovText/Properties/Resources.resx b/HovText/Properties/Resources.resx index eef91b6..e4a8f44 100644 --- a/HovText/Properties/Resources.resx +++ b/HovText/Properties/Resources.resx @@ -374,6 +374,10 @@ rEEAAKxBAACsQYABrEHAA6xB4AesQf//rEE= + + + ..\Resources\Favorite.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + AAABAAMAMDAAAAEAIACoJQAANgAAACAgAAABACAAqBAAAN4lAAAQEAAAAQAgAGgEAACGNgAAKAAAADAA diff --git a/HovText/Resources/Favorite.png b/HovText/Resources/Favorite.png new file mode 100644 index 0000000000000000000000000000000000000000..b5d233a518d8859f465123f910968ca7f2ec630c GIT binary patch literal 616 zcmV-u0+;=XP)t^9fRIv6n)B;B6So&?jjb0C$?VQN`_4Dtt{Blc{W#+z$5aKObwJ{?j5k`l%R!JLVqjAJIs zk&WHGu)+*xA+oev*YRPk26&p2ee{J%^m5U6yKQdwP-N+J9^>tW2Ku3gacHm?)i9!L zY=mhA1GV@aay;VV3E9gBNX;)IOY43E@5@E>Vov1KW@1yxVG5VTrPG))-H6DaM3y^G zoA^|@;v^GpGh?a(5@D=D3IfMm477iQ$nvat6FVE5tQm*4R%(%MrhdZfnJiAt(V|7o zI(S!I$A~R}(8pK9_J}n0DH^AVlOgc_o+#r{ql#CRtL}7=5W_x_9EKDOa-pl)(nJ|s zo9oyqlw9$_W<0PhLE*R6ygNOup*NzjR#O#amDu7#K#g@n)hzwbzJ7V#-55I*QA~{#}`@FE}g-y^0A+;xMJI{#)(9h z%cnhjtdw1oYR{ZpWa)Ohu1Qyw{GZ73;%?i0@O}Ued+4vNkpEi%0000(*bP& z%q&5m69%6E3OQjI6bgaDVQ~0A8^MBvBUlh{IPw&dh4lo?6Wb|Pwv*z- z5pcvmBmWm2zXDK5Kn}n`Kqvr=0zpuqV;X=401y-cK!E?i0)-=x00agCvoiaNoB#*{ zVMd0*5ukr&Kwt-<5%PHRQ3MT-;W;6k(-{HgOYJaURi}mo-*!af_`;w{m`}-{~MSFLP%848_ zrlvOU80o(%&|6s=LQ68(jbCx8`T35iC96r1c?VRjFWlV3RyS;Qq-`syW%V9C%jXNW z^cp@a>+Y}(TREq{d%+G}pO7B_GcJFj94sUptV9~MBf?BycW5#xz& z@88&sQO|ykKAKG9Q=8t{G*Oe=4oiNHrtdWvjd89DTP0#Oj5Xfg+qz2uSfKaf+i>sPHAuVVt0N!N}xl*IFcqXmoiR+Q#q zdQ1rYDODt+*a>P~n-$%&x6QLUprWU3Vv3s_PpF!x94R8pr$2rnKs7+xg~}R*UTGZm z^bvH_)8gL63JM3iKbw>{99X;1uvHdRcF^|(L+!P5fu<$z3k1}6_|N;)!yVpr`yaLI zcoolIL!9RhSgIuYq}yDoz=W~~yRUg}i2(i4lrfRS!;MW<+YxF2wdqB&W1g(OrA%m$ zL2nnujfdRTWf_0Rrd5AoI8vHRgZ!&uCx5lGcl!$MzSwQmp){7+TRv^MChglyXj$p6y0)Ca>ZwL?umTnqZL6x)16}XZ*3LXGL)qMT2YCy zzToH_1UHxM+wB{&HWDk`+|8@Akzf>*WUSMbXwd>0^Qw__o?ZA`y$>CmQ^QR()(ROz z4`O&zCSGV9oO6>ZG^+8MH;a7=>OazltkBS7%}31!MebXsB~E@k>(wwMSbNi^wn??F z<_l%Q3f&QTBjXRdRr<5PF?A+emHfevO>4DzJ7h$j=U(s35u~DvG2uVt(Cho53v2-o ztU+bCZj%0GnqbD)E02^y1?(q^-ttMbVs+w<0o%L2xU3uMZzV5F?eKqfRcke%e&jm1 z40B0cfGH7EaAu71&kXx&XHNB7tUAt#3A;DGO<<)4=Fwd&@6a|L0cApqk!Es%s!a|x z2Bzfrfy@iik_TIRVlN*EDyNmx@aof#l|p=_CF5o?B0d@&+*_I`@v869z($NUn~bM` zBWRC!k8lOv`^Y0{Z$KZ%vC!ucf@9g0sLl`CDdXn*Zk}=xCdK#)vb^d=TW!2&9ffdN zv*MB!v~Y?v=1%&&s2J7NUHhTz)3ZFE*&`m^46*4PL%;hZK0k5W`YfuM z4r)A;J3mrvG_Y{zH{)7|_XV-Pg>d9N+;@z4iTxY&=31D)0urm(=A0Y^ta7m*t`i0# zo;(+8vVY@)^5LOvZTnmg?GE!|1hpI0h`$I`QMFBzPFz(p_u~pec)4(yKf#p}_{if5 zhC@aa>}C;WiUad=z6%w2`OOjkg3v_|zlZ%19m>i<0)HxRg@glA(;D*^EXY@!%KGBC zQcH2!xyDx#`WSe)d9hFAyowIiURK6Zyr45_kogCFMTCX#l-+tIF=L^)6Dy!N(!LBQ zbAItSps;vg<-hkAkYrWB=}$NYh0g90oZFg`udV~b`^NxvMg4(FLuKb_RH+0(L$`T`I;yW?4$zbuX0g9vCe#&g@$X|Y9B?3aV5nhtfy1WJEK?kJGdfh~G zqG;!s_xF(deXL>|89U?Xj6v$dl`}(`&xK4`h(u%Cbp1)Ze4kU=@2QFCho!WD>A+ z7YEt(;Gb6)byTB-*-!Bfwu}6J){x8nhAUY+?N^sHn{J@fW=Tt;w8kFkX(AZFQ}LrM zNK7i>7;uX%(%dxvMl4i%F}PwnWy(AG>VFCntR{b7H`SvTGM^mSSMGt-ojFy zVe}|kx)mnEkf!9I$>65qXlF18-LCQTV*O}&az{;{dShv&MWKujJhyV#$z9p1lGNCN zifle#^n&JLWuHo>KJ`$_^iPkHg(J+8uDu1UdDm6yb1wM0&7Z@aBM{9hG#tye-X?i} zA6th%wcX(G9%+e$+)n*k WCepvEbyq$sUv9YTzCP1^JpDiTgJCcL literal 0 HcmV?d00001 diff --git a/HovText/Settings.Designer.cs b/HovText/Settings.Designer.cs index 711d8b7..c17c72f 100644 --- a/HovText/Settings.Designer.cs +++ b/HovText/Settings.Designer.cs @@ -48,6 +48,7 @@ private void InitializeComponent() this.label2 = new System.Windows.Forms.Label(); this.uiAppVer = new System.Windows.Forms.Label(); this.tabPage2 = new System.Windows.Forms.TabPage(); + this.uiDisplayGroup = new System.Windows.Forms.GroupBox(); this.groupBox6 = new System.Windows.Forms.GroupBox(); this.label5 = new System.Windows.Forms.Label(); this.labelHistoryElements = new System.Windows.Forms.Label(); @@ -69,6 +70,10 @@ private void InitializeComponent() this.uiHotkeyBehaviourSystem = new System.Windows.Forms.RadioButton(); this.uiHotkeyBehaviourPaste = new System.Windows.Forms.RadioButton(); this.groupBox5 = new System.Windows.Forms.GroupBox(); + this.uiHotkeyToggleView = new System.Windows.Forms.TextBox(); + this.uiHotkeyToggleFavorite = new System.Windows.Forms.TextBox(); + this.label12 = new System.Windows.Forms.Label(); + this.label13 = new System.Windows.Forms.Label(); this.uiHotkeyPaste = new System.Windows.Forms.TextBox(); this.uiHotkeyNewer = new System.Windows.Forms.TextBox(); this.uiHotkeyOlder = new System.Windows.Forms.TextBox(); @@ -133,6 +138,7 @@ private void InitializeComponent() this.colorDialogBottom = new System.Windows.Forms.ColorDialog(); this.colorDialogText = new System.Windows.Forms.ColorDialog(); this.colorDialogBorder = new System.Windows.Forms.ColorDialog(); + this.uiFavoritesEnabled = new System.Windows.Forms.CheckBox(); this.notifyIconMenuStrip.SuspendLayout(); this.tabPage4.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); @@ -220,7 +226,7 @@ private void InitializeComponent() // uiPasteOnSelection // this.uiPasteOnSelection.AutoSize = true; - this.uiPasteOnSelection.Location = new System.Drawing.Point(29, 191); + this.uiPasteOnSelection.Location = new System.Drawing.Point(29, 223); this.uiPasteOnSelection.Name = "uiPasteOnSelection"; this.uiPasteOnSelection.Size = new System.Drawing.Size(247, 29); this.uiPasteOnSelection.TabIndex = 116; @@ -232,7 +238,7 @@ private void InitializeComponent() // // uiHelp // - this.uiHelp.Location = new System.Drawing.Point(166, 507); + this.uiHelp.Location = new System.Drawing.Point(166, 539); this.uiHelp.Name = "uiHelp"; this.uiHelp.Size = new System.Drawing.Size(262, 38); this.uiHelp.TabIndex = 1000; @@ -259,7 +265,7 @@ private void InitializeComponent() this.tabPage4.Controls.Add(this.uiAppVer); this.tabPage4.Location = new System.Drawing.Point(4, 34); this.tabPage4.Name = "tabPage4"; - this.tabPage4.Size = new System.Drawing.Size(565, 444); + this.tabPage4.Size = new System.Drawing.Size(565, 483); this.tabPage4.TabIndex = 3; this.tabPage4.Text = "About"; // @@ -312,15 +318,25 @@ private void InitializeComponent() // tabPage2 // this.tabPage2.BackColor = System.Drawing.Color.WhiteSmoke; + this.tabPage2.Controls.Add(this.uiDisplayGroup); this.tabPage2.Controls.Add(this.groupBox6); this.tabPage2.Controls.Add(this.groupBox10); this.tabPage2.Location = new System.Drawing.Point(4, 34); this.tabPage2.Name = "tabPage2"; this.tabPage2.Padding = new System.Windows.Forms.Padding(3); - this.tabPage2.Size = new System.Drawing.Size(565, 444); + this.tabPage2.Size = new System.Drawing.Size(565, 483); this.tabPage2.TabIndex = 1; this.tabPage2.Text = "Layout"; // + // uiDisplayGroup + // + this.uiDisplayGroup.Location = new System.Drawing.Point(322, 242); + this.uiDisplayGroup.Name = "uiDisplayGroup"; + this.uiDisplayGroup.Size = new System.Drawing.Size(220, 220); + this.uiDisplayGroup.TabIndex = 311; + this.uiDisplayGroup.TabStop = false; + this.uiDisplayGroup.Text = "Display history on"; + // // groupBox6 // this.groupBox6.Controls.Add(this.label5); @@ -334,7 +350,7 @@ private void InitializeComponent() this.groupBox6.Controls.Add(this.uiHistorySizeHeight); this.groupBox6.Location = new System.Drawing.Point(22, 23); this.groupBox6.Name = "groupBox6"; - this.groupBox6.Size = new System.Drawing.Size(281, 413); + this.groupBox6.Size = new System.Drawing.Size(281, 439); this.groupBox6.TabIndex = 300; this.groupBox6.TabStop = false; this.groupBox6.Text = "History area"; @@ -444,7 +460,7 @@ private void InitializeComponent() this.groupBox10.Controls.Add(this.uiHistoryLocationRadioRightBottom); this.groupBox10.Location = new System.Drawing.Point(322, 23); this.groupBox10.Name = "groupBox10"; - this.groupBox10.Size = new System.Drawing.Size(220, 413); + this.groupBox10.Size = new System.Drawing.Size(220, 196); this.groupBox10.TabIndex = 310; this.groupBox10.TabStop = false; this.groupBox10.Text = "History location"; @@ -524,7 +540,7 @@ private void InitializeComponent() this.tabPage5.Location = new System.Drawing.Point(4, 34); this.tabPage5.Name = "tabPage5"; this.tabPage5.Padding = new System.Windows.Forms.Padding(3); - this.tabPage5.Size = new System.Drawing.Size(565, 444); + this.tabPage5.Size = new System.Drawing.Size(565, 483); this.tabPage5.TabIndex = 4; this.tabPage5.Text = "Hotkeys"; // @@ -565,6 +581,10 @@ private void InitializeComponent() // // groupBox5 // + this.groupBox5.Controls.Add(this.uiHotkeyToggleView); + this.groupBox5.Controls.Add(this.uiHotkeyToggleFavorite); + this.groupBox5.Controls.Add(this.label12); + this.groupBox5.Controls.Add(this.label13); this.groupBox5.Controls.Add(this.uiHotkeyPaste); this.groupBox5.Controls.Add(this.uiHotkeyNewer); this.groupBox5.Controls.Add(this.uiHotkeyOlder); @@ -577,15 +597,63 @@ private void InitializeComponent() this.groupBox5.Controls.Add(this.label8); this.groupBox5.Location = new System.Drawing.Point(22, 150); this.groupBox5.Name = "groupBox5"; - this.groupBox5.Size = new System.Drawing.Size(521, 286); + this.groupBox5.Size = new System.Drawing.Size(521, 312); this.groupBox5.TabIndex = 210; this.groupBox5.TabStop = false; this.groupBox5.Text = "Hotkeys"; // + // uiHotkeyToggleView + // + this.uiHotkeyToggleView.BackColor = System.Drawing.SystemColors.Window; + this.uiHotkeyToggleView.Location = new System.Drawing.Point(274, 219); + this.uiHotkeyToggleView.Name = "uiHotkeyToggleView"; + this.uiHotkeyToggleView.ReadOnly = true; + this.uiHotkeyToggleView.Size = new System.Drawing.Size(222, 32); + this.uiHotkeyToggleView.TabIndex = 216; + this.uiHotkeyToggleView.Text = "Default text"; + this.uiHotkeyToggleView.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.uiHotkeyToggleView.Enter += new System.EventHandler(this.hotkeyToggleView_Enter); + this.uiHotkeyToggleView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hotkeyToggleView_KeyDown); + // + // uiHotkeyToggleFavorite + // + this.uiHotkeyToggleFavorite.BackColor = System.Drawing.SystemColors.Window; + this.uiHotkeyToggleFavorite.Location = new System.Drawing.Point(274, 181); + this.uiHotkeyToggleFavorite.Name = "uiHotkeyToggleFavorite"; + this.uiHotkeyToggleFavorite.ReadOnly = true; + this.uiHotkeyToggleFavorite.Size = new System.Drawing.Size(222, 32); + this.uiHotkeyToggleFavorite.TabIndex = 215; + this.uiHotkeyToggleFavorite.Text = "Default text"; + this.uiHotkeyToggleFavorite.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.uiHotkeyToggleFavorite.Enter += new System.EventHandler(this.hotkeyToggleFavorite_Enter); + this.uiHotkeyToggleFavorite.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hotkeyToggleFavorite_KeyDown); + // + // label12 + // + this.label12.AutoSize = true; + this.label12.Font = new System.Drawing.Font("Segoe UI", 11.12727F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label12.Location = new System.Drawing.Point(24, 185); + this.label12.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label12.Name = "label12"; + this.label12.Size = new System.Drawing.Size(185, 25); + this.label12.TabIndex = 1007; + this.label12.Text = "Toggle favorite entry"; + // + // label13 + // + this.label13.AutoSize = true; + this.label13.Font = new System.Drawing.Font("Segoe UI", 11.12727F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label13.Location = new System.Drawing.Point(24, 223); + this.label13.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label13.Name = "label13"; + this.label13.Size = new System.Drawing.Size(140, 25); + this.label13.TabIndex = 1008; + this.label13.Text = "Toggle list view"; + // // uiHotkeyPaste // this.uiHotkeyPaste.BackColor = System.Drawing.SystemColors.Window; - this.uiHotkeyPaste.Location = new System.Drawing.Point(274, 143); + this.uiHotkeyPaste.Location = new System.Drawing.Point(274, 142); this.uiHotkeyPaste.Name = "uiHotkeyPaste"; this.uiHotkeyPaste.ReadOnly = true; this.uiHotkeyPaste.Size = new System.Drawing.Size(222, 32); @@ -624,10 +692,10 @@ private void InitializeComponent() // cancelHotkey // this.cancelHotkey.Enabled = false; - this.cancelHotkey.Location = new System.Drawing.Point(388, 180); + this.cancelHotkey.Location = new System.Drawing.Point(388, 256); this.cancelHotkey.Name = "cancelHotkey"; this.cancelHotkey.Size = new System.Drawing.Size(108, 38); - this.cancelHotkey.TabIndex = 216; + this.cancelHotkey.TabIndex = 218; this.cancelHotkey.Text = "Cancel"; this.cancelHotkey.UseVisualStyleBackColor = true; this.cancelHotkey.Click += new System.EventHandler(this.cancelHotkey_Click); @@ -648,10 +716,10 @@ private void InitializeComponent() // applyHotkey // this.applyHotkey.Enabled = false; - this.applyHotkey.Location = new System.Drawing.Point(274, 180); + this.applyHotkey.Location = new System.Drawing.Point(274, 256); this.applyHotkey.Name = "applyHotkey"; this.applyHotkey.Size = new System.Drawing.Size(108, 38); - this.applyHotkey.TabIndex = 215; + this.applyHotkey.TabIndex = 217; this.applyHotkey.Text = "Apply"; this.applyHotkey.UseVisualStyleBackColor = true; this.applyHotkey.Click += new System.EventHandler(this.ApplyHotkeys_Click); @@ -660,7 +728,7 @@ private void InitializeComponent() // this.label4.AutoSize = true; this.label4.Font = new System.Drawing.Font("Segoe UI", 11.12727F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label4.Location = new System.Drawing.Point(24, 147); + this.label4.Location = new System.Drawing.Point(24, 146); this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(144, 25); @@ -708,12 +776,13 @@ private void InitializeComponent() this.tabPage1.Location = new System.Drawing.Point(4, 34); this.tabPage1.Name = "tabPage1"; this.tabPage1.Padding = new System.Windows.Forms.Padding(3); - this.tabPage1.Size = new System.Drawing.Size(565, 444); + this.tabPage1.Size = new System.Drawing.Size(565, 483); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "General"; // // groupBox2 // + this.groupBox2.Controls.Add(this.uiFavoritesEnabled); this.groupBox2.Controls.Add(this.uiRestoreOriginal); this.groupBox2.Controls.Add(this.uiCopyImages); this.groupBox2.Controls.Add(this.uiPasteOnSelection); @@ -723,7 +792,7 @@ private void InitializeComponent() this.groupBox2.Controls.Add(this.uiHistoryEnabled); this.groupBox2.Location = new System.Drawing.Point(22, 150); this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(521, 286); + this.groupBox2.Size = new System.Drawing.Size(521, 312); this.groupBox2.TabIndex = 110; this.groupBox2.TabStop = false; this.groupBox2.Text = "Behaviour"; @@ -747,7 +816,7 @@ private void InitializeComponent() this.uiCopyImages.Checked = true; this.uiCopyImages.CheckState = System.Windows.Forms.CheckState.Checked; this.uiCopyImages.ForeColor = System.Drawing.SystemColors.ControlText; - this.uiCopyImages.Location = new System.Drawing.Point(29, 159); + this.uiCopyImages.Location = new System.Drawing.Point(29, 191); this.uiCopyImages.Name = "uiCopyImages"; this.uiCopyImages.Size = new System.Drawing.Size(226, 29); this.uiCopyImages.TabIndex = 115; @@ -760,7 +829,7 @@ private void InitializeComponent() this.uiTrimWhitespaces.AutoSize = true; this.uiTrimWhitespaces.Checked = true; this.uiTrimWhitespaces.CheckState = System.Windows.Forms.CheckState.Checked; - this.uiTrimWhitespaces.Location = new System.Drawing.Point(29, 223); + this.uiTrimWhitespaces.Location = new System.Drawing.Point(29, 255); this.uiTrimWhitespaces.Name = "uiTrimWhitespaces"; this.uiTrimWhitespaces.Size = new System.Drawing.Size(301, 29); this.uiTrimWhitespaces.TabIndex = 117; @@ -841,7 +910,7 @@ private void InitializeComponent() this.tabControl.Location = new System.Drawing.Point(12, 12); this.tabControl.Name = "tabControl"; this.tabControl.SelectedIndex = 0; - this.tabControl.Size = new System.Drawing.Size(573, 482); + this.tabControl.Size = new System.Drawing.Size(573, 521); this.tabControl.TabIndex = 0; this.tabControl.Selected += new System.Windows.Forms.TabControlEventHandler(this.tabControl_Selected); // @@ -853,7 +922,7 @@ private void InitializeComponent() this.tabPage3.Controls.Add(this.groupBox4); this.tabPage3.Location = new System.Drawing.Point(4, 34); this.tabPage3.Name = "tabPage3"; - this.tabPage3.Size = new System.Drawing.Size(565, 444); + this.tabPage3.Size = new System.Drawing.Size(565, 483); this.tabPage3.TabIndex = 5; this.tabPage3.Text = "Style"; // @@ -862,7 +931,7 @@ private void InitializeComponent() this.borderGroupBox.Controls.Add(this.uiHistoryBorder); this.borderGroupBox.Location = new System.Drawing.Point(22, 286); this.borderGroupBox.Name = "borderGroupBox"; - this.borderGroupBox.Size = new System.Drawing.Size(281, 150); + this.borderGroupBox.Size = new System.Drawing.Size(281, 176); this.borderGroupBox.TabIndex = 410; this.borderGroupBox.TabStop = false; this.borderGroupBox.Text = "History border"; @@ -888,7 +957,7 @@ private void InitializeComponent() this.groupBox8.Controls.Add(this.uiHistoryColorBrown); this.groupBox8.Location = new System.Drawing.Point(322, 23); this.groupBox8.Name = "groupBox8"; - this.groupBox8.Size = new System.Drawing.Size(220, 413); + this.groupBox8.Size = new System.Drawing.Size(220, 439); this.groupBox8.TabIndex = 420; this.groupBox8.TabStop = false; this.groupBox8.Text = "History color"; @@ -1105,7 +1174,7 @@ private void InitializeComponent() this.tabPage6.Controls.Add(this.groupBox3); this.tabPage6.Location = new System.Drawing.Point(4, 34); this.tabPage6.Name = "tabPage6"; - this.tabPage6.Size = new System.Drawing.Size(565, 444); + this.tabPage6.Size = new System.Drawing.Size(565, 483); this.tabPage6.TabIndex = 6; this.tabPage6.Text = "Advanced"; // @@ -1160,7 +1229,7 @@ private void InitializeComponent() this.groupBox9.Controls.Add(this.uiCleanUpExit); this.groupBox9.Location = new System.Drawing.Point(22, 310); this.groupBox9.Name = "groupBox9"; - this.groupBox9.Size = new System.Drawing.Size(523, 126); + this.groupBox9.Size = new System.Drawing.Size(523, 152); this.groupBox9.TabIndex = 520; this.groupBox9.TabStop = false; this.groupBox9.Text = "Clean-up HovText configuration settings"; @@ -1228,7 +1297,7 @@ private void InitializeComponent() this.tabPage7.Controls.Add(this.uiEmailAddr); this.tabPage7.Location = new System.Drawing.Point(4, 34); this.tabPage7.Name = "tabPage7"; - this.tabPage7.Size = new System.Drawing.Size(565, 444); + this.tabPage7.Size = new System.Drawing.Size(565, 483); this.tabPage7.TabIndex = 7; this.tabPage7.Text = "Feedback"; // @@ -1279,11 +1348,24 @@ private void InitializeComponent() this.uiEmailAddr.Size = new System.Drawing.Size(509, 32); this.uiEmailAddr.TabIndex = 600; // + // uiFavoritesEnabled + // + this.uiFavoritesEnabled.AutoSize = true; + this.uiFavoritesEnabled.Checked = true; + this.uiFavoritesEnabled.CheckState = System.Windows.Forms.CheckState.Checked; + this.uiFavoritesEnabled.Location = new System.Drawing.Point(29, 159); + this.uiFavoritesEnabled.Name = "uiFavoritesEnabled"; + this.uiFavoritesEnabled.Size = new System.Drawing.Size(168, 29); + this.uiFavoritesEnabled.TabIndex = 118; + this.uiFavoritesEnabled.Text = "Enable favorites"; + this.uiFavoritesEnabled.UseVisualStyleBackColor = true; + this.uiFavoritesEnabled.CheckedChanged += new System.EventHandler(this.uiFavoritesEnabled_CheckedChanged); + // // Settings // this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(596, 560); + this.ClientSize = new System.Drawing.Size(596, 584); this.Controls.Add(this.uiHelp); this.Controls.Add(this.tabControl); this.Font = new System.Drawing.Font("Segoe UI", 11.12727F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); @@ -1442,6 +1524,12 @@ private void InitializeComponent() private System.Windows.Forms.Label label1; private System.Windows.Forms.Label uiDevelopmentWarning; private System.Windows.Forms.Label uiDevelopmentVersion; + private System.Windows.Forms.GroupBox uiDisplayGroup; + private System.Windows.Forms.TextBox uiHotkeyToggleView; + private System.Windows.Forms.TextBox uiHotkeyToggleFavorite; + private System.Windows.Forms.Label label12; + private System.Windows.Forms.Label label13; + private System.Windows.Forms.CheckBox uiFavoritesEnabled; } } \ No newline at end of file diff --git a/HovText/Settings.cs b/HovText/Settings.cs index ed0c297..b3e339c 100644 --- a/HovText/Settings.cs +++ b/HovText/Settings.cs @@ -33,7 +33,7 @@ public partial class Settings : Form // ########################################################################################### // Is this a stable public RELEASE or a DEVELOPMENT version -// public static readonly string appType = ""; +// public static readonly string appType = ""; // STABLE RELEASE public static readonly string appType = "# DEVELOPMENT"; // History, default values @@ -86,12 +86,15 @@ public partial class Settings : Form private const string registryHotkeyGetOlderEntry = "Alt + H"; // hotkey "Show older entry" private const string registryHotkeyGetNewerEntry = "Shift + Alt + H"; // hotkey "Show newer entry" private const string registryHotkeyPasteOnHotkey = "Alt + O"; // hotkey "Paste on hotkey" + private const string registryHotkeyToggleFavorite = "Space"; // hotkey "Toggle favorite entry" + private const string registryHotkeyToggleView = "Q"; // hotkey "Toggle list view" private const string registryCheckUpdates = "1"; // 1 = check for updates private const string registryHotkeyBehaviour = "System"; // use system clipboard private const string registryCloseMinimizes = "1"; // 1 = minimize to tray private const string registryRestoreOriginal = "1"; // 1 = restore original private const string registryCopyImages = "1"; // 1 = copy images to history private const string registryEnableHistory = "1"; // 1 = enable history + private const string registryEnableFavorites = "1"; // 1 = enable favorites private const string registryPasteOnSelection = "0"; // 0 = do not paste selected entry when selected private const string registryTrimWhitespaces = "1"; // 1 = trim whitespaces private const string registryHistoryColorCustomTop = "#000000"; @@ -103,6 +106,7 @@ public partial class Settings : Form // UI elements public static bool isEnabledHistory; + public static bool isEnabledFavorites; public static bool isEnabledPasteOnSelection; public static bool isEnabledTrimWhitespacing; public static bool isRestoreOriginal; @@ -127,6 +131,7 @@ public partial class Settings : Form public readonly static SortedDictionary entriesImage = new SortedDictionary(); private readonly static SortedList> entriesOriginal = new SortedList>(); public readonly static SortedDictionary entriesImageTransparent = new SortedDictionary(); + public readonly static SortedDictionary entriesIsFavorite = new SortedDictionary(); const int WM_CLIPBOARDUPDATE = 0x031D; string whoUpdatedClipboardName = ""; public static bool pasteOnHotkeySetCleartext; @@ -142,17 +147,20 @@ public partial class Settings : Form public static bool hasTroubleshootLogged; public static string troubleshootLogfile = "HovText-troubleshooting.txt"; private static bool resetApp = false; + public static bool showFavoriteList = false; readonly History history = new History(); readonly Update update = new Update(); readonly PasteOnHotkey pasteOnHotkey = new PasteOnHotkey(); readonly HotkeyConflict hotkeyConflict = new HotkeyConflict(); + private static string originatingApplicationName = ""; + public static int activeScreen; // selected screen to show the history (default will be the main screen) + private static string hotkey; // needed for validating the keys as it is not set in the event // ########################################################################################### // Main // ########################################################################################### - public Settings() { // Get application file version from assembly @@ -185,14 +193,22 @@ public Settings() Assembly assembly = Assembly.GetExecutingAssembly(); FileVersionInfo verInfo = FileVersionInfo.GetVersionInfo(assembly.Location); int appBuildInt = verInfo.ProductPrivatePart; - string appBuildTxt = appBuildInt != 0 ? " (rev. " + appBuildInt + ")" : ""; // Set the full application version string - appVer = (date + appBuildTxt + " " + appType).Trim(); + if (appType != "") + { + string appBuildTxt = " (rev. " + appBuildInt + ")"; + appVer = (date + appBuildTxt + " " + appType).Trim(); + } + else + { + appVer = date; + } + // Start logging, if relevant - if (isTroubleshootEnabled) Logging.StartLogging(); - if (isTroubleshootEnabled) hasTroubleshootLogged = true; + Logging.StartLogging(); + hasTroubleshootLogged = isTroubleshootEnabled ? true : false; // Setup form InitializeComponent(); @@ -206,12 +222,15 @@ public Settings() // Catch repaint event for this specific element (to draw the border) uiShowFontBottom.Paint += new System.Windows.Forms.PaintEventHandler(this.uiShowFontBottom_Paint); + // Catch display change events (e.g. add/remove displays or change of main display) + SystemEvents.DisplaySettingsChanged += new EventHandler(DisplayChangesEvent); + // Initialize registry and get its values for the various checkboxes InitializeRegistry(); GetStartupSettings(); Program.AddClipboardFormatListener(this.Handle); - if (isTroubleshootEnabled) Logging.Log("Added HovText to clipboard chain"); + Logging.Log("Added HovText to clipboard chain"); // Write text for the "About" page @@ -253,7 +272,7 @@ protected override void WndProc(ref Message m) IntPtr whoUpdatedClipboardHwnd = Program.GetClipboardOwner(); Program.GetWindowThreadProcessId(whoUpdatedClipboardHwnd, out uint thisProcessId); whoUpdatedClipboardName = Process.GetProcessById((int)thisProcessId).ProcessName; - if (isTroubleshootEnabled) Logging.Log("Clipboard [UPDATE] event from [" + whoUpdatedClipboardName + "]"); + Logging.Log("Clipboard [UPDATE] event from [" + whoUpdatedClipboardName + "]"); // I am not sure why some(?) applications are returned as "Idle" or "svchost" when coming from clipboard - in this case the get the active application and use that name instead // This could potentially be a problem, if a process is correctly called "Idle" but not sure if this is realistic? @@ -261,7 +280,7 @@ protected override void WndProc(ref Message m) { string activeProcessName = GetActiveApplication(); whoUpdatedClipboardName = activeProcessName; - if (isTroubleshootEnabled) Logging.Log("Finding process name the secondary way, [" + whoUpdatedClipboardName + "]"); + Logging.Log("Finding process name the secondary way, [" + whoUpdatedClipboardName + "]"); } // Check if application is enabled @@ -337,7 +356,7 @@ private void ProcessClipboard() } } else - if (isClipboardImage) // Is clipboard an image + if (isClipboardImage && isEnabledHistory) // Is clipboard an image { // Only proceed if we should copy the images also if (isCopyImages) @@ -367,6 +386,7 @@ private void ProcessClipboard() } } } +/* else // We have come in to here, if clipboard has changed but it does not contains a text or an image // It could be empty or e.g. a file copy @@ -389,6 +409,7 @@ private void ProcessClipboard() clipboardTextLast = Clipboard.GetText(); } } +*/ } @@ -411,9 +432,9 @@ private Image GetImageFromClipboard() } catch (Exception ex) { - if (isTroubleshootEnabled) Logging.Log("Exception #10 raised (Settings):"); - if (isTroubleshootEnabled) Logging.Log(" " + ex.Message); - if (isTroubleshootEnabled) Logging.Log(" Failed converting image to byte array - fetching \"GetImage()\" instead"); + Logging.Log("Exception #10 raised (Settings):"); + Logging.Log(" " + ex.Message); + Logging.Log(" Failed converting image to byte array - fetching \"GetImage()\" instead"); return Clipboard.ContainsImage() ? Clipboard.GetImage() : null; } @@ -469,7 +490,7 @@ private static bool IsImageTransparent(Image image) public static void RestoreOriginal (int entryIndex) { - if (isTroubleshootEnabled) Logging.Log("Restoring original content to clipboard:"); + Logging.Log("Restoring original content to clipboard:"); try { @@ -481,7 +502,7 @@ public static void RestoreOriginal (int entryIndex) if (kvp.Value != null) { data.SetData(kvp.Key, kvp.Value); - if (isTroubleshootEnabled) Logging.Log(" Adding format to clipboard, ["+ kvp.Key +"]"); + Logging.Log(" Adding format to clipboard, ["+ kvp.Key +"]"); } } Clipboard.Clear(); @@ -490,8 +511,8 @@ public static void RestoreOriginal (int entryIndex) } catch (Exception ex) { - if (isTroubleshootEnabled) Logging.Log("Exception #1 raised (Settings):"); - if (isTroubleshootEnabled) Logging.Log(" " + ex.Message); + Logging.Log("Exception #1 raised (Settings):"); + Logging.Log(" " + ex.Message); MessageBox.Show("EXCEPTION #1 - please enable troubleshooting log and report to developer"); } } @@ -558,6 +579,7 @@ private void AddEntry() entriesText.Clear(); entriesImage.Clear(); entriesImageTransparent.Clear(); + entriesIsFavorite.Clear(); entriesApplication.Clear(); entriesOriginal.Clear(); } @@ -568,11 +590,11 @@ private void AddEntry() { if(isClipboardText) { - if (isTroubleshootEnabled) Logging.Log("Adding new [TEXT] clipboard to history:"); + Logging.Log("Adding new [TEXT] clipboard to history:"); } else { - if (isTroubleshootEnabled) Logging.Log("Adding new [IMAGE] clipboard to history:"); + Logging.Log("Adding new [IMAGE] clipboard to history:"); } // If this is the first time then set the index to 0 @@ -582,6 +604,7 @@ private void AddEntry() entriesText.Add(entryIndex, clipboardText); entriesImage.Add(entryIndex, clipboardImage); entriesImageTransparent.Add(entryIndex, isClipboardImageTransparent); + entriesIsFavorite.Add(entryIndex, false); // Walk through all (relevant) clipboard object formats and store them. // I am not sure how to do this differently as it does not work if I take everything!? @@ -608,15 +631,16 @@ private void AddEntry() || format.Contains("FileDrop") // used in e.g. animated GIF || format.Contains("FileContents") // used in e.g. animated GIF || format.Contains("FileGroupDescriptorW") // used in e.g. animated GIF -// || format.Contains("") + || format.Contains("Image") // seen on "CorelPHOTOPAINT.Image.20" and "CorelPhotoPaint.Image.9" + || format.Contains("Color") // seen on "Corel.Color.20" ) { clipboardObjects.Add(format, clipboardObject.GetData(format)); - if (isTroubleshootEnabled) Logging.Log(" Adding format ["+ format +"]"); + Logging.Log(" Adding format ["+ format +"]"); } else { - if (isTroubleshootEnabled) Logging.Log(" Discarding format [" + format + "]"); + Logging.Log(" Discarding format [" + format + "]"); } } entriesOriginal.Add(entryIndex, clipboardObjects); @@ -628,7 +652,7 @@ private void AddEntry() } entriesApplication.Add(entryIndex, whoUpdatedClipboardName); - if (isTroubleshootEnabled) Logging.Log("Entries in history list is now [" + entriesText.Count + "]"); + Logging.Log("Entries in history list is now [" + entriesText.Count + "]"); } // Update the entries on the tray icon @@ -674,14 +698,13 @@ public void SetClipboard() entryText = entryText.Trim(); } Clipboard.Clear(); -// Clipboard.SetText(entryText, TextDataFormat.Text); Clipboard.SetText(entryText, TextDataFormat.UnicodeText); // https://stackoverflow.com/a/14255608/2028935 } } catch (Exception ex) { - if (isTroubleshootEnabled) Logging.Log("Exception #2 raised (Settings):"); - if (isTroubleshootEnabled) Logging.Log(" " + ex.Message); + Logging.Log("Exception #2 raised (Settings):"); + Logging.Log(" " + ex.Message); MessageBox.Show("EXCEPTION #2 - please enable troubleshooting log and report to developer"); } } @@ -694,15 +717,15 @@ public void SetClipboard() } catch (Exception ex) { - if (isTroubleshootEnabled) Logging.Log("Exception #3 raised (Settings):"); - if (isTroubleshootEnabled) Logging.Log(" " + ex.Message); + Logging.Log("Exception #3 raised (Settings):"); + Logging.Log(" " + ex.Message); MessageBox.Show("EXCEPTION #3 - please enable troubleshooting log and report to developer"); } } else { - if (isTroubleshootEnabled) Logging.Log("Exception #4 raised (Settings):"); - if (isTroubleshootEnabled) Logging.Log(" Clipboard triggered but is not [isEntryText] or [isEntryImage]"); + Logging.Log("Exception #4 raised (Settings):"); + Logging.Log(" Clipboard triggered but is not [isEntryText] or [isEntryImage]"); MessageBox.Show("EXCEPTION #4 - please enable troubleshooting log and report to developer"); } } @@ -726,7 +749,7 @@ public void GoEntryLowerNumber() { Hide(); } - GetActiveApplication(); + originatingApplicationName = GetActiveApplication(); history.SetupForm(); } // Always change focus to HovText to ensure we can catch the key-up event @@ -735,17 +758,7 @@ public void GoEntryLowerNumber() // Only proceed if the entry counter is equal to or more than 0 if (entryCounter > 0) { - - // Check if this is the first call (we want to show the newest entry at the first keypress) - if (!isFirstCallAfterHotkey && entryCounter > 1) - { - var element = entriesText.ElementAt(entryCounter - 2); - entryIndex = element.Key; - } isFirstCallAfterHotkey = false; - - // Show history UI - GetEntryCounter(); history.UpdateHistory("down"); } } @@ -770,26 +783,16 @@ public void GoEntryHigherNumber() { Hide(); } - GetActiveApplication(); + originatingApplicationName = GetActiveApplication(); history.SetupForm(); } // Always change focus to HovText to ensure we can catch the key-up event - ChangeFocusToThisApplication(); + ChangeFocusToThisApplication(); // Only proceed if the entry counter is less than the total amount of entries if (entryCounter <= entriesText.Count) { - - // Check if this is the first call (we want to show the newest entry at the first keypress) - if (!isFirstCallAfterHotkey && entryCounter < entriesText.Count) - { - var element = entriesText.ElementAt(entryCounter); - entryIndex = element.Key; - } isFirstCallAfterHotkey = false; - - // Show history UI - GetEntryCounter(); history.UpdateHistory("up"); } } @@ -797,7 +800,7 @@ public void GoEntryHigherNumber() // ########################################################################################### - // Called when a history entry has been selected in the "HistoryList" form + // Called when a history entry has been selected in the "History" form // ########################################################################################### public void SelectHistoryEntry() @@ -807,17 +810,22 @@ public void SelectHistoryEntry() // Check if application is enabled if (uiAppEnabled.Checked && entryCounter > 0) { - MoveEntryToTop(); + // Only proceed if we should actually restore something (we could come here from an empty favorite list view) + int entriesInList = History.entriesInList; + if (entriesInList > 0) + { + MoveEntryToTop(); - pasteOnHotkeySetCleartext = true; + pasteOnHotkeySetCleartext = true; - // Set the clipboard with the new data - SetClipboard(); + // Set the clipboard with the new data + SetClipboard(); - // Restore the original clipboard, if we are within the "Paste on hotkey only" mode - if (uiHotkeyBehaviourPaste.Checked) - { - PasteOnHotkey.StartTimerToRestoreOriginal(); + // Restore the original clipboard, if we are within the "Paste on hotkey only" mode + if (uiHotkeyBehaviourPaste.Checked) + { + PasteOnHotkey.StartTimerToRestoreOriginal(); + } } // Set focus back to the originating application @@ -865,6 +873,7 @@ private void MoveEntryToTop() entriesText.Add(insertKey, entriesText[entryIndex]); entriesImage.Add(insertKey, entriesImage[entryIndex]); entriesImageTransparent.Add(insertKey, entriesImageTransparent[entryIndex]); + entriesIsFavorite.Add(insertKey, entriesIsFavorite[entryIndex]); entriesApplication.Add(insertKey, entriesApplication[entryIndex]); entriesOriginal.Add(insertKey, entriesOriginal[entryIndex]); @@ -872,6 +881,7 @@ private void MoveEntryToTop() entriesText.Remove(entryIndex); entriesImage.Remove(entryIndex); entriesImageTransparent.Remove(entryIndex); + entriesIsFavorite.Remove(entryIndex); entriesApplication.Remove(entryIndex); entriesOriginal.Remove(entryIndex); @@ -900,11 +910,11 @@ private void uiAppEnabled_CheckedChanged(object sender, EventArgs e) // Check if application is enabled if (uiAppEnabled.Checked) { - if (isTroubleshootEnabled) Logging.Log("Enabled HovText"); + Logging.Log("Enabled HovText"); // Add this application to the clipboard chain again Program.AddClipboardFormatListener(this.Handle); - if (isTroubleshootEnabled) Logging.Log("Added HovText to clipboard chain"); + Logging.Log("Added HovText to clipboard chain"); ProcessClipboard(); @@ -933,22 +943,31 @@ private void uiAppEnabled_CheckedChanged(object sender, EventArgs e) // Enable other checkboxes uiHistoryEnabled.Enabled = true; + if (uiHistoryEnabled.Checked) + { + uiCopyImages.Enabled = true; + uiPasteOnSelection.Enabled = true; + uiHotkeyOlder.Enabled = true; + uiHotkeyNewer.Enabled = true; + uiFavoritesEnabled.Enabled = true; + if (uiFavoritesEnabled.Checked) + { + uiHotkeyToggleFavorite.Enabled = true; + uiHotkeyToggleView.Enabled = true; + } + } uiRestoreOriginal.Enabled = true; - uiCopyImages.Enabled = true; - uiTrimWhitespaces.Enabled = true; - uiPasteOnSelection.Enabled = true; - uiHotkeyOlder.Enabled = true; - uiHotkeyNewer.Enabled = true; uiHotkeyBehaviourSystem.Enabled = true; uiHotkeyBehaviourPaste.Enabled = true; + uiTrimWhitespaces.Enabled = true; } else { - if (isTroubleshootEnabled) Logging.Log("Disabed HovText"); + Logging.Log("Disabed HovText"); // Remove this application from the clipboard chain Program.RemoveClipboardFormatListener(this.Handle); - if (isTroubleshootEnabled) Logging.Log("Removed HovText from clipboard chain"); + Logging.Log("Removed HovText from clipboard chain"); // Restore the original clipboard format if (isRestoreOriginal && entriesOriginal.Count > 0) @@ -962,6 +981,7 @@ private void uiAppEnabled_CheckedChanged(object sender, EventArgs e) // Disable other checkboxes uiHistoryEnabled.Enabled = false; + uiFavoritesEnabled.Enabled = false; uiRestoreOriginal.Enabled = false; uiCopyImages.Enabled = false; uiTrimWhitespaces.Enabled = false; @@ -971,6 +991,9 @@ private void uiAppEnabled_CheckedChanged(object sender, EventArgs e) uiHotkeyPaste.Enabled = false; uiHotkeyBehaviourSystem.Enabled = false; uiHotkeyBehaviourPaste.Enabled = false; + uiFavoritesEnabled.Enabled = false; + uiHotkeyToggleFavorite.Enabled = false; + uiHotkeyToggleView.Enabled = false; } } @@ -995,7 +1018,7 @@ private void MainWindow_Resize(object sender, EventArgs e) private void aboutBox_LinkClicked(object sender, LinkClickedEventArgs e) { - if (isTroubleshootEnabled) Logging.Log("Clicked the web page link in \"About\""); + Logging.Log("Clicked the web page link in \"About\""); System.Diagnostics.Process.Start(e.LinkText); } @@ -1009,23 +1032,23 @@ private void MainWindow_FormClosing(object sender, FormClosingEventArgs e) // In case windows is trying to shut down, don't hold up the process if (e.CloseReason == CloseReason.WindowsShutDown) { - if (isTroubleshootEnabled) Logging.Log("Exit HovText"); + Logging.Log("Exit HovText"); Program.RemoveClipboardFormatListener(this.Handle); - if (isTroubleshootEnabled) Logging.Log("Removed HovText from clipboard chain"); + Logging.Log("Removed HovText from clipboard chain"); RemoveAllHotkeys(); - if (isTroubleshootEnabled) Logging.EndLogging(); + Logging.EndLogging(); return; } if (!isCloseMinimizes || isClosedFromNotifyIcon) { - if (isTroubleshootEnabled) Logging.Log("Exit HovText"); + Logging.Log("Exit HovText"); Program.RemoveClipboardFormatListener(this.Handle); - if (isTroubleshootEnabled) Logging.Log("Removed HovText from clipboard chain"); + Logging.Log("Removed HovText from clipboard chain"); RemoveAllHotkeys(); - if (isTroubleshootEnabled) Logging.EndLogging(); + Logging.EndLogging(); return; } @@ -1066,7 +1089,6 @@ private static string GetActiveApplication() // Get the process ID and find the name for that ID Program.GetWindowThreadProcessId(originatingHandle, out uint processId); string appProcessName = Process.GetProcessById((int)processId).ProcessName; - Logging.Log("Active application is ["+ appProcessName +"]"); return appProcessName; } @@ -1089,7 +1111,7 @@ private void ChangeFocusToThisApplication() public static void ChangeFocusToOriginatingApplication() { Program.SetForegroundWindow(originatingHandle); - Logging.Log("Set focus to originating application"); + Logging.Log("Set focus to originating application ["+ originatingApplicationName +"]"); } @@ -1101,9 +1123,8 @@ private void updateTimer_Tick(object sender, EventArgs e) { updateTimer.Enabled = false; - if (isTroubleshootEnabled) Logging.Log("Update timer exceeded"); - - if (isTroubleshootEnabled) Logging.Log(" User version running = [" + appVer + "]"); + Logging.Log("Update timer expired"); + Logging.Log(" User version running = [" + appVer + "]"); // Check for a new stable version try @@ -1116,7 +1137,7 @@ private void updateTimer_Tick(object sender, EventArgs e) if (checkedVersion.Substring(0, 7) == "Version") { checkedVersion = checkedVersion.Substring(9); - if (isTroubleshootEnabled) Logging.Log(" Stable version available = [" + checkedVersion + "]"); + Logging.Log(" Stable version available = [" + checkedVersion + "]"); update.uiAppVerYours.Text = appVer; update.uiAppVerOnline.Text = checkedVersion; string lastCheckedVersion = GetRegistryKey(registryPath, "CheckedVersion"); @@ -1124,15 +1145,15 @@ private void updateTimer_Tick(object sender, EventArgs e) { update.Show(); update.Activate(); - if (isTroubleshootEnabled) Logging.Log(" Notified on newer version available"); + Logging.Log(" Notified on newer version available"); } } } catch (WebException ex) { // Catch the exception though this is not so critical that we need to disturb the developer - if (isTroubleshootEnabled) Logging.Log("Exception #11 raised (Settings):"); - if (isTroubleshootEnabled) Logging.Log(" " + ex.Message); + Logging.Log("Exception #11 raised (Settings):"); + Logging.Log(" " + ex.Message); } // Check for a new development version @@ -1148,14 +1169,14 @@ private void updateTimer_Tick(object sender, EventArgs e) checkedVersion = checkedVersion.Substring(9); uiDevelopmentVersion.Text = " "+ checkedVersion; uiDevelopmentDownload.Enabled = true; - if (isTroubleshootEnabled) Logging.Log(" Development version available = [" + checkedVersion + "]"); + Logging.Log(" Development version available = [" + checkedVersion + "]"); } } catch (WebException ex) { // Catch the exception though this is not so critical that we need to disturb the developer - if (isTroubleshootEnabled) Logging.Log("Exception #14 raised (Settings):"); - if (isTroubleshootEnabled) Logging.Log(" " + ex.Message); + Logging.Log("Exception #14 raised (Settings):"); + Logging.Log(" " + ex.Message); } } @@ -1172,7 +1193,7 @@ private void InitializeRegistry() if (registryPathExists == null) { Registry.CurrentUser.CreateSubKey(registryPath); - if (isTroubleshootEnabled) Logging.Log("Created registry path ["+ registryPath +"]"); + Logging.Log("Created registry path ["+ registryPath +"]"); } } @@ -1184,6 +1205,8 @@ private void InitializeRegistry() RegistryCheckOrCreate("Hotkey2", registryHotkeyGetOlderEntry); RegistryCheckOrCreate("Hotkey3", registryHotkeyGetNewerEntry); RegistryCheckOrCreate("Hotkey4", registryHotkeyPasteOnHotkey); + RegistryCheckOrCreate("Hotkey5", registryHotkeyToggleFavorite); + RegistryCheckOrCreate("Hotkey6", registryHotkeyToggleView); if (isTroubleshootEnabled) { @@ -1199,6 +1222,10 @@ private void InitializeRegistry() Logging.Log(" \"Hotkey3\" = [" + regVal + "]"); regVal = GetRegistryKey(registryPath, "Hotkey4"); Logging.Log(" \"Hotkey4\" = [" + regVal + "]"); + regVal = GetRegistryKey(registryPath, "Hotkey5"); + Logging.Log(" \"Hotkey5\" = [" + regVal + "]"); + regVal = GetRegistryKey(registryPath, "Hotkey6"); + Logging.Log(" \"Hotkey6\" = [" + regVal + "]"); } // General @@ -1207,6 +1234,7 @@ private void InitializeRegistry() RegistryCheckOrCreate("CloseMinimizes", registryCloseMinimizes); RegistryCheckOrCreate("RestoreOriginal", registryRestoreOriginal); RegistryCheckOrCreate("HistoryEnable", registryEnableHistory); + RegistryCheckOrCreate("FavoritesEnable", registryEnableFavorites); RegistryCheckOrCreate("CopyImages", registryCopyImages); RegistryCheckOrCreate("PasteOnSelection", registryPasteOnSelection); RegistryCheckOrCreate("TrimWhitespaces", registryTrimWhitespaces); @@ -1227,6 +1255,8 @@ private void InitializeRegistry() Logging.Log(" \"RestoreOriginal\" = [" + regVal + "]"); regVal = GetRegistryKey(registryPath, "HistoryEnable"); Logging.Log(" \"HistoryEnable\" = [" + regVal + "]"); + regVal = GetRegistryKey(registryPath, "FavoritesEnable"); + Logging.Log(" \"FavoritesEnable\" = [" + regVal + "]"); regVal = GetRegistryKey(registryPath, "CopyImages"); Logging.Log(" \"CopyImages\" = [" + regVal + "]"); regVal = GetRegistryKey(registryPath, "PasteOnSelection"); @@ -1235,11 +1265,25 @@ private void InitializeRegistry() Logging.Log(" \"TrimWhitespaces\" = [" + regVal + "]"); } + /* + // Handle the screen setup + // --- + // Get array of strings from registry + // https://docs.microsoft.com/en-us/dotnet/api/microsoft.win32.registry.setvalue?view=dotnet-plat-ext-5.0 + string idSystem = GetScreenIdSystem(); + string[] idDefault = { idSystem + ":" + activeScreen }; + RegistryCheckOrCreate("ScreenSelectionHEST", idDefault); + */ + + // Get the main system display (0-indexed) + activeScreen = ScreenGetPrimary(); + // Layout RegistryCheckOrCreate("HistoryEntries", historyListElements.ToString()); RegistryCheckOrCreate("HistorySizeWidth", historySizeWidth.ToString()); RegistryCheckOrCreate("HistorySizeHeight", historySizeHeight.ToString()); RegistryCheckOrCreate("HistoryLocation", historyLocation); + RegistryCheckOrCreate("ScreenSelection", activeScreen.ToString()); if (isTroubleshootEnabled) { @@ -1253,6 +1297,8 @@ private void InitializeRegistry() Logging.Log(" \"HistorySizeHeight\" = [" + regVal + "]"); regVal = GetRegistryKey(registryPath, "HistoryLocation"); Logging.Log(" \"HistoryLocation\" = [" + regVal + "]"); + regVal = GetRegistryKey(registryPath, "ScreenSelection"); + Logging.Log(" \"ScreenSelection\" = [" + regVal + "]"); } // Style @@ -1312,7 +1358,8 @@ private void InitializeRegistry() // ########################################################################################### - // Check if the registry key exists - if not then create it and set default value + // Check if the registry key exists - if not then create it and set default value. + // It has two methods - one with a string or one with an array of strings // ########################################################################################### private static void RegistryCheckOrCreate(string regKey, string regValue) @@ -1327,6 +1374,20 @@ private static void RegistryCheckOrCreate(string regKey, string regValue) } } + /* + private static void RegistryCheckOrCreate(string regKey, string[] regValue) + { + // Check if the registry key is set - if not then set default value + using (RegistryKey registryPathExists = Registry.CurrentUser.OpenSubKey(registryPath, true)) + { + if (registryPathExists.GetValue(regKey) == null) + { + SetRegistryKey(registryPath, regKey, regValue); + } + } + } + */ + // ########################################################################################### // Get regsitry key value @@ -1366,19 +1427,46 @@ public static void SetRegistryKey(string path, string key, string value) // Log it if (getKey == null) { - if (isTroubleshootEnabled) Logging.Log("Created registry key \"" + key + "\" with value [" + value + "] in [" + path + "]"); + Logging.Log("Created registry key \"" + key + "\" with value [" + value + "] in [" + path + "]"); + } + else + { + // Only log if there really is a modification done + if (value != getKey) + { + Logging.Log("Modified registry key \"" + key + "\" to value [" + value + "] in [" + path + "]"); + } + } + } + } + + /* + public static void SetRegistryKey(string path, string key, string[] value) + { + using (RegistryKey setKey = Registry.CurrentUser.OpenSubKey(path, true)) + { + // First check if the key is already created (only relevant for logging) + string getKey = GetRegistryKey(path, key); + + // Create or modify the value + setKey.SetValue(key, value); + + // Log it + if (getKey == null) + { + Logging.Log("Created registry key \"" + key + "\" with value [" + value + "] in [" + path + "]"); } else { // Only log if there really is a modification done if (value != getKey) { - if (isTroubleshootEnabled) Logging.Log("Modified registry key \"" + key + "\" to value [" + value + "] in [" + path + "]"); + Logging.Log("Modified registry key \"" + key + "\" to value [" + value + "] in [" + path + "]"); } - } } } + */ // ########################################################################################### @@ -1390,7 +1478,7 @@ private static void DeleteRegistryKey(string path, string key) using (RegistryKey deleteKey = Registry.CurrentUser.OpenSubKey(path, true)) { deleteKey.DeleteValue(key, false); - if (isTroubleshootEnabled) Logging.Log("Delete registry key \""+ key +"\" from ["+ path +"]"); + Logging.Log("Delete registry key \""+ key +"\" from ["+ path +"]"); } } @@ -1410,14 +1498,20 @@ private void GetStartupSettings() string hotkey2 = GetRegistryKey(registryPath, "Hotkey2"); string hotkey3 = GetRegistryKey(registryPath, "Hotkey3"); string hotkey4 = GetRegistryKey(registryPath, "Hotkey4"); + string hotkey5 = GetRegistryKey(registryPath, "Hotkey5"); + string hotkey6 = GetRegistryKey(registryPath, "Hotkey6"); hotkey1 = hotkey1.Length == 0 ? "Not set" : hotkey1; hotkey2 = hotkey2.Length == 0 ? "Not set" : hotkey2; hotkey3 = hotkey3.Length == 0 ? "Not set" : hotkey3; hotkey4 = hotkey4.Length == 0 ? "Not set" : hotkey4; + hotkey5 = hotkey5.Length == 0 ? "Not set" : hotkey5; + hotkey6 = hotkey6.Length == 0 ? "Not set" : hotkey6; uiHotkeyEnable.Text = hotkey1; uiHotkeyOlder.Text = hotkey2; uiHotkeyNewer.Text = hotkey3; uiHotkeyPaste.Text = hotkey4; + uiHotkeyToggleFavorite.Text = hotkey5; + uiHotkeyToggleView.Text = hotkey6; SetHotkeys("Startup of application"); // Hotkey behaviour @@ -1444,12 +1538,12 @@ private void GetStartupSettings() if (getKey == null) { uiStartWithWindows.Checked = false; - if (isTroubleshootEnabled) Logging.Log("Start with Windows = [No]"); + Logging.Log("Start with Windows = [No]"); } else { uiStartWithWindows.Checked = true; - if (isTroubleshootEnabled) Logging.Log("Start with Windows = [Yes]"); + Logging.Log("Start with Windows = [Yes]"); // Make sure the legacy HovText does not interfere - overwrite if it does not contain "HovText.exe" or "--start-minimized" string runEntry = GetRegistryKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", "HovText"); @@ -1468,13 +1562,8 @@ private void GetStartupSettings() uiDevelopmentVersion.Enabled = true; uiDevelopmentWarning.Enabled = true; uiDevelopmentVersion.Text = " Wait - checking ..."; -// uiDevelopmentVersion.BackColor = Color.Transparent; // Color.White; - if (isTroubleshootEnabled) Logging.Log("Update timer started"); + Logging.Log("Update timer started"); } -// else -// { -// uiDevelopmentVersion.BackColor = Color.Transparent; // SystemColors.Control; -// } // Restore original when disabling application int restoreOriginal = int.Parse((string)GetRegistryKey(registryPath, "RestoreOriginal")); @@ -1499,6 +1588,21 @@ private void GetStartupSettings() MinimizeBox = true; } + // Enable favorites + int favoritesEnabled = int.Parse((string)GetRegistryKey(registryPath, "FavoritesEnable")); + uiFavoritesEnabled.Checked = favoritesEnabled == 1 ? true : false; + isEnabledFavorites = uiFavoritesEnabled.Checked; + if (isEnabledFavorites) + { + uiHotkeyToggleFavorite.Enabled = true; + uiHotkeyToggleView.Enabled = true; + } + else + { + uiHotkeyToggleFavorite.Enabled = false; + uiHotkeyToggleView.Enabled = false; + } + // Enable history int historyEnabled = int.Parse((string)GetRegistryKey(registryPath, "HistoryEnable")); uiHistoryEnabled.Checked = historyEnabled == 1 ? true : false; @@ -1508,12 +1612,22 @@ private void GetStartupSettings() uiHotkeyOlder.Enabled = true; uiHotkeyNewer.Enabled = true; uiPasteOnSelection.Enabled = true; + uiFavoritesEnabled.Enabled = true; + if (uiFavoritesEnabled.Checked) + { + uiHotkeyToggleFavorite.Enabled = true; + uiHotkeyToggleView.Enabled = true; + } + } else { uiHotkeyOlder.Enabled = false; uiHotkeyNewer.Enabled = false; uiPasteOnSelection.Enabled = false; + uiFavoritesEnabled.Enabled = false; + uiHotkeyToggleFavorite.Enabled = false; + uiHotkeyToggleView.Enabled = false; } // Paste on history selection @@ -1526,6 +1640,7 @@ private void GetStartupSettings() uiTrimWhitespaces.Checked = trimWhitespaces == 1 ? true : false; isEnabledTrimWhitespacing = uiTrimWhitespaces.Checked; + // ------------------------------------------ // "Apperance" tab // ------------------------------------------ @@ -1615,6 +1730,31 @@ private void GetStartupSettings() uiShowFontBottom.Text = historyFontFamily + ", " + historyFontSize; SetHistoryColors(); + // Screen selection + int screenReg = Int32.Parse(GetRegistryKey(registryPath, "ScreenSelection")); + ScreenPopulateSetup(); + if (IsScreenValid(screenReg)) + { + activeScreen = screenReg; + Logging.Log("History will be shown on screen ID [" + activeScreen + "]"); + } + else + { + Logging.Log("History cannot be shown on screen ID [" + screenReg + "] and will instead be shown on screen ID ["+ activeScreen +"]"); + } + uiDisplayGroup.Controls["uiScreen" + activeScreen].Select(); + + /* + // Get array of strings from registry + // https://docs.microsoft.com/en-us/dotnet/api/microsoft.win32.registry.setvalue?view=dotnet-plat-ext-5.0 + string[] tArray = (string[])Registry.GetValue( + "HKEY_CURRENT_USER\\" + registryPath, + "ScreenSelectionHEST", + new string[] { "ScreenSelectionHEST does not exist" } + ); + */ + + // ------------------------------------------ // "Advanced" tab // ------------------------------------------ @@ -1641,8 +1781,6 @@ private void GetStartupSettings() uiTroubleshootOpenLocation.Enabled = false; uiTroubleshootDeleteFile.Enabled = false; } - - } @@ -1656,12 +1794,12 @@ private void uiStartWithWindows_CheckedChanged(object sender, EventArgs e) if (uiStartWithWindows.Checked) { SetRegistryKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", "HovText", "\"" + Application.ExecutablePath + "\" --start-minimized"); - if (isTroubleshootEnabled) Logging.Log("Changed \"Start with Windows\" from [No] to [Yes]"); + Logging.Log("Changed \"Start with Windows\" from [No] to [Yes]"); } else { DeleteRegistryKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", "HovText"); - if (isTroubleshootEnabled) Logging.Log("Changed \"Start with Windows\" from [Yes] to [No]"); + Logging.Log("Changed \"Start with Windows\" from [Yes] to [No]"); } } @@ -1861,7 +1999,6 @@ private void EnableDisableCustomColor() historyBorder = false; } } - } @@ -1909,21 +2046,18 @@ private void uiCheckUpdates_CheckedChanged(object sender, EventArgs e) if (uiCheckUpdates.Checked) { updateTimer.Enabled = true; - if (isTroubleshootEnabled) Logging.Log("Update timer started"); + Logging.Log("Update timer started"); uiDevelopmentVersion.Enabled = true; uiDevelopmentWarning.Enabled = true; uiDevelopmentVersion.Text = " Wait - checking ..."; -// uiDevelopmentVersion.BackColor = Color.White; } else { updateTimer.Enabled = false; - if (isTroubleshootEnabled) Logging.Log("Update timer disabled"); uiDevelopmentVersion.Enabled = false; uiDevelopmentWarning.Enabled = false; uiDevelopmentDownload.Enabled = false; uiDevelopmentVersion.Text = " Enable \"Check for updates online\""; -// uiDevelopmentVersion.BackColor = SystemColors.Control; } } @@ -1989,6 +2123,12 @@ private void uiHistoryEnabled_CheckedChanged(object sender, EventArgs e) uiHotkeyNewer.Enabled = true; uiCopyImages.Enabled = true; uiPasteOnSelection.Enabled = true; + uiFavoritesEnabled.Enabled = true; + if (uiFavoritesEnabled.Checked) + { + uiHotkeyToggleFavorite.Enabled = true; + uiHotkeyToggleView.Enabled = true; + } } else { @@ -1996,6 +2136,10 @@ private void uiHistoryEnabled_CheckedChanged(object sender, EventArgs e) uiHotkeyNewer.Enabled = false; uiCopyImages.Enabled = false; uiPasteOnSelection.Enabled = false; + uiFavoritesEnabled.Enabled = false; + uiHotkeyToggleFavorite.Enabled = false; + uiHotkeyToggleView.Enabled = false; + showFavoriteList = false; } // Enable/disable hotkeys @@ -2006,6 +2150,42 @@ private void uiHistoryEnabled_CheckedChanged(object sender, EventArgs e) } + // ########################################################################################### + // Changes in "Enable favorites" + // ########################################################################################### + + private void uiFavoritesEnabled_CheckedChanged(object sender, EventArgs e) + { + string status = uiFavoritesEnabled.Checked ? "1" : "0"; + isEnabledFavorites = uiFavoritesEnabled.Checked; + SetRegistryKey(registryPath, "FavoritesEnable", status); + if (isEnabledFavorites) + { + uiHotkeyToggleFavorite.Enabled = true; + uiHotkeyToggleView.Enabled = true; + } + else + { + uiHotkeyToggleFavorite.Enabled = false; + uiHotkeyToggleView.Enabled = false; + showFavoriteList = false; + + // Reset all favorites + if (entriesIsFavorite.Count > 0) + { + for (int i = 0; i <= entriesIsFavorite.ElementAt(Settings.entriesIsFavorite.Count - 1).Key; i++) + { + bool doesKeyExist = Settings.entriesText.ContainsKey(i); + if (doesKeyExist) + { + entriesIsFavorite[i] = false; + } + } + } + } + } + + // ########################################################################################### // Changes in "Paste on history selection" // ########################################################################################### @@ -2056,11 +2236,11 @@ private void MainWindow_Shown(object sender, EventArgs e) { WindowState = FormWindowState.Minimized; Hide(); - if (isTroubleshootEnabled) Logging.Log("Finalized initial setup and started HovText minimized"); + Logging.Log("Finalized initial setup and started HovText minimized"); } else { - if (isTroubleshootEnabled) Logging.Log("Finalized initial setup and started HovText in window mode"); + Logging.Log("Finalized initial setup and started HovText in window mode"); } } @@ -2071,7 +2251,7 @@ private void MainWindow_Shown(object sender, EventArgs e) private void trayIconAbout_Click(object sender, EventArgs e) { - if (isTroubleshootEnabled) Logging.Log("Clicked tray icon \"About\""); + Logging.Log("Clicked tray icon \"About\""); ShowSettingsForm(); tabControl.SelectedIndex = 6; // About } @@ -2085,7 +2265,7 @@ private void trayIconSettings_Click(object sender, EventArgs e) { ShowSettingsForm(); tabControl.SelectedIndex = 0; // General - if (isTroubleshootEnabled) Logging.Log("Clicked tray icon \"Settings\""); + Logging.Log("Clicked tray icon \"Settings\""); } @@ -2095,7 +2275,7 @@ private void trayIconSettings_Click(object sender, EventArgs e) private void trayIconExit_Click(object sender, EventArgs e) { - if (isTroubleshootEnabled) Logging.Log("Clicked tray icon \"Exit\""); + Logging.Log("Clicked tray icon \"Exit\""); isClosedFromNotifyIcon = true; Close(); } @@ -2118,7 +2298,7 @@ private void notifyIcon_MouseClick(object sender, MouseEventArgs e) private void mouseClickTimer_Tick(object sender, EventArgs e) { - if (isTroubleshootEnabled) Logging.Log("Tray icon single-click"); + Logging.Log("Tray icon single-click"); mouseClickTimer.Stop(); ToggleEnabled(); } @@ -2132,7 +2312,7 @@ private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { - if (isTroubleshootEnabled) Logging.Log("Tray icon double-click"); + Logging.Log("Tray icon double-click"); // Cancel the single-click mouseClickTimer.Stop(); @@ -2203,7 +2383,7 @@ private void uiHelp_Click(object sender, EventArgs e) releaseTrain += appType.Contains("TEST") ? "-dev" : ""; System.Diagnostics.Process.Start(hovtextPage +"documentation"+ releaseTrain +"/#"+ selectedTab); - if (isTroubleshootEnabled) Logging.Log("Clicked the \"Help\" for \""+ selectedTab +"\""); + Logging.Log("Clicked the \"Help\" for \""+ selectedTab +"\""); } @@ -2262,7 +2442,7 @@ private void HotkeyPasteOnHotkey(object sender, NHotkey.HotkeyEventArgs e) if (entriesText.Count > 0) { // Get active application and change focus to HovText - GetActiveApplication(); + originatingApplicationName = GetActiveApplication(); ChangeFocusToThisApplication(); // Show the invisible form, so we can catch the key-up event @@ -2281,7 +2461,7 @@ private void HotkeyPasteOnHotkey(object sender, NHotkey.HotkeyEventArgs e) private static string ConvertKeyboardInputToString(KeyEventArgs e) { - string hotkey = ""; + string thisHotkey = ""; // Check if any of the modifiers have been pressed also bool isShift = e.Shift; @@ -2297,20 +2477,22 @@ private static string ConvertKeyboardInputToString(KeyEventArgs e) keyCode = keyCode == "Menu" ? "Unsupported" : keyCode; keyCode = keyCode == "ControlKey" ? "Unsupported" : keyCode; keyCode = keyCode == "ShiftKey" ? "Unsupported" : keyCode; + keyCode = hotkey == "hotkeyToggleFavorite" && (isShift || isAlt || isControl) ? "Unsupported" : keyCode; + keyCode = hotkey == "hotkeyToggleView" && (isShift || isAlt || isControl) ? "Unsupported" : keyCode; // Build the hotkey string - hotkey = isShift ? hotkey + "Shift + " : hotkey; - hotkey = isAlt ? hotkey + "Alt + " : hotkey; - hotkey = isControl ? hotkey + "Control + " : hotkey; - hotkey += keyCode; + thisHotkey = isShift ? thisHotkey + "Shift + " : thisHotkey; + thisHotkey = isAlt ? thisHotkey + "Alt + " : thisHotkey; + thisHotkey = isControl ? thisHotkey + "Control + " : thisHotkey; + thisHotkey += keyCode; // Invalidate if the key is unspported - hotkey = keyCode == "Unsupported" ? "Unsupported" : hotkey; + thisHotkey = keyCode == "Unsupported" ? "Unsupported" : thisHotkey; // Mark the hotkey as deleted if pressing "Delete" og "Backspace" - hotkey = (keyCode == "Delete" || keyCode == "Back") && !isShift && !isAlt && !isControl ? "Not set" : hotkey; + thisHotkey = (keyCode == "Delete" || keyCode == "Back") && !isShift && !isAlt && !isControl ? "Not set" : thisHotkey; - return hotkey; + return thisHotkey; } @@ -2362,6 +2544,28 @@ private void hotkeyPaste_KeyDown(object sender, KeyEventArgs e) } } + private void hotkeyToggleFavorite_KeyDown(object sender, KeyEventArgs e) + { + string hotkey = ConvertKeyboardInputToString(e); + uiHotkeyToggleFavorite.Text = hotkey; + if (e.Alt) + { + // https://stackoverflow.com/a/3068797/2028935 + e.SuppressKeyPress = true; + } + } + + private void hotkeyToggleView_KeyDown(object sender, KeyEventArgs e) + { + string hotkey = ConvertKeyboardInputToString(e); + uiHotkeyToggleView.Text = hotkey; + if (e.Alt) + { + // https://stackoverflow.com/a/3068797/2028935 + e.SuppressKeyPress = true; + } + } + // ########################################################################################### // Mark hotkey field as modified when entering it @@ -2369,22 +2573,38 @@ private void hotkeyPaste_KeyDown(object sender, KeyEventArgs e) private void HotkeyEnable_Enter(object sender, EventArgs e) { - ModifyHotkey("hotkeyEnable"); + hotkey = "hotkeyEnable"; + ModifyHotkey(); } private void hotkeyOlder_Enter(object sender, EventArgs e) { - ModifyHotkey("hotkeyOlder"); + hotkey = "hotkeyOlder"; + ModifyHotkey(); } private void hotkeyNewer_Enter(object sender, EventArgs e) { - ModifyHotkey("hotkeyNewer"); + hotkey = "hotkeyNewer"; + ModifyHotkey(); } private void hotkeyPaste_Enter(object sender, EventArgs e) { - ModifyHotkey("hotkeyPaste"); + hotkey = "hotkeyPaste"; + ModifyHotkey(); + } + + private void hotkeyToggleFavorite_Enter(object sender, EventArgs e) + { + hotkey = "hotkeyToggleFavorite"; + ModifyHotkey(); + } + + private void hotkeyToggleView_Enter(object sender, EventArgs e) + { + hotkey = "hotkeyToggleView"; + ModifyHotkey(); } @@ -2392,7 +2612,7 @@ private void hotkeyPaste_Enter(object sender, EventArgs e) // Color the hotkey field and enable the "Apply" and "Cancel" buttons // ########################################################################################### - private void ModifyHotkey(string hotkey) + private void ModifyHotkey() { switch (hotkey) { @@ -2408,6 +2628,12 @@ private void ModifyHotkey(string hotkey) case "hotkeyPaste": uiHotkeyPaste.BackColor = SystemColors.Info; break; + case "hotkeyToggleFavorite": + uiHotkeyToggleFavorite.BackColor = SystemColors.Info; + break; + case "hotkeyToggleView": + uiHotkeyToggleView.BackColor = SystemColors.Info; + break; } // Enable the two buttons, "Apply" and "Cancel" @@ -2429,10 +2655,10 @@ private static void RemoveAllHotkeys() HotkeyManager.Current.Remove("GetOlderEntry"); HotkeyManager.Current.Remove("GetNewerEntry"); HotkeyManager.Current.Remove("PasteOnHotkey"); - if (isTroubleshootEnabled) Logging.Log("[Hotkey1] removed"); - if (isTroubleshootEnabled) Logging.Log("[Hotkey2] removed"); - if (isTroubleshootEnabled) Logging.Log("[Hotkey3] removed"); - if (isTroubleshootEnabled) Logging.Log("[Hotkey4] removed"); + Logging.Log("[Hotkey1] removed"); + Logging.Log("[Hotkey2] removed"); + Logging.Log("[Hotkey3] removed"); + Logging.Log("[Hotkey4] removed"); } @@ -2452,13 +2678,15 @@ private void ApplyHotkeys_Click(object sender, EventArgs e) private void SetHotkeys(string from) { - if (isTroubleshootEnabled) Logging.Log("Called \"SetHotkeys()\" from \"" + from +"\""); + Logging.Log("Called \"SetHotkeys()\" from \"" + from +"\""); // Get all hotkey strings string hotkey1 = uiHotkeyEnable.Text; string hotkey2 = uiHotkeyOlder.Text; string hotkey3 = uiHotkeyNewer.Text; string hotkey4 = uiHotkeyPaste.Text; + string hotkey5 = uiHotkeyToggleFavorite.Text; + string hotkey6 = uiHotkeyToggleView.Text; string conflictText = ""; KeysConverter cvt; @@ -2478,13 +2706,13 @@ private void SetHotkeys(string from) cvt = new KeysConverter(); key = (Keys)cvt.ConvertFrom(hotkey1); HotkeyManager.Current.AddOrReplace("ToggleApplication", key, HotkeyToggleApplication); - if (isTroubleshootEnabled) Logging.Log("[Hotkey1] added as global hotkey and set to ["+ hotkey1 +"]"); + Logging.Log("[Hotkey1] added as global hotkey and set to ["+ hotkey1 +"]"); } catch (Exception ex) { - if (isTroubleshootEnabled) Logging.Log("Exception #6 raised (Settings):"); - if (isTroubleshootEnabled) Logging.Log(" Hotkey [Hotkey1] conflicts"); - if (isTroubleshootEnabled) Logging.Log(" "+ ex.Message); + Logging.Log("Exception #6 raised (Settings):"); + Logging.Log(" Hotkey [Hotkey1] conflicts"); + Logging.Log(" "+ ex.Message); if (ex.Message.Contains("Hot key is already registered")) { hotkey1 = "Hotkey conflicts"; @@ -2506,13 +2734,13 @@ private void SetHotkeys(string from) cvt = new KeysConverter(); key = (Keys)cvt.ConvertFrom(hotkey2); HotkeyManager.Current.AddOrReplace("GetOlderEntry", key, HotkeyGetOlderEntry); - if (isTroubleshootEnabled) Logging.Log("[Hotkey2] added as global hotkey and set to [" + hotkey2 + "]"); + Logging.Log("[Hotkey2] added as global hotkey and set to [" + hotkey2 + "]"); } catch (Exception ex) { - if (isTroubleshootEnabled) Logging.Log("Exception #7 raised (Settings):"); - if (isTroubleshootEnabled) Logging.Log(" Hotkey [Hotkey2] conflicts"); - if (isTroubleshootEnabled) Logging.Log(" " + ex.Message); + Logging.Log("Exception #7 raised (Settings):"); + Logging.Log(" Hotkey [Hotkey2] conflicts"); + Logging.Log(" " + ex.Message); if (ex.Message.Contains("Hot key is already registered")) { hotkey2 = "Hotkey conflicts"; @@ -2539,13 +2767,13 @@ private void SetHotkeys(string from) cvt = new KeysConverter(); key = (Keys)cvt.ConvertFrom(hotkey3); HotkeyManager.Current.AddOrReplace("GetNewerEntry", key, HotkeyGetNewerEntry); - if (isTroubleshootEnabled) Logging.Log("[Hotkey3] added as global hotkey and set to [" + hotkey3 + "]"); + Logging.Log("[Hotkey3] added as global hotkey and set to [" + hotkey3 + "]"); } catch (Exception ex) { - if (isTroubleshootEnabled) Logging.Log("Exception #8 raised (Settings):"); - if (isTroubleshootEnabled) Logging.Log(" Hotkey [Hotkey3] conflicts"); - if (isTroubleshootEnabled) Logging.Log(" " + ex.Message); + Logging.Log("Exception #8 raised (Settings):"); + Logging.Log(" Hotkey [Hotkey3] conflicts"); + Logging.Log(" " + ex.Message); if (ex.Message.Contains("Hot key is already registered")) { hotkey3 = "Hotkey conflicts"; @@ -2576,14 +2804,14 @@ private void SetHotkeys(string from) if (uiHotkeyBehaviourPaste.Checked) { HotkeyManager.Current.AddOrReplace("PasteOnHotkey", key, HotkeyPasteOnHotkey); - if (isTroubleshootEnabled) Logging.Log("[Hotkey4] added as global hotkey and set to [" + hotkey4 + "]"); + Logging.Log("[Hotkey4] added as global hotkey and set to [" + hotkey4 + "]"); } } catch (Exception ex) { - if (isTroubleshootEnabled) Logging.Log("Exception #9 raised (Settings):"); - if (isTroubleshootEnabled) Logging.Log(" Hotkey [Hotkey4] conflicts"); - if (isTroubleshootEnabled) Logging.Log(" " + ex.Message); + Logging.Log("Exception #9 raised (Settings):"); + Logging.Log(" Hotkey [Hotkey4] conflicts"); + Logging.Log(" " + ex.Message); if (ex.Message.Contains("Hot key is already registered")) { hotkey4 = "Hotkey conflicts"; @@ -2595,7 +2823,7 @@ private void SetHotkeys(string from) // Remove the hotkey, if it is not available HotkeyManager.Current.Remove("PasteOnHotkey"); } - + // If this is called from startup then show an error, if there is a conflict if (conflictText.Length > 0 && from == "Startup of application") { @@ -2610,13 +2838,17 @@ private void SetHotkeys(string from) hotkey1 != "Unsupported" && hotkey1 != "Hotkey conflicts" && hotkey2 != "Unsupported" && hotkey2 != "Hotkey conflicts" && hotkey3 != "Unsupported" && hotkey3 != "Hotkey conflicts" && - hotkey4 != "Unsupported" && hotkey4 != "Hotkey conflicts" + hotkey4 != "Unsupported" && hotkey4 != "Hotkey conflicts" && + hotkey5 != "Unsupported" && hotkey5 != "Hotkey conflicts" && + hotkey6 != "Unsupported" && hotkey6 != "Hotkey conflicts" ) { SetRegistryKey(registryPath, "Hotkey1", hotkey1); SetRegistryKey(registryPath, "Hotkey2", hotkey2); SetRegistryKey(registryPath, "Hotkey3", hotkey3); SetRegistryKey(registryPath, "Hotkey4", hotkey4); + SetRegistryKey(registryPath, "Hotkey5", hotkey5); + SetRegistryKey(registryPath, "Hotkey6", hotkey6); } bool hasError = false; @@ -2641,7 +2873,6 @@ private void SetHotkeys(string from) hasError = true; uiHotkeyOlder.Text = hotkey2; uiHotkeyOlder.BackColor = Color.DarkSalmon; -// if (isTroubleshootEnabled) Logging.Log("[Hotkey2] has error [" + hotkey2 + "]"); } else { @@ -2654,7 +2885,6 @@ private void SetHotkeys(string from) hasError = true; uiHotkeyNewer.Text = hotkey3; uiHotkeyNewer.BackColor = Color.DarkSalmon; -// if (isTroubleshootEnabled) Logging.Log("[Hotkey3] has error [" + hotkey3 + "]"); } else { @@ -2667,13 +2897,36 @@ private void SetHotkeys(string from) hasError = true; uiHotkeyPaste.Text = hotkey4; uiHotkeyPaste.BackColor = Color.DarkSalmon; -// if (isTroubleshootEnabled) Logging.Log("[Hotkey4] has error [" + hotkey4 + "]"); } else { uiHotkeyPaste.BackColor = SystemColors.Window; } + // Hotkey 5, "Toggle favorite entry" + if (hotkey5 == "Unsupported" || hotkey5 == "Hotkey conflicts") + { + hasError = true; + uiHotkeyToggleFavorite.Text = hotkey5; + uiHotkeyToggleFavorite.BackColor = Color.DarkSalmon; + } + else + { + uiHotkeyToggleFavorite.BackColor = SystemColors.Window; + } + + // Hotkey 6, "Toggle list view" + if (hotkey6 == "Unsupported" || hotkey6 == "Hotkey conflicts") + { + hasError = true; + uiHotkeyToggleView.Text = hotkey6; + uiHotkeyToggleView.BackColor = Color.DarkSalmon; + } + else + { + uiHotkeyToggleView.BackColor = SystemColors.Window; + } + // Accept the changes and disable the two buttons again if (!hasError) { @@ -2693,12 +2946,16 @@ private void cancelHotkey_Click(object sender, EventArgs e) string hotkey2 = GetRegistryKey(registryPath, "Hotkey2"); string hotkey3 = GetRegistryKey(registryPath, "Hotkey3"); string hotkey4 = GetRegistryKey(registryPath, "Hotkey4"); + string hotkey5 = GetRegistryKey(registryPath, "Hotkey5"); + string hotkey6 = GetRegistryKey(registryPath, "Hotkey6"); uiHotkeyEnable.Text = hotkey1; uiHotkeyOlder.Text = hotkey2; uiHotkeyNewer.Text = hotkey3; uiHotkeyPaste.Text = hotkey4; + uiHotkeyToggleFavorite.Text = hotkey5; + uiHotkeyToggleView.Text = hotkey6; SetHotkeys("Cancel hotkeys button press"); - if (isTroubleshootEnabled) Logging.Log("Cancelling hotkeys association and reverting to previous values"); + Logging.Log("Cancelling hotkeys association and reverting to previous values"); } @@ -2759,7 +3016,7 @@ private void UpdateNotifyIconText() private void pictureBox1_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start("https://www.paypal.com/donate?hosted_button_id=U23UUA8YWABGU"); - if (isTroubleshootEnabled) Logging.Log("Clicked the \"Donate\" picture in \"About\""); + Logging.Log("Clicked the \"Donate\" picture in \"About\""); } @@ -2893,7 +3150,7 @@ private void uiTroubleshootOpenLocation_Click(object sender, EventArgs e) string argument = "/select, \"" + troubleshootLogfile + "\""; string folder = argument.Substring(6); Process.Start("explorer.exe", argument); - if (isTroubleshootEnabled) Logging.Log("Clicked the \"Open logfile location\""); + Logging.Log("Clicked the \"Open logfile location\""); } else { @@ -3012,8 +3269,8 @@ private void uiSendFeedback_Click(object sender, EventArgs e) if (email.Length > 0) { string txt = "Feedback sent - please allow for some time, if any response is required"; - if (isTroubleshootEnabled) Logging.Log(txt); - if (isTroubleshootEnabled) Logging.Log(" Email used = [" + email + "]"); + Logging.Log(txt); + Logging.Log(" Email used = [" + email + "]"); MessageBox.Show(txt); } else @@ -3027,8 +3284,8 @@ private void uiSendFeedback_Click(object sender, EventArgs e) catch (WebException ex) { // Catch the exception though this is not so critical that we need to disturb the developer - if (isTroubleshootEnabled) Logging.Log("Exception #13 raised (Settings):"); - if (isTroubleshootEnabled) Logging.Log(" " + ex.Message); + Logging.Log("Exception #13 raised (Settings):"); + Logging.Log(" " + ex.Message); MessageBox.Show("EXCEPTION #13 - please enable troubleshooting log and report to developer"); } @@ -3036,8 +3293,8 @@ private void uiSendFeedback_Click(object sender, EventArgs e) else { string txt = "Invalid email address ["+ email +"]"; - if (isTroubleshootEnabled) Logging.Log("EXCEPTION #12 raised:"); - if (isTroubleshootEnabled) Logging.Log(" "+ txt); + Logging.Log("EXCEPTION #12 raised:"); + Logging.Log(" "+ txt); MessageBox.Show(txt); } } @@ -3080,7 +3337,192 @@ private bool IsValidEmail(string email) private void uiDevelopmentDownload_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start(hovtextPage + "autoupdate/development/HovText.exe"); - if (isTroubleshootEnabled) Logging.Log("Clicked the \"Download\" development version"); + Logging.Log("Clicked the \"Download\" development version"); + } + + + // ########################################################################################### + // Detect the main/primary screen. + // Return will be a 0-indexed screen/display + // ########################################################################################### + + private int ScreenGetPrimary() + { + // Walk through all screens + int numScreens = Screen.AllScreens.Length; // total number of screens + for (int i = 0; i < numScreens; i++) + { + bool isScreenMain = Screen.AllScreens[i].Primary; + if (isScreenMain) + { + return i; + } + } + return 0; + } + + + /* + // ########################################################################################### + // Get the string ID for this screen setup + // ########################################################################################### + + private string GetScreenIdSystem() + { + // Walk through all screens + int numScreens = Screen.AllScreens.Length; // total number of screens + int primaryScreen = 0; + for (int i = 0; i < numScreens; i++) + { + bool isScreenMain = Screen.AllScreens[i].Primary; + if (isScreenMain) + { + primaryScreen = i; + } + } + + // Build the screen ID + string screenId = numScreens.ToString() + ":" + primaryScreen.ToString(); + + return screenId; + } + + private string GetScreenIdRegistry(string id) + { + string[] tokens = id.Split(':'); + return tokens[0] + ":" + tokens[1]; + } + + private string GetScreen() + { + // Walk through all screens + int numScreens = Screen.AllScreens.Length; // total number of screens + int primaryScreen = 0; + for (int i = 0; i < numScreens; i++) + { + bool isScreenMain = Screen.AllScreens[i].Primary; + if (isScreenMain) + { + primaryScreen = i; + } + } + + // Build the screen ID + string screenId = numScreens.ToString() + ":" + primaryScreen.ToString(); + + return screenId; + } + */ + + + // ########################################################################################### + // Check if the screen is valid + // ########################################################################################### + + private bool IsScreenValid (int screen) + { + int numScreens = Screen.AllScreens.Length; // total number of screens + if (numScreens >= screen + 1) + { + return true; + } + else + { + return false; + } + } + + + // ########################################################################################### + // Populate the screens to the setup + // Main contributor: FNI + // ########################################################################################### + + private void ScreenPopulateSetup () + { + // remove all elements + uiDisplayGroup.Controls.Clear(); + + // Build new radio buttons + int numScreens = Screen.AllScreens.Length; // total number of screens + if (numScreens > 1) + { + Logging.Log("Detected ["+ numScreens + "] screens"); + } + else + { + Logging.Log("Detected ["+ numScreens + "] screen"); + } + + // Walk through all screens + int dividerSpace = 32; + for (int i = 0; i < numScreens; i++) + { + // Check if this screen number is the main/primary one + bool isScreenMain = Screen.AllScreens[i].Primary; + var screen3 = Screen.PrimaryScreen; + + // Build a new radio UI element + RadioButton screen = new RadioButton(); + screen.Name = "uiScreen" + i; + screen.Tag = i; + if (isScreenMain) + { + screen.Text = "Screen " + (i + 1) + " (Main)"; + } + else + { + screen.Text = "Screen " + (i + 1); + } + screen.Location = new Point(32, dividerSpace); + screen.AutoSize = true; + screen.CheckedChanged += new System.EventHandler(uiDisplayGroup_Changed); + // Disable any possibility to select anything if we only have one screen + if (numScreens <= 1) + { + screen.Enabled = false; + } + uiDisplayGroup.Controls.Add(screen); + dividerSpace += 32; + } + } + + + // ########################################################################################### + // Catch event when changing the screen + // Main contributor: FNI + // ########################################################################################### + + private void uiDisplayGroup_Changed (object sender, EventArgs e) + { + RadioButton screenSelectedTag = (RadioButton)sender; + int screenSelected = Convert.ToInt32(screenSelectedTag.Tag); + if (screenSelected != activeScreen) + { + activeScreen = screenSelected; + SetRegistryKey(registryPath, "ScreenSelection", activeScreen.ToString()); + } + } + + + // ########################################################################################### + // Detect events for changing display properties - e.g. adding/removing displays + // ########################################################################################### + + private void DisplayChangesEvent (object sender, EventArgs e) + { + Logging.Log("Detected Windows display changes"); + + ScreenPopulateSetup(); + + // Check if the new display settings still validates the screen setup in HovText + if (!IsScreenValid(activeScreen)) + { + int activeScreenOld = activeScreen; + activeScreen = ScreenGetPrimary(); + Logging.Log("History cannot be shown on screen ID [" + activeScreenOld + "] and will instead be shown on screen ID [" + activeScreen + "]"); + } + uiDisplayGroup.Controls["uiScreen" + activeScreen].Select(); } diff --git a/HovText/Update.Designer.cs b/HovText/Update.Designer.cs index 8e468e0..524c893 100644 --- a/HovText/Update.Designer.cs +++ b/HovText/Update.Designer.cs @@ -167,6 +167,5 @@ private void InitializeComponent() public System.Windows.Forms.Label uiAppVerYours; public System.Windows.Forms.Label uiAppVerOnline; private System.Windows.Forms.TextBox textBox1; - } } \ No newline at end of file