From cd08482d9ac23c63d6764c50f0cb272d25a522a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Henriques?= Date: Fri, 9 Apr 2021 20:29:20 +0100 Subject: [PATCH 01/15] feat(ux): Configurable mode indicator (#2496) --- docs/docs/configuration/settings.md | 2 ++ src/Core/ConfigurationDefaults.re | 1 + src/Feature/StatusBar/Feature_StatusBar.re | 29 ++++++++++++++++++--- src/Feature/StatusBar/Feature_StatusBar.rei | 6 ++++- src/UI/Root.re | 3 +++ 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/docs/docs/configuration/settings.md b/docs/docs/configuration/settings.md index 16f7af9ec5..4d9a7f99ef 100644 --- a/docs/docs/configuration/settings.md +++ b/docs/docs/configuration/settings.md @@ -146,6 +146,8 @@ The configuration file, `configuration.json` is in the Oni2 directory, whose loc - `workbench.statusBar.visible` __(_bool_ default: `true`)__ - Controls the visibility of the status bar. +- `workbench.statusBar.modeIndicator` __(_"left"|"right"|"none"_ default: `right`)__ - Controls the position of the mode indicator. + - `window.menuBarVisibility` __(_"visible" | "hidden"_ default: `"visible"`)__ - Controls the visibility of the menu bar. - `oni.layout.showLayoutTabs` __(_"always"|"smart"|"never"_ default: `"smart"`)__ - Controls the display of layout tabs. `"smart"` will only show the tabs if there's more than one. diff --git a/src/Core/ConfigurationDefaults.re b/src/Core/ConfigurationDefaults.re index 8ee04db60a..0906a9e46a 100644 --- a/src/Core/ConfigurationDefaults.re +++ b/src/Core/ConfigurationDefaults.re @@ -36,6 +36,7 @@ let getDefaultConfigString = configName => "workbench.sideBar.location": "left", "workbench.sideBar.visible": true, "workbench.statusBar.visible": true, + "workbench.statusBar.modeIndicator": "left", "workbench.tree.indent": 2, "vim.useSystemClipboard": ["yank"] } diff --git a/src/Feature/StatusBar/Feature_StatusBar.re b/src/Feature/StatusBar/Feature_StatusBar.re index 5472c62acb..bbc1042f24 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.re +++ b/src/Feature/StatusBar/Feature_StatusBar.re @@ -392,6 +392,7 @@ module View = { ~theme, ~dispatch, ~workingDirectory: string, + ~modeIndicator: string, (), ) => { let activeNotifications = Feature_Notification.active(notifications); @@ -557,7 +558,27 @@ module View = { |> Option.map(register => ) |> Option.value(~default=React.empty); + let modeIndicatorStart = + switch (modeIndicator) { + | "left" => +
+ +
+ | _ => React.empty + }; + + let modeIndicatorEnd = + switch (modeIndicator) { + | "left" + | "none" => React.empty + | _ => +
+ +
+ }; + + modeIndicatorStart
-
- -
+ modeIndicatorEnd ; }; }; @@ -595,8 +614,10 @@ module View = { module Configuration = { open Config.Schema; let visible = setting("workbench.statusBar.visible", bool, ~default=true); + let modeIndicator = + setting("workbench.statusBar.modeIndicator", string, ~default="rigth"); }; module Contributions = { - let configuration = Configuration.[visible.spec]; + let configuration = Configuration.[visible.spec, modeIndicator.spec]; }; diff --git a/src/Feature/StatusBar/Feature_StatusBar.rei b/src/Feature/StatusBar/Feature_StatusBar.rei index 76620038e6..7a4c37ea8c 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.rei +++ b/src/Feature/StatusBar/Feature_StatusBar.rei @@ -61,6 +61,7 @@ module View: { ~theme: ColorTheme.Colors.t, ~dispatch: msg => unit, ~workingDirectory: string, + ~modeIndicator: string, unit ) => Revery.UI.element; @@ -68,7 +69,10 @@ module View: { // CONFIGURATION -module Configuration: {let visible: Config.Schema.setting(bool);}; +module Configuration: { + let visible: Config.Schema.setting(bool); + let modeIndicator: Config.Schema.setting(string); +}; // CONTRIBUTIONS diff --git a/src/UI/Root.re b/src/UI/Root.re index f4bdffb099..47db8df932 100644 --- a/src/UI/Root.re +++ b/src/UI/Root.re @@ -107,6 +107,9 @@ let make = (~dispatch, ~state: State.t, ()) => { workingDirectory={Feature_Workspace.workingDirectory( state.workspace, )} + modeIndicator={ + Feature_StatusBar.Configuration.modeIndicator.get(config) + } /> ; } else { From 21a2c5d53ccb171e7931d29a56dd447161bb679f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Henriques?= Date: Sat, 10 Apr 2021 23:56:13 +0100 Subject: [PATCH 02/15] Started work --- docs/docs/configuration/settings.md | 29 +++- src/Core/ConfigurationDefaults.re | 4 +- src/Feature/StatusBar/Feature_StatusBar.re | 140 ++++++++++++++------ src/Feature/StatusBar/Feature_StatusBar.rei | 8 +- src/UI/Root.re | 8 +- 5 files changed, 137 insertions(+), 52 deletions(-) diff --git a/docs/docs/configuration/settings.md b/docs/docs/configuration/settings.md index 4d9a7f99ef..f37bfc5e2e 100644 --- a/docs/docs/configuration/settings.md +++ b/docs/docs/configuration/settings.md @@ -144,10 +144,6 @@ The configuration file, `configuration.json` is in the Oni2 directory, whose loc - `workbench.sideBar.visible` __(_bool_ default: `true`)__ - Controls the visibility of the sidebar. -- `workbench.statusBar.visible` __(_bool_ default: `true`)__ - Controls the visibility of the status bar. - -- `workbench.statusBar.modeIndicator` __(_"left"|"right"|"none"_ default: `right`)__ - Controls the position of the mode indicator. - - `window.menuBarVisibility` __(_"visible" | "hidden"_ default: `"visible"`)__ - Controls the visibility of the menu bar. - `oni.layout.showLayoutTabs` __(_"always"|"smart"|"never"_ default: `"smart"`)__ - Controls the display of layout tabs. `"smart"` will only show the tabs if there's more than one. @@ -156,6 +152,31 @@ The configuration file, `configuration.json` is in the Oni2 directory, whose loc - `oni.layout.singleTabMode` __(_bool_ default: `false`)__ - When `true`, groups will only hold a single editor, and closing this editor will always close the group. It will also hide the editor tabs, and therefore essentially hide the concept of editor groups. +- `workbench.statusBar.visible` __(_bool_ default: `true`)__ - Controls the visibility of the status bar. + +- `workbench.statusBar.items.start` __(_[items]_ default: `["notificationCount"]`)__ - Defines the first group of items that appear. + +- `workbench.statusBar.items.notification.start` __(_[items]_ default: `["macro", "leftItems", "diagnosticCount", "git"]`)__ - Defines the group of items that appears after the right after `...items.start` group, these items are hidden by a notification message. + +- `workbench.statusBar.items.notification.center` __(_[items]_ default: `[]`)__ - Defines the group of items that appears after the `...items.notification.start` group, but these are centered, these items are hidden by a notification message. + +- `workbench.statusBar.items.notification.end` __(_[items]_ default: `["rightItems", "lineEndings", "indentation", "fileType", "position"]`)__ - Defines the group of items that appears before the `items.end` group, these items are hidden by a notification message. + +- `workbench.statusBar.items.end` __(_[items]_ default: `["modeIndicator"]`)__ - Defines the group of items that appears at the end of the status bar, these items are hidden by a notification message. + +- `workbench.statusBar.items.end` __(_[items]_ default: `["modeIndicator"]`)__ - Defines the group of items that appears at the end of the status bar, these items are hidden by a notification message. + - _"notificationCount"_ - Notification Count icon and counter + - _"macro"_ - The vim macro indicator + - _"leftItems/rightItems"_ - Items that generated based on other factors, like extensions + - _"diagnosticCount"_ - Problem icon and counter + - _"git"_ - Source control information + - _"lineEndings"_ - Line endings information + - _"indentation"_ - Indentation information + - _"fileType"_ - File type information + - _"position"_ - Position information + - _"modeIndicator"_ - Vim mode indicator + - _"..."_ - The rest of the items in that group, as by the default, that are not defined in other groups + ### Rendering - `vsync` __(_bool_ default: `false`)__ - Whether rendering should sync with vertical retrace of the monitor. VSync adds input latency, as rendering must sync with the refresh rate of the monitor, but it reduces screen tearing. diff --git a/src/Core/ConfigurationDefaults.re b/src/Core/ConfigurationDefaults.re index 0906a9e46a..641e7e6a19 100644 --- a/src/Core/ConfigurationDefaults.re +++ b/src/Core/ConfigurationDefaults.re @@ -36,7 +36,9 @@ let getDefaultConfigString = configName => "workbench.sideBar.location": "left", "workbench.sideBar.visible": true, "workbench.statusBar.visible": true, - "workbench.statusBar.modeIndicator": "left", + "workbench.statusBar.items.start": ["notificationCount", "macro", "leftItems", "diagnosticCount", "git"], + "workbench.statusBar.items.hideOnNotification": ["macro", "leftItems", "diagnosticCount", "git", "rightItems", "lineEndings", "indentation", "fileType", "position"], + "workbench.statusBar.items.end": ["rightItems", "lineEndings", "indentation", "fileType", "position", "modeIndicator"], "workbench.tree.indent": 2, "vim.useSystemClipboard": ["yank"] } diff --git a/src/Feature/StatusBar/Feature_StatusBar.re b/src/Feature/StatusBar/Feature_StatusBar.re index bbc1042f24..0e8d7774ad 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.re +++ b/src/Feature/StatusBar/Feature_StatusBar.re @@ -194,7 +194,8 @@ module Styles = { transform(Transform.[TranslateY(yOffset)]), ]; - let sectionGroup = [ + let sectionGroup = background => [ + backgroundColor(background), position(`Relative), flexDirection(`Row), justifyContent(`SpaceBetween), @@ -232,8 +233,7 @@ let positionToString = ) | None => ""; -let sectionGroup = (~children, ()) => - children ; +let sectionGroup = (~style, ~children, ()) => children ; let section = (~children=React.empty, ~align, ()) => children ; @@ -392,7 +392,9 @@ module View = { ~theme, ~dispatch, ~workingDirectory: string, - ~modeIndicator: string, + ~startItems: list(string), + ~hideOnNotification: list(string), + ~endItems: list(string), (), ) => { let activeNotifications = Feature_Notification.active(notifications); @@ -558,28 +560,43 @@ module View = { |> Option.map(register => ) |> Option.value(~default=React.empty); - let modeIndicatorStart = - switch (modeIndicator) { - | "left" => -
- -
- | _ => React.empty + let allItems = + List.concat([ + startItems, + endItems, + ]) + |> List.filter(a => a != "..."); + + let itemsTextMapper = (def, str) => + switch (str) { + | "..." => def + | str => [str] }; - let modeIndicatorEnd = - switch (modeIndicator) { - | "left" - | "none" => React.empty - | _ => -
- -
- }; + let def = ["macro", "leftItems", "diagnosticCount", "git", "rightItems", "lineEndings", "indentation", "fileType", "position"] |> List.filter(a => !List.exists(b => a == b, hideOnNotification)); + let hideOnNotification = hideOnNotification |> List.map(str => + switch (str) { + | "..." => def + | str => [str] + }) |> List.concat; + + let def = ["notificationCount", "macro", "leftItems", "diagnosticCount", "git"] |> List.filter(a => !List.exists(b => a == b, allItems)); + let startItems = startItems |> List.map(itemsTextMapper(def)) |> List.concat; + + let def = ["rightItems", "lineEndings", "indentation", "fileType", "position", "modeIndicator"] |> List.filter(a => !List.exists(b => a == b, allItems)); + let endItems = endItems |> List.map(itemsTextMapper(def)) |> List.concat; + + let notificationItemsStart = startItems |> List.filter(a => List.exists(b => a == b, hideOnNotification)) + let startItems = startItems |> List.filter(a => !List.exists(b => a == b, hideOnNotification)) + + let notificationItemsEnd = endItems |> List.filter(a => List.exists(b => a == b, hideOnNotification)) + let endItems = endItems |> List.filter(a => !List.exists(b => a == b, hideOnNotification)) - - modeIndicatorStart -
+ + let fieldMaper = str => + switch (str) { + | "modeIndicator" => + | "notificationCount" => -
- -
macroElement
-
leftItems
-
- - scmItems -
-
-
rightItems
-
- - - - -
+ | "diagnosticCount" => + + | "lineEndings" => + | "indentation" => + | "fileType" => + | "position" => + | "macro" => macroElement + | "leftItems" => leftItems + | "git" => scmItems + | "rightItems" => rightItems + | _ => React.empty + }; + + let startItems = + startItems |> List.map(fieldMaper) |> React.listToElement; + let notificationItemsStart = + notificationItemsStart |> List.map(fieldMaper) |> React.listToElement; + let notificationItemsEnd = + notificationItemsEnd |> List.map(fieldMaper) |> React.listToElement; + let endItems = endItems |> List.map(fieldMaper) |> React.listToElement; + + +
startItems
+ +
notificationItemsStart
+
notificationItemsEnd
- modeIndicatorEnd +
endItems
; }; }; @@ -614,10 +646,32 @@ module View = { module Configuration = { open Config.Schema; let visible = setting("workbench.statusBar.visible", bool, ~default=true); - let modeIndicator = - setting("workbench.statusBar.modeIndicator", string, ~default="rigth"); + let startItems = + setting( + "workbench.statusBar.items.start", + list(string), + ~default=["..."], + ); + let endItems = + setting( + "workbench.statusBar.items.end", + list(string), + ~default=["..."], + ); + let hideOnNotification = + setting( + "workbench.statusBar.items.hideOnNotification", + list(string), + ~default=["..."], + ); }; module Contributions = { - let configuration = Configuration.[visible.spec, modeIndicator.spec]; + let configuration = + Configuration.[ + visible.spec, + startItems.spec, + hideOnNotification.spec, + endItems.spec, + ]; }; diff --git a/src/Feature/StatusBar/Feature_StatusBar.rei b/src/Feature/StatusBar/Feature_StatusBar.rei index 7a4c37ea8c..52d7a98108 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.rei +++ b/src/Feature/StatusBar/Feature_StatusBar.rei @@ -61,7 +61,9 @@ module View: { ~theme: ColorTheme.Colors.t, ~dispatch: msg => unit, ~workingDirectory: string, - ~modeIndicator: string, + ~startItems: list(string), + ~hideOnNotification: list(string), + ~endItems: list(string), unit ) => Revery.UI.element; @@ -71,7 +73,9 @@ module View: { module Configuration: { let visible: Config.Schema.setting(bool); - let modeIndicator: Config.Schema.setting(string); + let startItems: Config.Schema.setting(list(string)); + let hideOnNotification: Config.Schema.setting(list(string)); + let endItems: Config.Schema.setting(list(string)); }; // CONTRIBUTIONS diff --git a/src/UI/Root.re b/src/UI/Root.re index 47db8df932..b67c7ffca2 100644 --- a/src/UI/Root.re +++ b/src/UI/Root.re @@ -107,8 +107,12 @@ let make = (~dispatch, ~state: State.t, ()) => { workingDirectory={Feature_Workspace.workingDirectory( state.workspace, )} - modeIndicator={ - Feature_StatusBar.Configuration.modeIndicator.get(config) + startItems={Feature_StatusBar.Configuration.startItems.get(config)} + endItems={Feature_StatusBar.Configuration.endItems.get(config)} + hideOnNotification={ + Feature_StatusBar.Configuration.hideOnNotification.get( + config, + ) } /> ; From 775b3e8a6324884cb09a1ccbe8772dbda8bcd00e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Henriques?= Date: Sun, 11 Apr 2021 10:24:06 +0100 Subject: [PATCH 03/15] Update settings.md, ConfigurationDefaults.re, and 3 more files... --- docs/docs/configuration/settings.md | 8 +------- src/Core/ConfigurationDefaults.re | 2 +- src/Feature/StatusBar/Feature_StatusBar.re | 22 ++++++++++----------- src/Feature/StatusBar/Feature_StatusBar.rei | 4 ++-- src/UI/Root.re | 4 ++-- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/docs/docs/configuration/settings.md b/docs/docs/configuration/settings.md index f37bfc5e2e..1afdb74554 100644 --- a/docs/docs/configuration/settings.md +++ b/docs/docs/configuration/settings.md @@ -156,13 +156,7 @@ The configuration file, `configuration.json` is in the Oni2 directory, whose loc - `workbench.statusBar.items.start` __(_[items]_ default: `["notificationCount"]`)__ - Defines the first group of items that appear. -- `workbench.statusBar.items.notification.start` __(_[items]_ default: `["macro", "leftItems", "diagnosticCount", "git"]`)__ - Defines the group of items that appears after the right after `...items.start` group, these items are hidden by a notification message. - -- `workbench.statusBar.items.notification.center` __(_[items]_ default: `[]`)__ - Defines the group of items that appears after the `...items.notification.start` group, but these are centered, these items are hidden by a notification message. - -- `workbench.statusBar.items.notification.end` __(_[items]_ default: `["rightItems", "lineEndings", "indentation", "fileType", "position"]`)__ - Defines the group of items that appears before the `items.end` group, these items are hidden by a notification message. - -- `workbench.statusBar.items.end` __(_[items]_ default: `["modeIndicator"]`)__ - Defines the group of items that appears at the end of the status bar, these items are hidden by a notification message. +- `workbench.statusBar.items.showOnNotification` __(_[items]_ default: `["notificationCount", "modeIndicator"]`)__ - Defines the group of items that are hiden by the notification popup text. - `workbench.statusBar.items.end` __(_[items]_ default: `["modeIndicator"]`)__ - Defines the group of items that appears at the end of the status bar, these items are hidden by a notification message. - _"notificationCount"_ - Notification Count icon and counter diff --git a/src/Core/ConfigurationDefaults.re b/src/Core/ConfigurationDefaults.re index 641e7e6a19..5b45e22b62 100644 --- a/src/Core/ConfigurationDefaults.re +++ b/src/Core/ConfigurationDefaults.re @@ -37,7 +37,7 @@ let getDefaultConfigString = configName => "workbench.sideBar.visible": true, "workbench.statusBar.visible": true, "workbench.statusBar.items.start": ["notificationCount", "macro", "leftItems", "diagnosticCount", "git"], - "workbench.statusBar.items.hideOnNotification": ["macro", "leftItems", "diagnosticCount", "git", "rightItems", "lineEndings", "indentation", "fileType", "position"], + "workbench.statusBar.items.showOnNotification": ["modeIndicator", "notificationCount"], "workbench.statusBar.items.end": ["rightItems", "lineEndings", "indentation", "fileType", "position", "modeIndicator"], "workbench.tree.indent": 2, "vim.useSystemClipboard": ["yank"] diff --git a/src/Feature/StatusBar/Feature_StatusBar.re b/src/Feature/StatusBar/Feature_StatusBar.re index 0e8d7774ad..ad452a4471 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.re +++ b/src/Feature/StatusBar/Feature_StatusBar.re @@ -393,7 +393,7 @@ module View = { ~dispatch, ~workingDirectory: string, ~startItems: list(string), - ~hideOnNotification: list(string), + ~showOnNotification: list(string), ~endItems: list(string), (), ) => { @@ -573,8 +573,8 @@ module View = { | str => [str] }; - let def = ["macro", "leftItems", "diagnosticCount", "git", "rightItems", "lineEndings", "indentation", "fileType", "position"] |> List.filter(a => !List.exists(b => a == b, hideOnNotification)); - let hideOnNotification = hideOnNotification |> List.map(str => + let def = ["notificationCount", "modeIndicator"]; + let showOnNotification = showOnNotification |> List.map(str => switch (str) { | "..." => def | str => [str] @@ -586,11 +586,11 @@ module View = { let def = ["rightItems", "lineEndings", "indentation", "fileType", "position", "modeIndicator"] |> List.filter(a => !List.exists(b => a == b, allItems)); let endItems = endItems |> List.map(itemsTextMapper(def)) |> List.concat; - let notificationItemsStart = startItems |> List.filter(a => List.exists(b => a == b, hideOnNotification)) - let startItems = startItems |> List.filter(a => !List.exists(b => a == b, hideOnNotification)) + let notificationItemsStart = startItems |> List.filter(a => !List.exists(b => a == b, showOnNotification)) + let startItems = startItems |> List.filter(a => List.exists(b => a == b, showOnNotification)) - let notificationItemsEnd = endItems |> List.filter(a => List.exists(b => a == b, hideOnNotification)) - let endItems = endItems |> List.filter(a => !List.exists(b => a == b, hideOnNotification)) + let notificationItemsEnd = endItems |> List.filter(a => !List.exists(b => a == b, showOnNotification)) + let endItems = endItems |> List.filter(a => List.exists(b => a == b, showOnNotification)) let fieldMaper = str => @@ -658,11 +658,11 @@ module Configuration = { list(string), ~default=["..."], ); - let hideOnNotification = + let showOnNotification = setting( - "workbench.statusBar.items.hideOnNotification", + "workbench.statusBar.items.showOnNotification", list(string), - ~default=["..."], + ~default=["notificationCount", "modeIndicator"], ); }; @@ -671,7 +671,7 @@ module Contributions = { Configuration.[ visible.spec, startItems.spec, - hideOnNotification.spec, + showOnNotification.spec, endItems.spec, ]; }; diff --git a/src/Feature/StatusBar/Feature_StatusBar.rei b/src/Feature/StatusBar/Feature_StatusBar.rei index 52d7a98108..1b63786d9a 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.rei +++ b/src/Feature/StatusBar/Feature_StatusBar.rei @@ -62,7 +62,7 @@ module View: { ~dispatch: msg => unit, ~workingDirectory: string, ~startItems: list(string), - ~hideOnNotification: list(string), + ~showOnNotification: list(string), ~endItems: list(string), unit ) => @@ -74,7 +74,7 @@ module View: { module Configuration: { let visible: Config.Schema.setting(bool); let startItems: Config.Schema.setting(list(string)); - let hideOnNotification: Config.Schema.setting(list(string)); + let showOnNotification: Config.Schema.setting(list(string)); let endItems: Config.Schema.setting(list(string)); }; diff --git a/src/UI/Root.re b/src/UI/Root.re index b67c7ffca2..a1ccfade44 100644 --- a/src/UI/Root.re +++ b/src/UI/Root.re @@ -109,8 +109,8 @@ let make = (~dispatch, ~state: State.t, ()) => { )} startItems={Feature_StatusBar.Configuration.startItems.get(config)} endItems={Feature_StatusBar.Configuration.endItems.get(config)} - hideOnNotification={ - Feature_StatusBar.Configuration.hideOnNotification.get( + showOnNotification={ + Feature_StatusBar.Configuration.showOnNotification.get( config, ) } From 91793e17dbfc1b76bc126b9594af52c607434a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Henriques?= Date: Sun, 11 Apr 2021 11:56:29 +0100 Subject: [PATCH 04/15] Formated --- src/Feature/StatusBar/Feature_StatusBar.re | 57 ++++++++++++++-------- src/UI/Root.re | 4 +- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/Feature/StatusBar/Feature_StatusBar.re b/src/Feature/StatusBar/Feature_StatusBar.re index ad452a4471..8f4fd362c0 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.re +++ b/src/Feature/StatusBar/Feature_StatusBar.re @@ -561,11 +561,7 @@ module View = { |> Option.value(~default=React.empty); let allItems = - List.concat([ - startItems, - endItems, - ]) - |> List.filter(a => a != "..."); + List.concat([startItems, endItems]) |> List.filter(a => a != "..."); let itemsTextMapper = (def, str) => switch (str) { @@ -574,24 +570,47 @@ module View = { }; let def = ["notificationCount", "modeIndicator"]; - let showOnNotification = showOnNotification |> List.map(str => - switch (str) { - | "..." => def - | str => [str] - }) |> List.concat; - - let def = ["notificationCount", "macro", "leftItems", "diagnosticCount", "git"] |> List.filter(a => !List.exists(b => a == b, allItems)); - let startItems = startItems |> List.map(itemsTextMapper(def)) |> List.concat; + let showOnNotification = + showOnNotification + |> List.map(str => + switch (str) { + | "..." => def + | str => [str] + } + ) + |> List.concat; - let def = ["rightItems", "lineEndings", "indentation", "fileType", "position", "modeIndicator"] |> List.filter(a => !List.exists(b => a == b, allItems)); + let def = + ["notificationCount", "macro", "leftItems", "diagnosticCount", "git"] + |> List.filter(a => !List.exists(b => a == b, allItems)); + let startItems = + startItems |> List.map(itemsTextMapper(def)) |> List.concat; + + let def = + [ + "rightItems", + "lineEndings", + "indentation", + "fileType", + "position", + "modeIndicator", + ] + |> List.filter(a => !List.exists(b => a == b, allItems)); let endItems = endItems |> List.map(itemsTextMapper(def)) |> List.concat; - let notificationItemsStart = startItems |> List.filter(a => !List.exists(b => a == b, showOnNotification)) - let startItems = startItems |> List.filter(a => List.exists(b => a == b, showOnNotification)) - - let notificationItemsEnd = endItems |> List.filter(a => !List.exists(b => a == b, showOnNotification)) - let endItems = endItems |> List.filter(a => List.exists(b => a == b, showOnNotification)) + let notificationItemsStart = + startItems + |> List.filter(a => !List.exists(b => a == b, showOnNotification)); + let startItems = + startItems + |> List.filter(a => List.exists(b => a == b, showOnNotification)); + let notificationItemsEnd = + endItems + |> List.filter(a => !List.exists(b => a == b, showOnNotification)); + let endItems = + endItems + |> List.filter(a => List.exists(b => a == b, showOnNotification)); let fieldMaper = str => switch (str) { diff --git a/src/UI/Root.re b/src/UI/Root.re index a1ccfade44..223df772d8 100644 --- a/src/UI/Root.re +++ b/src/UI/Root.re @@ -110,9 +110,7 @@ let make = (~dispatch, ~state: State.t, ()) => { startItems={Feature_StatusBar.Configuration.startItems.get(config)} endItems={Feature_StatusBar.Configuration.endItems.get(config)} showOnNotification={ - Feature_StatusBar.Configuration.showOnNotification.get( - config, - ) + Feature_StatusBar.Configuration.showOnNotification.get(config) } /> ; From 42dd87d49fb8cf8a9d7290dde7ac79d92b9b2dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Henriques?= Date: Sun, 11 Apr 2021 20:31:09 +0100 Subject: [PATCH 05/15] Added possible extencion control(need testing), changed configuration for object --- src/Core/ConfigurationDefaults.re | 8 +- src/Feature/StatusBar/Feature_StatusBar.re | 134 ++++++++++++-------- src/Feature/StatusBar/Feature_StatusBar.rei | 15 ++- src/UI/Root.re | 6 +- 4 files changed, 99 insertions(+), 64 deletions(-) diff --git a/src/Core/ConfigurationDefaults.re b/src/Core/ConfigurationDefaults.re index 5b45e22b62..2ecddd6fe2 100644 --- a/src/Core/ConfigurationDefaults.re +++ b/src/Core/ConfigurationDefaults.re @@ -36,9 +36,11 @@ let getDefaultConfigString = configName => "workbench.sideBar.location": "left", "workbench.sideBar.visible": true, "workbench.statusBar.visible": true, - "workbench.statusBar.items.start": ["notificationCount", "macro", "leftItems", "diagnosticCount", "git"], - "workbench.statusBar.items.showOnNotification": ["modeIndicator", "notificationCount"], - "workbench.statusBar.items.end": ["rightItems", "lineEndings", "indentation", "fileType", "position", "modeIndicator"], + "workbench.statusBar.items": { + "start": ["notificationCount", "macro", "leftItems", "diagnosticCount", "git"], + "showOnNotification": ["modeIndicator", "notificationCount"], + "end": ["rightItems", "lineEndings", "indentation", "fileType", "position", "modeIndicator"], + }, "workbench.tree.indent": 2, "vim.useSystemClipboard": ["yank"] } diff --git a/src/Feature/StatusBar/Feature_StatusBar.re b/src/Feature/StatusBar/Feature_StatusBar.re index 8f4fd362c0..d18c464112 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.re +++ b/src/Feature/StatusBar/Feature_StatusBar.re @@ -40,6 +40,41 @@ module Item = { }; }; +module ConfigurationItems = { + [@deriving show] + type t = { + startItems: list(string), + endItems: list(string), + showOnNotification: list(string), + }; + + let decode = + Json.Decode.( + obj(({field, _}) => + { + startItems: field.withDefault("start", ["..."], list(string)), + endItems: field.withDefault("end", ["..."], list(string)), + showOnNotification: + field.withDefault("showOnNotification", ["..."], list(string)), + } + ) + ); + + let encode = configurationItems => + Json.Encode.( + obj([ + ("start", configurationItems.startItems |> list(string)), + ( + "showOnNotification", + configurationItems.showOnNotification |> list(string), + ), + ("end", configurationItems.endItems |> list(string)), + ]) + ); + + let codec = Config.Schema.DSL.custom(~decode, ~encode); +}; + // MSG [@deriving show] @@ -392,11 +427,13 @@ module View = { ~theme, ~dispatch, ~workingDirectory: string, - ~startItems: list(string), - ~showOnNotification: list(string), - ~endItems: list(string), + ~items: ConfigurationItems.t, (), ) => { + let startItems = items.startItems; + let endItems = items.endItems; + let showOnNotification = items.showOnNotification; + let activeNotifications = Feature_Notification.active(notifications); let background = Feature_Notification.statusBarBackground(~theme, notifications); @@ -443,21 +480,6 @@ module View = { viewOrTooltip ; }; - let leftItems = - statusBar.items - |> List.filter((item: Item.t) => item.alignment == Left) - |> List.map( - ({command, label, color, tooltip, backgroundColor, _}: Item.t) => - toStatusBarElement( - ~command?, - ~backgroundColor?, - ~color?, - ~tooltip?, - label, - ) - ) - |> React.listToElement; - let scmItems = scm |> Feature_SCM.statusBarCommands(~workingDirectory) @@ -470,14 +492,6 @@ module View = { ) |> React.listToElement; - let rightItems = - statusBar.items - |> List.filter((item: Item.t) => item.alignment == Right) - |> List.map(({command, label, color, tooltip, _}: Item.t) => - toStatusBarElement(~command?, ~color?, ~tooltip?, label) - ) - |> React.listToElement; - let indentation = () => { let text = indentationSettings |> indentationToString; @@ -569,6 +583,34 @@ module View = { | str => [str] }; + let rightItems = + statusBar.items + |> List.filter((item: Item.t) => + item.alignment == Right + && !List.exists(s => s == item.id, allItems) + ) + |> List.map(({command, label, color, tooltip, _}: Item.t) => + toStatusBarElement(~command?, ~color?, ~tooltip?, label) + ) + |> React.listToElement; + + let leftItems = + statusBar.items + |> List.filter((item: Item.t) => + item.alignment == Left && !List.exists(s => s == item.id, allItems) + ) + |> List.map( + ({command, label, color, tooltip, backgroundColor, _}: Item.t) => + toStatusBarElement( + ~command?, + ~backgroundColor?, + ~color?, + ~tooltip?, + label, + ) + ) + |> React.listToElement; + let def = ["notificationCount", "modeIndicator"]; let showOnNotification = showOnNotification @@ -634,7 +676,13 @@ module View = { | "leftItems" => leftItems | "git" => scmItems | "rightItems" => rightItems - | _ => React.empty + | str => + statusBar.items + |> List.filter((item: Item.t) => item.id == str) + |> List.map(({command, label, color, tooltip, _}: Item.t) => + toStatusBarElement(~command?, ~color?, ~tooltip?, label) + ) + |> React.listToElement }; let startItems = @@ -665,32 +713,18 @@ module View = { module Configuration = { open Config.Schema; let visible = setting("workbench.statusBar.visible", bool, ~default=true); - let startItems = - setting( - "workbench.statusBar.items.start", - list(string), - ~default=["..."], - ); - let endItems = - setting( - "workbench.statusBar.items.end", - list(string), - ~default=["..."], - ); - let showOnNotification = + let items = setting( - "workbench.statusBar.items.showOnNotification", - list(string), - ~default=["notificationCount", "modeIndicator"], + "workbench.statusBar.items", + ConfigurationItems.codec, + ~default={ + startItems: ["..."], + endItems: ["..."], + showOnNotification: ["..."], + }, ); }; module Contributions = { - let configuration = - Configuration.[ - visible.spec, - startItems.spec, - showOnNotification.spec, - endItems.spec, - ]; + let configuration = Configuration.[visible.spec, items.spec]; }; diff --git a/src/Feature/StatusBar/Feature_StatusBar.rei b/src/Feature/StatusBar/Feature_StatusBar.rei index 1b63786d9a..fc6adc10a8 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.rei +++ b/src/Feature/StatusBar/Feature_StatusBar.rei @@ -17,6 +17,13 @@ module Item: { t; }; +module ConfigurationItems: { + type t = { + startItems: list(string), + endItems: list(string), + showOnNotification: list(string), + }; +}; // MODEL [@deriving show] @@ -61,9 +68,7 @@ module View: { ~theme: ColorTheme.Colors.t, ~dispatch: msg => unit, ~workingDirectory: string, - ~startItems: list(string), - ~showOnNotification: list(string), - ~endItems: list(string), + ~items: ConfigurationItems.t, unit ) => Revery.UI.element; @@ -73,9 +78,7 @@ module View: { module Configuration: { let visible: Config.Schema.setting(bool); - let startItems: Config.Schema.setting(list(string)); - let showOnNotification: Config.Schema.setting(list(string)); - let endItems: Config.Schema.setting(list(string)); + let items: Config.Schema.setting(ConfigurationItems.t); }; // CONTRIBUTIONS diff --git a/src/UI/Root.re b/src/UI/Root.re index 223df772d8..dce4732263 100644 --- a/src/UI/Root.re +++ b/src/UI/Root.re @@ -107,11 +107,7 @@ let make = (~dispatch, ~state: State.t, ()) => { workingDirectory={Feature_Workspace.workingDirectory( state.workspace, )} - startItems={Feature_StatusBar.Configuration.startItems.get(config)} - endItems={Feature_StatusBar.Configuration.endItems.get(config)} - showOnNotification={ - Feature_StatusBar.Configuration.showOnNotification.get(config) - } + items={Feature_StatusBar.Configuration.items.get(config)} /> ; } else { From cb9822c8800b751965f95f6de07570653b9241a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Henriques?= Date: Mon, 12 Apr 2021 13:36:39 +0100 Subject: [PATCH 06/15] Notification now works on It self without moving items around --- .../Notification/Feature_Notification.re | 12 +- .../Notification/Feature_Notification.rei | 1 + src/Feature/StatusBar/Feature_StatusBar.re | 148 +++++++++--------- 3 files changed, 83 insertions(+), 78 deletions(-) diff --git a/src/Feature/Notification/Feature_Notification.re b/src/Feature/Notification/Feature_Notification.re index 70b1fb0581..e2b89de6a6 100644 --- a/src/Feature/Notification/Feature_Notification.re +++ b/src/Feature/Notification/Feature_Notification.re @@ -436,6 +436,7 @@ module View = { ~background, ~foreground, ~font: UiFont.t, + ~onlyAnimation: bool, (), ) => { let yOffset = model.yOffset; @@ -455,7 +456,16 @@ module View = { />; | None => React.empty }; - + + onlyAnimation ? + + + : diff --git a/src/Feature/Notification/Feature_Notification.rei b/src/Feature/Notification/Feature_Notification.rei index eb77b683f5..9576d8b237 100644 --- a/src/Feature/Notification/Feature_Notification.rei +++ b/src/Feature/Notification/Feature_Notification.rei @@ -99,6 +99,7 @@ module View: { ~background: Color.t, ~foreground: Color.t, ~font: UiFont.t, + ~onlyAnimation: bool, unit ) => React.element(React.node); diff --git a/src/Feature/StatusBar/Feature_StatusBar.re b/src/Feature/StatusBar/Feature_StatusBar.re index d18c464112..fd9afd5d04 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.re +++ b/src/Feature/StatusBar/Feature_StatusBar.re @@ -55,7 +55,7 @@ module ConfigurationItems = { startItems: field.withDefault("start", ["..."], list(string)), endItems: field.withDefault("end", ["..."], list(string)), showOnNotification: - field.withDefault("showOnNotification", ["..."], list(string)), + field.withDefault("showOnNotification", [ "notificationCount", "modeIndicator" ], list(string)), } ) ); @@ -229,8 +229,7 @@ module Styles = { transform(Transform.[TranslateY(yOffset)]), ]; - let sectionGroup = background => [ - backgroundColor(background), + let sectionGroup = () => [ position(`Relative), flexDirection(`Row), justifyContent(`SpaceBetween), @@ -268,7 +267,7 @@ let positionToString = ) | None => ""; -let sectionGroup = (~style, ~children, ()) => children ; +let sectionGroup = (~children, ()) => children ; let section = (~children=React.empty, ~align, ()) => children ; @@ -430,6 +429,7 @@ module View = { ~items: ConfigurationItems.t, (), ) => { + let startItems = items.startItems; let endItems = items.endItems; let showOnNotification = items.showOnNotification; @@ -561,11 +561,11 @@ module View = { ; }; - let notificationPopups = () => + let notificationPopups = (~onlyAnimation, ()) => activeNotifications |> List.rev |> List.map(model => - + ) |> React.listToElement; @@ -577,18 +577,18 @@ module View = { let allItems = List.concat([startItems, endItems]) |> List.filter(a => a != "..."); - let itemsTextMapper = (def, str) => + let itemsPreProcess = (def, list) => list |> List.map( str => switch (str) { | "..." => def | str => [str] - }; + }) |> List.flatten |> + List.map(str => (str, !List.mem(str, showOnNotification))); + + let removeFromList = (listToRemove, list) => list |> List.filter(a => !List.mem(a, listToRemove)); let rightItems = statusBar.items - |> List.filter((item: Item.t) => - item.alignment == Right - && !List.exists(s => s == item.id, allItems) - ) + |> List.filter((item: Item.t) => item.alignment == Right && !List.mem(item.id, allItems)) |> List.map(({command, label, color, tooltip, _}: Item.t) => toStatusBarElement(~command?, ~color?, ~tooltip?, label) ) @@ -596,66 +596,54 @@ module View = { let leftItems = statusBar.items - |> List.filter((item: Item.t) => - item.alignment == Left && !List.exists(s => s == item.id, allItems) - ) + |> List.filter((item: Item.t) => item.alignment == Left && !List.mem(item.id, allItems)) |> List.map( ({command, label, color, tooltip, backgroundColor, _}: Item.t) => toStatusBarElement( ~command?, - ~backgroundColor?, - ~color?, + ~backgroundColor?, ~color?, ~tooltip?, label, ) ) |> React.listToElement; - let def = ["notificationCount", "modeIndicator"]; - let showOnNotification = - showOnNotification - |> List.map(str => - switch (str) { - | "..." => def - | str => [str] - } - ) - |> List.concat; - - let def = - ["notificationCount", "macro", "leftItems", "diagnosticCount", "git"] - |> List.filter(a => !List.exists(b => a == b, allItems)); - let startItems = - startItems |> List.map(itemsTextMapper(def)) |> List.concat; - - let def = - [ - "rightItems", - "lineEndings", - "indentation", - "fileType", - "position", - "modeIndicator", - ] - |> List.filter(a => !List.exists(b => a == b, allItems)); - let endItems = endItems |> List.map(itemsTextMapper(def)) |> List.concat; - - let notificationItemsStart = - startItems - |> List.filter(a => !List.exists(b => a == b, showOnNotification)); - let startItems = - startItems - |> List.filter(a => List.exists(b => a == b, showOnNotification)); - - let notificationItemsEnd = - endItems - |> List.filter(a => !List.exists(b => a == b, showOnNotification)); - let endItems = - endItems - |> List.filter(a => List.exists(b => a == b, showOnNotification)); - - let fieldMaper = str => - switch (str) { + + let startItems = startItems |> itemsPreProcess([ + "notificationCount", + "macro", + "leftItems", + "diagnosticCount", + "git", + "notificationPopup" + ] |> removeFromList(allItems)); + + let endItems = endItems |> itemsPreProcess([ + "rightItems", + "lineEndings", + "indentation", + "fileType", + "position", + "modeIndicator", + ] |> removeFromList(allItems)); + + let itemsToElement = list => list |> + //List (item) -> List ((List ( item name ), notificaion)) + List.fold_left((a, item) => { + let (toAdd, notificationToAdd) = item; + let (head, notification) = a |> List.hd; + + switch (notificationToAdd == notification) { + | true => List.append([(List.append(head, [toAdd]),notification)], a |> List.tl) + | false => List.append([([toAdd], notificationToAdd)],a) + } + }, [([], false)]) |> + + //List ((List ( item name ), notificaion)) -> List(elements) + List.rev_map(item => { + let (list, noti) = item; + let onlyAnimation = !List.mem("notificationPopup", list) + let list = list |> List.map(str => switch str { | "modeIndicator" => | "notificationCount" => React.listToElement - }; - - let startItems = - startItems |> List.map(fieldMaper) |> React.listToElement; - let notificationItemsStart = - notificationItemsStart |> List.map(fieldMaper) |> React.listToElement; - let notificationItemsEnd = - notificationItemsEnd |> List.map(fieldMaper) |> React.listToElement; - let endItems = endItems |> List.map(fieldMaper) |> React.listToElement; + }) |> React.listToElement + if (noti) { + +
+ {list} +
+ +
+ } else { + list + } + }) + |> React.listToElement; + + let startItems = startItems |> itemsToElement; + let endItems = endItems |> itemsToElement; + let center = List.mem("center", showOnNotification) ? React.empty : ;
startItems
- -
notificationItemsStart
-
notificationItemsEnd
- -
+
+ center +
endItems
; }; @@ -720,7 +714,7 @@ module Configuration = { ~default={ startItems: ["..."], endItems: ["..."], - showOnNotification: ["..."], + showOnNotification: [ "notificationCount", "modeIndicator" ], }, ); }; From 745c3f8c8b1a9fe6af931a4f7d97c005be2d7260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Henriques?= Date: Mon, 12 Apr 2021 14:09:22 +0100 Subject: [PATCH 07/15] Refactoring --- .../Notification/Feature_Notification.re | 40 +-- src/Feature/StatusBar/Feature_StatusBar.re | 261 ++++++++++-------- 2 files changed, 170 insertions(+), 131 deletions(-) diff --git a/src/Feature/Notification/Feature_Notification.re b/src/Feature/Notification/Feature_Notification.re index e2b89de6a6..6826cb9d7a 100644 --- a/src/Feature/Notification/Feature_Notification.re +++ b/src/Feature/Notification/Feature_Notification.re @@ -456,26 +456,26 @@ module View = { />; | None => React.empty }; - - onlyAnimation ? - - - : - - - - - ; + + onlyAnimation + ? + + + : + + + + ; }; }; diff --git a/src/Feature/StatusBar/Feature_StatusBar.re b/src/Feature/StatusBar/Feature_StatusBar.re index fd9afd5d04..c71d0376d7 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.re +++ b/src/Feature/StatusBar/Feature_StatusBar.re @@ -55,7 +55,11 @@ module ConfigurationItems = { startItems: field.withDefault("start", ["..."], list(string)), endItems: field.withDefault("end", ["..."], list(string)), showOnNotification: - field.withDefault("showOnNotification", [ "notificationCount", "modeIndicator" ], list(string)), + field.withDefault( + "showOnNotification", + ["notificationCount", "modeIndicator"], + list(string), + ), } ) ); @@ -73,6 +77,78 @@ module ConfigurationItems = { ); let codec = Config.Schema.DSL.custom(~decode, ~encode); + + let startItemsDef = [ + "notificationCount", + "macro", + "leftItems", + "diagnosticCount", + "git", + "notificationPopup", + ]; + + let endItemsDef = [ + "rightItems", + "lineEndings", + "indentation", + "fileType", + "position", + "modeIndicator", + ]; + + let preProcess = (t, statusBarItems) => { + //Helper funcions + let removeFromList = (listToRemove, list) => + list |> List.filter(a => !List.mem(a, listToRemove)); + + let process = (def, list) => + list + //List (srt) -> List ((str, notificaion)) + |> List.map(str => + switch (str) { + | "..." => def + | str => [str] + } + ) + |> List.flatten + |> List.map(str => (str, !List.mem(str, t.showOnNotification))) + //List ((str, notificaion)) -> List (list(str), notificaion) + |> List.fold_left( + (a, item) => { + let (toAdd, notificationToAdd) = item; + let (head, notification) = a |> List.hd; + + notificationToAdd == notification + ? List.append( + [(List.append(head, [toAdd]), notification)], + a |> List.tl, + ) + : List.append([([toAdd], notificationToAdd)], a); + }, + [([], false)], + ); + + let allItems = + List.concat([t.startItems, t.endItems]) |> List.filter(a => a != "..."); + + let startItemsDef = startItemsDef |> removeFromList(allItems); + + let endItemsDef = endItemsDef |> removeFromList(allItems); + + let getItemsFromAlign = align => + statusBarItems + |> List.filter((item: Item.t) => + item.alignment == align && !List.mem(item.id, allItems) + ); + + ( + process(startItemsDef, t.startItems), + process(endItemsDef, t.endItems), + List.mem("center", t.showOnNotification), + getItemsFromAlign(Right), + getItemsFromAlign(Left), + ); + }; }; // MSG @@ -429,11 +505,6 @@ module View = { ~items: ConfigurationItems.t, (), ) => { - - let startItems = items.startItems; - let endItems = items.endItems; - let showOnNotification = items.showOnNotification; - let activeNotifications = Feature_Notification.active(notifications); let background = Feature_Notification.statusBarBackground(~theme, notifications); @@ -565,7 +636,13 @@ module View = { activeNotifications |> List.rev |> List.map(model => - + ) |> React.listToElement; @@ -574,120 +651,84 @@ module View = { |> Option.map(register => ) |> Option.value(~default=React.empty); - let allItems = - List.concat([startItems, endItems]) |> List.filter(a => a != "..."); - - let itemsPreProcess = (def, list) => list |> List.map( str => - switch (str) { - | "..." => def - | str => [str] - }) |> List.flatten |> - List.map(str => (str, !List.mem(str, showOnNotification))); - - let removeFromList = (listToRemove, list) => list |> List.filter(a => !List.mem(a, listToRemove)); + let (startItems, endItems, center, rightItems, leftItems) = + ConfigurationItems.preProcess(items, statusBar.items); let rightItems = - statusBar.items - |> List.filter((item: Item.t) => item.alignment == Right && !List.mem(item.id, allItems)) + rightItems |> List.map(({command, label, color, tooltip, _}: Item.t) => toStatusBarElement(~command?, ~color?, ~tooltip?, label) ) |> React.listToElement; let leftItems = - statusBar.items - |> List.filter((item: Item.t) => item.alignment == Left && !List.mem(item.id, allItems)) - |> List.map( - ({command, label, color, tooltip, backgroundColor, _}: Item.t) => - toStatusBarElement( - ~command?, - ~backgroundColor?, ~color?, - ~tooltip?, - label, - ) + leftItems + |> List.map(({command, label, color, tooltip, _}: Item.t) => + toStatusBarElement(~command?, ~color?, ~tooltip?, label) ) |> React.listToElement; - - let startItems = startItems |> itemsPreProcess([ - "notificationCount", - "macro", - "leftItems", - "diagnosticCount", - "git", - "notificationPopup" - ] |> removeFromList(allItems)); - - let endItems = endItems |> itemsPreProcess([ - "rightItems", - "lineEndings", - "indentation", - "fileType", - "position", - "modeIndicator", - ] |> removeFromList(allItems)); - - let itemsToElement = list => list |> - //List (item) -> List ((List ( item name ), notificaion)) - List.fold_left((a, item) => { - let (toAdd, notificationToAdd) = item; - let (head, notification) = a |> List.hd; - - switch (notificationToAdd == notification) { - | true => List.append([(List.append(head, [toAdd]),notification)], a |> List.tl) - | false => List.append([([toAdd], notificationToAdd)],a) - } - }, [([], false)]) |> - - //List ((List ( item name ), notificaion)) -> List(elements) - List.rev_map(item => { - let (list, noti) = item; - let onlyAnimation = !List.mem("notificationPopup", list) - let list = list |> List.map(str => switch str { - | "modeIndicator" => - | "notificationCount" => - - | "diagnosticCount" => - - | "lineEndings" => - | "indentation" => - | "fileType" => - | "position" => - | "macro" => macroElement - | "leftItems" => leftItems - | "git" => scmItems - | "rightItems" => rightItems - | str => - statusBar.items - |> List.filter((item: Item.t) => item.id == str) - |> List.map(({command, label, color, tooltip, _}: Item.t) => - toStatusBarElement(~command?, ~color?, ~tooltip?, label) - ) - |> React.listToElement - }) |> React.listToElement - if (noti) { - -
- {list} -
- -
- } else { - list - } - }) - |> React.listToElement; + let itemsToElement = list => + list + |> List.rev_map(item => { + let (list, noti) = item; + let onlyAnimation = !List.mem("notificationPopup", list); + let list = + list + |> List.map(str => + switch (str) { + | "modeIndicator" => + + | "notificationCount" => + + | "diagnosticCount" => + + | "lineEndings" => + | "indentation" => + | "fileType" => + | "position" => + | "macro" => macroElement + | "leftItems" => leftItems + | "git" => scmItems + | "rightItems" => rightItems + | str => + statusBar.items + |> List.filter((item: Item.t) => item.id == str) + |> List.map( + ({command, label, color, tooltip, _}: Item.t) => + toStatusBarElement( + ~command?, + ~color?, + ~tooltip?, + label, + ) + ) + |> React.listToElement + } + ) + |> React.listToElement; + if (noti) { + +
list
+ +
; + } else { + list; + }; + }) + |> React.listToElement; let startItems = startItems |> itemsToElement; let endItems = endItems |> itemsToElement; - let center = List.mem("center", showOnNotification) ? React.empty : ; + let center = + center ? React.empty : ;
startItems
-
- center -
+
center
endItems
; }; @@ -714,7 +753,7 @@ module Configuration = { ~default={ startItems: ["..."], endItems: ["..."], - showOnNotification: [ "notificationCount", "modeIndicator" ], + showOnNotification: ["notificationCount", "modeIndicator"], }, ); }; From b3e5bac9ea9e466f04e6b9ddc32a19369d5c8fae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Henriques?= Date: Mon, 12 Apr 2021 14:24:39 +0100 Subject: [PATCH 08/15] Changed extencion items detection from id to id || command --- src/Feature/StatusBar/Feature_StatusBar.re | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Feature/StatusBar/Feature_StatusBar.re b/src/Feature/StatusBar/Feature_StatusBar.re index c71d0376d7..52f5444bdc 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.re +++ b/src/Feature/StatusBar/Feature_StatusBar.re @@ -138,7 +138,16 @@ module ConfigurationItems = { let getItemsFromAlign = align => statusBarItems |> List.filter((item: Item.t) => - item.alignment == align && !List.mem(item.id, allItems) + item.alignment == align + && !( + ( + switch (item.command) { + | Some(command) => List.mem(command, allItems) + | None => false + } + ) + || List.mem(item.id, allItems) + ) ); ( @@ -700,7 +709,15 @@ module View = { | "rightItems" => rightItems | str => statusBar.items - |> List.filter((item: Item.t) => item.id == str) + |> List.filter((item: Item.t) => + ( + switch (item.command) { + | Some(command) => command == str + | None => false + } + ) + || item.id == str + ) |> List.map( ({command, label, color, tooltip, _}: Item.t) => toStatusBarElement( From 203c4ecfbe9e21c71513d3943f3a6618eb95f993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Henriques?= Date: Tue, 13 Apr 2021 00:09:38 +0100 Subject: [PATCH 09/15] Started working on the 1st to items of the list --- src/Core/ConfigurationDefaults.re | 4 +- src/Feature/StatusBar/Feature_StatusBar.re | 67 ++++++++++++++------- src/Feature/StatusBar/Feature_StatusBar.rei | 4 +- 3 files changed, 49 insertions(+), 26 deletions(-) diff --git a/src/Core/ConfigurationDefaults.re b/src/Core/ConfigurationDefaults.re index 2ecddd6fe2..81e7dc0287 100644 --- a/src/Core/ConfigurationDefaults.re +++ b/src/Core/ConfigurationDefaults.re @@ -37,9 +37,9 @@ let getDefaultConfigString = configName => "workbench.sideBar.visible": true, "workbench.statusBar.visible": true, "workbench.statusBar.items": { - "start": ["notificationCount", "macro", "leftItems", "diagnosticCount", "git"], + "left": ["notificationCount", "macro", "leftItems", "diagnosticCount", "git"], "showOnNotification": ["modeIndicator", "notificationCount"], - "end": ["rightItems", "lineEndings", "indentation", "fileType", "position", "modeIndicator"], + "rigth": ["rightItems", "lineEndings", "indentation", "fileType", "position", "modeIndicator"], }, "workbench.tree.indent": 2, "vim.useSystemClipboard": ["yank"] diff --git a/src/Feature/StatusBar/Feature_StatusBar.re b/src/Feature/StatusBar/Feature_StatusBar.re index 52f5444bdc..44dc3877c5 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.re +++ b/src/Feature/StatusBar/Feature_StatusBar.re @@ -43,8 +43,8 @@ module Item = { module ConfigurationItems = { [@deriving show] type t = { - startItems: list(string), - endItems: list(string), + leftItems: list(string), + rightItems: list(string), showOnNotification: list(string), }; @@ -52,8 +52,8 @@ module ConfigurationItems = { Json.Decode.( obj(({field, _}) => { - startItems: field.withDefault("start", ["..."], list(string)), - endItems: field.withDefault("end", ["..."], list(string)), + leftItems: field.withDefault("left", ["..."], list(string)), + rightItems: field.withDefault("right", ["..."], list(string)), showOnNotification: field.withDefault( "showOnNotification", @@ -67,18 +67,18 @@ module ConfigurationItems = { let encode = configurationItems => Json.Encode.( obj([ - ("start", configurationItems.startItems |> list(string)), + ("right", configurationItems.rightItems |> list(string)), ( "showOnNotification", configurationItems.showOnNotification |> list(string), ), - ("end", configurationItems.endItems |> list(string)), + ("left", configurationItems.leftItems |> list(string)), ]) ); let codec = Config.Schema.DSL.custom(~decode, ~encode); - let startItemsDef = [ + let leftItemsDef = [ "notificationCount", "macro", "leftItems", @@ -87,7 +87,7 @@ module ConfigurationItems = { "notificationPopup", ]; - let endItemsDef = [ + let rightItemsDef = [ "rightItems", "lineEndings", "indentation", @@ -96,6 +96,8 @@ module ConfigurationItems = { "modeIndicator", ]; + let extendItem = "..."; + let preProcess = (t, statusBarItems) => { //Helper funcions let removeFromList = (listToRemove, list) => @@ -105,10 +107,11 @@ module ConfigurationItems = { list //List (srt) -> List ((str, notificaion)) |> List.map(str => - switch (str) { - | "..." => def - | str => [str] - } + if (str == extendItem) { + def + } else { + [str] + } ) |> List.flatten |> List.map(str => (str, !List.mem(str, t.showOnNotification))) @@ -128,12 +131,32 @@ module ConfigurationItems = { [([], false)], ); - let allItems = - List.concat([t.startItems, t.endItems]) |> List.filter(a => a != "..."); - - let startItemsDef = startItemsDef |> removeFromList(allItems); - - let endItemsDef = endItemsDef |> removeFromList(allItems); + let allItems = (t.rightItems @ t.leftItems) |> List.filter(a => a != extendItem); + + //Get if `...` if its, on the rigth and left + let extendRight = List.mem(extendItem, t.rightItems) + let extendLeft = List.mem(extendItem, t.leftItems) + + /* + if x has `...` and !x doesn't then add them all + else if x can extended then do + else then no default + */ + let leftItemsPDef = (if (extendLeft && !extendRight) { + leftItemsDef @ rightItemsDef + } else if (extendLeft) { + leftItemsDef + } else { + [] + }) |> removeFromList(allItems); + + let rightItemsPDef = (if (extendRight && !extendLeft) { + leftItemsDef @ rightItemsDef + } else if (extendRight) { + rightItemsDef + } else { + [] + }) |> removeFromList(allItems); let getItemsFromAlign = align => statusBarItems @@ -151,8 +174,8 @@ module ConfigurationItems = { ); ( - process(startItemsDef, t.startItems), - process(endItemsDef, t.endItems), + process(leftItemsPDef, t.leftItems), + process(rightItemsPDef, t.rightItems), List.mem("center", t.showOnNotification), getItemsFromAlign(Right), getItemsFromAlign(Left), @@ -768,8 +791,8 @@ module Configuration = { "workbench.statusBar.items", ConfigurationItems.codec, ~default={ - startItems: ["..."], - endItems: ["..."], + rightItems: ["..."], + leftItems: ["..."], showOnNotification: ["notificationCount", "modeIndicator"], }, ); diff --git a/src/Feature/StatusBar/Feature_StatusBar.rei b/src/Feature/StatusBar/Feature_StatusBar.rei index fc6adc10a8..73047794df 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.rei +++ b/src/Feature/StatusBar/Feature_StatusBar.rei @@ -19,8 +19,8 @@ module Item: { module ConfigurationItems: { type t = { - startItems: list(string), - endItems: list(string), + leftItems: list(string), + rightItems: list(string), showOnNotification: list(string), }; }; From 600c48a0ad48737e5ca4d361abacbddbbfd8e3b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Henriques?= Date: Tue, 13 Apr 2021 11:19:28 +0100 Subject: [PATCH 10/15] Added "compact" mode for notifications --- src/Core/ConfigurationDefaults.re | 1 + .../Notification/Feature_Notification.re | 27 ++-- .../Notification/Feature_Notification.rei | 1 + src/Feature/StatusBar/Feature_StatusBar.re | 151 ++++++++++++------ src/Feature/StatusBar/Feature_StatusBar.rei | 2 + 5 files changed, 120 insertions(+), 62 deletions(-) diff --git a/src/Core/ConfigurationDefaults.re b/src/Core/ConfigurationDefaults.re index 81e7dc0287..402c963396 100644 --- a/src/Core/ConfigurationDefaults.re +++ b/src/Core/ConfigurationDefaults.re @@ -40,6 +40,7 @@ let getDefaultConfigString = configName => "left": ["notificationCount", "macro", "leftItems", "diagnosticCount", "git"], "showOnNotification": ["modeIndicator", "notificationCount"], "rigth": ["rightItems", "lineEndings", "indentation", "fileType", "position", "modeIndicator"], + "hidden": [], }, "workbench.tree.indent": 2, "vim.useSystemClipboard": ["yank"] diff --git a/src/Feature/Notification/Feature_Notification.re b/src/Feature/Notification/Feature_Notification.re index 6826cb9d7a..cc890079ea 100644 --- a/src/Feature/Notification/Feature_Notification.re +++ b/src/Feature/Notification/Feature_Notification.re @@ -415,6 +415,15 @@ module View = { transform(Transform.[TranslateY(yOffset)]), ]; + let containerCompact = (~background, ~yOffset) => [ + position(`Relative), + backgroundColor(background), + flexDirection(`Row), + alignItems(`Center), + paddingHorizontal(10), + transform(Transform.[TranslateY(yOffset)]), + ]; + let text = (~foreground) => [ textWrap(TextWrapping.NoWrap), marginLeft(6), @@ -437,6 +446,7 @@ module View = { ~foreground, ~font: UiFont.t, ~onlyAnimation: bool, + ~compact: bool, (), ) => { let yOffset = model.yOffset; @@ -458,15 +468,14 @@ module View = { }; onlyAnimation - ? - - - : + ? + : React.element(React.node); diff --git a/src/Feature/StatusBar/Feature_StatusBar.re b/src/Feature/StatusBar/Feature_StatusBar.re index 44dc3877c5..1446b10842 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.re +++ b/src/Feature/StatusBar/Feature_StatusBar.re @@ -45,7 +45,9 @@ module ConfigurationItems = { type t = { leftItems: list(string), rightItems: list(string), + hidden: list(string), showOnNotification: list(string), + notificationMode: string, }; let decode = @@ -54,12 +56,16 @@ module ConfigurationItems = { { leftItems: field.withDefault("left", ["..."], list(string)), rightItems: field.withDefault("right", ["..."], list(string)), + + hidden: field.withDefault("hidden", [], list(string)), showOnNotification: field.withDefault( "showOnNotification", ["notificationCount", "modeIndicator"], list(string), ), + notificationMode: + field.withDefault("notificationMode", "default", string), } ) ); @@ -73,6 +79,8 @@ module ConfigurationItems = { configurationItems.showOnNotification |> list(string), ), ("left", configurationItems.leftItems |> list(string)), + ("hidden", configurationItems.hidden |> list(string)), + ("notificationMode", configurationItems.notificationMode |> string), ]) ); @@ -105,17 +113,21 @@ module ConfigurationItems = { let process = (def, list) => list - //List (srt) -> List ((str, notificaion)) |> List.map(str => - if (str == extendItem) { - def - } else { - [str] - } + if (str == extendItem) { + def; + } else { + [str]; + } ) |> List.flatten - |> List.map(str => (str, !List.mem(str, t.showOnNotification))) - //List ((str, notificaion)) -> List (list(str), notificaion) + |> List.map(str => + ( + str, + t.notificationMode == "default" + && !List.mem(str, t.showOnNotification), + ) + ) |> List.fold_left( (a, item) => { let (toAdd, notificationToAdd) = item; @@ -131,32 +143,41 @@ module ConfigurationItems = { [([], false)], ); - let allItems = (t.rightItems @ t.leftItems) |> List.filter(a => a != extendItem); + let allItems = + t.rightItems @ t.leftItems |> List.filter(a => a != extendItem); //Get if `...` if its, on the rigth and left - let extendRight = List.mem(extendItem, t.rightItems) - let extendLeft = List.mem(extendItem, t.leftItems) - + let extendRight = List.mem(extendItem, t.rightItems); + let extendLeft = List.mem(extendItem, t.leftItems); + /* - if x has `...` and !x doesn't then add them all - else if x can extended then do - else then no default - */ - let leftItemsPDef = (if (extendLeft && !extendRight) { - leftItemsDef @ rightItemsDef - } else if (extendLeft) { - leftItemsDef - } else { - [] - }) |> removeFromList(allItems); - - let rightItemsPDef = (if (extendRight && !extendLeft) { - leftItemsDef @ rightItemsDef - } else if (extendRight) { - rightItemsDef - } else { - [] - }) |> removeFromList(allItems); + if x has `...` and !x doesn't then add them all + else if x can extended then do + else then no default + */ + let leftItemsPDef = + ( + if (extendLeft && !extendRight) { + leftItemsDef @ rightItemsDef; + } else if (extendLeft) { + leftItemsDef; + } else { + []; + } + ) + |> removeFromList(allItems @ t.hidden); + + let rightItemsPDef = + ( + if (extendRight && !extendLeft) { + leftItemsDef @ rightItemsDef; + } else if (extendRight) { + rightItemsDef; + } else { + []; + } + ) + |> removeFromList(allItems @ t.hidden); let getItemsFromAlign = align => statusBarItems @@ -165,20 +186,22 @@ module ConfigurationItems = { && !( ( switch (item.command) { - | Some(command) => List.mem(command, allItems) + | Some(command) => List.mem(command, allItems @ t.hidden) | None => false } ) - || List.mem(item.id, allItems) + || List.mem(item.id, allItems @ t.hidden) ) ); ( process(leftItemsPDef, t.leftItems), process(rightItemsPDef, t.rightItems), - List.mem("center", t.showOnNotification), + List.mem("center", t.showOnNotification) + || t.notificationMode != "default", getItemsFromAlign(Right), getItemsFromAlign(Left), + t.notificationMode, ); }; }; @@ -664,28 +687,43 @@ module View = { ; }; - let notificationPopups = (~onlyAnimation, ()) => - activeNotifications - |> List.rev - |> List.map(model => - - ) - |> React.listToElement; - let macroElement = recordingMacro |> Option.map(register => ) |> Option.value(~default=React.empty); - let (startItems, endItems, center, rightItems, leftItems) = + let ( + startItems, + endItems, + center, + rightItems, + leftItems, + notificationMode, + ) = ConfigurationItems.preProcess(items, statusBar.items); + let notificationPopups = (~onlyAnimation, ~compact, ()) => + activeNotifications + |> List.rev + |> ( + list => + ( + notificationMode == "compact+" && list |> List.length > 0 + ? [list |> List.hd] : list + ) + |> List.map(model => + + ) + |> React.listToElement + ); + let rightItems = rightItems |> List.map(({command, label, color, tooltip, _}: Item.t) => @@ -730,16 +768,20 @@ module View = { | "leftItems" => leftItems | "git" => scmItems | "rightItems" => rightItems + | "notificationPopup" => + notificationMode != "default" + ? + : React.empty | str => statusBar.items |> List.filter((item: Item.t) => - ( + item.id == str + || ( switch (item.command) { | Some(command) => command == str | None => false } ) - || item.id == str ) |> List.map( ({command, label, color, tooltip, _}: Item.t) => @@ -757,7 +799,7 @@ module View = { if (noti) {
list
- +
; } else { list; @@ -768,7 +810,8 @@ module View = { let startItems = startItems |> itemsToElement; let endItems = endItems |> itemsToElement; let center = - center ? React.empty : ; + center + ? React.empty : ; Date: Wed, 14 Apr 2021 11:06:08 +0100 Subject: [PATCH 11/15] Fixes and update to the docs --- docs/docs/configuration/settings.md | 32 +++- src/Core/ConfigurationDefaults.re | 4 +- src/Feature/StatusBar/Feature_StatusBar.re | 156 ++++++++++++++------ src/Feature/StatusBar/Feature_StatusBar.rei | 13 +- 4 files changed, 154 insertions(+), 51 deletions(-) diff --git a/docs/docs/configuration/settings.md b/docs/docs/configuration/settings.md index 1afdb74554..b4f339b95a 100644 --- a/docs/docs/configuration/settings.md +++ b/docs/docs/configuration/settings.md @@ -152,13 +152,32 @@ The configuration file, `configuration.json` is in the Oni2 directory, whose loc - `oni.layout.singleTabMode` __(_bool_ default: `false`)__ - When `true`, groups will only hold a single editor, and closing this editor will always close the group. It will also hide the editor tabs, and therefore essentially hide the concept of editor groups. +#### Status Bar + - `workbench.statusBar.visible` __(_bool_ default: `true`)__ - Controls the visibility of the status bar. -- `workbench.statusBar.items.start` __(_[items]_ default: `["notificationCount"]`)__ - Defines the first group of items that appear. +##### Status Bar Items +- `workbench.statusBar.items` - Controls the position and visibility of the individual items on the status bar. + +```JSON + "workbench.statusBar.items": { + "start": ["notificationCount", "macro", "...", "diagnosticCount", "git"], + "end": ["...", "lineEndings", "indentation", "fileType", "position", "modeIndicator"], + "showOnNotification": ["modeIndicator", "notificationCount"], + "hidden": [], + "notificationMode": "default", + } +``` + +- `start` __(_[ __items__ ]_ default: `["notificationCount", "macro", "...", "diagnosticCount", "git"]`)__ - Defines the first group of items that appear. + +- `end` __(_[ __items__ ]_ default: `["...", "lineEndings", "indentation", "fileType", "position", "modeIndicator"]`)__ - Defines the group of items that appears at the end of the status bar. -- `workbench.statusBar.items.showOnNotification` __(_[items]_ default: `["notificationCount", "modeIndicator"]`)__ - Defines the group of items that are hiden by the notification popup text. +- `showOnNotification` __(_[ __items__ ]_ default: `["notificationCount", "modeIndicator"]`)__ - Defines the group of items that are hidden by the notification popup text. Only works on `notificationMode` `default|keepPosition` -- `workbench.statusBar.items.end` __(_[items]_ default: `["modeIndicator"]`)__ - Defines the group of items that appears at the end of the status bar, these items are hidden by a notification message. +- `hidden` __(_[ __items__ ]_ default: `[ ]`)__ - Defines the group of items that are always hiden. + +- Possible __Items__: - _"notificationCount"_ - Notification Count icon and counter - _"macro"_ - The vim macro indicator - _"leftItems/rightItems"_ - Items that generated based on other factors, like extensions @@ -170,6 +189,13 @@ The configuration file, `configuration.json` is in the Oni2 directory, whose loc - _"position"_ - Position information - _"modeIndicator"_ - Vim mode indicator - _"..."_ - The rest of the items in that group, as by the default, that are not defined in other groups + - _Extension Item ID_ - Any known extension item ID can be used to as an item. + +- `notificationMode` __(_"default | keepPosition | compact | compact+"_ default: `[ ]`)__ - Defines how the notification popup. + - _"default"_ - The notification popup hides the __items__ on the `showOnNotification`, and reorganizes the items to be together based on if they are on `showOnNotification`. + - _"keepPosition"_ - The notification popup hides the __items__ on the `showOnNotification`. + - _"compact"_ - The notification popups take the minimum space available, but notifications can stack up on the status bar. + - _"compact+"_ - The same as `compact` but notification popups do not stack up. ### Rendering diff --git a/src/Core/ConfigurationDefaults.re b/src/Core/ConfigurationDefaults.re index 402c963396..d50debceda 100644 --- a/src/Core/ConfigurationDefaults.re +++ b/src/Core/ConfigurationDefaults.re @@ -37,9 +37,9 @@ let getDefaultConfigString = configName => "workbench.sideBar.visible": true, "workbench.statusBar.visible": true, "workbench.statusBar.items": { - "left": ["notificationCount", "macro", "leftItems", "diagnosticCount", "git"], + "start": ["notificationCount", "macro", "...", "diagnosticCount", "git"], "showOnNotification": ["modeIndicator", "notificationCount"], - "rigth": ["rightItems", "lineEndings", "indentation", "fileType", "position", "modeIndicator"], + "end": ["...", "lineEndings", "indentation", "fileType", "position", "modeIndicator"], "hidden": [], }, "workbench.tree.indent": 2, diff --git a/src/Feature/StatusBar/Feature_StatusBar.re b/src/Feature/StatusBar/Feature_StatusBar.re index 1446b10842..623ec9d0aa 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.re +++ b/src/Feature/StatusBar/Feature_StatusBar.re @@ -4,6 +4,8 @@ open Exthost.Msg.StatusBar; // MODEL +module Log = (val Log.withNamespace("TESTE")); + module Item = { [@deriving show] type t = { @@ -41,22 +43,28 @@ module Item = { }; module ConfigurationItems = { + [@deriving show] + type notificationMode = + | Default + | KeepPosition + | Compact + | CompactPlus; + [@deriving show] type t = { - leftItems: list(string), - rightItems: list(string), + startItems: list(string), + endItems: list(string), hidden: list(string), showOnNotification: list(string), - notificationMode: string, + notificationMode, }; let decode = Json.Decode.( obj(({field, _}) => { - leftItems: field.withDefault("left", ["..."], list(string)), - rightItems: field.withDefault("right", ["..."], list(string)), - + startItems: field.withDefault("left", ["..."], list(string)), + endItems: field.withDefault("right", ["..."], list(string)), hidden: field.withDefault("hidden", [], list(string)), showOnNotification: field.withDefault( @@ -65,7 +73,21 @@ module ConfigurationItems = { list(string), ), notificationMode: - field.withDefault("notificationMode", "default", string), + field.withDefault( + "notificationMode", + Default, + string + |> map(String.lowercase_ascii) + |> and_then( + fun + | "default" => succeed(Default) + | "keepposition" => succeed(KeepPosition) + | "compact" => succeed(Compact) + | "compact+" => succeed(CompactPlus) + | invalid => + fail("Invalid notification mode: " ++ invalid), + ), + ), } ) ); @@ -73,14 +95,25 @@ module ConfigurationItems = { let encode = configurationItems => Json.Encode.( obj([ - ("right", configurationItems.rightItems |> list(string)), + ("start", configurationItems.startItems |> list(string)), ( "showOnNotification", configurationItems.showOnNotification |> list(string), ), - ("left", configurationItems.leftItems |> list(string)), + ("end", configurationItems.endItems |> list(string)), ("hidden", configurationItems.hidden |> list(string)), - ("notificationMode", configurationItems.notificationMode |> string), + ( + "notificationMode", + configurationItems.notificationMode + |> ( + fun + | Default => "default" + | Compact => "compact" + | CompactPlus => "compact+" + | KeepPosition => "keepPosition" + ) + |> string, + ), ]) ); @@ -107,11 +140,14 @@ module ConfigurationItems = { let extendItem = "..."; let preProcess = (t, statusBarItems) => { + + Log.error("MODE KEEP:" ++ string_of_bool(t.notificationMode == KeepPosition)) + //Helper funcions let removeFromList = (listToRemove, list) => list |> List.filter(a => !List.mem(a, listToRemove)); - let process = (def, list) => + let process = (def, alignment, list) => list |> List.map(str => if (str == extendItem) { @@ -124,38 +160,63 @@ module ConfigurationItems = { |> List.map(str => ( str, - t.notificationMode == "default" + ( + t.notificationMode == Default + || t.notificationMode == KeepPosition + ) && !List.mem(str, t.showOnNotification), ) ) - |> List.fold_left( + |> (t.notificationMode != Default ? + + List.fold_left( (a, item) => { let (toAdd, notificationToAdd) = item; let (head, notification) = a |> List.hd; notificationToAdd == notification - ? List.append( - [(List.append(head, [toAdd]), notification)], - a |> List.tl, - ) - : List.append([([toAdd], notificationToAdd)], a); + ? [(head @ [toAdd], notification)] @ (a |> List.tl) + : [([toAdd], notificationToAdd)] @ a; }, [([], false)], - ); + ) : + //Merge all Items that are to be hidden notificaion and those that arent into + //separate positions + List.fold_left( + (a, item) => { + let (toAdd, notificationToAdd) = item; + let (head, _) = a |> List.hd; + let (tail, _) = a |> List.tl |> List.hd; + + let isRight = alignment == Right; + + if (isRight) { + !notificationToAdd + ? [(head, true), (tail @ [toAdd], false)] + : [(head @ [toAdd], true), (tail, false)] + } else { + notificationToAdd + ? [(head, false), (tail @ [toAdd], true)] + : [(head @ [toAdd], false), (tail, true)] + } + + }, + [([], false), ([], false)], + )); let allItems = - t.rightItems @ t.leftItems |> List.filter(a => a != extendItem); + t.startItems @ t.endItems |> List.filter(a => a != extendItem); //Get if `...` if its, on the rigth and left - let extendRight = List.mem(extendItem, t.rightItems); - let extendLeft = List.mem(extendItem, t.leftItems); + let extendRight = List.mem(extendItem, t.startItems); + let extendLeft = List.mem(extendItem, t.endItems); /* if x has `...` and !x doesn't then add them all else if x can extended then do else then no default */ - let leftItemsPDef = + let startItemsPDef = ( if (extendLeft && !extendRight) { leftItemsDef @ rightItemsDef; @@ -167,7 +228,7 @@ module ConfigurationItems = { ) |> removeFromList(allItems @ t.hidden); - let rightItemsPDef = + let endItemsPDef = ( if (extendRight && !extendLeft) { leftItemsDef @ rightItemsDef; @@ -195,10 +256,10 @@ module ConfigurationItems = { ); ( - process(leftItemsPDef, t.leftItems), - process(rightItemsPDef, t.rightItems), + process(startItemsPDef, Right, t.startItems), + process(endItemsPDef, Left, t.endItems), List.mem("center", t.showOnNotification) - || t.notificationMode != "default", + || (t.notificationMode != Default && t.notificationMode != KeepPosition), getItemsFromAlign(Right), getItemsFromAlign(Left), t.notificationMode, @@ -360,7 +421,8 @@ module Styles = { transform(Transform.[TranslateY(yOffset)]), ]; - let sectionGroup = () => [ + let sectionGroup = (background) => [ + backgroundColor(background), position(`Relative), flexDirection(`Row), justifyContent(`SpaceBetween), @@ -398,7 +460,7 @@ let positionToString = ) | None => ""; -let sectionGroup = (~children, ()) => children ; +let sectionGroup = (~background, ~children, ()) => children ; let section = (~children=React.empty, ~align, ()) => children ; @@ -539,6 +601,8 @@ let indentationToString = (indentation: IndentationSettings.t) => { }; }; +module Log1 = (val Log.withNamespace("TESTE")); + module View = { let make = ( @@ -567,6 +631,8 @@ module View = { Feature_Notification.statusBarForeground(~theme, notifications); let defaultForeground = Colors.StatusBar.foreground.from(theme); + let defaultBackground = + Feature_Theme.Colors.StatusBar.background.from(theme); let yOffset = 0.; @@ -708,7 +774,7 @@ module View = { |> ( list => ( - notificationMode == "compact+" && list |> List.length > 0 + notificationMode == CompactPlus && list |> List.length > 0 ? [list |> List.hd] : list ) |> List.map(model => @@ -743,6 +809,7 @@ module View = { |> List.rev_map(item => { let (list, noti) = item; let onlyAnimation = !List.mem("notificationPopup", list); + Log1.error("Noti:" ++ string_of_bool(noti)); let list = list |> List.map(str => @@ -769,7 +836,7 @@ module View = { | "git" => scmItems | "rightItems" => rightItems | "notificationPopup" => - notificationMode != "default" + notificationMode != Default ? : React.empty | str => @@ -794,15 +861,18 @@ module View = { ) |> React.listToElement } - ) - |> React.listToElement; - if (noti) { - -
list
+ ) ; + let reactList = list |> React.listToElement; + + if (noti && list |> List.length > 0 ) { + +
reactList
; - } else { - list; + } else { + +
reactList
+
; }; }) |> React.listToElement; @@ -812,11 +882,11 @@ module View = { let center = center ? React.empty : ; - + //Feature_Theme.Colors.StatusBar.background.from(theme)
startItems
@@ -834,11 +904,11 @@ module Configuration = { "workbench.statusBar.items", ConfigurationItems.codec, ~default={ - rightItems: ["..."], - leftItems: ["..."], + startItems: ["..."], + endItems: ["..."], showOnNotification: ["notificationCount", "modeIndicator"], hidden: [], - notificationMode: "default", + notificationMode: Default, }, ); }; diff --git a/src/Feature/StatusBar/Feature_StatusBar.rei b/src/Feature/StatusBar/Feature_StatusBar.rei index c94d5a53ff..7eb1910852 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.rei +++ b/src/Feature/StatusBar/Feature_StatusBar.rei @@ -18,12 +18,19 @@ module Item: { }; module ConfigurationItems: { + + type notificationMode = + | Default + | KeepPosition + | Compact + | CompactPlus; + type t = { - leftItems: list(string), - rightItems: list(string), + startItems: list(string), + endItems: list(string), hidden: list(string), showOnNotification: list(string), - notificationMode: string, + notificationMode: notificationMode, }; }; // MODEL From 6792f0baa3e002b3d47e9a749a5e72b1564d1498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Henriques?= Date: Wed, 14 Apr 2021 11:11:00 +0100 Subject: [PATCH 12/15] Format and removed logs --- src/Feature/StatusBar/Feature_StatusBar.re | 103 ++++++++++---------- src/Feature/StatusBar/Feature_StatusBar.rei | 5 +- 2 files changed, 51 insertions(+), 57 deletions(-) diff --git a/src/Feature/StatusBar/Feature_StatusBar.re b/src/Feature/StatusBar/Feature_StatusBar.re index 623ec9d0aa..e5c591311e 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.re +++ b/src/Feature/StatusBar/Feature_StatusBar.re @@ -4,8 +4,6 @@ open Exthost.Msg.StatusBar; // MODEL -module Log = (val Log.withNamespace("TESTE")); - module Item = { [@deriving show] type t = { @@ -140,9 +138,6 @@ module ConfigurationItems = { let extendItem = "..."; let preProcess = (t, statusBarItems) => { - - Log.error("MODE KEEP:" ++ string_of_bool(t.notificationMode == KeepPosition)) - //Helper funcions let removeFromList = (listToRemove, list) => list |> List.filter(a => !List.mem(a, listToRemove)); @@ -167,42 +162,42 @@ module ConfigurationItems = { && !List.mem(str, t.showOnNotification), ) ) - |> (t.notificationMode != Default ? - - List.fold_left( - (a, item) => { - let (toAdd, notificationToAdd) = item; - let (head, notification) = a |> List.hd; - - notificationToAdd == notification - ? [(head @ [toAdd], notification)] @ (a |> List.tl) - : [([toAdd], notificationToAdd)] @ a; - }, - [([], false)], - ) : - //Merge all Items that are to be hidden notificaion and those that arent into - //separate positions - List.fold_left( - (a, item) => { - let (toAdd, notificationToAdd) = item; - let (head, _) = a |> List.hd; - let (tail, _) = a |> List.tl |> List.hd; - - let isRight = alignment == Right; - - if (isRight) { - !notificationToAdd - ? [(head, true), (tail @ [toAdd], false)] - : [(head @ [toAdd], true), (tail, false)] - } else { - notificationToAdd - ? [(head, false), (tail @ [toAdd], true)] - : [(head @ [toAdd], false), (tail, true)] - } - - }, - [([], false), ([], false)], - )); + |> ( + t.notificationMode != Default + ? List.fold_left( + (a, item) => { + let (toAdd, notificationToAdd) = item; + let (head, notification) = a |> List.hd; + + notificationToAdd == notification + ? [(head @ [toAdd], notification)] @ (a |> List.tl) + : [([toAdd], notificationToAdd)] @ a; + }, + [([], false)], + ) + //Merge all Items that are to be hidden notificaion and those that arent into + //separate positions + : List.fold_left( + (a, item) => { + let (toAdd, notificationToAdd) = item; + let (head, _) = a |> List.hd; + let (tail, _) = a |> List.tl |> List.hd; + + let isRight = alignment == Right; + + if (isRight) { + !notificationToAdd + ? [(head, true), (tail @ [toAdd], false)] + : [(head @ [toAdd], true), (tail, false)]; + } else { + notificationToAdd + ? [(head, false), (tail @ [toAdd], true)] + : [(head @ [toAdd], false), (tail, true)]; + }; + }, + [([], false), ([], false)], + ) + ); let allItems = t.startItems @ t.endItems |> List.filter(a => a != extendItem); @@ -259,7 +254,8 @@ module ConfigurationItems = { process(startItemsPDef, Right, t.startItems), process(endItemsPDef, Left, t.endItems), List.mem("center", t.showOnNotification) - || (t.notificationMode != Default && t.notificationMode != KeepPosition), + || t.notificationMode != Default + && t.notificationMode != KeepPosition, getItemsFromAlign(Right), getItemsFromAlign(Left), t.notificationMode, @@ -421,7 +417,7 @@ module Styles = { transform(Transform.[TranslateY(yOffset)]), ]; - let sectionGroup = (background) => [ + let sectionGroup = background => [ backgroundColor(background), position(`Relative), flexDirection(`Row), @@ -460,7 +456,8 @@ let positionToString = ) | None => ""; -let sectionGroup = (~background, ~children, ()) => children ; +let sectionGroup = (~background, ~children, ()) => + children ; let section = (~children=React.empty, ~align, ()) => children ; @@ -601,8 +598,6 @@ let indentationToString = (indentation: IndentationSettings.t) => { }; }; -module Log1 = (val Log.withNamespace("TESTE")); - module View = { let make = ( @@ -809,7 +804,6 @@ module View = { |> List.rev_map(item => { let (list, noti) = item; let onlyAnimation = !List.mem("notificationPopup", list); - Log1.error("Noti:" ++ string_of_bool(noti)); let list = list |> List.map(str => @@ -861,16 +855,16 @@ module View = { ) |> React.listToElement } - ) ; - let reactList = list |> React.listToElement; + ); + let reactList = list |> React.listToElement; - if (noti && list |> List.length > 0 ) { + if (noti && list |> List.length > 0) {
reactList
; - } else { - + } else { +
reactList
; }; @@ -882,11 +876,12 @@ module View = { let center = center ? React.empty : ; - //Feature_Theme.Colors.StatusBar.background.from(theme) + //Feature_Theme.Colors.StatusBar.background.from(theme)
startItems
diff --git a/src/Feature/StatusBar/Feature_StatusBar.rei b/src/Feature/StatusBar/Feature_StatusBar.rei index 7eb1910852..f6274a97fa 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.rei +++ b/src/Feature/StatusBar/Feature_StatusBar.rei @@ -18,8 +18,7 @@ module Item: { }; module ConfigurationItems: { - - type notificationMode = + type notificationMode = | Default | KeepPosition | Compact @@ -30,7 +29,7 @@ module ConfigurationItems: { endItems: list(string), hidden: list(string), showOnNotification: list(string), - notificationMode: notificationMode, + notificationMode, }; }; // MODEL From 34bd3108a308498b2c219f02e17878512a582286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Henriques?= Date: Wed, 14 Apr 2021 11:50:52 +0100 Subject: [PATCH 13/15] Fixed "left/rigth" to "start/end" --- src/Feature/StatusBar/Feature_StatusBar.re | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Feature/StatusBar/Feature_StatusBar.re b/src/Feature/StatusBar/Feature_StatusBar.re index e5c591311e..b40fc3e45c 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.re +++ b/src/Feature/StatusBar/Feature_StatusBar.re @@ -61,8 +61,8 @@ module ConfigurationItems = { Json.Decode.( obj(({field, _}) => { - startItems: field.withDefault("left", ["..."], list(string)), - endItems: field.withDefault("right", ["..."], list(string)), + startItems: field.withDefault("start", ["..."], list(string)), + endItems: field.withDefault("end", ["..."], list(string)), hidden: field.withDefault("hidden", [], list(string)), showOnNotification: field.withDefault( @@ -117,7 +117,7 @@ module ConfigurationItems = { let codec = Config.Schema.DSL.custom(~decode, ~encode); - let leftItemsDef = [ + let startItemsDef = [ "notificationCount", "macro", "leftItems", @@ -126,7 +126,7 @@ module ConfigurationItems = { "notificationPopup", ]; - let rightItemsDef = [ + let endItemsDef = [ "rightItems", "lineEndings", "indentation", @@ -203,8 +203,8 @@ module ConfigurationItems = { t.startItems @ t.endItems |> List.filter(a => a != extendItem); //Get if `...` if its, on the rigth and left - let extendRight = List.mem(extendItem, t.startItems); - let extendLeft = List.mem(extendItem, t.endItems); + let extendStart = List.mem(extendItem, t.startItems); + let extendEnd = List.mem(extendItem, t.endItems); /* if x has `...` and !x doesn't then add them all @@ -213,10 +213,10 @@ module ConfigurationItems = { */ let startItemsPDef = ( - if (extendLeft && !extendRight) { - leftItemsDef @ rightItemsDef; - } else if (extendLeft) { - leftItemsDef; + if (extendStart && !extendEnd) { + endItemsDef @ startItemsDef; + } else if (extendStart) { + startItemsDef; } else { []; } @@ -225,10 +225,10 @@ module ConfigurationItems = { let endItemsPDef = ( - if (extendRight && !extendLeft) { - leftItemsDef @ rightItemsDef; - } else if (extendRight) { - rightItemsDef; + if (extendEnd && !extendStart) { + startItemsDef @ endItemsDef; + } else if (extendEnd) { + endItemsDef; } else { []; } From 9744bff3eccd1485b3fc77298cf96237fdcdb747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Henriques?= Date: Wed, 14 Apr 2021 12:21:10 +0100 Subject: [PATCH 14/15] Fixed if configuration was alone the text din't appear --- src/Feature/StatusBar/Feature_StatusBar.re | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Feature/StatusBar/Feature_StatusBar.re b/src/Feature/StatusBar/Feature_StatusBar.re index b40fc3e45c..615bc5e8be 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.re +++ b/src/Feature/StatusBar/Feature_StatusBar.re @@ -857,12 +857,18 @@ module View = { } ); let reactList = list |> React.listToElement; - - if (noti && list |> List.length > 0) { + + let count = list |> List.fold_left(((a, b) => b != React.empty ? a + 1 : a), 0); + + if (noti && count > 0) {
reactList
; + } else if (noti) { + + + } else {
reactList
From aa2b3ee5e9e137ecf87d074131885d97d5edb4c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Henriques?= Date: Mon, 12 Jul 2021 13:49:21 +0100 Subject: [PATCH 15/15] Formated --- src/Feature/StatusBar/Feature_StatusBar.re | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Feature/StatusBar/Feature_StatusBar.re b/src/Feature/StatusBar/Feature_StatusBar.re index bf029d6f50..42d224fb79 100644 --- a/src/Feature/StatusBar/Feature_StatusBar.re +++ b/src/Feature/StatusBar/Feature_StatusBar.re @@ -866,9 +866,11 @@ module View = { } ); let reactList = list |> React.listToElement; - - let count = list |> List.fold_left(((a, b) => b != React.empty ? a + 1 : a), 0); - + + let count = + list + |> List.fold_left((a, b) => b != React.empty ? a + 1 : a, 0); + if (noti && count > 0) {
reactList
@@ -876,8 +878,8 @@ module View = {
; } else if (noti) { - - + +
; } else {
reactList