This commit is contained in:
Till Salinger 2018-02-24 10:31:11 +01:00
Родитель 338c855487
Коммит 0ef07b28f0
6 изменённых файлов: 107 добавлений и 44 удалений

8
.vscode/extensions.json поставляемый Normal file
Просмотреть файл

@ -0,0 +1,8 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
]
}

Просмотреть файл

@ -1,23 +1,13 @@
<!doctype html>
<html>
<head>
<style>
.fakelink {
cursor: pointer;
text-decoration: underline;
}
</style>
<!-- <meta http-equiv="Content-Security-Policy" content="default-src *;"> -->
$$IMPORT_CSS_SCRIPTS$$
</head>
<body>
<div id="navbar">
<ul id="submlime-settings">
<li class="wanted" id="navbar-One">show-line-numbers: true</li>
<li class="wanted" id="navbar-Two">show-grid: false</li>
</ul>
</div>
<table id='dynamic-table--sublime-settings' class='greyGridTable'></table>
</body>
$$GUI_JS_PATH$$
$$IMPORT_JS_SCRIPTS$$
</html>

Просмотреть файл

@ -6,6 +6,14 @@ const fs = require('fs');
const promisifier = require('./FileSystem');
const previewUri = vscode.Uri.parse('vs-code-html-preview://authority/vs-code-html-preview');
// // TODO: hardcoded
const tableTag = `<table id='dynamic-table--sublime-settings' class='greyGridTable'></table>`;
function getMediaPath(context, mediaFile) {
return vscode.Uri.file(context.asAbsolutePath(mediaFile))
.with({ scheme: 'vscode-extension-resource' })
.toString();
}
class Extension {
@ -24,7 +32,7 @@ class Extension {
start() {
const that = this;
this.importer.analyze().then(analysis => {
return this.importer.analyze().then(analysis => {
var analysisTextParts = []
if (analysis.globalCount) {
@ -87,13 +95,14 @@ const activate = (context) => {
// const promise = wsServer.setupWebsocketConnection(context);
context.subscriptions.push([
vscode.commands.registerCommand('extension.importFromSublime', () => {
extension.start();
vscode.commands.executeCommand(
'vscode.previewHtml',
previewUri,
vscode.ViewColumn.Two,
'Sublime Settings Importer'
).then(null, error => console.error(error));
extension.start().then(() => {
vscode.commands.executeCommand(
'vscode.previewHtml',
previewUri,
vscode.ViewColumn.Two,
'Sublime Settings Importer'
).then(null, error => console.error(error));
});
}),
vscode.commands.registerCommand('extension.getResponseFromGUI', (msg) => {
console.log('Received:', msg);
@ -125,46 +134,60 @@ class TextDocumentContentProvider {
constructor(context) {
this.context = context;
// this._onDidChange = new vscode.EventEmitter();
this.htmlCache = null;
this.html = null;
this.callUpdate = null;
this._onDidChange = new vscode.EventEmitter();
}
provideTextDocumentContent() {
return new Promise((resolve, reject) => {
if (this.htmlCache) {
resolve(this.htmlCache);
if (this.html) {
resolve(this.html);
return;
} else {
let htmlPath = vscode.Uri.file(`${this.context.asAbsolutePath('src/content.html')}`);
return promisifier.nfcall(fs.readFile, htmlPath.fsPath, 'utf8').then((html) => {
const htmlWithDeps = html.replace('$$GUI_JS_PATH$$', `<script src="file://${this.context.asAbsolutePath('src/gui.js')}"></script>`);
this.htmlCache = htmlWithDeps;
resolve(htmlWithDeps);
this.html = html.replace('$$IMPORT_CSS_SCRIPTS$$', `<link rel="stylesheet" type="text/css" href="file://${this.context.asAbsolutePath('src/style.css')}">`)
.replace('$$IMPORT_JS_SCRIPTS$$', `<script src="file://${this.context.asAbsolutePath('src/gui.js')}"></script>`);
resolve(this.html);
})
.catch(err => {
console.error(err);
reject(err);
});
}
});
};
})
}
onDidChange(fn) {
this.callUpdate = fn;
// return this._onDidChange.event;
get onDidChange() {
return this._onDidChange.event;
}
update(newData) {
if (this.htmlCache) {
this.htmlCache = this.htmlCache.replace('</ul>', `<li>${newData.name}: ${newData.value}</li></ul>`)
// this._onDidChange.fire(previewUri);
this.callUpdate(previewUri);
// vscode.workspace.provideTextDocumentContent(previewUri.scheme);
}
this.html = this.html.replace(tableTag, createTable(newData));
this._onDidChange.fire(previewUri);
}
}
function createTable(...newData) {
// TODO: hardcoded
var tableString = tableTag.replace('</table>', '');
for (let row of newData) {
tableString += "<tr>";
tableString += "<td class='wanted'>" + row.name + "</td>";
tableString += "<td class='wanted'>" + row.value + "</td>";
tableString += "</tr>";
}
tableString += "</table>";
return tableString;
}
module.exports = {
activate
};

Просмотреть файл

@ -1,11 +1,16 @@
console.log('gui.js has been launched.');
start();
function start() {
document.addEventListener('click', function (e) {
if (e.target.classList.contains('wanted')) {
const [name, value] = e.target.textContent.split(':');
const tds = Array.from(e.target.parentElement.getElementsByClassName('td'));
console.log('tr: ' + e.target.parentElement);
console.log('tds: ' + tds);
const [name, value] = [tds[0].textContent, tds[1].textContent];
sendToExtension({ name, value });
}
}
}, false);
}

Просмотреть файл

@ -84,7 +84,7 @@ class Importer {
resolve(mappedSettings);
})
}).catch(e => console.error(e));;
}).catch(e => console.error(e));
}
importGlobalSettings() {
@ -134,7 +134,7 @@ class Importer {
if (!sublimePath) {
return undefined;
}
var settingsPath = path.resolve(sublimePath.fsPath, 'Packages', 'User', 'Preferences.sublime-settings')
var settingsPath = path.resolve(sublimePath.fsPath, 'Packages', 'User', 'Preferences.sublime-settings'); // C:\Users\t-tisali\AppData\Roaming\Sublime Text 3
// TODO: Check if files exists first
return promisifier.nfcall(fs.readFile, settingsPath)

37
src/style.css Normal file
Просмотреть файл

@ -0,0 +1,37 @@
table.greyGridTable {
border: 2px solid #FFFFFF;
width: 100%;
text-align: center;
border-collapse: collapse;
}
table.greyGridTable td, table.greyGridTable th {
border: 1px solid #FFFFFF;
padding: 3px 4px;
}
table.greyGridTable tbody td {
font-size: 13px;
}
table.greyGridTable thead {
background: #FFFFFF;
border-bottom: 4px solid #333333;
}
table.greyGridTable thead th {
font-size: 15px;
font-weight: bold;
color: #333333;
text-align: center;
border-left: 2px solid #333333;
}
table.greyGridTable thead th:first-child {
border-left: none;
}
table.greyGridTable tfoot {
font-size: 14px;
font-weight: bold;
color: #333333;
border-top: 4px solid #333333;
}
table.greyGridTable tfoot td {
font-size: 14px;
}