ShareX/ShareX/QuickTaskMenu.cs

142 lines
5.1 KiB
C#
Raw Normal View History

2016-02-07 03:52:15 +13:00
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
2023-01-10 09:31:02 +13:00
Copyright (c) 2007-2023 ShareX Team
2016-02-07 03:52:15 +13:00
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
using ShareX.HelpersLib;
using ShareX.Properties;
2016-02-07 03:52:15 +13:00
using System.Drawing;
using System.Windows.Forms;
namespace ShareX
{
public class QuickTaskMenu
{
public delegate void TaskInfoSelectedEventHandler(QuickTaskInfo taskInfo);
public TaskInfoSelectedEventHandler TaskInfoSelected;
public void ShowMenu()
{
ContextMenuStrip cms = new ContextMenuStrip()
2016-02-07 03:52:15 +13:00
{
Font = new Font("Arial", 10f),
AutoClose = false
2016-02-07 03:52:15 +13:00
};
cms.KeyUp += (sender, e) =>
{
if (e.KeyCode == Keys.Escape)
{
cms.Close();
}
};
ToolStripMenuItem tsmiContinue = new ToolStripMenuItem(Resources.QuickTaskMenu_ShowMenu_Continue);
tsmiContinue.Image = Resources.control;
tsmiContinue.Click += (sender, e) =>
{
cms.Close();
OnTaskInfoSelected(null);
};
cms.Items.Add(tsmiContinue);
cms.Items.Add(new ToolStripSeparator());
2016-02-07 05:41:05 +13:00
if (Program.Settings != null && Program.Settings.QuickTaskPresets != null && Program.Settings.QuickTaskPresets.Count > 0)
2016-02-07 03:52:15 +13:00
{
2016-02-07 05:41:05 +13:00
foreach (QuickTaskInfo taskInfo in Program.Settings.QuickTaskPresets)
2016-02-07 03:52:15 +13:00
{
2016-02-07 07:10:01 +13:00
if (taskInfo.IsValid)
2016-02-07 05:41:05 +13:00
{
2016-02-07 07:10:01 +13:00
ToolStripMenuItem tsmi = new ToolStripMenuItem { Text = taskInfo.ToString().Replace("&", "&&"), Tag = taskInfo };
tsmi.Image = FindSuitableIcon(taskInfo);
2016-02-07 07:10:01 +13:00
tsmi.Click += (sender, e) =>
{
QuickTaskInfo selectedTaskInfo = ((ToolStripMenuItem)sender).Tag as QuickTaskInfo;
cms.Close();
2016-02-07 07:10:01 +13:00
OnTaskInfoSelected(selectedTaskInfo);
};
cms.Items.Add(tsmi);
}
else
{
cms.Items.Add(new ToolStripSeparator());
}
2016-02-07 05:41:05 +13:00
}
cms.Items[0].Select();
cms.Items.Add(new ToolStripSeparator());
2016-02-07 03:52:15 +13:00
}
ToolStripMenuItem tsmiEdit = new ToolStripMenuItem(Resources.QuickTaskMenu_ShowMenu_Edit_this_menu___);
tsmiEdit.Image = Resources.pencil;
2016-02-07 07:10:01 +13:00
tsmiEdit.Click += (sender, e) =>
{
cms.Close();
2016-02-07 07:10:01 +13:00
new QuickTaskMenuEditorForm().ShowDialog();
};
2016-02-07 03:52:15 +13:00
cms.Items.Add(tsmiEdit);
cms.Items.Add(new ToolStripSeparator());
ToolStripMenuItem tsmiCancel = new ToolStripMenuItem(Resources.QuickTaskMenu_ShowMenu_Cancel);
tsmiCancel.Image = Resources.cross;
tsmiCancel.Click += (sender, e) => cms.Close();
2016-02-07 03:52:15 +13:00
cms.Items.Add(tsmiCancel);
if (ShareXResources.UseCustomTheme)
{
ShareXResources.ApplyCustomThemeToContextMenuStrip(cms);
}
2016-02-07 05:41:05 +13:00
Point cursorPosition = CaptureHelpers.GetCursorPosition();
cursorPosition.Offset(-10, -10);
cms.Show(cursorPosition);
cms.Focus();
2016-02-07 03:52:15 +13:00
}
protected void OnTaskInfoSelected(QuickTaskInfo taskInfo)
{
2021-06-10 10:14:01 +12:00
TaskInfoSelected?.Invoke(taskInfo);
}
public Image FindSuitableIcon(QuickTaskInfo taskInfo)
{
if (taskInfo.AfterCaptureTasks.HasFlag(AfterCaptureTasks.UploadImageToHost))
{
return Resources.upload_cloud;
}
else if (taskInfo.AfterCaptureTasks.HasFlag(AfterCaptureTasks.CopyImageToClipboard) || taskInfo.AfterCaptureTasks.HasFlag(AfterCaptureTasks.CopyFileToClipboard))
{
return Resources.clipboard;
}
else if (taskInfo.AfterCaptureTasks.HasFlag(AfterCaptureTasks.SaveImageToFile) || taskInfo.AfterCaptureTasks.HasFlag(AfterCaptureTasks.SaveImageToFileWithDialog))
2016-02-07 03:52:15 +13:00
{
return Resources.disk_black;
2016-02-07 03:52:15 +13:00
}
return Resources.image;
2016-02-07 03:52:15 +13:00
}
}
}