Skip to content

Commit efefea1

Browse files
committed
Context menu functional
1 parent 1eb9cdf commit efefea1

File tree

5 files changed

+55
-26
lines changed

5 files changed

+55
-26
lines changed

build.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import initFM from './src';
2+
import ImagePreview from "./src/plugins/ImagePreview";
23

34
window.openFileManager = initFM('/react-filemanager-server/', document.querySelector('.app'));
45

@@ -8,3 +9,5 @@ window.openFileManager = initFM('/react-filemanager-server/', document.querySele
89
link.href = href;
910
document.head.insertBefore(link, document.head.firstChild);
1011
});
12+
13+
window.ReactFileManager.registerPlugin(ImagePreview);

src/core/PluginContainer.jsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import React, {Component} from 'react'
22
import {inject, observer} from "mobx-react";
33

44
const PluginContainer = class PluginContainer extends Component {
5-
constructor(props) {
6-
super(props);
7-
}
5+
constructor(props) {
6+
super(props);
7+
}
88

9-
render = () => {
10-
const store = this.props.fm_store;
11-
if(!store.plugin.component)
12-
return null;
13-
return (
14-
<store.plugin.component key={store.plugin.key} store={store}/>
15-
);
16-
};
9+
render = () => {
10+
const store = this.props.fm_store;
11+
if (!store.plugin.component)
12+
return null;
13+
return (
14+
<store.plugin.component key={store.plugin.key} store={store}/>
15+
);
16+
};
1717
};
1818

1919
export default inject("fm_store")(observer(PluginContainer))

src/core/file_types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
text: ['txt', 'html', 'css', 'js', 'php', 'log', 'inc'],
33
image: ['png', 'jpg', 'jpeg', 'bmp', 'webm', 'gif', 'svg'],
4-
video: ['mp4', 'flv', 'mkv', 'vob'],
4+
video: ['mkv', 'flv', 'mp4', 'vob', '3gp'],
55
audio: ['mp3', 'aac', 'ogg'],
66
};

src/core/fm/content/index.jsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,20 @@ const FMContent = class FMContent extends Component {
3838

3939
const menu_items = this.getFilteredMenuItems(ext).map(menu_item => {
4040
const {callback} = menu_item;
41-
menu_item.callback = () => {
42-
return callback.call(this, item);
41+
const n_menu_item = Object.assign({}, menu_item);
42+
n_menu_item.callback = () => {
43+
console.log('Inside callback', item);
44+
return callback.call(this, this.props.fm_store, item);
4345
};
44-
return menu_item;
46+
return n_menu_item;
4547
});
4648

4749
this.setState({menu_items});
4850
};
4951

5052
getFilteredMenuItems = ext => {
51-
const menu = [
53+
const menu = this.props.fm_store.context_menu;
54+
/*[
5255
{
5356
scopes: ['image'],
5457
label: 'Preview',
@@ -89,7 +92,7 @@ const FMContent = class FMContent extends Component {
8992
},
9093
category: ['general']
9194
},
92-
];
95+
];*/
9396
const type = ['screen', 'dir'].indexOf(ext) >= 0 ? ext : Object.keys(file_types).find(type => {
9497
return file_types[type].indexOf(ext) >= 0;
9598
});

src/core/store.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Rename from "./general/rename/index";
1616
import FileInfo from "./general/file-info/index";
1717
import FM from "./fm";
1818
import {remove_duplicate_slash} from "./Helper";
19+
import {audio, image, video} from "./file_types";
1920

2021
require('antd/lib/message/style');
2122

@@ -70,7 +71,8 @@ export default class FMStore {
7071
},
7172
file_info: {
7273
file: null
73-
}
74+
},
75+
item_in_action: null,
7476
},
7577
//all the core information
7678
data: {
@@ -91,6 +93,8 @@ export default class FMStore {
9193
},
9294
//action menu buttons
9395
action_menu: {},
96+
//context menu items
97+
context_menu: [],
9498
//tab panels
9599
tabs: [
96100
{
@@ -102,9 +106,9 @@ export default class FMStore {
102106
],
103107
filter_types: {
104108
null: {title: "All", types: []},
105-
image: {title: null, icon: "picture", types: ['png', 'jpeg', 'svg', 'jpg', 'bmp', 'gif']},
106-
audio: {title: null, icon: "sound", types: ['mp3', 'ogg', 'aac']},
107-
video: {title: null, icon: "video-camera", types: ['mkv', 'flv', 'mp4', 'vob', '3gp']}
109+
image: {title: null, icon: "picture", types: image},
110+
audio: {title: null, icon: "sound", types: audio},
111+
video: {title: null, icon: "video-camera", types: video}
108112
}
109113
});
110114

@@ -147,6 +151,9 @@ export default class FMStore {
147151
//add the action menu
148152
plugin[hook].action_menu && (this.config.action_menu[hook] = plugin[hook].action_menu);
149153

154+
//ad context menu
155+
plugin[hook].context_menu && this.config.context_menu.push(plugin[hook].context_menu);
156+
150157
//add the tab entry
151158
plugin[hook].tab && this.config.tabs.push({
152159
title: [<span key="title">{plugin[hook].tab}</span>],
@@ -164,11 +171,13 @@ export default class FMStore {
164171
message.error('The requested plugin is not installed.');
165172
return;
166173
}
167-
const plugin = this.config.plugins[alias];
168-
this.config.plugin.component = plugin.component;
169-
this.config.plugin.alias = alias;
170-
this.config.plugin.plugin = plugin.plugin;
171-
this.config.plugin.key = Math.random();
174+
try {
175+
const plugin = this.config.plugins[alias];
176+
this.config.plugin.component = plugin.component;
177+
this.config.plugin.alias = alias;
178+
this.config.plugin.plugin = plugin.plugin;
179+
this.config.plugin.key = Math.random();
180+
}catch(e) {console.log(e)}
172181
};
173182
});
174183

@@ -234,6 +243,10 @@ export default class FMStore {
234243
this.config.data.filter_type = filter_type;
235244
}
236245

246+
set item_in_action(item) {
247+
this.config.plugin_data.item_in_action = item;
248+
};
249+
237250
//endregion
238251

239252
//region Config getters
@@ -253,6 +266,11 @@ export default class FMStore {
253266
return this.config.action_menu;
254267
}
255268

269+
//context menu items
270+
get context_menu() {
271+
return this.config.context_menu;
272+
}
273+
256274
//tabs list
257275
get tabs() {
258276
return this.config.tabs.filter(tab=>{
@@ -323,6 +341,11 @@ export default class FMStore {
323341
return this.list.filter(item => item.selected);
324342
};
325343

344+
// get the item selected for action
345+
get item_in_action() {
346+
return this.config.plugin_data.item_in_action;
347+
}
348+
326349
//endregion
327350

328351
//region Http

0 commit comments

Comments
 (0)