-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWatch.js
More file actions
78 lines (68 loc) · 2 KB
/
Watch.js
File metadata and controls
78 lines (68 loc) · 2 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
include("../NewFile/NewFile.js");
WATCH_TIME = 2;
LAST_MODIFIED = null;
var enableWatch = false;
/**
* \class Watch
* \brief Handles all user interaction to open documents.
* \ingroup ecma_file
*/
function Watch(guiAction) {
NewFile.call(this, guiAction);
}
Watch.prototype = new NewFile();
Watch.prototype.beginEvent = function () {
File.prototype.beginEvent.call(this);
enableWatch = !enableWatch;
var interval = WATCH_TIME * 1000;
var fileName = EAction.getDocument().getFileName();
Watch.watchTimer = new QTimer(this);
Watch.watchTimer.interval = interval;
Watch.watchTimer.timeout.connect(Watch, "watch");
if (enableWatch) {
var appWin = EAction.getMainWindow();
QMessageBox.information(
appWin,
qsTr("Info"),
qsTr('Start watch: ' + fileName)
);
Watch.watchTimer.start(interval);
}
else {
QMessageBox.information(
appWin,
qsTr("Info"),
qsTr('Stop watch: ' + fileName)
);
Watch.watchTimer.stop();
}
};
Watch.getTimestamp = function () {
return QTime.currentTime().toString("hh:mm:ss");
};
Watch.watch = function () {
//qDebug(Watch.getTimestamp());
if (!enableWatch) {
return;
}
var document = EAction.getDocument();
var fileName = document.getFileName();
var fi = new QFileInfo(fileName);
if (fi.lastModified().toString() != LAST_MODIFIED) {
if (LAST_MODIFIED != null) {
qDebug('reload');
Watch.reloadFile(fileName);
EAction.handleUserMessage("[" + Watch.getTimestamp() + "] "
+ qsTr("Reload complete."));
}
LAST_MODIFIED = fi.lastModified().toString();
}
};
Watch.reloadFile = function (fileName) {
var appWin = EAction.getMainWindow();
var mdiArea = appWin.getMdiArea();
var tabBar = appWin.getTabBar();
var currentIndex = tabBar.currentIndex;
NewFile.createMdiChild(fileName);
mdiArea.closeTab(currentIndex);
};