-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackupDialogHelper.cs
More file actions
219 lines (185 loc) · 9.66 KB
/
Copy pathBackupDialogHelper.cs
File metadata and controls
219 lines (185 loc) · 9.66 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
// Design-Rule / UI consistency:
// Keep layout, spacing, colors, sizes, and fonts aligned with ModernTheme.
// Add new shared visual values to ModernTheme instead of hardcoding local exceptions here.
// 03.05.2026 /dc
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace EasyVersionBackup
{
public static class BackupDialogHelper
{
public static DialogResult ShowDestinationConflictDialog(Form owner, string destinationPath, out string selectedConflictAction)
{
using DestinationConflictDialog dialog = new DestinationConflictDialog(owner, destinationPath);
DialogResult result = dialog.ShowDialog(owner);
selectedConflictAction = dialog.SelectedConflictAction;
return result;
}
public static void ShowBackupCanceledBecauseDestinationExists(Form owner, string destinationPath)
{
ModernMessageDialog.Show(
owner,
"Backup canceled",
BackupHelper.FormatBackupCanceledBecauseDestinationExistsMessage(destinationPath));
}
private sealed class DestinationConflictDialog : Form
{
private const int WmNclButtonDown = 0xA1;
private const int HtCaption = 0x2;
private const int WmNcHitTest = 0x84;
private const int HtBottomRight = 17;
private readonly Panel panelTitleBar;
private readonly PictureBox pictureBoxTitleIcon;
private readonly Label labelTitle;
private readonly Label labelMessageTitle;
private readonly Label labelDestinationPath;
private readonly ComboBox comboBoxConflictAction;
private readonly Button buttonOk;
private readonly Button buttonCancel;
public string SelectedConflictAction { get; private set; } = BackupHelper.DestinationConflictAppend;
public DestinationConflictDialog(Form owner, string destinationPath)
{
Icon = owner.Icon;
Text = "Destination Conflict";
StartPosition = FormStartPosition.CenterParent;
ClientSize = ModernTheme.BackupDialogDefaultSize;
MinimumSize = ModernTheme.BackupDialogMinimumSize;
FormBorderStyle = FormBorderStyle.None;
BackColor = ModernTheme.WindowBackColor;
Font = new Font(ModernTheme.FontFamilyName, ModernTheme.DefaultFontSize);
ShowInTaskbar = false;
DoubleBuffered = true;
ModernWindowFrame.Apply(this);
panelTitleBar = new Panel
{
Name = "panelTitleBar",
Height = ModernTheme.TitleBarHeight,
Dock = DockStyle.Top,
BackColor = ModernTheme.TitleBarBackColor,
Cursor = Cursors.SizeAll
};
pictureBoxTitleIcon = new PictureBox
{
Name = "pictureBoxTitleIcon",
Location = new Point(ModernTheme.TitleBarIconLeft, ModernTheme.TitleBarIconTop),
Size = new Size(ModernTheme.TitleBarIconSize, ModernTheme.TitleBarIconSize),
SizeMode = PictureBoxSizeMode.StretchImage,
Image = Icon?.ToBitmap(),
BackColor = Color.Transparent
};
labelTitle = new Label
{
Name = "labelTitle",
Text = "Destination Conflict",
AutoSize = false,
Location = new Point(ModernTheme.TitleBarTextLeft, 0),
Size = new Size(ClientSize.Width - ModernTheme.TitleBarTextLeft - 12, ModernTheme.TitleBarHeight),
Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
TextAlign = ContentAlignment.MiddleLeft,
ForeColor = ModernTheme.TextColor,
Font = new Font(ModernTheme.FontFamilyName, ModernTheme.TitleFontSize, FontStyle.Bold),
BackColor = Color.Transparent,
Cursor = Cursors.SizeAll
};
labelMessageTitle = new Label
{
Name = "labelMessageTitle",
Text = "Destination already exists:",
Location = new Point(ModernTheme.BackupDialogContentLeft, ModernTheme.BackupDialogContentTop),
Size = new Size(ClientSize.Width - ModernTheme.BackupDialogContentLeft - ModernTheme.BackupDialogContentRightMargin, ModernTheme.SettingsLabelHeight),
Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
ForeColor = ModernTheme.TextColor,
BackColor = Color.Transparent,
TextAlign = ContentAlignment.MiddleLeft
};
labelDestinationPath = new Label
{
Name = "labelDestinationPath",
Text = destinationPath,
Location = new Point(ModernTheme.BackupDialogContentLeft, labelMessageTitle.Bottom + ModernTheme.BackupDialogControlSpacing),
Size = new Size(ClientSize.Width - ModernTheme.BackupDialogContentLeft - ModernTheme.BackupDialogContentRightMargin, ModernTheme.BackupDialogPathLabelHeight),
Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
ForeColor = ModernTheme.TextColor,
BackColor = Color.Transparent,
TextAlign = ContentAlignment.MiddleLeft,
AutoEllipsis = false
};
comboBoxConflictAction = new ComboBox
{
Name = "comboBoxConflictAction",
Location = new Point(ModernTheme.BackupDialogContentLeft, labelDestinationPath.Bottom + ModernTheme.BackupDialogControlSpacing),
Size = new Size(ModernTheme.BackupDialogComboBoxWidth, ModernTheme.SettingsControlHeight),
Anchor = AnchorStyles.Top | AnchorStyles.Left,
DropDownStyle = ComboBoxStyle.DropDownList,
FlatStyle = FlatStyle.Flat,
BackColor = ModernTheme.TitleBarBackColor,
ForeColor = ModernTheme.TextColor
};
comboBoxConflictAction.Items.Add(BackupHelper.DestinationConflictAppend);
comboBoxConflictAction.Items.Add(BackupHelper.DestinationConflictOverwrite);
comboBoxConflictAction.Text = BackupHelper.DestinationConflictAppend;
buttonOk = ModernTheme.CreateDialogPrimaryButton("buttonOk", "OK");
buttonCancel = ModernTheme.CreateDialogSecondaryButton("buttonCancel", "Cancel", DialogResult.Cancel);
ModernTheme.PositionDialogButtons(this, buttonOk, buttonCancel, true);
buttonOk.Click += buttonOk_Click;
panelTitleBar.MouseDown += titleBar_MouseDown;
labelTitle.MouseDown += titleBar_MouseDown;
pictureBoxTitleIcon.MouseDown += titleBar_MouseDown;
panelTitleBar.Controls.Add(pictureBoxTitleIcon);
panelTitleBar.Controls.Add(labelTitle);
Controls.Add(panelTitleBar);
Controls.Add(labelMessageTitle);
Controls.Add(labelDestinationPath);
Controls.Add(comboBoxConflictAction);
Controls.Add(buttonOk);
Controls.Add(buttonCancel);
AcceptButton = buttonOk;
CancelButton = buttonCancel;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
using Pen pen = new Pen(ModernTheme.WindowBorderColor, 1F);
int right = ClientSize.Width - 5;
int bottom = ClientSize.Height - 5;
e.Graphics.DrawLine(pen, right - 10, bottom, right, bottom - 10);
e.Graphics.DrawLine(pen, right - 6, bottom, right, bottom - 6);
e.Graphics.DrawLine(pen, right - 2, bottom, right, bottom - 2);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WmNcHitTest)
{
base.WndProc(ref m);
Point cursorPosition = PointToClient(Cursor.Position);
if (cursorPosition.X >= ClientSize.Width - ModernTheme.BackupDialogResizeGripSize &&
cursorPosition.Y >= ClientSize.Height - ModernTheme.BackupDialogResizeGripSize)
{
m.Result = HtBottomRight;
}
return;
}
base.WndProc(ref m);
}
private void buttonOk_Click(object? sender, System.EventArgs e)
{
SelectedConflictAction = BackupHelper.NormalizeDestinationConflictHandling(comboBoxConflictAction.Text);
DialogResult = DialogResult.OK;
Close();
}
private void titleBar_MouseDown(object? sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WmNclButtonDown, HtCaption, 0);
}
}
[DllImport("user32.dll")]
private static extern bool ReleaseCapture();
[DllImport("user32.dll")]
private static extern int SendMessage(nint hWnd, int msg, int wParam, int lParam);
}
}
}