Files
BQP/srcs/RobotNet10/Components/RobotNet10.ScriptEditor/wwwroot/fileExplorer.js
2026-07-13 09:25:40 +07:00

112 lines
3.9 KiB
JavaScript

// File Explorer JavaScript functions
let escapeKeyHandler = null;
export function registerEscapeKeyHandler(dotNetHelper) {
// Remove existing handler if any
if (escapeKeyHandler) {
document.removeEventListener('keydown', escapeKeyHandler);
}
// Create new handler
escapeKeyHandler = (e) => {
if (e.key === 'Escape' || e.key === 'Esc') {
dotNetHelper.invokeMethodAsync('HandleEscapeKey');
}
};
// Register handler
document.addEventListener('keydown', escapeKeyHandler);
}
export function unregisterEscapeKeyHandler() {
if (escapeKeyHandler) {
document.removeEventListener('keydown', escapeKeyHandler);
escapeKeyHandler = null;
}
}
export function init(treeContainerRef) {
// Initialize file explorer if needed
}
export function updateFolderBadges(folderPath, hasWarnings, hasErrors, isModified, warningCount, errorCount, folderName) {
// Update folder badges via DOM manipulation
const folderElement = document.querySelector(`[data-folder-path="${folderPath}"]`);
if (folderElement) {
const warningBadge = folderElement.querySelector('[data-badge="warning"]');
const errorBadge = folderElement.querySelector('[data-badge="error"]');
const modifiedBadge = folderElement.querySelector('[data-badge="modified"]');
if (warningBadge) {
warningBadge.style.display = hasWarnings ? 'inline' : 'none';
warningBadge.textContent = warningCount;
warningBadge.setAttribute('data-count', warningCount);
}
if (errorBadge) {
errorBadge.style.display = hasErrors ? 'inline' : 'none';
errorBadge.textContent = errorCount;
errorBadge.setAttribute('data-count', errorCount);
}
if (modifiedBadge) {
modifiedBadge.style.display = isModified ? 'inline' : 'none';
}
}
}
export function updateFileBadges(filePath, hasWarnings, hasErrors, isModified, warningCount, errorCount, fileName) {
// Update file badges via DOM manipulation
const fileElement = document.querySelector(`[data-file-path="${filePath}"]`);
if (fileElement) {
const warningBadge = fileElement.querySelector('[data-badge="warning"]');
const errorBadge = fileElement.querySelector('[data-badge="error"]');
const modifiedBadge = fileElement.querySelector('[data-badge="modified"]');
if (warningBadge) {
warningBadge.style.display = hasWarnings ? 'inline' : 'none';
warningBadge.textContent = warningCount;
warningBadge.setAttribute('data-count', warningCount);
}
if (errorBadge) {
errorBadge.style.display = hasErrors ? 'inline' : 'none';
errorBadge.textContent = errorCount;
errorBadge.setAttribute('data-count', errorCount);
}
if (modifiedBadge) {
modifiedBadge.style.display = isModified ? 'inline' : 'none';
}
}
}
export function UncheckRadioByName(radioName) {
const radios = document.querySelectorAll(`input[type="radio"][name="${radioName}"]`);
radios.forEach(radio => {
radio.checked = false;
});
}
export function CheckRadioById(itemId) {
const radio = document.getElementById(itemId);
if (radio) {
radio.checked = true;
}
}
export function setElementPosition(elementId, x, y) {
const element = document.getElementById(elementId);
if (element) {
element.style.position = 'fixed';
element.style.left = x + 'px';
element.style.top = y + 'px';
element.style.width = '1px';
element.style.height = '1px';
element.style.pointerEvents = 'none';
element.style.zIndex = '-1';
}
}