// The module 'vscode' contains the VS Code extensibility API // Import the module and reference it with the alias vscode in your code below const vscode = require('vscode'); const openFilesAndURLs = require('./openFilesAndUrls.js') // const path = require('path'); // This method is called when your extension is activated // Your extension is activated the very first time the command is executed /** * * @param {vscode.ExtensionContext} context */ console.log("ITK LOGS!!!!!") let treeView; let _context; function activate(context) { console.log('Congratulations, your extension "itk" is now active!'); initTreeView(context); initCmdInVsCodeTerminal(context) initOpenChromeUrl(context) initCloseTabs(context) initHtml(context, getTemplate()) initWelcome(context) initTests(context) initGetTabs(context) startAction(context); } async function startAction(context) { _context = context; updateCount(127) openFilesAndURLs({beforeFn: closeAllTabs}) // openHtml() // openWelcomeFrame() // openTestsFrame() setTimeout(() => { getTabs(); }) // openTabsDirectly() // openUrlInChrome(); } async function openStartTabs(groups) { const openPromises = []; const workspaceFolder = vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders[0]; let columnIndex = 1; // Start from the first column groups.forEach((group, index) => { group.forEach((file) => { if (file.url) { // If the object contains a URL, open it in a Webview (iframe) // openPromises.push( runFrame(file)); runFrame(file, columnIndex + index) } else if (file.relPath) { // Resolve the file path relative to the workspace folder const filePath = vscode.Uri.joinPath(workspaceFolder.uri, file.relPath); // Open the file in a new tab (in a new column, if needed) openPromises.push(vscode.workspace.openTextDocument(filePath) .then(doc => { // If it's the first file of a group, open it in the first column const columnToUse = columnIndex + index; // Show the document in the appropriate column vscode.window.showTextDocument(doc, { viewColumn: columnToUse, preview: false }); // Move to the next column after opening each file })); } }); }); } function initGetTabs(context) { let disposable = vscode.commands.registerCommand('itk.getTabs', () => { getTabs() }); // Add to your extension's subscriptions context.subscriptions.push(disposable); } function getTabs() { const tabGroups = vscode.window.tabGroups.all; if (tabGroups.length === 0) { vscode.window.showInformationMessage('No open tabs found.'); return; } let tabInfo = []; tabGroups.forEach((group, index) => { group.tabs.forEach(tab => { let filePath = "Unknown"; // Check if the tab is a text file and extract its full path if (tab.input instanceof vscode.TabInputText) { filePath = tab.input.uri.fsPath; } tabInfo.push(`Group ${index + 1}: ${tab.label} - ${filePath}`); }); }); vscode.window.showInformationMessage(`Opened Tabs:\n${tabInfo.join('\n')}`); console.log('tabInfo', tabInfo) return tabGroups; } function initOpenChromeUrl(context) { let disposable = vscode.commands.registerCommand('itk.openUrlInBrowser', async () => { openUrlInChrome() }); context.subscriptions.push(disposable); } async function openUrlInChrome() { let url = 'https://new.csb.app'; // if (url) { // try { // new URL(url); // Validate URL // } catch (error) { // vscode.window.showErrorMessage("Invalid URL: " + error.message); // return; // } // // Dynamic import: // try { // const open = await import('open'); // Correct way to import ES module // await open.default(url); // Use open.default to call the function // } catch (error) { // vscode.window.showErrorMessage("Could not open URL: " + error.message); // console.error("Open URL Error:", error); // } // } } function initCloseTabs(context) { let disposable = vscode.commands.registerCommand('itk.closeAllTabs', () => { // Call your close all tabs logic here (the code from above) closeAllTabs() }); context.subscriptions.push(disposable); } async function closeAllTabs() { try { await vscode.commands.executeCommand('workbench.action.closeAllEditors'); } catch (e) { vscode.window.showInformationMessage("Tabs Closing Error"); } } function initHtml(context, defaultUrl) { context.subscriptions.push( vscode.commands.registerCommand('itk.openWelcome', () => { openHtml(context, defaultUrl); }) ); } function openHtml(context, html) { context = context || _context; html = html || getTemplate(); const panel = vscode.window.createWebviewPanel( 'HTML ITK', // Identifies the webview 'ITK HTML', // Title of the panel vscode.ViewColumn.One, // Show in the first column { enableScripts: true, // Allows JavaScript execution } ); // Set HTML content for the Webview panel.webview.html = html panel.webview.onDidReceiveMessage(message => { console.log('message', message, message.command) switch (message.command) { case 'buttonClicked': vscode.window.showInformationMessage('Button clicked!' + new Date().getTime()); return; } }, undefined, context.subscriptions); } function initWelcome(context, defaultUrl) { context.subscriptions.push( vscode.commands.registerCommand('itk.openWelcomeFrame', () => { openWelcomeFrame(); }) ); } function initTests(context, defaultUrl) { context.subscriptions.push( vscode.commands.registerCommand('itk.openTests', () => { openTestsFrame(); }) ); } function openWelcomeFrame() { runFrame({ url: 'https://itrum.ru', name: 'ITK Welcome Frame', id: 'itkWelcomeFrame' }) } function openTestsFrame() { runFrame({ url: 'https://itrum.ru', name: 'ITK Tests', id: 'itkTests' }) } function runFrame({ url, name, id} , groupId) { const panel = vscode.window.createWebviewPanel( id, // Identifies the webview name, // Title of the panel vscode.ViewColumn.One, // Show in the first column { enableScripts: true, // Allows JavaScript execution localResourceRoots: [] // Define where local resources can be loaded from (if needed) } ); panel.reveal(vscode.ViewColumn.One + groupId - 1); console.log('groupId', groupId) // Set HTML content for the Webview panel.webview.html = getWebviewContent(url); function getWebviewContent(url) { return `
This is a custom welcome view.
You can add your own HTML content here.
`; } // This method is called when your extension is deactivated function deactivate() { console.log("ITK DEACTIVE") } module.exports = { activate, deactivate }