-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathFeature_Workspace.re
126 lines (107 loc) · 3.01 KB
/
Feature_Workspace.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* 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
*/
open Oni_Core;
module Log = (val Log.withNamespace("Feature_Workspace"));
[@deriving show]
type command =
| CloseFolder
| OpenFolder;
[@deriving show]
type msg =
| Command(command)
| FolderSelectionCanceled
| FolderPicked([@opaque] Fp.t(Fp.absolute))
| WorkingDirectoryChanged(string);
module Msg = {
let workingDirectoryChanged = workingDirectory =>
WorkingDirectoryChanged(workingDirectory);
};
type model = {
workingDirectory: string,
openedFolder: option(string),
rootName: string,
};
let initial = (~openedFolder: option(string), workingDirectory) => {
workingDirectory,
openedFolder,
rootName: Filename.basename(workingDirectory),
};
let openedFolder = ({openedFolder, _}) => openedFolder;
let workingDirectory = ({workingDirectory, _}) => workingDirectory;
let rootName = ({rootName, _}) => rootName;
type outmsg =
| Nothing
| Effect(Isolinear.Effect.t(msg))
| WorkspaceChanged(option(string));
module Effects = {
let changeDirectory = (path: Fp.t(Fp.absolute)) =>
Isolinear.Effect.createWithDispatch(
~name="Feature_Workspace.changeDirectory", dispatch => {
let newDirectory = Fp.toString(path);
switch (Luv.Path.chdir(newDirectory)) {
| Ok () => dispatch(WorkingDirectoryChanged(newDirectory))
| Error(msg) =>
Log.errorf(m =>
m("Error changing directory: %s\n", Luv.Error.strerror(msg))
)
};
});
let pickFolder =
Service_OS.Effect.Dialog.openFolder(
fun
| None => FolderSelectionCanceled
| Some(fp) => FolderPicked(fp),
);
};
let update = (msg, model) => {
switch (msg) {
| FolderSelectionCanceled => (model, Nothing)
| WorkingDirectoryChanged(workingDirectory) => (
{
workingDirectory,
rootName: Filename.basename(workingDirectory),
openedFolder: Some(workingDirectory),
},
WorkspaceChanged(Some(workingDirectory)),
)
| Command(CloseFolder) => (
{...model, rootName: "", openedFolder: None},
WorkspaceChanged(None),
)
| Command(OpenFolder) => (model, Effect(Effects.pickFolder))
| FolderPicked(path) => (model, Effect(Effects.changeDirectory(path)))
};
};
// COMMANDS
module Commands = {
open Feature_Commands.Schema;
let closeFolder =
define(
~category="Workspace",
~title="Close Folder",
"workspace.action.closeFolder",
Command(CloseFolder),
);
let openFolder =
define(
~category="Workspace",
~title="Open Folder",
"_workbench.pickWorkspaceFolder",
Command(OpenFolder),
);
let all = model =>
model.openedFolder == None
? [openFolder]
// Always show open folder, so the user can switch folders from command palette
: [openFolder, closeFolder];
};
module Contributions = {
let commands = model => Commands.all(model);
};