-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Implement a basic OE Depends Dot view
- Loading branch information
1 parent
8355fc5
commit 37c327f
Showing
4 changed files
with
173 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,47 @@ | ||
/** -------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2023 Savoir-faire Linux. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
* ------------------------------------------------------------------------------------------ */ | ||
//@ts-check | ||
|
||
// This script will be run within the webview itself | ||
// It cannot access the main VS Code APIs directly. | ||
(function () { | ||
const vscode = acquireVsCodeApi(); | ||
const oldState = vscode.getState() || { }; | ||
|
||
const oldState = vscode.getState() || { colors: [] }; | ||
// HTML Listeners | ||
document.querySelector('#depType').addEventListener('click', () => { | ||
vscode.postMessage({ type: 'depType', value: event.target.value }); | ||
}); | ||
|
||
/** @type {Array<{ value: string }>} */ | ||
let colors = oldState.colors; | ||
document.querySelector('#graphRecipe').addEventListener('input', () => { | ||
const value = document.querySelector('#graphRecipe').value; | ||
vscode.postMessage({ type: 'graphRecipe', value }); | ||
}); | ||
|
||
updateColorList(colors); | ||
document.querySelector('#packageName').addEventListener('input', () => { | ||
const value = document.querySelector('#packageName').value; | ||
vscode.postMessage({ type: 'packageName', value }); | ||
}); | ||
|
||
document.querySelector('#genDotFile').addEventListener('click', () => { | ||
vscode.postMessage({ type: 'genDotFile' }); | ||
}); | ||
|
||
document.querySelector('.add-color-button').addEventListener('click', () => { | ||
addColor(); | ||
document.querySelector('#runOeDepends').addEventListener('click', () => { | ||
vscode.postMessage({ type: 'runOeDepends' }); | ||
}); | ||
|
||
// Handle messages sent from the extension to the webview | ||
// Extension Listeners | ||
window.addEventListener('message', event => { | ||
const message = event.data; // The json data that the extension sent | ||
switch (message.type) { | ||
case 'addColor': | ||
case 'results': | ||
{ | ||
addColor(); | ||
document.querySelector('#results').textContent = message.value; | ||
break; | ||
} | ||
case 'clearColors': | ||
{ | ||
colors = []; | ||
updateColorList(colors); | ||
break; | ||
} | ||
|
||
} | ||
}); | ||
|
||
/** | ||
* @param {Array<{ value: string }>} colors | ||
*/ | ||
function updateColorList(colors) { | ||
const ul = document.querySelector('.color-list'); | ||
ul.textContent = ''; | ||
for (const color of colors) { | ||
const li = document.createElement('li'); | ||
li.className = 'color-entry'; | ||
|
||
const colorPreview = document.createElement('div'); | ||
colorPreview.className = 'color-preview'; | ||
colorPreview.style.backgroundColor = `#${color.value}`; | ||
colorPreview.addEventListener('click', () => { | ||
onColorClicked(color.value); | ||
}); | ||
li.appendChild(colorPreview); | ||
|
||
const input = document.createElement('input'); | ||
input.className = 'color-input'; | ||
input.type = 'text'; | ||
input.value = color.value; | ||
input.addEventListener('change', (e) => { | ||
const value = e.target.value; | ||
if (!value) { | ||
// Treat empty value as delete | ||
colors.splice(colors.indexOf(color), 1); | ||
} else { | ||
color.value = value; | ||
} | ||
updateColorList(colors); | ||
}); | ||
li.appendChild(input); | ||
|
||
ul.appendChild(li); | ||
} | ||
|
||
// Update the saved state | ||
vscode.setState({ colors: colors }); | ||
} | ||
|
||
/** | ||
* @param {string} color | ||
*/ | ||
function onColorClicked(color) { | ||
vscode.postMessage({ type: 'colorSelected', value: color }); | ||
} | ||
|
||
/** | ||
* @returns string | ||
*/ | ||
function getNewCalicoColor() { | ||
const colors = ['020202', 'f1eeee', 'a85b20', 'daab70', 'efcb99']; | ||
return colors[Math.floor(Math.random() * colors.length)]; | ||
} | ||
|
||
function addColor() { | ||
colors.push({ value: getNewCalicoColor() }); | ||
updateColorList(colors); | ||
} | ||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters