-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathTitleStoreConnector.re
77 lines (66 loc) · 2.26 KB
/
TitleStoreConnector.re
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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;
};