Skip to content

Commit 24fcee6

Browse files
committed
Updated iconview settings and abstraction (#51)
1 parent 30881fc commit 24fcee6

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

src/adapters/ui/iconview.js

+31-10
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export class DesktopIconView extends EventEmitter {
8585
this.core = core;
8686
this.$root = null;
8787
this.iconview = null;
88+
this.root = 'home:/.desktop';
8889
}
8990

9091
destroy() {
@@ -112,24 +113,37 @@ export class DesktopIconView extends EventEmitter {
112113
this.$root.style.right = `${rect.right}px`;
113114
}
114115

115-
render() {
116+
_render(root) {
117+
const oldRoot = this.root;
118+
if (root) {
119+
this.root = root;
120+
}
121+
116122
if (this.$root) {
123+
if (this.root !== oldRoot) {
124+
this.iconview.reload();
125+
}
126+
127+
return false;
128+
}
129+
130+
return true;
131+
}
132+
133+
render(root) {
134+
if (!this._render(root)) {
117135
return;
118136
}
119137

120138
this.$root = document.createElement('div');
121139
this.$root.className = 'osjs-desktop-iconview';
122140
this.core.$root.appendChild(this.$root);
123141

124-
const root = 'home:/.desktop'; // FIXME
125142
const {droppable} = this.core.make('osjs/dnd');
126143
const {icon: fileIcon} = this.core.make('osjs/fs');
127144
const {icon: themeIcon} = this.core.make('osjs/theme');
128145
const {copy, readdir, unlink} = this.core.make('osjs/vfs');
129146
const error = err => console.error(err);
130-
const reload = () => readdir(root)
131-
.then(entries => entries.filter(e => e.filename !== '..'))
132-
.then(entries => this.iconview.setEntries(entries));
133147

134148
this.iconview = app({
135149
selected: -1,
@@ -161,26 +175,33 @@ export class DesktopIconView extends EventEmitter {
161175
// TODO
162176
},
163177

164-
addEntry: entry => {
178+
addEntry: entry => (state, actions) => {
165179
const dest = `${root}/${entry.filename}`;
166180

167181
copy(entry, dest)
168-
.then(reload)
182+
.then(() => actions.reload())
169183
.catch(error);
170184

171185
return {selected: -1};
172186
},
173187

174-
removeEntry: entry => {
188+
removeEntry: entry => (state, actions) => {
175189
unlink(entry)
176-
.then(reload)
190+
.then(() => actions.reload())
177191
.catch(error);
178192

179193
return {selected: -1};
194+
},
195+
196+
reload: () => (state, actions) => {
197+
readdir(root)
198+
.then(entries => entries.filter(e => e.filename !== '..'))
199+
.then(entries => actions.setEntries(entries));
180200
}
201+
181202
}, view(fileIcon, themeIcon, droppable), this.$root);
182203

183-
reload();
204+
this.iconview.reload();
184205
}
185206

186207
createFileContextMenu(ev, entry) {

src/config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ export const defaultConfiguration = {
176176
style: 'cover'
177177
},
178178
iconview: {
179-
enabled: false
179+
enabled: false,
180+
path: 'home:/.desktop'
180181
}
181182
}
182183
},

src/desktop.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,7 @@ export default class Desktop extends EventEmitter {
480480
this.applyTheme(newSettings.theme);
481481
this.applyIcons(newSettings.icons);
482482

483-
// TODO
484-
//this.applyIconView(newSettings.iconview.enabled);
485-
this.applyIconView(true);
483+
this.applyIconView(newSettings.iconview);
486484

487485
this.core.emit('osjs/desktop:applySettings');
488486

@@ -527,13 +525,13 @@ export default class Desktop extends EventEmitter {
527525
/**
528526
* Adds or removes the icon view
529527
*/
530-
applyIconView(enable) {
528+
applyIconView(settings) {
531529
if (!this.iconview) {
532530
return;
533531
}
534532

535-
if (enable) {
536-
this.iconview.render();
533+
if (settings.enabled) {
534+
this.iconview.render(settings.path);
537535
this.iconview.resize(this.getRect());
538536
} else {
539537
this.iconview.destroy();

src/styles/_iconview.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
&__entry {
4848
$self: &;
4949

50-
display: inline-flex;
50+
display: inline-block;
5151
position: relative;
5252
z-index: 1;
5353
text-align: center;

0 commit comments

Comments
 (0)