Generate URL shortcut by drag drop url from browser to a menu (#190), version 1.0.17.64

This commit is contained in:
Markus Hofknecht 2021-06-26 13:24:56 +02:00
parent 99f4c6e46c
commit 74c68b6d46
18 changed files with 516 additions and 96 deletions

View file

@ -220,8 +220,7 @@ namespace SystemTrayMenu.Business
keyboardInput.RowSelected += AdjustScrollbarToDisplayedRow;
void AdjustScrollbarToDisplayedRow(DataGridView dgv, int index)
{
#warning to improve arguments, do not use .Parent.Parent.Parent
Menu menu = dgv.Parent.Parent.Parent as Menu;
Menu menu = (Menu)dgv.FindForm();
menu.AdjustScrollbar();
}
@ -466,7 +465,9 @@ namespace SystemTrayMenu.Business
internal void SwitchOpenClose(bool byClick)
{
waitToOpenMenu.MouseActive = byClick;
if (byClick && (DateTime.Now - deactivatedTime).TotalMilliseconds < 200)
if (byClick &&
!Config.AlwaysOpenByPin &&
(DateTime.Now - deactivatedTime).TotalMilliseconds < 200)
{
// By click on notifyicon the menu gets deactivated and closed
}
@ -610,9 +611,15 @@ namespace SystemTrayMenu.Business
return Form.ActiveForm is Menu;
}
private static void OpenFolder()
private static void OpenFolder(string pathToFolder = "")
{
Log.ProcessStart(Config.Path);
string path = pathToFolder;
if (string.IsNullOrEmpty(path))
{
path = Config.Path;
}
Log.ProcessStart(path);
}
private Menu Create(MenuData menuData, string title = null)
@ -627,7 +634,20 @@ namespace SystemTrayMenu.Business
}
menu.SetTitle(title);
menu.UserClickedOpenFolder += OpenFolder;
menu.UserClickedOpenFolder += OpenMainFolder;
void OpenMainFolder()
{
OpenFolder();
}
}
else
{
menu.SetTitle(Path.GetFileName(menuData.RowDataParent.TargetFilePath));
menu.UserClickedOpenFolder += OpenSubFolder;
void OpenSubFolder()
{
OpenFolder(menuData.RowDataParent.TargetFilePath);
}
}
menu.Level = menuData.Level;
@ -884,6 +904,10 @@ namespace SystemTrayMenu.Business
AsList.ForEach(menu => menu.ShowTransparent());
}
}
else if (Config.AlwaysOpenByPin)
{
AsList.ForEach(menu => menu.ShowTransparent());
}
else
{
MenusFadeOut();
@ -904,6 +928,8 @@ namespace SystemTrayMenu.Business
menu.HideWithFade();
});
Config.AlwaysOpenByPin = false;
}
private void AdjustMenusSizeAndLocation()

View file

@ -43,6 +43,8 @@ namespace SystemTrayMenu
Application.Run();
}
}
Config.Dispose();
}
catch (Exception ex)
{

View file

@ -9,15 +9,19 @@ namespace SystemTrayMenu
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using Microsoft.Win32;
using Svg;
using SystemTrayMenu.Properties;
using SystemTrayMenu.UserInterface.FolderBrowseDialog;
using SystemTrayMenu.Utilities;
public static class Config
{
internal static readonly Bitmap BitmapOpenFolder = ReadSvg(Properties.Resources.ic_fluent_folder_48_regular);
internal static readonly Bitmap BitmapPin = ReadSvg(Properties.Resources.ic_fluent_pin_48_regular);
internal static readonly Bitmap BitmapPinActive = ReadSvg(Properties.Resources.ic_fluent_pin_48_filled);
private static bool readDarkModeDone;
private static bool isDarkMode;
private static bool readHideFileExtdone;
@ -27,12 +31,21 @@ namespace SystemTrayMenu
public static string Path => Settings.Default.PathDirectory;
public static bool AlwaysOpenByPin { get; internal set; }
public static void Initialize()
{
UpgradeIfNotUpgraded();
InitializeColors();
}
public static void Dispose()
{
BitmapOpenFolder.Dispose();
BitmapPin.Dispose();
BitmapPinActive.Dispose();
}
public static bool LoadOrSetByUser()
{
bool pathOK = Directory.Exists(Path);
@ -374,6 +387,15 @@ namespace SystemTrayMenu
}
}
private static Bitmap ReadSvg(byte[] byteArray)
{
using (var stream = new MemoryStream(byteArray))
{
var svgDocument = SvgDocument.Open<SvgDocument>(stream);
return svgDocument.Draw();
}
}
private static bool IsRegistryValueThisValue(string keyName, string valueName, string value)
{
bool isRegistryValueThisValue = false;

View file

@ -62,7 +62,9 @@ namespace SystemTrayMenu.DataClasses
public void Dispose()
{
Dispose(true);
#if DEBUG
GC.SuppressFinalize(this);
#endif
}
internal void SetText(string text)

View file

@ -31,7 +31,9 @@ namespace SystemTrayMenu.Helper
public void Dispose()
{
Dispose(true);
#if DEBUG
GC.SuppressFinalize(this);
#endif
}
internal void CellMouseEnter(object sender, DataGridViewCellEventArgs newEventArgs)

131
Helpers/DragDropHelper.cs Normal file
View file

@ -0,0 +1,131 @@
namespace SystemTrayMenu.Helpers
{
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;
using SystemTrayMenu.DataClasses;
using SystemTrayMenu.UserInterface;
public static class DragDropHelper
{
public static void DragEnter(object sender, DragEventArgs e)
{
object data = e.Data.GetData("UniformResourceLocator");
MemoryStream ms = data as MemoryStream;
if (ms != null)
{
byte[] bytes = ms.ToArray();
Encoding encod = Encoding.ASCII;
string url = encod.GetString(bytes);
if (!string.IsNullOrEmpty(url))
{
e.Effect = DragDropEffects.Copy;
}
}
}
public static void DragDrop(object sender, DragEventArgs e)
{
Menu menu = (Menu)sender;
string path;
if (menu == null)
{
path = Config.Path;
}
else
{
RowData rowData = (RowData)menu.Tag;
path = rowData.TargetFilePath;
}
object data = e.Data.GetData("UniformResourceLocator");
MemoryStream ms = data as MemoryStream;
byte[] bytes = ms.ToArray();
Encoding encod = Encoding.ASCII;
string url = encod.GetString(bytes);
CreateShortcut(url.Replace("\0", string.Empty), path);
}
private static void CreateShortcut(string url, string pathToStoreFile)
{
string pathToStoreIcons = Path.Combine(pathToStoreFile, "ico");
var client = new WebClient();
if (!Directory.Exists(pathToStoreIcons))
{
Directory.CreateDirectory(pathToStoreIcons);
}
Uri uri = new Uri(url);
string hostname = uri.Host.ToString();
string pathIconPng = Path.Combine(pathToStoreIcons, $"{hostname}.png");
client.DownloadFile(
@"http://www.google.com/s2/favicons?sz=32&domain=" + url,
pathIconPng);
string pathIcon = Path.Combine(pathToStoreIcons, $"{hostname}.ico");
ImagingHelper.ConvertToIcon(pathIconPng, pathIcon, 32);
File.Delete(pathIconPng);
var title = url;
// e.g. not working for https://web.skype.com/
// var webGet = new HtmlWeb();
// var document = webGet.Load(url);
// var matchingElements = document.DocumentNode.Descendants()
// .Where(x => x.Name.Equals("title", StringComparison.InvariantCultureIgnoreCase));
// if (matchingElements != null && matchingElements.Count() > 0)
// {
// var titleNode = matchingElements.Last();
// if (titleNode != null)
// {
// title = titleNode.InnerText;
// }
// }
// e.g. not working for https://web.skype.com/
////var titleNode = document.DocumentNode.SelectNodes("title").Last(); //.SelectSingleNode("html/head/title");
// e.g. not working for https://web.skype.com/
////WebClient client = new WebClient();
// client.Headers.Add("user-agent", "Mozilla/5.0");
// string source = client.DownloadString(url);
// title = Regex.Match(source, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>",
// RegexOptions.IgnoreCase).Groups["Title"].Value;
title = title.Replace("/", " ").
Replace("https", string.Empty).
Replace("http", string.Empty);
string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
foreach (char c in invalid)
{
title = title.Replace(c.ToString(), string.Empty);
}
title = Truncate(title, 128); // max 255
string Truncate(string value, int maxLength)
{
if (!string.IsNullOrEmpty(value) &&
value.Length > maxLength)
{
value = value.Substring(0, maxLength);
}
return value;
}
using (StreamWriter writer = new StreamWriter(pathToStoreFile + "\\" + title.Trim() + ".url"))
{
writer.WriteLine("[InternetShortcut]");
writer.WriteLine($"URL={url.TrimEnd('\0')}");
writer.WriteLine("IconIndex=0");
writer.WriteLine($"HotKey=0");
writer.WriteLine($"IDList=");
writer.WriteLine($"IconFile={pathIcon}");
writer.Flush();
}
}
}
}

View file

@ -54,7 +54,9 @@ namespace SystemTrayMenu.UserInterface
public void Dispose()
{
Dispose(true);
#if DEBUG
GC.SuppressFinalize(this);
#endif
}
internal void Fade(FadingState state)

113
Helpers/ImagingHelper.cs Normal file
View file

@ -0,0 +1,113 @@
namespace SystemTrayMenu.Helpers
{
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
/// <summary>
/// Provides helper methods for imaging.
/// </summary>
public static class ImagingHelper
{
/// <summary>
/// Converts a PNG image to a icon (ico).
/// </summary>
/// <param name="input">The input stream.</param>
/// <param name="output">The output stream.</param>
/// <param name="size">The size (16x16 px by default).</param>
/// <param name="preserveAspectRatio">Preserve the aspect ratio.</param>
/// <returns>Wether or not the icon was succesfully generated.</returns>
public static bool ConvertToIcon(Stream input, Stream output, int size = 16, bool preserveAspectRatio = false)
{
Bitmap inputBitmap = (Bitmap)Bitmap.FromStream(input);
if (inputBitmap != null)
{
int width, height;
if (preserveAspectRatio)
{
width = size;
height = inputBitmap.Height / inputBitmap.Width * size;
}
else
{
width = height = size;
}
Bitmap newBitmap = new Bitmap(inputBitmap, new Size(width, height));
if (newBitmap != null)
{
// save the resized png into a memory stream for future use
using (MemoryStream memoryStream = new MemoryStream())
{
newBitmap.Save(memoryStream, ImageFormat.Png);
BinaryWriter iconWriter = new BinaryWriter(output);
if (output != null && iconWriter != null)
{
// 0-1 reserved, 0
iconWriter.Write((byte)0);
iconWriter.Write((byte)0);
// 2-3 image type, 1 = icon, 2 = cursor
iconWriter.Write((short)1);
// 4-5 number of images
iconWriter.Write((short)1);
// image entry 1
// 0 image width
iconWriter.Write((byte)width);
// 1 image height
iconWriter.Write((byte)height);
// 2 number of colors
iconWriter.Write((byte)0);
// 3 reserved
iconWriter.Write((byte)0);
// 4-5 color planes
iconWriter.Write((short)0);
// 6-7 bits per pixel
iconWriter.Write((short)32);
// 8-11 size of image data
iconWriter.Write((int)memoryStream.Length);
// 12-15 offset of image data
iconWriter.Write((int)(6 + 16));
// write image data
// png data must contain the whole png data file
iconWriter.Write(memoryStream.ToArray());
iconWriter.Flush();
return true;
}
}
}
return false;
}
return false;
}
/// <summary>
/// Converts a PNG image to a icon (ico).
/// </summary>
/// <param name="inputPath">The input path.</param>
/// <param name="outputPath">The output path.</param>
/// <param name="size">The size (16x16 px by default).</param>
/// <param name="preserveAspectRatio">Preserve the aspect ratio.</param>
/// <returns>Wether or not the icon was succesfully generated.</returns>
public static bool ConvertToIcon(string inputPath, string outputPath, int size = 16, bool preserveAspectRatio = false)
{
using (FileStream inputStream = new FileStream(inputPath, FileMode.Open))
using (FileStream outputStream = new FileStream(outputPath, FileMode.OpenOrCreate))
{
return ConvertToIcon(inputStream, outputStream, size, preserveAspectRatio);
}
}
}
}

View file

@ -60,6 +60,36 @@ namespace SystemTrayMenu.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
public static byte[] ic_fluent_folder_48_regular {
get {
object obj = ResourceManager.GetObject("ic_fluent_folder_48_regular", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
public static byte[] ic_fluent_pin_48_filled {
get {
object obj = ResourceManager.GetObject("ic_fluent_pin_48_filled", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
public static byte[] ic_fluent_pin_48_regular {
get {
object obj = ResourceManager.GetObject("ic_fluent_pin_48_regular", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>

View file

@ -181,4 +181,13 @@
<data name="search" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\search.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ic_fluent_pin_48_filled" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ic_fluent_pin_48_filled.svg;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="ic_fluent_pin_48_regular" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ic_fluent_pin_48_regular.svg;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="ic_fluent_folder_48_regular" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ic_fluent_folder_48_regular.svg;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>

View file

@ -0,0 +1,3 @@
<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill="#585858" d="M17.0607 9C17.8933 9 18.7 9.27703 19.3552 9.78393L19.5301 9.92784L22.1162 12.1907C22.3061 12.3569 22.5409 12.4609 22.7891 12.4909L22.9393 12.5H40.25C42.2543 12.5 43.8913 14.0724 43.9948 16.0508L44 16.25V35.25C44 37.2543 42.4276 38.8913 40.4492 38.9948L40.25 39H7.75C5.74574 39 4.10873 37.4276 4.0052 35.4492L4 35.25V12.75C4 10.7457 5.57236 9.10873 7.55084 9.0052L7.75 9H17.0607ZM22.8474 14.9989L20.7205 17.6147C20.0559 18.4327 19.0803 18.9305 18.035 18.9933L17.8101 19L6.5 18.999V35.25C6.5 35.8972 6.99187 36.4295 7.62219 36.4935L7.75 36.5H40.25C40.8972 36.5 41.4295 36.0081 41.4935 35.3778L41.5 35.25V16.25C41.5 15.6028 41.0081 15.0705 40.3778 15.0065L40.25 15L22.8474 14.9989ZM17.0607 11.5H7.75C7.10279 11.5 6.57047 11.9919 6.50645 12.6222L6.5 12.75V16.499L17.8101 16.5C18.1394 16.5 18.4534 16.3701 18.6858 16.142L18.7802 16.0382L20.415 14.025L17.8838 11.8093C17.6939 11.6431 17.4591 11.5391 17.2109 11.5091L17.0607 11.5Z"/>
</svg>

After

Width:  |  Height:  |  Size: 1 KiB

View file

@ -0,0 +1,3 @@
<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill="#585858" d="M31.8176 5.54984L42.4502 16.1824C44.7427 18.475 44.1155 22.3398 41.2157 23.7897L30.6711 29.062C30.3788 29.2082 30.1553 29.463 30.0486 29.7719L27.3645 37.5418C26.7012 39.4617 24.257 40.0247 22.8207 38.5884L17 32.7678L7.76777 42H6V40.2322L15.2323 31L9.41167 25.1794C7.97536 23.7431 8.53836 21.2988 10.4583 20.6356L18.2281 17.9515C18.537 17.8447 18.7919 17.6213 18.938 17.329L24.2103 6.78435C25.6602 3.88447 29.525 3.25729 31.8176 5.54984Z"/>
</svg>

After

Width:  |  Height:  |  Size: 567 B

View file

@ -0,0 +1,3 @@
<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill="#585858" d="M42.4502 16.1824L31.8176 5.54984C29.525 3.25729 25.6602 3.88447 24.2103 6.78435L18.938 17.329C18.7919 17.6213 18.537 17.8447 18.2281 17.9515L10.4583 20.6356C8.53836 21.2988 7.97536 23.7431 9.41167 25.1794L15.2323 31L6 40.2322V42H7.76777L17 32.7678L22.8207 38.5884C24.257 40.0247 26.7012 39.4617 27.3645 37.5418L30.0486 29.7719C30.1553 29.463 30.3788 29.2082 30.6711 29.062L41.2157 23.7897C44.1155 22.3398 44.7427 18.475 42.4502 16.1824ZM30.0498 7.31761L40.6824 17.9502C41.7683 19.0361 41.4713 20.8668 40.0976 21.5536L29.553 26.826C28.6761 27.2644 28.0058 28.0289 27.6856 28.9556L25.0015 36.7255C24.9412 36.9 24.719 36.9512 24.5884 36.8206L11.1794 23.4116C11.0489 23.2811 11.1 23.0589 11.2746 22.9986L19.0444 20.3144C19.9711 19.9943 20.7356 19.324 21.1741 18.447L26.4464 7.90237C27.1332 6.52875 28.9639 6.23166 30.0498 7.31761Z"/>
</svg>

After

Width:  |  Height:  |  Size: 957 B

View file

@ -281,6 +281,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Svg" Version="3.2.3" />
</ItemGroup>
<ItemGroup>
<Folder Include="Packaging\AppPackages\" />

View file

@ -142,7 +142,9 @@ namespace SystemTrayMenu.UserInterface.FolderBrowseDialog
public void Dispose()
{
Dispose(true);
#if DEBUG
GC.SuppressFinalize(this);
#endif
}
protected virtual void Dispose(bool disposing)

View file

@ -20,18 +20,17 @@
tableLayoutPanelDgvAndScrollbar.Controls.Add(customScrollbar, 1, 0);
//tableLayoutPanelDgvAndScrollbar.SuspendLayout();
//((System.ComponentModel.ISupportInitialize)dgv).BeginInit();
//tableLayoutPanelSearch.SuspendLayout();
//((System.ComponentModel.ISupportInitialize)pictureBoxSearch).BeginInit();
//tableLayoutPanelMenu.SuspendLayout();
//SuspendLayout();
// tableLayoutPanelDgvAndScrollbar.SuspendLayout();
// ((System.ComponentModel.ISupportInitialize)dgv).BeginInit();
// tableLayoutPanelSearch.SuspendLayout();
// ((System.ComponentModel.ISupportInitialize)pictureBoxSearch).BeginInit();
// tableLayoutPanelMenu.SuspendLayout();
// SuspendLayout();
// labelTitle
labelTitle.AutoEllipsis = true;
labelTitle.AutoSize = true;
labelTitle.Dock = DockStyle.Fill;
labelTitle.BackColor = Color.Azure;
labelTitle.Font = new Font("Segoe UI", 8.25F, FontStyle.Bold, GraphicsUnit.Point, (byte)0);
labelTitle.ForeColor = Color.Black;
labelTitle.Location = new Point(0, 0);
@ -41,9 +40,6 @@
labelTitle.Size = new Size(70, 14);
labelTitle.Text = "STM";
labelTitle.TextAlign = ContentAlignment.MiddleCenter;
labelTitle.MouseDoubleClick += new MouseEventHandler(LabelTitle_MouseDoubleClick);
labelTitle.MouseEnter += new EventHandler(LabelTitle_MouseEnter);
labelTitle.MouseLeave += new EventHandler(LabelTitle_MouseLeave);
labelTitle.MouseWheel += new MouseEventHandler(DgvMouseWheel);
// ColumnIcon
@ -90,23 +86,22 @@
textBoxSearch.ContextMenuStrip = new ContextMenuStrip();
tableLayoutPanelTitle.Controls.Add(labelTitle, 1, 0);
//tableLayoutPanelMenu.Controls.Add(labelTitle, 0, 0);
// customScrollbar
customScrollbar.Location = new Point(0, 0);
customScrollbar.Name = "customScrollbar";
customScrollbar.Size = new Size(15, 40);
//tableLayoutPanelDgvAndScrollbar.ResumeLayout(false);
//((System.ComponentModel.ISupportInitialize)dgv).EndInit();
//tableLayoutPanelSearch.ResumeLayout(false);
//tableLayoutPanelSearch.PerformLayout();
//((System.ComponentModel.ISupportInitialize)pictureBoxSearch).EndInit();
//tableLayoutPanelMenu.ResumeLayout(false);
//tableLayoutPanelMenu.PerformLayout();
//customScrollbar.PerformLayout();
//ResumeLayout(false);
//PerformLayout();
// tableLayoutPanelDgvAndScrollbar.ResumeLayout(false);
// ((System.ComponentModel.ISupportInitialize)dgv).EndInit();
// tableLayoutPanelSearch.ResumeLayout(false);
// tableLayoutPanelSearch.PerformLayout();
// ((System.ComponentModel.ISupportInitialize)pictureBoxSearch).EndInit();
// tableLayoutPanelMenu.ResumeLayout(false);
// tableLayoutPanelMenu.PerformLayout();
// customScrollbar.PerformLayout();
// ResumeLayout(false);
// PerformLayout();
}
}
}

View file

@ -38,16 +38,16 @@
this.pictureBoxSearch = new System.Windows.Forms.PictureBox();
this.tableLayoutPanelMenu = new System.Windows.Forms.TableLayoutPanel();
this.tableLayoutPanelTitle = new System.Windows.Forms.TableLayoutPanel();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.pictureBoxOpenFolder = new System.Windows.Forms.PictureBox();
this.pictureBoxMenuAlwaysOpen = new System.Windows.Forms.PictureBox();
this.tableLayoutPanelDgvAndScrollbar.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgv)).BeginInit();
this.tableLayoutPanelSearch.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxSearch)).BeginInit();
this.tableLayoutPanelMenu.SuspendLayout();
this.tableLayoutPanelTitle.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxOpenFolder)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxMenuAlwaysOpen)).BeginInit();
this.SuspendLayout();
// Controls like the scrollbar are removed when open the designer
// When adding after InitializeComponent(), then e.g. scrollbar on high dpi not more working
@ -62,7 +62,7 @@
this.tableLayoutPanelDgvAndScrollbar.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanelDgvAndScrollbar.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanelDgvAndScrollbar.Controls.Add(this.dgv, 0, 0);
this.tableLayoutPanelDgvAndScrollbar.Location = new System.Drawing.Point(0, 14);
this.tableLayoutPanelDgvAndScrollbar.Location = new System.Drawing.Point(0, 16);
this.tableLayoutPanelDgvAndScrollbar.Margin = new System.Windows.Forms.Padding(0);
this.tableLayoutPanelDgvAndScrollbar.Name = "tableLayoutPanelDgvAndScrollbar";
this.tableLayoutPanelDgvAndScrollbar.RowCount = 1;
@ -114,7 +114,7 @@
this.tableLayoutPanelSearch.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanelSearch.Controls.Add(this.textBoxSearch, 1, 0);
this.tableLayoutPanelSearch.Controls.Add(this.pictureBoxSearch, 0, 0);
this.tableLayoutPanelSearch.Location = new System.Drawing.Point(0, 55);
this.tableLayoutPanelSearch.Location = new System.Drawing.Point(0, 57);
this.tableLayoutPanelSearch.Margin = new System.Windows.Forms.Padding(0, 1, 0, 0);
this.tableLayoutPanelSearch.Name = "tableLayoutPanelSearch";
this.tableLayoutPanelSearch.RowCount = 1;
@ -146,6 +146,8 @@
this.pictureBoxSearch.Size = new System.Drawing.Size(16, 16);
this.pictureBoxSearch.TabIndex = 1;
this.pictureBoxSearch.TabStop = false;
this.pictureBoxSearch.Paint += new System.Windows.Forms.PaintEventHandler(this.PictureBoxSearch_Paint);
this.pictureBoxSearch.Resize += new System.EventHandler(this.PictureBox_Resize);
//
// tableLayoutPanelMenu
//
@ -163,7 +165,7 @@
this.tableLayoutPanelMenu.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanelMenu.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanelMenu.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanelMenu.Size = new System.Drawing.Size(83, 77);
this.tableLayoutPanelMenu.Size = new System.Drawing.Size(83, 79);
this.tableLayoutPanelMenu.TabIndex = 4;
this.tableLayoutPanelMenu.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.DgvMouseWheel);
//
@ -176,37 +178,48 @@
this.tableLayoutPanelTitle.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanelTitle.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanelTitle.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanelTitle.Controls.Add(this.pictureBox1, 0, 0);
this.tableLayoutPanelTitle.Controls.Add(this.pictureBox2, 2, 0);
this.tableLayoutPanelTitle.Controls.Add(this.pictureBoxOpenFolder, 0, 0);
this.tableLayoutPanelTitle.Controls.Add(this.pictureBoxMenuAlwaysOpen, 2, 0);
this.tableLayoutPanelTitle.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanelTitle.Margin = new System.Windows.Forms.Padding(0);
this.tableLayoutPanelTitle.Name = "tableLayoutPanelTitle";
this.tableLayoutPanelTitle.RowCount = 1;
this.tableLayoutPanelTitle.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanelTitle.Size = new System.Drawing.Size(83, 14);
this.tableLayoutPanelTitle.Size = new System.Drawing.Size(83, 16);
this.tableLayoutPanelTitle.TabIndex = 5;
//
// pictureBox1
// pictureBoxOpenFolder
//
this.pictureBox1.BackColor = System.Drawing.Color.White;
this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Margin = new System.Windows.Forms.Padding(0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(14, 14);
this.pictureBox1.TabIndex = 1;
this.pictureBox1.TabStop = false;
this.pictureBoxOpenFolder.BackColor = System.Drawing.Color.Transparent;
this.pictureBoxOpenFolder.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.pictureBoxOpenFolder.Location = new System.Drawing.Point(0, 0);
this.pictureBoxOpenFolder.Margin = new System.Windows.Forms.Padding(0);
this.pictureBoxOpenFolder.Name = "pictureBoxOpenFolder";
this.pictureBoxOpenFolder.Size = new System.Drawing.Size(16, 16);
this.pictureBoxOpenFolder.TabIndex = 1;
this.pictureBoxOpenFolder.TabStop = false;
this.pictureBoxOpenFolder.Paint += new System.Windows.Forms.PaintEventHandler(this.PictureBoxMenuOpenFolder_Paint);
this.pictureBoxOpenFolder.MouseClick += new System.Windows.Forms.MouseEventHandler(this.PictureBoxOpenFolder_Click);
this.pictureBoxOpenFolder.MouseEnter += new System.EventHandler(this.PictureBox_MouseEnter);
this.pictureBoxOpenFolder.MouseLeave += new System.EventHandler(this.PictureBox_MouseLeave);
this.pictureBoxOpenFolder.Resize += new System.EventHandler(this.PictureBox_Resize);
//
// pictureBox2
// pictureBoxMenuAlwaysOpen
//
this.pictureBox2.BackColor = System.Drawing.Color.White;
this.pictureBox2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.pictureBox2.Location = new System.Drawing.Point(69, 0);
this.pictureBox2.Margin = new System.Windows.Forms.Padding(0);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(14, 14);
this.pictureBox2.TabIndex = 1;
this.pictureBox2.TabStop = false;
this.pictureBoxMenuAlwaysOpen.BackColor = System.Drawing.Color.Transparent;
this.pictureBoxMenuAlwaysOpen.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.pictureBoxMenuAlwaysOpen.Location = new System.Drawing.Point(67, 0);
this.pictureBoxMenuAlwaysOpen.Margin = new System.Windows.Forms.Padding(0);
this.pictureBoxMenuAlwaysOpen.Name = "pictureBoxMenuAlwaysOpen";
this.pictureBoxMenuAlwaysOpen.Size = new System.Drawing.Size(16, 16);
this.pictureBoxMenuAlwaysOpen.TabIndex = 1;
this.pictureBoxMenuAlwaysOpen.TabStop = false;
this.pictureBoxMenuAlwaysOpen.Click += new System.EventHandler(this.PictureBoxMenuAlwaysOpen_Click);
this.pictureBoxMenuAlwaysOpen.Paint += new System.Windows.Forms.PaintEventHandler(this.PictureBoxMenuAlwaysOpen_Paint);
this.pictureBoxMenuAlwaysOpen.DoubleClick += new System.EventHandler(this.PictureBoxMenuAlwaysOpen_Click);
this.pictureBoxMenuAlwaysOpen.MouseEnter += new System.EventHandler(this.PictureBox_MouseEnter);
this.pictureBoxMenuAlwaysOpen.MouseLeave += new System.EventHandler(this.PictureBox_MouseLeave);
this.pictureBoxMenuAlwaysOpen.Resize += new System.EventHandler(this.PictureBox_Resize);
//
// Menu
//
@ -233,8 +246,8 @@
this.tableLayoutPanelMenu.ResumeLayout(false);
this.tableLayoutPanelMenu.PerformLayout();
this.tableLayoutPanelTitle.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxOpenFolder)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxMenuAlwaysOpen)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@ -252,7 +265,7 @@
private UserInterface.CustomScrollbar customScrollbar;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanelMenu;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanelTitle;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.PictureBox pictureBoxOpenFolder;
private System.Windows.Forms.PictureBox pictureBoxMenuAlwaysOpen;
}
}

View file

@ -8,11 +8,13 @@ namespace SystemTrayMenu.UserInterface
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using Svg;
using SystemTrayMenu.DataClasses;
using SystemTrayMenu.DllImports;
using SystemTrayMenu.Helpers;
using SystemTrayMenu.Utilities;
internal partial class Menu : Form
@ -70,13 +72,6 @@ namespace SystemTrayMenu.UserInterface
fading.Hide += Hide;
InitializeComponent();
pictureBoxSearch.Paint += PictureBoxSearch_Paint;
void PictureBoxSearch_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawIcon(
Search,
new Rectangle(0, 0, pictureBoxSearch.Width, pictureBoxSearch.Height));
}
SetDoubleBuffer(dgv, true);
@ -84,6 +79,7 @@ namespace SystemTrayMenu.UserInterface
Color titleBackColor = AppColors.Title;
Color backColor = AppColors.Background;
Color backColorSearch = AppColors.SearchField;
if (Config.IsDarkMode())
{
foreColor = Color.White;
@ -99,7 +95,7 @@ namespace SystemTrayMenu.UserInterface
backColor = Color.White;
}
labelTitle.BackColor = titleBackColor;
tableLayoutPanelTitle.BackColor = titleBackColor;
tableLayoutPanelDgvAndScrollbar.BackColor = backColor;
dgv.BackgroundColor = backColor;
textBoxSearch.BackColor = backColorSearch;
@ -123,7 +119,7 @@ namespace SystemTrayMenu.UserInterface
void CustomScrollbar_Scroll(object sender, EventArgs e)
{
decimal firstIndex = customScrollbar.Value * dgv.Rows.Count / (decimal)customScrollbar.Maximum;
int firstIndexRounded = (int)Math.Round(firstIndex, 0, MidpointRounding.AwayFromZero);
int firstIndexRounded = (int)Math.Ceiling(firstIndex);
if (firstIndexRounded > -1 && firstIndexRounded < dgv.RowCount)
{
dgv.FirstDisplayedScrollingRowIndex = firstIndexRounded;
@ -145,6 +141,10 @@ namespace SystemTrayMenu.UserInterface
{
MouseLeave?.Invoke();
}
AllowDrop = true;
DragEnter += DragDropHelper.DragEnter;
DragDrop += DragDropHelper.DragDrop;
}
internal new event EventHandlerEmpty MouseWheel;
@ -215,14 +215,14 @@ namespace SystemTrayMenu.UserInterface
internal void SetType(MenuType type)
{
if (type != MenuType.Main)
{
pictureBoxMenuAlwaysOpen.Visible = false;
}
switch (type)
{
case MenuType.Sub:
if (!labelTitle.IsDisposed)
{
labelTitle.Dispose();
}
break;
case MenuType.Empty:
SetTitle(Translator.GetText("Folder empty"));
@ -406,6 +406,12 @@ namespace SystemTrayMenu.UserInterface
// Set position on same height as the selected row from predecessor
y = menuPredecessor.Location.Y + menuPredecessor.dgv.Location.Y + distanceFromItemToDgvTop;
// when FolderEmpty or NoAccess the title should appear in same height as selected row
if (GetDataGridView().RowCount == 0)
{
y += tableLayoutPanelTitle.Height;
}
// Move vertically when out of bounds
if (bounds.Y + bounds.Height < y + Height)
{
@ -561,10 +567,10 @@ namespace SystemTrayMenu.UserInterface
widthScrollbar = customScrollbar.Width;
}
if (labelTitle.Width > (widthIcon + widthText + widthScrollbar))
if (tableLayoutPanelTitle.Width > (widthIcon + widthText + widthScrollbar))
{
dgv.Width = labelTitle.Width - widthScrollbar;
dgv.Columns[1].Width = labelTitle.Width - widthIcon - widthScrollbar;
dgv.Width = tableLayoutPanelTitle.Width - widthScrollbar;
dgv.Columns[1].Width = tableLayoutPanelTitle.Width - widthIcon - widthScrollbar;
}
else
{
@ -587,24 +593,6 @@ namespace SystemTrayMenu.UserInterface
MouseWheel?.Invoke();
}
private void LabelTitle_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
UserClickedOpenFolder?.Invoke();
}
}
private void LabelTitle_MouseEnter(object sender, EventArgs e)
{
labelTitle.BackColor = MenuDefines.ColorTitleSelected;
}
private void LabelTitle_MouseLeave(object sender, EventArgs e)
{
labelTitle.BackColor = MenuDefines.ColorTitleBackground;
}
private void TextBoxSearch_TextChanged(object sender, EventArgs e)
{
customScrollbar.Value = 0;
@ -684,5 +672,78 @@ namespace SystemTrayMenu.UserInterface
SearchTextChanged.Invoke(this, null);
}
private void PictureBox_MouseEnter(object sender, EventArgs e)
{
PictureBox pictureBox = (PictureBox)sender;
pictureBox.BackColor = MenuDefines.ColorSelectedItem;
pictureBox.Tag = true;
}
private void PictureBox_MouseLeave(object sender, EventArgs e)
{
PictureBox pictureBox = (PictureBox)sender;
pictureBox.BackColor = Color.Transparent;
pictureBox.Tag = false;
}
private void PictureBox_Resize(object sender, EventArgs e)
{
PictureBox pictureBox = (PictureBox)sender;
pictureBox.Invalidate();
}
private void PictureBoxSearch_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawIcon(Search, new Rectangle(0, 0, pictureBoxSearch.Width, pictureBoxSearch.Height));
}
private void PictureBoxMenuAlwaysOpen_Paint(object sender, PaintEventArgs e)
{
PictureBox pictureBox = (PictureBox)sender;
if (Config.AlwaysOpenByPin)
{
e.Graphics.DrawImage(Config.BitmapPinActive, new Rectangle(Point.Empty, pictureBox.ClientSize));
}
else
{
e.Graphics.DrawImage(Config.BitmapPin, new Rectangle(Point.Empty, pictureBox.ClientSize));
}
if (pictureBox.Tag != null && (bool)pictureBox.Tag)
{
Rectangle rowBounds = new Rectangle(0, 0, pictureBox.Width, pictureBox.Height);
ControlPaint.DrawBorder(e.Graphics, rowBounds, MenuDefines.ColorSelectedItemBorder, ButtonBorderStyle.Solid);
}
}
private void PictureBoxMenuOpenFolder_Paint(object sender, PaintEventArgs e)
{
PictureBox pictureBox = (PictureBox)sender;
e.Graphics.DrawImage(Config.BitmapOpenFolder, new Rectangle(Point.Empty, pictureBox.ClientSize));
if (pictureBox.Tag != null && (bool)pictureBox.Tag)
{
Rectangle rowBounds = new Rectangle(0, 0, pictureBox.Width, pictureBox.Height);
ControlPaint.DrawBorder(e.Graphics, rowBounds, MenuDefines.ColorSelectedItemBorder, ButtonBorderStyle.Solid);
}
}
private void PictureBoxMenuAlwaysOpen_Click(object sender, EventArgs e)
{
PictureBox pictureBox = (PictureBox)sender;
Config.AlwaysOpenByPin = !Config.AlwaysOpenByPin;
pictureBox.Invalidate();
}
private void PictureBoxOpenFolder_Click(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
UserClickedOpenFolder?.Invoke();
}
}
}
}