Skip to content

Commit ae20c34

Browse files
authored
Add support for labels in iconview (#179)
Adds support for the `label` property of a iconview shortcut along with localization of application shortcuts.
1 parent 7bb5509 commit ae20c34

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/adapters/ui/iconview.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,20 @@ const onDropAction = actions => (ev, data, files, shortcut = true) => {
4444
}
4545
};
4646

47+
const createLabelComputer = (core) => {
48+
const packages = f => core.make('osjs/packages').getPackages(f)[0];
49+
const translate = n => core.make('osjs/locale').translatableFlat(n);
50+
51+
return ({filename, mime, label}) => {
52+
const metadata = (mime === 'osjs/application' ? packages(pkg => (pkg.name === filename)) : null);
53+
return label || (metadata ? translate(metadata.title) : filename);
54+
};
55+
};
56+
4757
const isRootElement = ev =>
4858
ev.target && ev.target.classList.contains('osjs-desktop-iconview__wrapper');
4959

50-
const view = (fileIcon, themeIcon, droppable) => (state, actions) =>
60+
const view = (computeLabel, fileIcon, themeIcon, droppable) => (state, actions) =>
5161
h('div', {
5262
class: 'osjs-desktop-iconview__wrapper',
5363
oncontextmenu: ev => {
@@ -104,7 +114,7 @@ const view = (fileIcon, themeIcon, droppable) => (state, actions) =>
104114
]),
105115
h('div', {
106116
class: 'osjs-desktop-iconview__entry__label'
107-
}, entry.filename)
117+
}, computeLabel(entry))
108118
])
109119
]);
110120
}));
@@ -222,6 +232,7 @@ export class DesktopIconView extends EventEmitter {
222232
const error = err => console.error(err);
223233
const shortcuts = createShortcuts(root, readfile, writefile);
224234
const read = readDesktopFolder(root, readdir, shortcuts);
235+
const computeLabel = createLabelComputer(this.core);
225236

226237
this.iconview = app({
227238
selected: -1,
@@ -311,11 +322,13 @@ export class DesktopIconView extends EventEmitter {
311322
.then(entries => actions.setEntries(entries));
312323
}
313324

314-
}, view(fileIcon, themeIcon, droppable), this.$root);
325+
}, view(computeLabel, fileIcon, themeIcon, droppable), this.$root);
315326

316327
this.applySettings();
317328
this.iconview.reload();
318329
this._createWatcher();
330+
331+
this.core.on('osjs/settings:save', () => this.iconview.reload());
319332
}
320333

321334
createFileContextMenu(ev, entry) {

0 commit comments

Comments
 (0)