Skip to content

Commit be25558

Browse files
committed
Added ghost when dropping on iconview (#51)
1 parent c8e8230 commit be25558

File tree

3 files changed

+67
-41
lines changed

3 files changed

+67
-41
lines changed

src/adapters/ui/iconview.js

+61-40
Original file line numberDiff line numberDiff line change
@@ -68,44 +68,58 @@ const view = (fileIcon, themeIcon, droppable) => (state, actions) =>
6868
} else {
6969
onDropAction(actions)(ev, data, files);
7070
}
71-
}
71+
72+
actions.setGhost(false);
73+
},
74+
75+
ondragleave: () => actions.setGhost(false),
76+
ondragenter: () => actions.setGhost(true),
77+
ondragover: ev => actions.setGhost(ev)
7278
});
7379
}
74-
}, state.entries.map((entry, index) => {
75-
return h('div', {
76-
class: 'osjs-desktop-iconview__entry' + (
77-
state.selected === index
78-
? ' osjs-desktop-iconview__entry--selected'
79-
: ''
80-
),
81-
oncontextmenu: ev => actions.openContextMenu({ev, entry, index}),
82-
ontouchstart: ev => tapper(ev, () => actions.openEntry({ev, entry, index})),
83-
ondblclick: ev => actions.openEntry({ev, entry, index}),
84-
onclick: ev => actions.selectEntry({ev, entry, index})
85-
}, [
86-
h('div', {
87-
class: 'osjs-desktop-iconview__entry__inner'
80+
}, [
81+
...state.entries.map((entry, index) => {
82+
return h('div', {
83+
class: 'osjs-desktop-iconview__entry' + (
84+
state.selected === index
85+
? ' osjs-desktop-iconview__entry--selected'
86+
: ''
87+
),
88+
oncontextmenu: ev => actions.openContextMenu({ev, entry, index}),
89+
ontouchstart: ev => tapper(ev, () => actions.openEntry({ev, entry, index})),
90+
ondblclick: ev => actions.openEntry({ev, entry, index}),
91+
onclick: ev => actions.selectEntry({ev, entry, index})
8892
}, [
8993
h('div', {
90-
class: 'osjs-desktop-iconview__entry__icon'
94+
class: 'osjs-desktop-iconview__entry__inner'
9195
}, [
92-
h('img', {
93-
src: entry.icon ? entry.icon : themeIcon(fileIcon(entry).name),
94-
class: 'osjs-desktop-iconview__entry__icon__icon'
95-
}),
96-
entry.shortcut !== false
97-
? h('img', {
98-
src: themeIcon('emblem-symbolic-link'),
99-
class: 'osjs-desktop-iconview__entry__icon__shortcut'
100-
})
101-
: null
102-
]),
103-
h('div', {
104-
class: 'osjs-desktop-iconview__entry__label'
105-
}, entry.filename)
106-
])
107-
]);
108-
}));
96+
h('div', {
97+
class: 'osjs-desktop-iconview__entry__icon'
98+
}, [
99+
h('img', {
100+
src: entry.icon ? entry.icon : themeIcon(fileIcon(entry).name),
101+
class: 'osjs-desktop-iconview__entry__icon__icon'
102+
}),
103+
entry.shortcut !== false
104+
? h('img', {
105+
src: themeIcon('emblem-symbolic-link'),
106+
class: 'osjs-desktop-iconview__entry__icon__shortcut'
107+
})
108+
: null
109+
]),
110+
h('div', {
111+
class: 'osjs-desktop-iconview__entry__label'
112+
}, entry.filename)
113+
])
114+
]);
115+
}),
116+
h('div', {
117+
class: 'osjs-desktop-iconview__entry osjs-desktop-iconview__entry--ghost',
118+
style: {
119+
display: state.ghost ? undefined : 'none'
120+
}
121+
})
122+
]);
109123

110124
const createShortcuts = (root, readfile, writefile) => {
111125
const read = () => {
@@ -195,32 +209,35 @@ export class DesktopIconView extends EventEmitter {
195209
this.$root.style.right = `${rect.right}px`;
196210
}
197211

198-
_render(root) {
212+
_render(settings) {
199213
const oldRoot = this.root;
200-
if (root) {
201-
this.root = root;
214+
if (settings.path) {
215+
this.root = settings.path;
202216
}
203217

204218
if (this.$root) {
205219
if (this.root !== oldRoot) {
206220
this.iconview.reload();
207221
}
208222

223+
this.iconview.toggleGrid(settings.grid);
224+
209225
return false;
210226
}
211227

212228
return true;
213229
}
214230

215-
render(root) {
216-
if (!this._render(root)) {
231+
render(settings) {
232+
if (!this._render(settings)) {
217233
return;
218234
}
219235

220236
this.$root = document.createElement('div');
221237
this.$root.className = 'osjs-desktop-iconview';
222238
this.core.$root.appendChild(this.$root);
223239

240+
const root = settings.path;
224241
const {droppable} = this.core.make('osjs/dnd');
225242
const {icon: fileIcon} = this.core.make('osjs/fs');
226243
const {icon: themeIcon} = this.core.make('osjs/theme');
@@ -231,7 +248,8 @@ export class DesktopIconView extends EventEmitter {
231248

232249
this.iconview = app({
233250
selected: -1,
234-
entries: []
251+
entries: [],
252+
ghost: false
235253
}, {
236254
setEntries: entries => ({entries}),
237255

@@ -311,8 +329,11 @@ export class DesktopIconView extends EventEmitter {
311329
read()
312330
.then(entries => entries.filter(e => e.filename !== '..'))
313331
.then(entries => actions.setEntries(entries));
314-
}
332+
},
315333

334+
setGhost: ev => {
335+
return {ghost: ev};
336+
}
316337
}, view(fileIcon, themeIcon, droppable), this.$root);
317338

318339
this.iconview.reload();

src/desktop.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ export default class Desktop extends EventEmitter {
532532
}
533533

534534
if (settings.enabled) {
535-
this.iconview.render(settings.path);
535+
this.iconview.render(settings);
536536
this.iconview.resize(this.getRect());
537537
} else {
538538
this.iconview.destroy();

src/styles/_iconview.scss

+5
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@
8888
text-overflow: ellipsis;
8989
}
9090

91+
&--ghost {
92+
pointer-events: none;
93+
background-color: rgba(255, 255, 255, 0.1);
94+
}
95+
9196
&--selected {
9297
z-index: 1;
9398
overflow: visible;

0 commit comments

Comments
 (0)