Skip to content

Commit

Permalink
fix(exthost): Support full set of codicons (onivim#1812)
Browse files Browse the repository at this point in the history
* Hook up codicon support for statusbar labels

* Clean-up
  • Loading branch information
bryphe authored May 23, 2020
1 parent 6e4b564 commit f8246e9
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 17 deletions.
2 changes: 1 addition & 1 deletion development_extensions/oni-dev-extension/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function activate(context) {
let item = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 1000);
item.color = new vscode.ThemeColor("foreground");
item.command = "developer.oni.statusBarClicked";
item.text = "Developer";
item.text = "$(wrench) Developer";
item.show();

let cleanup = (disposable) => context.subscriptions.push(disposable);
Expand Down
26 changes: 24 additions & 2 deletions src/Components/Codicon.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
* Helper constants for VSCode's Codicons
*/

let fontFamily = "codicon.ttf";
open Revery.UI;
module ZedBundled = Oni_Core.ZedBundled;

module Constants = {
let fontFamily = "codicon.ttf";
let none = 0x0;
};

let add = 0xea60;
let plus = 0xea60;
Expand Down Expand Up @@ -819,5 +825,21 @@ let stringToGlyph = name =>
| "github-inverted" => githubInverted
| "server-process" => serverProcess
| "server-environment" => serverEnvironment
| _ => 0x0
| _ => Constants.none
};

module Styles = {
open Style;

let text = (~fontSize, ~color) => [
Style.fontFamily(Constants.fontFamily),
Style.fontSize(fontSize),
Style.color(color),
textWrap(Revery.TextWrapping.NoWrap),
];
};

let codeToIcon = icon => ZedBundled.singleton(Uchar.of_int(icon));

let make = (~icon, ~fontSize=15., ~color, ()) =>
<Text text={codeToIcon(icon)} style={Styles.text(~fontSize, ~color)} />;
16 changes: 10 additions & 6 deletions src/UI/Label.re → src/Components/Label.re
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
open Revery;
open Revery.UI;
open Oni_Core;
open Oni_Components;

module Styles = {
open Style;
Expand All @@ -23,13 +22,18 @@ let textToElement = (~color, ~font, ~text) => {
<Text style={Styles.text(~color, font)} text />;
};

let iconNameToCharacter =
fun
| "alert" => Some(FontAwesome.exclamationTriangle)
| _ => None;
let iconNameToCharacter = name => {
let iconCode = name |> Codicon.stringToGlyph;

if (iconCode == Codicon.Constants.none) {
None;
} else {
Some(iconCode);
};
};

let iconToElement = (~color, icon) => {
<View style=Style.[margin(4)]> <FontIcon icon color /> </View>;
<View style=Style.[margin(4)]> <Codicon icon color /> </View>;
};

let make = (~font, ~color, ~label: Exthost.Label.t, ()) => {
Expand Down
1 change: 1 addition & 0 deletions src/Components/dune
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
lwt.unix
Oni2.core
Oni2.input
Oni2.exthost
Oni2.service.font
Oni2.feature.theme
Rench
Expand Down
1 change: 1 addition & 0 deletions src/UI/StatusBar.re
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module ContextMenu = Oni_Components.ContextMenu;
module CustomHooks = Oni_Components.CustomHooks;
module FontAwesome = Oni_Components.FontAwesome;
module FontIcon = Oni_Components.FontIcon;
module Label = Oni_Components.Label;
module Diagnostics = Feature_LanguageSupport.Diagnostics;
module Diagnostic = Feature_LanguageSupport.Diagnostic;
module Editor = Feature_Editor.Editor;
Expand Down
12 changes: 4 additions & 8 deletions src/UI/Titlebar.re
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,8 @@ module Windows = {
onMouseUp
onMouseEnter={_ => setHovered(_ => true)}
onMouseLeave={_ => setHovered(_ => false)}>
<FontIcon
<Codicon
icon=Codicon.chromeClose
fontFamily=Codicon.fontFamily
color={Colors.activeForeground.from(theme)}
fontSize=14.
/>
Expand Down Expand Up @@ -183,15 +182,13 @@ module Windows = {
onMouseEnter={_ => setHovered(_ => true)}
onMouseLeave={_ => setHovered(_ => false)}>
{windowDisplayMode == Model.State.Maximized
? <FontIcon
? <Codicon
icon=Codicon.chromeRestore
fontFamily=Codicon.fontFamily
color={Colors.activeForeground.from(theme)}
fontSize=14.
/>
: <FontIcon
: <Codicon
icon=Codicon.chromeMaximize
fontFamily=Codicon.fontFamily
color={Colors.activeForeground.from(theme)}
fontSize=14.
/>}
Expand All @@ -217,9 +214,8 @@ module Windows = {
onMouseUp
onMouseEnter={_ => setHovered(_ => true)}
onMouseLeave={_ => setHovered(_ => false)}>
<FontIcon
<Codicon
icon=Codicon.chromeMinimize
fontFamily=Codicon.fontFamily
color={Colors.activeForeground.from(theme)}
fontSize=14.
/>
Expand Down

0 comments on commit f8246e9

Please sign in to comment.