Permalink
Browse files

Handle to click content in collection

  • Loading branch information...
hirohisa committed Jun 3, 2018
1 parent 4dfa894 commit 252b32803400b3b745addfbdbbb4df6ff1f098c0
Showing with 56 additions and 15 deletions.
  1. +4 −0 css/main.css
  2. +1 −1 main-process/search.js
  3. +12 −2 renderer-process/collection_view.js
  4. +39 −12 renderer-process/file_cursor.js
@@ -6,6 +6,10 @@ nav.nav-group {
color: orange;
}
#directory-current-page span {
color: orange;
}
.pane {
background-color: #333;
}
@@ -32,7 +32,7 @@ ipc.on('keydown', function(event, data) {
})
// delegate
const proxyList = ['click', 'endedVideo', 'selectFile', 'changeLayoutToCollection', 'changeLayoutToContent']
const proxyList = ['click', 'endedVideo', 'selectFile', 'changeLayoutToCollection', 'changeLayoutToContent', 'selectCurrent']
proxyList.forEach(function(e) {
ipc.on(e, function(event, data) {
event.sender.send(e, data);
@@ -3,6 +3,7 @@ const ui = require('../lib/ui');
const utils = require('./utils');
const path = require('path');
const queue = require('queue');
const ipc = require('electron').ipcRenderer;
const q = queue();
q.autostart = true;
@@ -14,6 +15,17 @@ function createItem(filePath) {
element.appendChild(createText(fileName));
element.id = fileName;
element.setAttribute('href', filePath);
element.addEventListener("click", function(e) {
var href = e.target.getAttribute('href');
if (!href) {
href = e.target.parentNode.getAttribute('href');
}
if (href) {
var data = {href: href};
ipc.send('selectCurrent', data);
}
}, false);
return element;
}
@@ -62,8 +74,6 @@ function renderToCollection(filePath) {
}
}
const ipc = require('electron').ipcRenderer;
ipc.on('selectFile', function(event, data) {
if (!utils.isShowingContent()) {
element = document.getElementById(path.basename(data.filePath));
@@ -24,12 +24,11 @@ function clear() {
}
}
function makeLink(filePath, fileName, referer, click) {
var linkId = referer == filePath ? 'directory-current-page' : '';
function makeLink(filePath, fileName, click) {
var klass = sy.isDirectory(filePath) ? "icon-folder" : "icon-picture"
var html = `
<span class="nav-group-item" id="${linkId}" href="${path.normalize(filePath)}">
<span class="nav-group-item" id="" href="${path.normalize(filePath)}">
<span class="icon ${klass}"></span>${fileName}</span>
</span>
`;
@@ -61,6 +60,31 @@ function reload(data) {
render(data.files, data.referer, undefined, undefined)
}
function getElementBy(href) {
var array = Array.from(document.getElementsByClassName('nav-group-item'));
return array.find(e => e.getAttribute('href') == href);
}
function selectCurrent(href, focusTarget) {
var current = undefined;
if (href) {
current = getElementBy(href);
if (current) {
current.id = 'directory-current-page';
}
}
if (!current) {
current = ui.getCurrent();
}
fileCursor.select(current);
if (!focusTarget) {
focusTarget = current;
}
scrollTo(focusTarget);
}
function render(files, referer, term, focusTarget) {
const queue = require('queue');
@@ -79,9 +103,13 @@ function render(files, referer, term, focusTarget) {
// Bug: wrong links occur when queue has tasks
() => {
var link = makeLink(filePath, fileName, referer, (e) => {
fileCursor.select(e.target);
clickFileLink(e.target.getAttribute('href'));
var link = makeLink(filePath, fileName, (e) => {
var target = e.target;
if (e.target.className != "nav-group-item") {
target = target.parentNode;
}
fileCursor.select(target);
clickFileLink(target.getAttribute('href'));
})
ui.directoryTree.appendChild(link);
@@ -91,12 +119,7 @@ function render(files, referer, term, focusTarget) {
q.push(
() => {
var current = ui.getCurrent();
fileCursor.select(current);
if (!focusTarget) {
focusTarget = current;
}
scrollTo(focusTarget);
selectCurrent(referer, focusTarget);
}
)
@@ -232,6 +255,10 @@ ipc.on('click', (event, data) => {
}
})
ipc.on('selectCurrent', (event, data) => {
selectCurrent(data.href, undefined);
});
ipc.on('removePath', function(event, data) {
var current = ui.getCurrent()

0 comments on commit 252b328

Please sign in to comment.