forked from fdorg/flashdevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecoveryDialog.cs
More file actions
185 lines (170 loc) · 6.67 KB
/
Copy pathRecoveryDialog.cs
File metadata and controls
185 lines (170 loc) · 6.67 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
using System;
using System.IO;
using System.Windows.Forms;
using PluginCore.Localization;
using PluginCore.Utilities;
using PluginCore.Helpers;
using PluginCore.Controls;
using PluginCore;
namespace FlashDevelop.Dialogs
{
public class RecoveryDialog : SmartForm
{
Label infoLabel;
Button deleteButton;
Button notifyButton;
Button openButton;
public RecoveryDialog()
{
Owner = Globals.MainForm;
Font = PluginBase.Settings.DefaultFont;
FormGuid = "54452519-b993-47f6-9d27-22d31bced4ff";
InitializeComponent();
ApplyLocalizedTexts();
}
#region Windows Form Designer Generated Code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent()
{
deleteButton = new ButtonEx();
openButton = new ButtonEx();
notifyButton = new ButtonEx();
infoLabel = new Label();
SuspendLayout();
//
// deleteButton
//
deleteButton.FlatStyle = FlatStyle.System;
deleteButton.Location = new System.Drawing.Point(133, 88);
deleteButton.Name = "deleteButton";
deleteButton.Size = new System.Drawing.Size(85, 23);
deleteButton.TabIndex = 2;
deleteButton.Text = "&Delete Files";
deleteButton.UseVisualStyleBackColor = true;
deleteButton.Click += DeleteButtonClick;
//
// openButton
//
openButton.FlatStyle = FlatStyle.System;
openButton.Location = new System.Drawing.Point(42, 88);
openButton.Name = "openButton";
openButton.Size = new System.Drawing.Size(85, 23);
openButton.TabIndex = 3;
openButton.Text = "&Open Files";
openButton.UseVisualStyleBackColor = true;
openButton.Click += OpenButtonClick;
//
// notifyButton
//
notifyButton.FlatStyle = FlatStyle.System;
notifyButton.Location = new System.Drawing.Point(224, 88);
notifyButton.Name = "notifyButton";
notifyButton.Size = new System.Drawing.Size(85, 23);
notifyButton.TabIndex = 1;
notifyButton.Text = "&Notify Later";
notifyButton.UseVisualStyleBackColor = true;
notifyButton.Click += NotifyButtonClick;
//
// infoLabel
//
infoLabel.Anchor = (AnchorStyles.Top | AnchorStyles.Left) | AnchorStyles.Right;
infoLabel.FlatStyle = FlatStyle.System;
infoLabel.Location = new System.Drawing.Point(13, 13);
infoLabel.Name = "infoLabel";
infoLabel.Size = new System.Drawing.Size(331, 66);
infoLabel.TabIndex = 4;
infoLabel.Text = "The recovery folder contains temporary backup files and this possibly means that your previous coding session was interrupted. \r\n\r\nWhat do you want to do to these files?";
infoLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// RecoveryDialog
//
AcceptButton = openButton;
CancelButton = notifyButton;
AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new System.Drawing.Size(356, 124);
Controls.Add(notifyButton);
Controls.Add(openButton);
Controls.Add(deleteButton);
Controls.Add(infoLabel);
FormBorderStyle = FormBorderStyle.FixedDialog;
MaximizeBox = false;
MinimizeBox = false;
Name = "RecoveryDialog";
StartPosition = FormStartPosition.CenterParent;
Text = " Recovery File Notification";
ResumeLayout(false);
}
#endregion
#region Methods And Event Handlers
/// <summary>
/// Applies the localized texts to the form
/// </summary>
void ApplyLocalizedTexts()
{
openButton.Text = TextHelper.GetString("Label.OpenFiles");
notifyButton.Text = TextHelper.GetString("Label.NotifyLater");
deleteButton.Text = TextHelper.GetString("Label.DeleteFiles");
Text = " " + TextHelper.GetString("Title.RecoveryDialog");
string info = TextHelper.GetString("Info.RecoveryInfo");
infoLabel.Text = string.Format(info, "\n\n");
}
/// <summary>
/// Notifies the user next time with the same info
/// </summary>
void NotifyButtonClick(object sender, EventArgs e) => Close();
/// <summary>
/// Opens the files from the recovery files folder
/// </summary>
void OpenButtonClick(object sender, EventArgs e)
{
string[] files = GetRecoveryFiles();
foreach (string file in files)
{
string arguments = "bak;" + file;
PluginBase.MainForm.CallCommand("NewFromTemplate", arguments);
}
string message = TextHelper.GetString("Info.DeleteFilesAlso");
string caption = " " + TextHelper.GetString("Title.ConfirmDialog");
if (MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
DeleteButtonClick(null, null);
}
else Close();
}
/// <summary>
/// Deletes the files from the recovery files folder
/// </summary>
void DeleteButtonClick(object sender, EventArgs e)
{
var files = GetRecoveryFiles();
foreach (string file in files) FileHelper.Recycle(file);
Close();
}
/// <summary>
/// Gets the files from the recovery folder
/// </summary>
static string[] GetRecoveryFiles()
{
var path = Path.Combine(PathHelper.SettingDir, "Recovery");
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
return Directory.GetFiles(path);
}
/// <summary>
/// Checks whether we should show the dialog
/// </summary>
public static bool ShouldShowDialog() => !SingleInstanceApp.AlreadyExists && GetRecoveryFiles().Length > 0;
/// <summary>
/// Shows the recovery dialog
/// </summary>
public new static void Show()
{
using var dialog = new RecoveryDialog();
dialog.ShowDialog();
}
#endregion
}
}