Permalink
Browse files

Add filter function with search input form

  • Loading branch information...
hirohisa committed Apr 18, 2018
1 parent 94704db commit a0632d74684aa38ff6b6e7f0387c7273b5ea4939
Showing with 61 additions and 19 deletions.
  1. +6 −2 index.html
  2. +3 −0 lib/ui.js
  3. +4 −6 main-process/search.js
  4. +1 −5 main.js
  5. +47 −6 renderer-process/directory_view.js
@@ -18,9 +18,13 @@
<nav class="nav-group">
<span class="nav-group-item icon icon-reply" id="move-parent-directory"></span>
<h5 class="nav-group-title">Directory</h5>
<span class="nav-group-item nav-group-item-disactive" id="path-directory" >
</span>
<span class="nav-group-item nav-group-item-disactive" id="path-directory"></span>
<h5 class="nav-group-title">Files</h5>
<ul class="list-group">
<li class="list-group-header">
<input class="form-control" type="text" placeholder="Search" id="search-form-input">
</li>
</ul>
<nav id="directory-tree"></nav>
</nav>
</div>
@@ -9,6 +9,9 @@ module.exports.sideBar = document.getElementById('sidebar')
const directoryPath = document.getElementById('path-directory')
module.exports.directoryPath = directoryPath
const searchInputForm = document.getElementById('search-form-input')
module.exports.searchInputForm = searchInputForm
// get element
module.exports.getCurrent = function() {
@@ -27,13 +27,11 @@ ipc.on('movePath', function(event, data) {
})
ipc.on('moveToTrash', function(event, data) {
fileFinder.moveToTrash(event, data.filePath)
})
ipc.on('keydown', function(event, data) {
switch (data.code) {
case "Backspace":
fileFinder.moveToTrash(event, data.filePath)
break;
default:
}
event.sender.send('keydown', data);
})
@@ -21,18 +21,14 @@ function createWindow() {
}))
if (process.env.NODE_ENV == 'development') {
openDevTools()
win.webContents.openDevTools();
}
win.on('closed', () => {
win = null
})
}
function openDevTools() {
win.webContents.openDevTools();
}
require('./main-process/search.js');
function onReady() {
@@ -24,14 +24,14 @@ function clear() {
}
}
function appendLink(filePath, referer, click) {
function appendLink(filePath, fileName, referer, click) {
var link = document.createElement('span')
link.className = 'nav-group-item'
link.id = referer == filePath ? 'directory-current-page' : ''
var klass = sy.isDirectory(filePath) ? "icon-folder" : "icon-picture"
link.innerHTML = '<span class="icon ' + klass + '"></span>' + path.basename(filePath) + '</span>'
link.innerHTML = '<span class="icon ' + klass + '"></span>' + fileName + '</span>'
link.setAttribute('href', path.normalize(filePath))
@@ -47,23 +47,41 @@ function clickFileLink(filePath) {
class DirectoryView {
filter(term) {
clear()
var referer = ui.getCurrent() ? ui.getCurrent().getAttribute('href') : undefined;
this._render(this.files, referer, term)
}
render(data) {
clear()
ui.searchInputForm.value = ''
// TODO: get current directory and validate with data.path
clear()
this.files = data.files
this._render(data.files, data.referer, undefined)
}
_render(files, referer, term) {
const queue = require('queue');
var q = queue();
q.autostart = true;
for (var i in data.files) {
var filePath = data.files[i]
for (var i in files) {
var filePath = files[i]
var fileName = path.basename(filePath)
if (term && !fileName.includes(term)) {
continue;
}
q.push(
// Bug: wrong links occur when queue has tasks
() => {
appendLink(filePath, data.referer, (e) => {
appendLink(filePath, fileName, referer, (e) => {
this.select(e.target);
clickFileLink(e.target.getAttribute('href'));
})
@@ -80,6 +98,7 @@ class DirectoryView {
}
}
)
}
select(element) {
@@ -139,10 +158,19 @@ class DirectoryView {
const directoryView = new DirectoryView();
var previousSearchInputValue = undefined
function filterIfNeeded() {
if (previousSearchInputValue != ui.searchInputForm.value) {
directoryView.filter(ui.searchInputForm.value)
}
previousSearchInputValue = ui.searchInputForm.value
}
ipc.on('searchFiles', (event, data) => {
directoryView.render(data)
})
var previousKey = undefined
ipc.on('keydown', (event, data) => {
switch (data.code) {
case "ArrowUp":
@@ -157,8 +185,21 @@ ipc.on('keydown', (event, data) => {
case "ArrowRight":
directoryView.down()
break;
case "Backspace":
if (document.activeElement.tagName.toLowerCase() != "input") {
ipc.send('moveToTrash', data);
}
break;
case "KeyS":
if (["MetaLeft", "MetaRight"].includes(previousKey)) {
ui.searchInputForm.focus();
}
break;
default:
}
previousKey = data.code
filterIfNeeded();
})
ipc.on('click', (event, data) => {

0 comments on commit a0632d7

Please sign in to comment.