forked from datokrat/X-Tree-M
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuc_browsing_model.js
More file actions
188 lines (161 loc) · 5.16 KB
/
Copy pathuc_browsing_model.js
File metadata and controls
188 lines (161 loc) · 5.16 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import { c_LANG_LIB_TREE_ELEMTYPE } from "./lib_tree_lang.js";
import { VisibleState } from "./uc_browsing/state.js";
import { ClipboardSaga } from "./uc_browsing/clipboard.js";
import { BrowsingSaga } from "./uc_browsing/browse.js";
import { DeleteSaga } from "./uc_browsing/delete.js";
import { RenameSaga } from "./uc_browsing/rename.js";
import { CreateSaga } from "./uc_browsing/create.js";
import { SetTypeSaga } from "./uc_browsing/set_type.js";
export function uc_browsing_model(dispatcher, cache_manager) {
var self = this;
// public
self.get_state = get_state;
self.reload = reload;
self.adopt_newest_cache = adopt_newest_cache;
self.select_and_zoom = select_and_zoom;
self.select_and_zoom_to = select_and_zoom_to;
self.toggle_in_multiselection = toggle_in_multiselection;
self.set_type_of_selected = set_type_of_selected;
// self.begin_renaming = begin_renaming;
// self.begin_creating = begin_creating;
// self.apply_name_input = apply_name_input;
// private
self.visible_state = new VisibleState();
self.dispatcher = dispatcher;
self.cache_manager = cache_manager;
self.browsing_dispatcher = {
tree_changed: () => dispatcher.tree_changed(),
};
self.browsing_saga = new BrowsingSaga(
self.browsing_dispatcher,
self.visible_state,
self.cache_manager
);
self.edit_dispatcher = {
tree_changed: () => dispatcher.tree_changed(),
select_and_zoom: (path) => self.browsing_saga.select_and_zoom(path),
expand_children: () => self.browsing_saga.expand_children(),
};
self.clipboard_saga = new ClipboardSaga(
self.edit_dispatcher,
self.visible_state,
(copy_ids, target_id, cb_success) =>
cache_manager.copy_items({ src_ids: copy_ids, target_id, cb_success }),
(copy_links, target_id, cb_success) =>
cache_manager.move_items({ sources: copy_links, target_id, cb_success })
);
self.delete_saga = new DeleteSaga(
self.edit_dispatcher,
self.visible_state,
(links) => {
const deferred = $.Deferred();
cache_manager.delete_tree_item({
links,
cb_success: () => deferred.resolve(),
});
return deferred.promise();
}
);
self.rename_saga = new RenameSaga(
self.edit_dispatcher,
self.visible_state,
(id, name, cb_success) =>
cache_manager.change_tree_item_field({
elem_id: id,
field_id: "name",
content: name,
cb_success: cb_success,
})
);
self.create_saga = new CreateSaga(
self.edit_dispatcher,
self.visible_state,
(id, name, cb_success) =>
cache_manager.create_tree_item({
parent_elem_id: id,
name: name,
type: c_LANG_LIB_TREE_ELEMTYPE[1][0],
cb_success: cb_success,
})
);
self.set_type_saga = new SetTypeSaga(
self.browsing_dispatcher,
self.visible_state,
(links, cb_success) =>
cache_manager.set_link_types(links, cb_success),
);
function get_state() {
return self.visible_state;
}
function reload() {
return self.browsing_saga.reload();
}
function adopt_newest_cache() {
return self.browsing_saga.adopt_newest_cache();
}
function select_and_zoom(path) {
return self.browsing_saga.select_and_zoom(path);
}
function select_and_zoom_to(gui_id) {
return self.browsing_saga.select_and_zoom_to(gui_id);
}
function toggle_in_multiselection(gui_id) {
return self.browsing_saga.toggle_in_multiselection(gui_id);
}
function set_type_of_selected(type) {
return self.set_type_saga.set_type_of_selected(type);
}
this.handle_key_press = (key_chord, shift_pressed) => {
self.browsing_saga.handle_key_press(key_chord, shift_pressed);
switch (key_chord) {
case "Ctrl+C":
self.clipboard_saga.copy_by_reference();
break;
case "Ctrl-L":
// cloning not yet supported
break;
case "Ctrl+X":
self.clipboard_saga.cut();
break;
case "Ctrl+V":
self.clipboard_saga.paste();
break;
}
};
this.expand_children = () => {
this.browsing_saga.expand_children();
};
this.expand_children_of = (gui_id) => {
this.browsing_saga.expand_children_of(gui_id);
};
this.collapse_children = () => {
this.browsing_saga.collapse_children();
};
this.collapse_children_of = (gui_id) => {
this.browsing_saga.collapse_children_of(gui_id);
};
this.move_selection_down = (shift_pressed) => {
this.browsing_saga.move_selection_down(shift_pressed);
};
this.move_selection_up = (shift_pressed) => {
this.browsing_saga.move_selection_up(shift_pressed);
};
this.delete_selected = () => {
this.delete_saga.delete_selected().then((path) => {
path && this.select_and_zoom(path);
});
};
this.begin_renaming = () => {
this.rename_saga.begin();
};
this.begin_creating = () => {
this.create_saga.begin();
};
this.apply_name_input = (name) => {
this.rename_saga.apply(name);
this.create_saga.apply(name);
};
this.skip_name_input = () => {
this.rename_saga.skip();
};
}