Skip to content

Commit

Permalink
feat(layout/#592): layout tabs - part 3 - single tab mode (#2032)
Browse files Browse the repository at this point in the history
* add oni.layout.singleTabMode configuration setting

* hide tabs when singleTabMode=true

* replace tabs on open in single tab mode
  • Loading branch information
glennsl authored Jun 28, 2020
1 parent f30baca commit 2470fbe
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Feature/Layout/Configuration.re
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ let layoutTabPosition =
Codec.layoutTabPosition,
~default=`bottom,
);

let singleTabMode = setting("oni.layout.singleTabMode", bool, ~default=false);
13 changes: 12 additions & 1 deletion src/Feature/Layout/Feature_Layout.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ open Oni_Core.Utility;

include Model;

let openEditor = (~config, editor) =>
if (Local.Configuration.singleTabMode.get(config)) {
updateActiveGroup(Group.replaceAllWith(editor));
} else {
updateActiveGroup(Group.openEditor(editor));
};

// UPDATE

open Msg;
Expand Down Expand Up @@ -747,5 +754,9 @@ module Contributions = {
];

let configuration =
Configuration.[showLayoutTabs.spec, layoutTabPosition.spec];
Configuration.[
showLayoutTabs.spec,
layoutTabPosition.spec,
singleTabMode.spec,
];
};
2 changes: 1 addition & 1 deletion src/Feature/Layout/Feature_Layout.rei
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let split: ([ | `Horizontal | `Vertical], model) => model;

let activeEditor: model => Editor.t;

let openEditor: (Editor.t, model) => model;
let openEditor: (~config: Config.resolver, Editor.t, model) => model;
let closeBuffer: (~force: bool, Vim.Types.buffer, model) => option(model);

let addLayoutTab: model => model;
Expand Down
12 changes: 10 additions & 2 deletions src/Feature/Layout/Model.re
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
module Local = {
module Configuration = Configuration;
};
open Oni_Core;
open Utility;
open Feature_Editor;
Expand All @@ -18,6 +21,7 @@ module Group: {
let nextEditor: t => t;
let previousEditor: t => t;
let openEditor: (Editor.t, t) => t;
let replaceAllWith: (Editor.t, t) => t;
let removeEditor: (int, t) => option(t);

let map: (Editor.t => Editor.t, t) => t;
Expand Down Expand Up @@ -92,6 +96,12 @@ module Group: {
};
};

let replaceAllWith = (editor, group) => {
...group,
editors: [editor],
selectedId: Editor.getId(editor),
};

let removeEditor = (editorId, group) => {
switch (List.filter(e => Editor.getId(e) != editorId, group.editors)) {
| [] => None
Expand Down Expand Up @@ -252,8 +262,6 @@ let nextEditor = updateActiveGroup(Group.nextEditor);

let previousEditor = updateActiveGroup(Group.previousEditor);

let openEditor = editor => updateActiveGroup(Group.openEditor(editor));

let removeLayoutTab = (index, model) => {
let left = Base.List.take(model.layouts, index);
let right = Base.List.drop(model.layouts, index + 1);
Expand Down
6 changes: 5 additions & 1 deletion src/Feature/Layout/View.re
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ module EditorGroupView = {
let make =
(
~provider as module ContentModel: ContentModel,
~config,
~showTabs,
~uiFont,
~theme,
Expand All @@ -280,7 +281,7 @@ module EditorGroupView = {
| None => React.empty
};

if (showTabs) {
if (showTabs && !Local.Configuration.singleTabMode.get(config)) {
let editors = model.editors |> List.rev;
let tabs =
<Tabs
Expand Down Expand Up @@ -461,6 +462,7 @@ module Layout = {
(
~provider,
~model as layout,
~config,
~isZenMode,
~showTabs,
~uiFont,
Expand Down Expand Up @@ -494,6 +496,7 @@ module Layout = {
<EditorGroupView
provider
uiFont
config
showTabs
isActive={group.id == layout.activeGroupId}
theme
Expand Down Expand Up @@ -553,6 +556,7 @@ let make =
<Layout
provider
model={activeLayout(model)}
config
isZenMode
showTabs
uiFont
Expand Down
1 change: 1 addition & 0 deletions src/Store/Features.re
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ let update =
...state,
layout:
Feature_Layout.openEditor(
~config=Feature_Configuration.resolver(state.config),
Feature_Editor.Editor.create(
~font=state.editorFont,
~buffer=editorBuffer,
Expand Down

0 comments on commit 2470fbe

Please sign in to comment.