forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui-controller.js
More file actions
130 lines (114 loc) · 3.4 KB
/
ui-controller.js
File metadata and controls
130 lines (114 loc) · 3.4 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
// ui-controller.js - UI event handlers and state management
/**
* UI state and file metadata
*/
let filePath = null;
let fileEditStatus = null;
/**
* Initialize and set up UI elements and their event handlers
* @param {string} initialPath - The initial file path
* @param {string} initialStatus - The initial file edit status
*/
function setupUI(initialPath = null, initialStatus = null) {
filePath = initialPath;
fileEditStatus = initialStatus;
const keepButton = document.getElementById('keep-button');
const undoButton = document.getElementById('undo-button');
const choiceButtons = document.getElementById('choice-buttons');
if (!keepButton || !undoButton || !choiceButtons) {
console.error("Could not find UI elements");
return;
}
// Set initial UI state
updateUIStatus(initialStatus);
// Setup event listeners
keepButton.addEventListener('click', handleKeepButtonClick);
undoButton.addEventListener('click', handleUndoButtonClick);
}
/**
* Update the UI based on file edit status
* @param {string} status - The current file edit status
*/
function updateUIStatus(status) {
fileEditStatus = status;
const choiceButtons = document.getElementById('choice-buttons');
if (!choiceButtons) return;
// Hide buttons if file has been modified
if (status && status !== "none") {
choiceButtons.classList.add('hidden');
} else {
choiceButtons.classList.remove('hidden');
}
}
/**
* Update the file metadata
* @param {string} path - The file path
* @param {string} status - The file edit status
*/
function updateFileMetadata(path, status) {
filePath = path;
updateUIStatus(status);
}
/**
* Handle the "Keep" button click
*/
function handleKeepButtonClick() {
// Send message to Swift handler
if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.swiftHandler) {
window.webkit.messageHandlers.swiftHandler.postMessage({
event: 'keepButtonClicked',
data: {
filePath: filePath
}
});
} else {
console.log('Keep button clicked, but no message handler found');
}
// Hide the choice buttons
const choiceButtons = document.getElementById('choice-buttons');
if (choiceButtons) {
choiceButtons.classList.add('hidden');
}
}
/**
* Handle the "Undo" button click
*/
function handleUndoButtonClick() {
// Send message to Swift handler
if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.swiftHandler) {
window.webkit.messageHandlers.swiftHandler.postMessage({
event: 'undoButtonClicked',
data: {
filePath: filePath
}
});
} else {
console.log('Undo button clicked, but no message handler found');
}
// Hide the choice buttons
const choiceButtons = document.getElementById('choice-buttons');
if (choiceButtons) {
choiceButtons.classList.add('hidden');
}
}
/**
* Get the current file path
* @returns {string} The current file path
*/
function getFilePath() {
return filePath;
}
/**
* Get the current file edit status
* @returns {string} The current file edit status
*/
function getFileEditStatus() {
return fileEditStatus;
}
export {
setupUI,
updateUIStatus,
updateFileMetadata,
getFilePath,
getFileEditStatus
};