-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathContextMenuView.cs
More file actions
138 lines (114 loc) · 3.84 KB
/
Copy pathContextMenuView.cs
File metadata and controls
138 lines (114 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using MW5.Api.Enums;
using MW5.Plugins.Interfaces;
using MW5.Plugins.Mvp;
namespace MW5.Menu
{
public partial class ContextMenuView : UserControl, IMenuProvider
{
private readonly IAppContext _context;
public ContextMenuView(IAppContext context)
{
if (context == null) throw new ArgumentNullException("context");
_context = context;
InitializeComponent();
ctxScale.Tag = 0; // to avoid automatic handler
ctxZoomToLayer.Tag = 0; // to avoid automatic handler
contextMeasuring.Opening += MeasuringMenuOpening;
contextZooming.Opening += ZoomingMenuOpening;
}
public ContextMenuStrip MeasuringMenu
{
get { return contextMeasuring; }
}
public ContextMenuStrip ZoomingMenu
{
get { return contextZooming; }
}
public IEnumerable<ToolStripItemCollection> ToolStrips
{
get
{
yield return contextMeasuring.Items;
yield return contextZooming.Items;
}
}
public IEnumerable<Control> Buttons
{
get { yield break; }
}
private void ZoomingMenuOpening(object sender, CancelEventArgs e)
{
InitScaleMenu();
InitLayersMenu();
}
private void InitLayersMenu()
{
ctxZoomToLayer.DropDownItems.Clear();
foreach (var layer in _context.Map.Layers.Where(l => l.Visible))
{
var item = ctxZoomToLayer.DropDownItems.Add(layer.Name);
item.Tag = layer.Handle;
item.Click += OnZoomToLayerClick;
}
}
private void InitScaleMenu()
{
ctxScale.DropDownItems.Clear();
ctxScale.DropDownItems.Add("1: " + _context.Map.CurrentScale.ToString("0.0"));
ctxScale.DropDownItems.Add(new ToolStripSeparator());
int[] scales = {
100,
1000,
5000,
10000,
25000,
50000,
100000,
250000,
500000,
1000000,
5000000,
1000000,
};
foreach (var scale in scales)
{
var item = ctxScale.DropDownItems.Add("1: " + scale);
item.Tag = scale;
item.Click += OnSetScale;
}
}
private void OnZoomToLayerClick(object sender, EventArgs e)
{
var item = sender as ToolStripItem;
if (item != null)
{
int layerHandle = (int)item.Tag;
_context.Map.ZoomToLayer(layerHandle);
}
}
private void OnSetScale(object sender, EventArgs e)
{
var item = sender as ToolStripItem;
if (item != null)
{
_context.Map.CurrentScale = (int) item.Tag;
}
}
private void MeasuringMenuOpening(object sender, CancelEventArgs e)
{
var options = _context.Map.Measuring.Options;
ctxShowBearing.Checked = options.ShowBearing;
ctxShowLength.Checked = options.ShowLength;
ctxMetric.Checked = options.LengthUnits == LengthDisplay.Metric;
ctxAmerican.Checked = options.LengthUnits == LengthDisplay.American;
ctxDegrees.Checked = options.AngleFormat == AngleFormat.Degrees;
ctxMinutes.Checked = options.AngleFormat == AngleFormat.Minutes;
ctxSeconds.Checked = options.AngleFormat == AngleFormat.Seconds;
}
}
}