From 9eebf6657f6e62f2118a1fcec3c1fd2edc22c9fd Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Wed, 13 Jan 2016 15:06:25 +0100 Subject: [PATCH] move up octicon logic so that it can be reused in quick open --- build/gulpfile.vscode.js | 2 +- .../browser/ui/octiconLabel/octiconLabel.ts | 31 +++++++++++ .../ui/octiconLabel}/octicons/OSSREADME.json | 0 .../ui/octiconLabel}/octicons/README.md | 0 .../octiconLabel}/octicons/octicons-local.ttf | Bin .../ui/octiconLabel}/octicons/octicons.css | 0 .../ui/octiconLabel}/octicons/octicons.eot | Bin .../ui/octiconLabel}/octicons/octicons.less | 0 .../ui/octiconLabel}/octicons/octicons.scss | 0 .../ui/octiconLabel}/octicons/octicons.svg | 0 .../ui/octiconLabel}/octicons/octicons.ttf | Bin .../ui/octiconLabel}/octicons/octicons.woff | Bin .../octicons/sprockets-octicons.scss | 0 .../browser/parts/statusbar/statusbarPart.ts | 51 ++---------------- src/vs/workbench/browser/workbench.ts | 1 - 15 files changed, 35 insertions(+), 50 deletions(-) create mode 100644 src/vs/base/browser/ui/octiconLabel/octiconLabel.ts rename src/vs/{workbench/browser/media => base/browser/ui/octiconLabel}/octicons/OSSREADME.json (100%) rename src/vs/{workbench/browser/media => base/browser/ui/octiconLabel}/octicons/README.md (100%) rename src/vs/{workbench/browser/media => base/browser/ui/octiconLabel}/octicons/octicons-local.ttf (100%) rename src/vs/{workbench/browser/media => base/browser/ui/octiconLabel}/octicons/octicons.css (100%) rename src/vs/{workbench/browser/media => base/browser/ui/octiconLabel}/octicons/octicons.eot (100%) rename src/vs/{workbench/browser/media => base/browser/ui/octiconLabel}/octicons/octicons.less (100%) rename src/vs/{workbench/browser/media => base/browser/ui/octiconLabel}/octicons/octicons.scss (100%) rename src/vs/{workbench/browser/media => base/browser/ui/octiconLabel}/octicons/octicons.svg (100%) rename src/vs/{workbench/browser/media => base/browser/ui/octiconLabel}/octicons/octicons.ttf (100%) rename src/vs/{workbench/browser/media => base/browser/ui/octiconLabel}/octicons/octicons.woff (100%) rename src/vs/{workbench/browser/media => base/browser/ui/octiconLabel}/octicons/sprockets-octicons.scss (100%) diff --git a/build/gulpfile.vscode.js b/build/gulpfile.vscode.js index f1aad0fb9dc..7b0641b5429 100644 --- a/build/gulpfile.vscode.js +++ b/build/gulpfile.vscode.js @@ -56,11 +56,11 @@ var vscodeResources = [ 'out-build/vs/base/node/{stdForkStart.js,terminateProcess.sh}', 'out-build/vs/base/worker/workerMainCompatibility.html', 'out-build/vs/base/worker/workerMain.{js,js.map}', + 'out-build/vs/base/browser/ui/octiconLabel/octicons/**', 'out-build/vs/editor/css/*.css', 'out-build/vs/languages/typescript/common/lib/lib.{d.ts,es6.d.ts}', 'out-build/vs/languages/markdown/common/*.css', 'out-build/vs/workbench/browser/media/*-theme.css', - 'out-build/vs/workbench/browser/media/octicons/**', 'out-build/vs/workbench/electron-browser/index.html', 'out-build/vs/workbench/electron-main/bootstrap.js', 'out-build/vs/workbench/parts/debug/**/*.json', diff --git a/src/vs/base/browser/ui/octiconLabel/octiconLabel.ts b/src/vs/base/browser/ui/octiconLabel/octiconLabel.ts new file mode 100644 index 00000000000..a1f10bcbd55 --- /dev/null +++ b/src/vs/base/browser/ui/octiconLabel/octiconLabel.ts @@ -0,0 +1,31 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +'use strict'; + + +import 'vs/css!./octicons/octicons'; +import {escape} from 'vs/base/common/strings'; + +export function expand(text: string): string { + return text.replace(/\$\((\w+)\)/g, (match, g1) => { + return ``; + }); +} + +export class OcticonLabel { + + private _container: HTMLElement; + + constructor(container: HTMLElement) { + this._container = container; + } + + set text(text: string) { + let innerHTML = text || ''; + innerHTML = escape(innerHTML); + innerHTML = expand(innerHTML) + this._container.innerHTML = innerHTML; + } +} diff --git a/src/vs/workbench/browser/media/octicons/OSSREADME.json b/src/vs/base/browser/ui/octiconLabel/octicons/OSSREADME.json similarity index 100% rename from src/vs/workbench/browser/media/octicons/OSSREADME.json rename to src/vs/base/browser/ui/octiconLabel/octicons/OSSREADME.json diff --git a/src/vs/workbench/browser/media/octicons/README.md b/src/vs/base/browser/ui/octiconLabel/octicons/README.md similarity index 100% rename from src/vs/workbench/browser/media/octicons/README.md rename to src/vs/base/browser/ui/octiconLabel/octicons/README.md diff --git a/src/vs/workbench/browser/media/octicons/octicons-local.ttf b/src/vs/base/browser/ui/octiconLabel/octicons/octicons-local.ttf similarity index 100% rename from src/vs/workbench/browser/media/octicons/octicons-local.ttf rename to src/vs/base/browser/ui/octiconLabel/octicons/octicons-local.ttf diff --git a/src/vs/workbench/browser/media/octicons/octicons.css b/src/vs/base/browser/ui/octiconLabel/octicons/octicons.css similarity index 100% rename from src/vs/workbench/browser/media/octicons/octicons.css rename to src/vs/base/browser/ui/octiconLabel/octicons/octicons.css diff --git a/src/vs/workbench/browser/media/octicons/octicons.eot b/src/vs/base/browser/ui/octiconLabel/octicons/octicons.eot similarity index 100% rename from src/vs/workbench/browser/media/octicons/octicons.eot rename to src/vs/base/browser/ui/octiconLabel/octicons/octicons.eot diff --git a/src/vs/workbench/browser/media/octicons/octicons.less b/src/vs/base/browser/ui/octiconLabel/octicons/octicons.less similarity index 100% rename from src/vs/workbench/browser/media/octicons/octicons.less rename to src/vs/base/browser/ui/octiconLabel/octicons/octicons.less diff --git a/src/vs/workbench/browser/media/octicons/octicons.scss b/src/vs/base/browser/ui/octiconLabel/octicons/octicons.scss similarity index 100% rename from src/vs/workbench/browser/media/octicons/octicons.scss rename to src/vs/base/browser/ui/octiconLabel/octicons/octicons.scss diff --git a/src/vs/workbench/browser/media/octicons/octicons.svg b/src/vs/base/browser/ui/octiconLabel/octicons/octicons.svg similarity index 100% rename from src/vs/workbench/browser/media/octicons/octicons.svg rename to src/vs/base/browser/ui/octiconLabel/octicons/octicons.svg diff --git a/src/vs/workbench/browser/media/octicons/octicons.ttf b/src/vs/base/browser/ui/octiconLabel/octicons/octicons.ttf similarity index 100% rename from src/vs/workbench/browser/media/octicons/octicons.ttf rename to src/vs/base/browser/ui/octiconLabel/octicons/octicons.ttf diff --git a/src/vs/workbench/browser/media/octicons/octicons.woff b/src/vs/base/browser/ui/octiconLabel/octicons/octicons.woff similarity index 100% rename from src/vs/workbench/browser/media/octicons/octicons.woff rename to src/vs/base/browser/ui/octiconLabel/octicons/octicons.woff diff --git a/src/vs/workbench/browser/media/octicons/sprockets-octicons.scss b/src/vs/base/browser/ui/octiconLabel/octicons/sprockets-octicons.scss similarity index 100% rename from src/vs/workbench/browser/media/octicons/sprockets-octicons.scss rename to src/vs/base/browser/ui/octiconLabel/octicons/sprockets-octicons.scss diff --git a/src/vs/workbench/browser/parts/statusbar/statusbarPart.ts b/src/vs/workbench/browser/parts/statusbar/statusbarPart.ts index 2f4f2007b87..a470452f1f9 100644 --- a/src/vs/workbench/browser/parts/statusbar/statusbarPart.ts +++ b/src/vs/workbench/browser/parts/statusbar/statusbarPart.ts @@ -13,6 +13,7 @@ import {toErrorMessage} from 'vs/base/common/errors'; import {Promise} from 'vs/base/common/winjs.base'; import {disposeAll, IDisposable} from 'vs/base/common/lifecycle'; import {Builder, $} from 'vs/base/browser/builder'; +import {OcticonLabel} from 'vs/base/browser/ui/octiconLabel/octiconLabel'; import {Registry} from 'vs/platform/platform'; import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService'; import {IAction} from 'vs/base/common/actions'; @@ -178,54 +179,8 @@ class StatusBarEntryItem implements IStatusbarItem { textContainer = document.createElement('span'); } - // Text Value with support for icons - // For example: '${zap} Power is ${zap} on' - let textBuffer = ''; - let iconBuffer = ''; - let inPlaceholder = false; - let text = this.entry.text || ''; - for (let i = 0, len = text.length; i < len; i++) { - - // Opening $(... - if (text[i] === '$' && text[i + 1] === '(') { - inPlaceholder = true; - i++; // unread the opening '(' - - continue; - } - - if (inPlaceholder) { - - // Closing ...) - if (text[i] === ')') { - if (textBuffer) { - textContainer.appendChild(document.createTextNode(textBuffer)); - textBuffer = ''; - } - - let iconContainer = document.createElement('span'); - dom.addClass(iconContainer, `octicon octicon-${iconBuffer}`); - textContainer.appendChild(iconContainer); - - iconBuffer = ''; - inPlaceholder = false; - } - - // Icon value - else { - iconBuffer += text[i]; - } - } - - // Any normal text - else { - textBuffer += text[i]; - } - } - - if (textBuffer) { - textContainer.appendChild(document.createTextNode(textBuffer)); - } + // Label + new OcticonLabel(textContainer).text = this.entry.text; // Tooltip if (this.entry.tooltip) { diff --git a/src/vs/workbench/browser/workbench.ts b/src/vs/workbench/browser/workbench.ts index 84892542b87..7ef7e4c4330 100644 --- a/src/vs/workbench/browser/workbench.ts +++ b/src/vs/workbench/browser/workbench.ts @@ -6,7 +6,6 @@ 'use strict'; import 'vs/css!./media/workbench'; -import 'vs/css!./media/octicons/octicons'; import {TPromise, Promise, ValueCallback} from 'vs/base/common/winjs.base'; import types = require('vs/base/common/types'); import {IDisposable, disposeAll} from 'vs/base/common/lifecycle';