forked from fdorg/flashdevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilePollManager.cs
More file actions
97 lines (90 loc) · 3.53 KB
/
Copy pathFilePollManager.cs
File metadata and controls
97 lines (90 loc) · 3.53 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
using System;
using System.Windows.Forms;
using FlashDevelop.Docking;
using PluginCore;
using PluginCore.Localization;
namespace FlashDevelop.Managers
{
class FilePollManager
{
private static Timer FilePollTimer;
private static Boolean YesToAll = false;
/// <summary>
/// Initialize the file change polling
/// </summary>
public static void InitializePolling()
{
CheckSettingValues();
FilePollTimer = new Timer();
FilePollTimer.Interval = Globals.Settings.FilePollInterval;
FilePollTimer.Tick += new EventHandler(FilePollTimerTick);
FilePollTimer.Start();
}
/// <summary>
/// Checks the setting value validity
/// </summary>
private static void CheckSettingValues()
{
Int32 interval = Globals.Settings.FilePollInterval;
if (interval == 0) Globals.Settings.FilePollInterval = 3000;
}
/// <summary>
/// Checks if a file has been changed outside
/// </summary>
private static void CheckFileChange(ITabbedDocument document)
{
TabbedDocument casted = document as TabbedDocument;
if (casted.IsEditable && casted.CheckFileChange())
{
if (Globals.Settings.AutoReloadModifiedFiles)
{
casted.RefreshFileInfo();
casted.Reload(false);
}
else
{
if (YesToAll)
{
casted.RefreshFileInfo();
casted.Reload(false);
return;
}
String dlgTitle = TextHelper.GetString("Title.InfoDialog");
String dlgMessage = TextHelper.GetString("Info.FileIsModifiedOutside");
String formatted = String.Format(dlgMessage, "\n", casted.FileName);
MessageBoxManager.Cancel = TextHelper.GetString("Label.YesToAll");
MessageBoxManager.Register(); // Use custom labels...
DialogResult result = MessageBox.Show(Globals.MainForm, formatted, " " + dlgTitle, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
casted.RefreshFileInfo(); // User may have waited before responding, save info now
if (result == DialogResult.Yes) casted.Reload(false);
else if (result == DialogResult.Cancel)
{
casted.Reload(false);
YesToAll = true;
}
MessageBoxManager.Unregister();
}
}
}
/// <summary>
/// After an interval check if the files have changed
/// </summary>
private static void FilePollTimerTick(Object sender, EventArgs e)
{
try
{
FilePollTimer.Enabled = false;
ITabbedDocument[] documents = Globals.MainForm.Documents;
ITabbedDocument current = Globals.MainForm.CurrentDocument;
CheckFileChange(current); // Check the current first..
foreach (ITabbedDocument document in documents)
{
if (document != current) CheckFileChange(document);
}
FilePollTimer.Enabled = true;
YesToAll = false;
}
catch { /* No errors shown here.. */ }
}
}
}