-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
92 lines (68 loc) · 1.98 KB
/
script.js
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
global.$ = $;
var dir;
const {remote} = require('electron');
const {Menu, BrowserWindow, MenuItem, shell} = remote;
var abar = require('address_bar');
var folder_view = require('folder_view');
// append default actions to menu for OSX
var initMenu = function () {
try {
var nativeMenuBar = new Menu();
if (process.platform == "darwin") {
nativeMenuBar.createMacBuiltin && nativeMenuBar.createMacBuiltin("FileExplorer");
}
} catch (error) {
console.error(error);
setTimeout(function () { throw error }, 1);
}
};
var aboutWindow = null;
var App = {
// show "about" window
about: function () {
var params = {toolbar: false, resizable: false, show: true, height: 150, width: 400};
aboutWindow = new BrowserWindow(params);
aboutWindow.loadURL('file://' + __dirname + '/about.html');
},
// change folder for sidebar links
cd: function (anchor) {
anchor = $(anchor);
$('#sidebar li').removeClass('active');
$('#sidebar i').removeClass('icon-white');
anchor.closest('li').addClass('active');
anchor.find('i').addClass('icon-white');
this.setPath(anchor.attr('nw-path'));
},
// set path for file explorer
setPath: function (path) {
if (path.indexOf('~') == 0) {
path = path.replace('~', process.env['HOME']);
}
this.folder.open(path);
this.addressbar.set(path);
}
};
$(document).ready(function() {
initMenu();
var folder = new folder_view.Folder($('#files'));
var addressbar = new abar.AddressBar($('#addressbar'));
folder.open(process.cwd());
addressbar.set(process.cwd());
App.folder = folder;
App.addressbar = addressbar;
folder.on('navigate', function(dir, mime) {
if (mime.type == 'folder') {
addressbar.enter(mime);
} else {
shell.openItem(mime.path);
}
});
addressbar.on('navigate', function(dir) {
folder.open(dir);
});
// sidebar favorites
$('[nw-path]').bind('click', function (event) {
event.preventDefault();
App.cd(this);
});
});