-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update model / title * Title parsing * test case * model + tests * Get tests green * Formatting * Add window.title configuration * Stub out more title pieces * Fix build * Wire up titlebar * Start populating some variables * Add workspace model * Update workspace to include rootName, use for title * Formatting * Use setTitle API * Fix warning * Fix warnings * Formatting
- Loading branch information
Showing
13 changed files
with
252 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Title.re | ||
* | ||
* Model for working with the window title | ||
*/ | ||
|
||
open Oni_Core; | ||
|
||
type titleSections = | ||
| Text(string) | ||
| Separator | ||
| Variable(string); | ||
|
||
type t = list(titleSections); | ||
|
||
let regexp = Str.regexp("\\${\\([a-zA-Z0-9]+\\)}"); | ||
|
||
let ofString = str => { | ||
let idx = ref(0); | ||
let len = String.length(str); | ||
let result = ref([]); | ||
while (idx^ < len) { | ||
switch (Str.search_forward(regexp, str, idx^)) { | ||
| exception Not_found => | ||
result := [Text(String.sub(str, idx^, len - idx^)), ...result^]; | ||
idx := len; | ||
| v => | ||
let prev = v - idx^; | ||
|
||
if (prev > 0) { | ||
result := [Text(String.sub(str, idx^, prev)), ...result^]; | ||
}; | ||
|
||
let group = Str.matched_group(1, str); | ||
idx := v + String.length(group) + 3; | ||
if (String.equal(group, "separator")) { | ||
result := [Separator, ...result^]; | ||
} else { | ||
result := [Variable(group), ...result^]; | ||
}; | ||
}; | ||
}; | ||
|
||
result^ |> List.rev; | ||
}; | ||
|
||
let _resolve = (v: t, items: StringMap.t(string)) => { | ||
let f = section => { | ||
switch (section) { | ||
| Text(sz) => Some(Text(sz)) | ||
| Separator => Some(Separator) | ||
| Variable(sz) => | ||
switch (StringMap.find_opt(sz, items)) { | ||
| Some(v) => Some(Text(v)) | ||
| None => None | ||
} | ||
}; | ||
}; | ||
|
||
v |> List.map(f) |> Utility.filterMap(v => v); | ||
}; | ||
|
||
let toString = (v: t, items: StringMap.t(string)) => { | ||
let resolvedItems = _resolve(v, items); | ||
|
||
let rec f = (v: t, hadText) => { | ||
switch (v) { | ||
| [Separator, Text(t2), ...tail] when hadText => | ||
" - " ++ t2 ++ f(tail, true) | ||
| [Text(t), ...tail] => t ++ f(tail, true) | ||
| [Separator, ...tail] => f(tail, false) | ||
| [Variable(_v), ...tail] => f(tail, false) | ||
| [] => "" | ||
}; | ||
}; | ||
|
||
f(resolvedItems, false); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* A workspace models the current 'ambient environment' of the editor, in particular: | ||
* - Current directory | ||
* | ||
* ...and eventually | ||
* - Open editors | ||
* - Local modifications (hot exit) | ||
* - Per-workspace configuration | ||
*/ | ||
|
||
type workspace = { | ||
workingDirectory: string, | ||
rootName: string, | ||
}; | ||
|
||
type t = option(workspace); | ||
|
||
let empty: t = None; | ||
|
||
let reduce = (v: t, a) => { | ||
switch (a) { | ||
| Actions.OpenExplorer(dir) => | ||
Some({workingDirectory: dir, rootName: Filename.basename(dir)}) | ||
| _ => v | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* TitleStoreConnector | ||
* | ||
* This implements an updater (reducer + side effects) for the window title | ||
*/ | ||
|
||
module Core = Oni_Core; | ||
module Model = Oni_Model; | ||
|
||
module Actions = Model.Actions; | ||
|
||
let start = setTitle => { | ||
let _lastTitle = ref(""); | ||
|
||
let getTemplateVariables: Model.State.t => Core.StringMap.t(string) = | ||
state => { | ||
let initialValues = [("appName", "Onivim 2")]; | ||
|
||
let initialValues = | ||
switch (Model.Selectors.getActiveBuffer(state)) { | ||
| None => initialValues | ||
| Some(buf) => | ||
let fp = Model.Buffer.getFilePath(buf); | ||
let ret = | ||
switch (fp) { | ||
| None => initialValues | ||
| Some(fp) => | ||
let activeEditorShort = Filename.basename(fp); | ||
[("activeEditorShort", activeEditorShort), ...initialValues]; | ||
}; | ||
switch (Model.Buffer.isModified(buf)) { | ||
| false => ret | ||
| true => [("dirty", "*"), ...ret] | ||
}; | ||
}; | ||
|
||
let initialValues = | ||
switch (state.workspace) { | ||
| None => initialValues | ||
| Some(workspace) => [ | ||
("rootName", workspace.rootName), | ||
...initialValues, | ||
] | ||
}; | ||
|
||
initialValues |> List.to_seq |> Core.StringMap.of_seq; | ||
}; | ||
|
||
let updateTitleEffect = state => | ||
Isolinear.Effect.createWithDispatch(~name="title.update", _dispatch => { | ||
let templateVariables = getTemplateVariables(state); | ||
let titleTemplate = | ||
Core.Configuration.getValue(c => c.windowTitle, state.configuration); | ||
|
||
let titleModel = Model.Title.ofString(titleTemplate); | ||
let title = Model.Title.toString(titleModel, templateVariables); | ||
print_endline("!!! got title: " ++ title); | ||
|
||
if (!String.equal(_lastTitle^, title)) { | ||
print_endline("!!! TITLE: " ++ title); | ||
_lastTitle := title; | ||
setTitle(title); | ||
}; | ||
}); | ||
|
||
let updater = (state: Model.State.t, action: Actions.t) => { | ||
switch (action) { | ||
| Init => (state, updateTitleEffect(state)) | ||
| BufferEnter(_) => (state, updateTitleEffect(state)) | ||
| BufferSetModified(_) => (state, updateTitleEffect(state)) | ||
// Catch directory changes | ||
| OpenExplorer(_) => (state, updateTitleEffect(state)) | ||
| _ => (state, Isolinear.Effect.none) | ||
}; | ||
}; | ||
updater; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
open TestFramework; | ||
|
||
open Oni_Core; | ||
|
||
module Title = Oni_Model.Title; | ||
|
||
describe("Title", ({describe, _}) => { | ||
describe("parse", ({test, _}) => { | ||
test("plain string", ({expect}) => { | ||
let title = Title.ofString("abc"); | ||
expect.equal(title, [Title.Text("abc")]); | ||
}); | ||
test("string with separator", ({expect}) => { | ||
let title = Title.ofString("abc${separator}def"); | ||
expect.equal( | ||
title, | ||
[Title.Text("abc"), Title.Separator, Title.Text("def")], | ||
); | ||
}); | ||
test("string with variables", ({expect}) => { | ||
let title = Title.ofString("${variable1}${separator}${variable2}"); | ||
expect.equal( | ||
title, | ||
[ | ||
Title.Variable("variable1"), | ||
Title.Separator, | ||
Title.Variable("variable2"), | ||
], | ||
); | ||
}); | ||
}); | ||
|
||
describe("toString", ({test, _}) => { | ||
let simpleMap = | ||
[("variable1", "rv1"), ("variable2", "rv2")] | ||
|> List.to_seq | ||
|> StringMap.of_seq; | ||
|
||
test("basic case", ({expect}) => { | ||
let title = | ||
Title.ofString("prefix${variable1}${separator}${variable2}postfix"); | ||
let result = Title.toString(title, simpleMap); | ||
expect.string(result).toEqual("prefixrv1 - rv2postfix"); | ||
}); | ||
}); | ||
}); |