Skip to content

Commit c8a8cfe

Browse files
committed
HotKeys continuation 2.
1 parent 672d65b commit c8a8cfe

File tree

8 files changed

+412
-124
lines changed

8 files changed

+412
-124
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 = this.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 (this.FormattedValue is String)
65+
{
66+
TextRenderer.DrawText(graphics, (string)this.FormattedValue, this.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+
}

SmartSystemMenu/Forms/SettingsForm.Designer.cs

Lines changed: 198 additions & 107 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SmartSystemMenu/Forms/SettingsForm.cs

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
22
using System.Windows.Forms;
33
using System.IO;
4+
using System.Linq;
45
using SmartSystemMenu.Settings;
6+
using SmartSystemMenu.Controls;
57

68
namespace SmartSystemMenu.Forms
79
{
@@ -87,6 +89,71 @@ private void InitializeControls(SmartSystemMenuSettings settings)
8789

8890
cmbLanguage.DataSource = languageItems;
8991
cmbLanguage.SelectedValue = settings.LanguageName;
92+
93+
FillGridViewRowHotkey(gvHotkeys, settings, "information");
94+
FillGridViewRowHotkey(gvHotkeys, settings, "roll_up");
95+
FillGridViewRowHotkey(gvHotkeys, settings, "aero_glass");
96+
FillGridViewRowHotkey(gvHotkeys, settings, "always_on_top");
97+
FillGridViewRowHotkey(gvHotkeys, settings, "send_to_bottom");
98+
FillGridViewRowHotkey(gvHotkeys, settings, "save_screenshot");
99+
FillGridViewRowHotkey(gvHotkeys, settings, "open_file_in_explorer");
100+
FillGridViewRowHotkey(gvHotkeys, settings, "copy_text_to_clipboard");
101+
FillGridViewRowHotkey(gvHotkeys, settings, "drag_by_mouse");
102+
FillGridViewGroupHotkey(gvHotkeys, settings, "size");
103+
FillGridViewRowHotkey(gvHotkeys, settings, "640_480", "640x480", true);
104+
FillGridViewRowHotkey(gvHotkeys, settings, "720_480", "720x480", true);
105+
FillGridViewRowHotkey(gvHotkeys, settings, "720_576", "720x576", true);
106+
FillGridViewRowHotkey(gvHotkeys, settings, "800_600", "800x600", true);
107+
FillGridViewRowHotkey(gvHotkeys, settings, "1024_768", "1024x768", true);
108+
FillGridViewRowHotkey(gvHotkeys, settings, "1152_864", "1024x768", true);
109+
FillGridViewRowHotkey(gvHotkeys, settings, "1280_800", "1280x800", true);
110+
FillGridViewRowHotkey(gvHotkeys, settings, "1280_960", "1280x960", true);
111+
FillGridViewRowHotkey(gvHotkeys, settings, "1280_1024", "1280x1024", true);
112+
FillGridViewRowHotkey(gvHotkeys, settings, "1440_900", "1440x900", true);
113+
FillGridViewRowHotkey(gvHotkeys, settings, "1600_900", "1600x900", true);
114+
FillGridViewRowHotkey(gvHotkeys, settings, "1680_1050", "1680x1050", true);
115+
FillGridViewRowHotkey(gvHotkeys, settings, "size_default", null, true);
116+
FillGridViewRowHotkey(gvHotkeys, settings, "size_custom", null, true);
117+
FillGridViewGroupHotkey(gvHotkeys, settings, "move_to");
118+
FillGridViewGroupHotkey(gvHotkeys, settings, "alignment");
119+
FillGridViewRowHotkey(gvHotkeys, settings, "align_top_left", null, true);
120+
FillGridViewRowHotkey(gvHotkeys, settings, "align_top_center", null, true);
121+
FillGridViewRowHotkey(gvHotkeys, settings, "align_top_right", null, true);
122+
FillGridViewRowHotkey(gvHotkeys, settings, "align_middle_left", null, true);
123+
FillGridViewRowHotkey(gvHotkeys, settings, "align_middle_center", null, true);
124+
FillGridViewRowHotkey(gvHotkeys, settings, "align_middle_right", null, true);
125+
FillGridViewRowHotkey(gvHotkeys, settings, "align_bottom_left", null, true);
126+
FillGridViewRowHotkey(gvHotkeys, settings, "align_bottom_center", null, true);
127+
FillGridViewRowHotkey(gvHotkeys, settings, "align_bottom_right", null, true);
128+
FillGridViewRowHotkey(gvHotkeys, settings, "align_default", null, true);
129+
FillGridViewRowHotkey(gvHotkeys, settings, "align_custom", null, true);
130+
FillGridViewGroupHotkey(gvHotkeys, settings, "transparency");
131+
FillGridViewRowHotkey(gvHotkeys, settings, "trans_opaque", "0%" + settings.LanguageSettings.GetValue("trans_opaque"), true);
132+
FillGridViewRowHotkey(gvHotkeys, settings, "10%", "10%", true);
133+
FillGridViewRowHotkey(gvHotkeys, settings, "20%", "20%", true);
134+
FillGridViewRowHotkey(gvHotkeys, settings, "30%", "30%", true);
135+
FillGridViewRowHotkey(gvHotkeys, settings, "40%", "40%", true);
136+
FillGridViewRowHotkey(gvHotkeys, settings, "50%", "50%", true);
137+
FillGridViewRowHotkey(gvHotkeys, settings, "60%", "60%", true);
138+
FillGridViewRowHotkey(gvHotkeys, settings, "70%", "70%", true);
139+
FillGridViewRowHotkey(gvHotkeys, settings, "80%", "80%", true);
140+
FillGridViewRowHotkey(gvHotkeys, settings, "90%", "90%", true);
141+
FillGridViewRowHotkey(gvHotkeys, settings, "trans_invisible", "100%" + settings.LanguageSettings.GetValue("trans_invisible"), true);
142+
FillGridViewRowHotkey(gvHotkeys, settings, "trans_default", null, true);
143+
FillGridViewRowHotkey(gvHotkeys, settings, "trans_custom", null, true);
144+
FillGridViewGroupHotkey(gvHotkeys, settings, "priority");
145+
FillGridViewRowHotkey(gvHotkeys, settings, "priority_real_time", null, true);
146+
FillGridViewRowHotkey(gvHotkeys, settings, "priority_high", null, true);
147+
FillGridViewRowHotkey(gvHotkeys, settings, "priority_above_normal", null, true);
148+
FillGridViewRowHotkey(gvHotkeys, settings, "priority_normal", null, true);
149+
FillGridViewRowHotkey(gvHotkeys, settings, "priority_below_normal", null, true);
150+
FillGridViewRowHotkey(gvHotkeys, settings, "priority_idle", null, true);
151+
FillGridViewGroupHotkey(gvHotkeys, settings, "system_tray");
152+
FillGridViewRowHotkey(gvHotkeys, settings, "minimize_to_systemtray", null, true);
153+
FillGridViewRowHotkey(gvHotkeys, settings, "minimize_always_to_systemtray", null, true);
154+
FillGridViewGroupHotkey(gvHotkeys, settings, "other_windows");
155+
FillGridViewRowHotkey(gvHotkeys, settings, "minimize_other_windows", null, true);
156+
FillGridViewRowHotkey(gvHotkeys, settings, "close_other_windows", null, true);
90157
}
91158

92159
private void GridViewProcessExclusionsCellContentClick(object sender, DataGridViewCellEventArgs e)
@@ -154,6 +221,32 @@ private void GridViewProcessExclusionsCellDoubleClick(object sender, DataGridVie
154221
}
155222
}
156223

224+
private void GridViewHotkeysCellContentClick(object sender, DataGridViewCellEventArgs e)
225+
{
226+
var grid = (DataGridView)sender;
227+
if (grid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0)
228+
{
229+
var row = grid.Rows[e.RowIndex];
230+
if (row.Tag != null)
231+
{
232+
MessageBox.Show("Hotkeys1");
233+
}
234+
}
235+
}
236+
237+
private void GridViewHotkeysCellDoubleClick(object sender, DataGridViewCellEventArgs e)
238+
{
239+
var grid = (DataGridView)sender;
240+
if ((e.ColumnIndex == 0 || e.ColumnIndex == 1) && e.RowIndex >= 0)
241+
{
242+
var row = grid.Rows[e.RowIndex];
243+
if (row.Tag != null)
244+
{
245+
MessageBox.Show("Hotkeys2");
246+
}
247+
}
248+
}
249+
157250
private void GridViewStartProgramCellDoubleClick(object sender, DataGridViewCellEventArgs e)
158251
{
159252
var grid = (DataGridView)sender;
@@ -286,6 +379,31 @@ private void KeyDownClick(object sender, KeyEventArgs e)
286379
Close();
287380
}
288381
}
382+
383+
private void FillGridViewRowHotkey(DataGridView gridView, SmartSystemMenuSettings settings, string itemName, string title = null, bool isPadding = false)
384+
{
385+
var index = gridView.Rows.Add();
386+
var row = gridView.Rows[index];
387+
var menuItem = settings.MenuItems.Items.FirstOrDefault(x => x.Name == itemName);
388+
title = title != null ? title : settings.LanguageSettings.GetValue(itemName);
389+
row.Tag = menuItem;
390+
row.Cells[0].Value = title;
391+
row.Cells[1].Value = menuItem == null ? "" : menuItem.ToString();
392+
if (isPadding)
393+
{
394+
var padding = row.Cells[0].Style.Padding;
395+
row.Cells[0].Style.Padding = new Padding(20, padding.Top, padding.Right, padding.Bottom);
396+
}
397+
}
398+
399+
private void FillGridViewGroupHotkey(DataGridView gridView, SmartSystemMenuSettings settings, string itemName)
400+
{
401+
var index = gridView.Rows.Add();
402+
var row = gridView.Rows[index];
403+
row.Cells[0].Value = settings.LanguageSettings.GetValue(itemName);
404+
row.ReadOnly = true;
405+
((DataGridViewDisableButtonCell)row.Cells[2]).Enabled = false;
406+
}
289407
}
290408

291409
public class SmartSystemMenuSettingsEventArgs : EventArgs

SmartSystemMenu/Forms/SettingsForm.resx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,13 @@
141141
<metadata name="clmStartProgramDelete.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
142142
<value>True</value>
143143
</metadata>
144-
<metadata name="clmStartProgramTitle.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
144+
<metadata name="clmnMenuItemName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
145145
<value>True</value>
146146
</metadata>
147-
<metadata name="clmStartProgramPath.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
148-
<value>True</value>
149-
</metadata>
150-
<metadata name="clmStartProgramArguments.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
147+
<metadata name="clmnHotkeys.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
151148
<value>True</value>
152149
</metadata>
153-
<metadata name="clmStartProgramEdit.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
154-
<value>True</value>
155-
</metadata>
156-
<metadata name="clmStartProgramDelete.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
150+
<metadata name="clmnChangeHotkey.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
157151
<value>True</value>
158152
</metadata>
159153
<metadata name="toolTipAddProcessName.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">

SmartSystemMenu/SmartSystemMenu.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
<Reference Include="UIAutomationTypes" />
7777
</ItemGroup>
7878
<ItemGroup>
79+
<Compile Include="Controls\DataGridViewDisableButtonCell.cs" />
80+
<Compile Include="Controls\DataGridViewDisableButtonColumn.cs" />
7981
<Compile Include="Extensions\EnumExtensions.cs" />
8082
<Compile Include="Forms\StartProgramForm.cs">
8183
<SubType>Form</SubType>
5.5 KB
Binary file not shown.

SmartSystemMenu/SystemMenu.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,9 @@ public void UncheckTransparencyMenu()
306306

307307
#region Methods.Private
308308

309-
private string GetTitle(string name)
310-
{
311-
var title = _languageSettings.GetValue(name);
312-
var hotKey = _menuItems.GetHotKeysCombination(name);
313-
return string.IsNullOrEmpty(hotKey) ? title : title + "\t" + hotKey;
314-
}
315-
316-
private string GetTitle(string name, string title)
309+
private string GetTitle(string name, string title = null)
317310
{
311+
title = title != null ? title : _languageSettings.GetValue(name);
318312
var hotKey = _menuItems.GetHotKeysCombination(name);
319313
return string.IsNullOrEmpty(hotKey) ? title : title + "\t" + hotKey;
320314
}

0 commit comments

Comments
 (0)