Skip to content

Commit 36c75a8

Browse files
author
minjk-bl
committed
Edit FileNavigation to get use multi-extensions
1 parent 97457ff commit 36c75a8

File tree

1 file changed

+58
-45
lines changed

1 file changed

+58
-45
lines changed

visualpython/js/com/component/FileNavigation.js

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ define([
8484
this.pathStackPointer = -1;
8585
this.pathStack = [];
8686
this.currentFileList = [];
87+
this.selectedExt = '';
88+
if (this.state.extensions.length > 0) {
89+
this.selectedExt = this.state.extensions[0];
90+
}
8791

8892
this.pathState = {
8993
parentPath: '',
@@ -280,6 +284,32 @@ define([
280284
// clear body
281285
$(this.wrapSelector('.fileNavigationPage-body')).html('');
282286

287+
/**
288+
* Filter file/dir which included in this.state.extensions
289+
*/
290+
if (Array.isArray(this.state.extensions) && this.state.extensions.length > 0 && this.state.extensions.toString() !== '') {
291+
fileList = fileList.filter((data, index) => {
292+
if (index == 0) {
293+
return true;
294+
}
295+
296+
if (data.type && data.type == 'dir') {
297+
// if directory, just show
298+
return true;
299+
} else if (data.name) {
300+
var extension = data.name.substring(data.name.lastIndexOf('.') + 1);
301+
// if (that.state.extensions.includes(extension)) {
302+
if (that.selectedExt === '' || extension === that.selectedExt) {
303+
return true;
304+
} else {
305+
return false;
306+
}
307+
} else {
308+
return false;
309+
}
310+
});
311+
}
312+
283313
// render file items
284314
let dirArr = [];
285315
let fileArr = [];
@@ -411,12 +441,12 @@ define([
411441
page.appendFormatLine('<input id="{0}" type="text" class="vp-input" placeholder="{1}" value="{2}"/>'
412442
, 'vp_fileNavigationInput', 'New File Name', this.state.fileName);
413443
page.appendFormatLine('<select id="{0}" class="vp-select">', 'vp_fileNavigationExt');
444+
page.appendLine('<option value="">All files(*.*)</option>');
414445
if (this.state.extensions && this.state.extensions.length > 0) {
446+
let selectedExt = this.selectedExt;
415447
this.state.extensions.forEach(ext => {
416-
page.appendFormatLine('<option value="{0}">*.{1}</option>', ext, ext);
448+
page.appendFormatLine('<option value="{0}" {1}>*.{2}</option>', ext, (selectedExt === ext?'selected':''), ext);
417449
});
418-
} else {
419-
page.appendLine('<option value="">All files(*.*)</option>');
420450
}
421451
page.appendLine('</select>');
422452
page.appendFormatLine('<button class="{0} vp-button" data-menu="{1}">{2}</button>', 'vp-filenavi-btn', 'select', 'Select');
@@ -430,6 +460,13 @@ define([
430460

431461
that.handleSelectFile(filePath, fileName);
432462
});
463+
// bind file extension change event
464+
$(this.wrapSelector('#vp_fileNavigationExt')).on('change', function() {
465+
let ext = $(this).val();
466+
that.selectedExt = ext;
467+
468+
that.renderFileList();
469+
});
433470
// bind save cancel event
434471
$(this.wrapSelector('.vp-filenavi-btn')).on('click', function() {
435472
let menu = $(this).data('menu');
@@ -477,10 +514,10 @@ define([
477514
let that = this;
478515
/** Implement after rendering */
479516
// if save mode
480-
if (this.state.type == 'save') {
481-
// render saving box
482-
this.renderSaveBox();
483-
}
517+
// if (this.state.type == 'save') {
518+
// render saving box
519+
this.renderSaveBox();
520+
// }
484521

485522
// get current path
486523
this.getCurrentDirectory().then(function(currentPath) {
@@ -527,20 +564,21 @@ define([
527564
//============================================================================
528565
// Set selection result
529566
//============================================================================
530-
if (this.state.type == 'save') {
531-
// add as saving file
532-
this.setSelectedFile(fileInput, pathInput);
533-
} else {
534-
// Manage result using finish function
535-
let filesPath = [{ file: fileInput, path: pathInput }]; //FIXME: fix it if multiple selection implemented
536-
let status = true;
537-
let error = null;
538-
vpLog.display(VP_LOG_TYPE.DEVELOP, 'fileNavigation finished', filesPath, status, error);
539-
this.state.finish(filesPath, status, error);
567+
this.setSelectedFile(fileInput, pathInput);
568+
// if (this.state.type == 'save') {
569+
// // add as saving file
570+
// this.setSelectedFile(fileInput, pathInput);
571+
// } else {
572+
// // Manage result using finish function
573+
// let filesPath = [{ file: fileInput, path: pathInput }]; //FIXME: fix it if multiple selection implemented
574+
// let status = true;
575+
// let error = null;
576+
// vpLog.display(VP_LOG_TYPE.DEVELOP, 'fileNavigation finished', filesPath, status, error);
577+
// this.state.finish(filesPath, status, error);
540578

541-
// remove and close file navigation
542-
this.close();
543-
}
579+
// // remove and close file navigation
580+
// this.close();
581+
// }
544582
}
545583
getCurrentDirectory() {
546584
return vpKernel.getCurrentDirectory();
@@ -588,31 +626,6 @@ define([
588626
return a - b;
589627
});
590628

591-
/**
592-
* Filter file/dir which included in this.state.extensions
593-
*/
594-
if (Array.isArray(that.state.extensions) && that.state.extensions.length > 0 && that.state.extensions.toString() !== '') {
595-
filtered_varList = filtered_varList.filter((data, index) => {
596-
if (index == 0) {
597-
return true;
598-
}
599-
600-
if (data.type && data.type == 'dir') {
601-
// if file, just show
602-
return true;
603-
} else if (data.name) {
604-
var extension = data.name.substring(data.name.lastIndexOf('.') + 1);
605-
if (that.state.extensions.includes(extension)) {
606-
return true;
607-
} else {
608-
return false;
609-
}
610-
} else {
611-
return false;
612-
}
613-
});
614-
}
615-
616629
vpLog.display(VP_LOG_TYPE.DEVELOP, 'FileNavigation - getFileList: ', filtered_varList);
617630

618631
var { currentDirStr, currentRelativePathStr } = that.splitPathStrAndSetStack(dirObj, filtered_varList);

0 commit comments

Comments
 (0)