Skip to content

Commit 08ea253

Browse files
committed
Merge branch 'HotKeys'
2 parents 601b5a1 + fd1306e commit 08ea253

31 files changed

+1978
-438
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System;
2+
using System.Windows.Forms;
3+
using System.Windows.Forms.VisualStyles;
4+
using System.Drawing;
5+
6+
namespace SmartSystemMenu.Controls
7+
{
8+
public class DataGridViewDisableButtonCell : DataGridViewButtonCell
9+
{
10+
public bool Enabled { get; set; }
11+
12+
// Override the Clone method so that the Enabled property is copied.
13+
public override object Clone()
14+
{
15+
DataGridViewDisableButtonCell cell = (DataGridViewDisableButtonCell)base.Clone();
16+
cell.Enabled = this.Enabled;
17+
return cell;
18+
}
19+
20+
// By default, enable the button cell.
21+
public DataGridViewDisableButtonCell()
22+
{
23+
Enabled = true;
24+
}
25+
26+
protected override void Paint(Graphics graphics,
27+
Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
28+
DataGridViewElementStates elementState, object value,
29+
object formattedValue, string errorText,
30+
DataGridViewCellStyle cellStyle,
31+
DataGridViewAdvancedBorderStyle advancedBorderStyle,
32+
DataGridViewPaintParts paintParts)
33+
{
34+
// The button cell is disabled, so paint the border,
35+
// background, and disabled button for the cell.
36+
if (!Enabled)
37+
{
38+
// Draw the cell background, if specified.
39+
if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background)
40+
{
41+
SolidBrush cellBackground = new SolidBrush(cellStyle.BackColor);
42+
graphics.FillRectangle(cellBackground, cellBounds);
43+
cellBackground.Dispose();
44+
}
45+
46+
// Draw the cell borders, if specified.
47+
if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border)
48+
{
49+
PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
50+
}
51+
52+
// Calculate the area in which to draw the button.
53+
Rectangle buttonArea = cellBounds;
54+
Rectangle buttonAdjustment = BorderWidths(advancedBorderStyle);
55+
buttonArea.X += buttonAdjustment.X;
56+
buttonArea.Y += buttonAdjustment.Y;
57+
buttonArea.Height -= buttonAdjustment.Height;
58+
buttonArea.Width -= buttonAdjustment.Width;
59+
60+
// Draw the disabled button.
61+
ButtonRenderer.DrawButton(graphics, buttonArea, PushButtonState.Disabled);
62+
63+
// Draw the disabled button text.
64+
if (FormattedValue is string)
65+
{
66+
TextRenderer.DrawText(graphics, (string)FormattedValue, DataGridView.Font, buttonArea, SystemColors.GrayText);
67+
}
68+
}
69+
else
70+
{
71+
// The button cell is enabled, so let the base class
72+
// handle the painting.
73+
base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
74+
}
75+
}
76+
}
77+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Windows.Forms;
2+
3+
namespace SmartSystemMenu.Controls
4+
{
5+
public class DataGridViewDisableButtonColumn : DataGridViewButtonColumn
6+
{
7+
public DataGridViewDisableButtonColumn()
8+
{
9+
this.CellTemplate = new DataGridViewDisableButtonCell();
10+
}
11+
}
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Linq;
3+
using System.ComponentModel;
4+
5+
namespace SmartSystemMenu.Extensions
6+
{
7+
static class EnumExtensions
8+
{
9+
public static string GetDescription(this Enum value)
10+
{
11+
var attribute = value.GetType().GetField(value.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault() as DescriptionAttribute;
12+
var description = attribute == null ? null : attribute.Description;
13+
return description;
14+
}
15+
}
16+
}

SmartSystemMenu/Extensions/PriorityExtensions.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ public static int GetMenuItemId(this Priority priority)
88
{
99
switch (priority)
1010
{
11-
case Priority.RealTime: return (int)SystemMenu.SC_PRIORITY_REAL_TIME;
12-
case Priority.High: return (int)SystemMenu.SC_PRIORITY_HIGH;
13-
case Priority.AboveNormal: return (int)SystemMenu.SC_PRIORITY_ABOVE_NORMAL;
14-
case Priority.Normal: return (int)SystemMenu.SC_PRIORITY_NORMAL;
15-
case Priority.BelowNormal: return (int)SystemMenu.SC_PRIORITY_BELOW_NORMAL;
16-
case Priority.Idle: return (int)SystemMenu.SC_PRIORITY_IDLE;
17-
default: return (int)SystemMenu.SC_PRIORITY_NORMAL;
11+
case Priority.RealTime: return (int)MenuItemId.SC_PRIORITY_REAL_TIME;
12+
case Priority.High: return (int)MenuItemId.SC_PRIORITY_HIGH;
13+
case Priority.AboveNormal: return (int)MenuItemId.SC_PRIORITY_ABOVE_NORMAL;
14+
case Priority.Normal: return (int)MenuItemId.SC_PRIORITY_NORMAL;
15+
case Priority.BelowNormal: return (int)MenuItemId.SC_PRIORITY_BELOW_NORMAL;
16+
case Priority.Idle: return (int)MenuItemId.SC_PRIORITY_IDLE;
17+
default: return (int)MenuItemId.SC_PRIORITY_NORMAL;
1818
}
1919
}
2020

SmartSystemMenu/Forms/HotkeysForm.Designer.cs

Lines changed: 154 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System;
2+
using System.Data;
3+
using System.Linq;
4+
using System.Windows.Forms;
5+
using SmartSystemMenu.HotKeys;
6+
using SmartSystemMenu.Extensions;
7+
using SmartSystemMenu.Settings;
8+
9+
namespace SmartSystemMenu.Forms
10+
{
11+
public partial class HotkeysForm : Form
12+
{
13+
public Settings.MenuItem MenuItem { get; set; }
14+
15+
public HotkeysForm(SmartSystemMenuSettings settings, Settings.MenuItem menuItem)
16+
{
17+
InitializeComponent();
18+
MenuItem = menuItem;
19+
InitializeControls(settings, menuItem);
20+
}
21+
22+
private void InitializeControls(SmartSystemMenuSettings settings, Settings.MenuItem menuItem)
23+
{
24+
Text = settings.LanguageSettings.GetValue("hotkeys_form");
25+
btnApply.Text = settings.LanguageSettings.GetValue("hotkeys_btn_apply");
26+
btnCancel.Text = settings.LanguageSettings.GetValue("hotkeys_btn_cancel");
27+
lblKey1.Text = settings.LanguageSettings.GetValue("hotkeys_lbl_key1");
28+
lblKey2.Text = settings.LanguageSettings.GetValue("hotkeys_lbl_key2");
29+
lblKey3.Text = settings.LanguageSettings.GetValue("hotkeys_lbl_key3");
30+
31+
cmbKey1.ValueMember = "Id";
32+
cmbKey1.DisplayMember = "Text";
33+
cmbKey1.DataSource = ((VirtualKeyModifier[])Enum.GetValues(typeof(VirtualKeyModifier))).Where(x => !string.IsNullOrEmpty(x.GetDescription())).Select(x => new { Id = x, Text = x.GetDescription() }).ToList();
34+
cmbKey1.SelectedValue = menuItem.Key1;
35+
36+
cmbKey2.ValueMember = "Id";
37+
cmbKey2.DisplayMember = "Text";
38+
cmbKey2.DataSource = ((VirtualKeyModifier[])Enum.GetValues(typeof(VirtualKeyModifier))).Where(x => !string.IsNullOrEmpty(x.GetDescription())).Select(x => new { Id = x, Text = x.GetDescription() }).ToList();
39+
cmbKey2.SelectedValue = menuItem.Key2;
40+
41+
cmbKey3.ValueMember = "Id";
42+
cmbKey3.DisplayMember = "Text";
43+
cmbKey3.DataSource = ((VirtualKey[])Enum.GetValues(typeof(VirtualKey))).Where(x => !string.IsNullOrEmpty(x.GetDescription())).Select(x => new { Id = x, Text = x.GetDescription() }).ToList();
44+
cmbKey3.SelectedValue = menuItem.Key3;
45+
}
46+
47+
private void ButtonApplyClick(object sender, EventArgs e)
48+
{
49+
var menuItem = new Settings.MenuItem();
50+
menuItem.Key1 = (VirtualKeyModifier)cmbKey1.SelectedValue;
51+
menuItem.Key2 = (VirtualKeyModifier)cmbKey2.SelectedValue;
52+
menuItem.Key3 = (VirtualKey)cmbKey3.SelectedValue;
53+
menuItem.Name = MenuItem.Name;
54+
MenuItem = menuItem;
55+
DialogResult = DialogResult.OK;
56+
Close();
57+
}
58+
59+
private void ButtonCancelClick(object sender, EventArgs e)
60+
{
61+
Close();
62+
}
63+
64+
private void KeyDownClick(object sender, KeyEventArgs e)
65+
{
66+
if (e.KeyValue == 13)
67+
{
68+
ButtonApplyClick(sender, e);
69+
}
70+
71+
if (e.KeyValue == 27)
72+
{
73+
Close();
74+
}
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)