Skip to content

Commit 83f7a91

Browse files
committed
add ft4 context menus; fix save dialog
1 parent 9941ce7 commit 83f7a91

15 files changed

+279
-160
lines changed

SkyRoof/Context.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ public class Context
3737
public QsoEntryPanel? QsoEntryPanel;
3838
public Ft4ConsolePanel? Ft4ConsolePanel;
3939

40-
// dialogs
41-
internal LoqFt4QsoDialog LoqFt4QsoDialog = new();
42-
4340
// devices
4441
public SoapySdrDevice? Sdr;
4542
public Slicer? Slicer;

SkyRoof/ControlsEx/PropertyGridEx.cs

Lines changed: 107 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -11,109 +11,107 @@
1111

1212
namespace VE3NEA
1313
{
14-
internal class PropertyGridEx : PropertyGrid
14+
internal class PropertyGridEx : PropertyGrid
15+
{
16+
protected override void OnHandleCreated(EventArgs e)
1517
{
16-
protected override void OnHandleCreated(EventArgs e)
17-
{
18-
base.OnHandleCreated(e);
19-
GetPropertyGridView().MouseClick += grid_MouseClick;
20-
}
21-
private void grid_MouseClick(object sender, MouseEventArgs e)
22-
{
23-
var entry = GetEntryAtPoint(e.X, e.Y);
24-
if (entry == null || !(entry.Value is VisibleSettings)) return;
18+
base.OnHandleCreated(e);
19+
GetPropertyGridView().MouseClick += grid_MouseClick;
20+
}
21+
private void grid_MouseClick(object sender, MouseEventArgs e)
22+
{
23+
var entry = GetEntryAtPoint(e.X, e.Y);
24+
if (entry == null || !(entry.Value is VisibleSettings)) return;
2525

26-
var settings = (VisibleSettings)entry.Value;
27-
bool oldValue = settings.Visible;
28-
settings.Visible = !settings.Visible;
26+
var settings = (VisibleSettings)entry.Value;
27+
bool oldValue = settings.Visible;
28+
settings.Visible = !settings.Visible;
2929

30-
Refresh();
30+
Refresh();
3131

32-
var args = new PropertyValueChangedEventArgs(entry, entry);
33-
OnPropertyValueChanged(args);
34-
}
32+
var args = new PropertyValueChangedEventArgs(entry, entry);
33+
OnPropertyValueChanged(args);
34+
}
3535

3636

37-
// access item's property by name
38-
internal static string GetItemProperty(GridItem item, string propertyName)
39-
{
40-
var flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty;
41-
return (string)item.GetType().GetProperty(propertyName, flags).GetValue(item);
42-
}
37+
// access item's property by name
38+
internal static string GetItemProperty(GridItem item, string propertyName)
39+
{
40+
var flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty;
41+
return (string)item.GetType().GetProperty(propertyName, flags).GetValue(item);
42+
}
4343

4444
// https://stackoverflow.com/questions/4086105/
45-
public void ExpandTopLevelProperties(bool twoLevels = false)
45+
public void ExpandTopLevelProperties(GridItem? root = null, bool twoLevels = false)
4646
{
47-
//Invoke((System.Windows.Forms.MethodInvoker)delegate
48-
{
49-
GridItem root = GetRoot();
50-
51-
if (root != null)
52-
foreach (GridItem item in root.GridItems)
53-
if (item.GridItemType == GridItemType.Property)
54-
{
55-
item.Expanded = true;
56-
if (twoLevels && item.Expandable)
57-
foreach (GridItem subitem in item.GridItems)
58-
subitem.Expanded = true;
59-
}
60-
}
61-
//);
47+
root ??= GetRoot();
48+
root.Expanded = true;
49+
50+
if (root != null)
51+
foreach (GridItem item in root.GridItems)
52+
if (item.GridItemType == GridItemType.Property)
53+
{
54+
item.Expanded = true;
55+
if (twoLevels && item.Expandable)
56+
foreach (GridItem subitem in item.GridItems)
57+
subitem.Expanded = true;
58+
}
6259
}
6360

64-
private Control GetPropertyGridView()
65-
{
66-
foreach (Control control in Controls)
67-
if (control.GetType().Name == "PropertyGridView")
68-
return control;
61+
private Control GetPropertyGridView()
62+
{
63+
foreach (Control control in Controls)
64+
if (control.GetType().Name == "PropertyGridView")
65+
return control;
6966

70-
return null;
71-
}
67+
return null;
68+
}
7269

73-
private GridItem GetRoot()
74-
{
75-
GridItem root = SelectedGridItem;
76-
while (root?.Parent != null) root = root.Parent;
77-
return root;
78-
}
70+
private GridItem GetRoot()
71+
{
72+
GridItem root = SelectedGridItem;
73+
while (root?.Parent != null) root = root.Parent;
74+
return root;
75+
}
7976

80-
private GridItem GetChildByName(GridItem parent, string fullName)
77+
private GridItem GetChildByName(GridItem parent, string fullName)
78+
{
79+
if (parent == null) return null;
80+
81+
foreach (GridItem item in parent.GridItems)
82+
if (item.GridItemType != GridItemType.Property)
83+
continue;
84+
else if (GetItemProperty(item, "HelpKeyword") == fullName)
85+
return item;
86+
else
8187
{
82-
if (parent == null) return null;
83-
84-
foreach (GridItem item in parent.GridItems)
85-
if (item.GridItemType != GridItemType.Property) continue;
86-
else if (GetItemProperty(item, "HelpKeyword") == fullName)
87-
return item;
88-
else
89-
{
90-
var result = GetChildByName(item, fullName);
91-
if (result != null) return result;
92-
}
93-
94-
return null;
88+
var result = GetChildByName(item, fullName);
89+
if (result != null) return result;
9590
}
9691

97-
internal GridItem GetItemByFullName(string fullName)
98-
{
99-
return GetChildByName(GetRoot(), fullName);
100-
}
92+
return null;
93+
}
10194

102-
private GridItem GetEntryAtPoint(int x, int y)
103-
{
104-
var grid = GetPropertyGridView();
105-
var flags = BindingFlags.Instance | BindingFlags.NonPublic;
106-
var FindPosition = grid.GetType().GetMethod("FindPosition", flags);
107-
if (FindPosition == null) return null;
95+
internal GridItem GetItemByFullName(string fullName)
96+
{
97+
return GetChildByName(GetRoot(), fullName);
98+
}
10899

109-
var point = (Point)FindPosition.Invoke(grid, new object[] { x, y });
100+
private GridItem GetEntryAtPoint(int x, int y)
101+
{
102+
var grid = GetPropertyGridView();
103+
var flags = BindingFlags.Instance | BindingFlags.NonPublic;
104+
var FindPosition = grid.GetType().GetMethod("FindPosition", flags);
105+
if (FindPosition == null) return null;
110106

111-
Point invalidPoint = new Point(int.MinValue, int.MinValue);
112-
if (point == invalidPoint || point.X != 2) return null;
107+
var point = (Point)FindPosition.Invoke(grid, new object[] { x, y });
113108

114-
var GetGridEntryFromRow = grid.GetType().GetMethod("GetGridEntryFromRow", flags);
115-
return (GridItem)GetGridEntryFromRow.Invoke(grid, new object[] { point.Y });
116-
}
109+
Point invalidPoint = new Point(int.MinValue, int.MinValue);
110+
if (point == invalidPoint || point.X != 2) return null;
111+
112+
var GetGridEntryFromRow = grid.GetType().GetMethod("GetGridEntryFromRow", flags);
113+
return (GridItem)GetGridEntryFromRow.Invoke(grid, new object[] { point.Y });
114+
}
117115

118116
internal void ExpandAndSelect(GridItem gridItem)
119117
{
@@ -130,39 +128,39 @@ internal void ExpandAndSelect(GridItem gridItem)
130128

131129

132130

133-
//--------------------------------------------------------------------------------------------------------------
134-
// VisibleSettings
135-
//--------------------------------------------------------------------------------------------------------------
136-
// expandable settings with a Visible property controlled by a checkbox
137-
internal class VisibleSettings
138-
{
139-
[Browsable(false)]
140-
public bool Visible { get; set; }
131+
//--------------------------------------------------------------------------------------------------------------
132+
// VisibleSettings
133+
//--------------------------------------------------------------------------------------------------------------
134+
// expandable settings with a Visible property controlled by a checkbox
135+
internal class VisibleSettings
136+
{
137+
[Browsable(false)]
138+
public bool Visible { get; set; }
141139

142-
internal VisibleSettings(bool value) { Visible = value; }
140+
internal VisibleSettings(bool value) { Visible = value; }
143141

144-
public override string ToString() { return "Visible"; }
145-
}
142+
public override string ToString() { return "Visible"; }
143+
}
146144

147145

148146

149147

150-
//--------------------------------------------------------------------------------------------------------------
151-
// checkbox in the property grid
152-
//--------------------------------------------------------------------------------------------------------------
153-
// https://stackoverflow.com/questions/37659850
154-
public class CheckboxEditor : UITypeEditor
155-
{
156-
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
157-
{ return true; }
148+
//--------------------------------------------------------------------------------------------------------------
149+
// checkbox in the property grid
150+
//--------------------------------------------------------------------------------------------------------------
151+
// https://stackoverflow.com/questions/37659850
152+
public class CheckboxEditor : UITypeEditor
153+
{
154+
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
155+
{ return true; }
158156

159-
public override void PaintValue(PaintValueEventArgs e)
160-
{
161-
var rect = e.Bounds;
162-
rect.Inflate(1, 1);
163-
var settings = (VisibleSettings)e.Value;
164-
var checkmark = (settings.Visible) ? ButtonState.Checked : ButtonState.Normal;
165-
ControlPaint.DrawCheckBox(e.Graphics, rect, ButtonState.Flat | checkmark);
166-
}
157+
public override void PaintValue(PaintValueEventArgs e)
158+
{
159+
var rect = e.Bounds;
160+
rect.Inflate(1, 1);
161+
var settings = (VisibleSettings)e.Value;
162+
var checkmark = (settings.Visible) ? ButtonState.Checked : ButtonState.Normal;
163+
ControlPaint.DrawCheckBox(e.Graphics, rect, ButtonState.Flat | checkmark);
167164
}
165+
}
168166
}

SkyRoof/Forms/LoqFt4QsoDialog.Designer.cs

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SkyRoof/Forms/LoqFt4QsoDialog.cs

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,45 @@
1-
namespace SkyRoof
1+

2+
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar;
3+
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
4+
5+
namespace SkyRoof
26
{
37
public partial class LoqFt4QsoDialog : Form
48
{
59
private Context ctx;
610
private QsoInfo qso;
11+
private static Point LastLocation = Point.Empty;
712

8-
public LoqFt4QsoDialog()
13+
public LoqFt4QsoDialog(Context ctx, QsoInfo qso)
914
{
1015
InitializeComponent();
11-
}
1216

13-
internal void PopUp(Context ctx, QsoInfo qso)
14-
{
1517
this.ctx = ctx;
1618
this.qso = qso;
17-
label1.Text = $"Save FT4 QSO with {qso.Call}?";
18-
Show(ctx.MainForm);
19+
SetRandomLocation();
20+
}
21+
22+
internal static void PopUp(Context ctx, QsoInfo qso)
23+
{
24+
var dialog = new LoqFt4QsoDialog(ctx, qso);
25+
dialog.label1.Text = $"Save FT4 QSO with {qso.Call}?";
26+
dialog.Show(ctx.MainForm);
27+
}
28+
29+
private void SetRandomLocation()
30+
{
31+
if (LastLocation == Point.Empty)
32+
LastLocation = new(
33+
(Screen.PrimaryScreen!.WorkingArea.Width - Size.Width) / 2,
34+
(Screen.PrimaryScreen!.WorkingArea.Height - Size.Width) / 2
35+
);
36+
37+
Random rand = new Random();
38+
39+
Location = new(
40+
LastLocation.X + rand.Next(-50, 50),
41+
LastLocation.Y + rand.Next(-50, 50)
42+
);
1943
}
2044

2145
private void SaveBtn_Click(object sender, EventArgs e)
@@ -49,5 +73,10 @@ private void CancelBtn_Click(object sender, EventArgs e)
4973
{
5074
Hide();
5175
}
76+
77+
private void LoqFt4QsoDialog_Move(object sender, EventArgs e)
78+
{
79+
LastLocation = Location;
80+
}
5281
}
5382
}

SkyRoof/Panels/Ft4ConsolePanel.Designer.cs

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

0 commit comments

Comments
 (0)