|
|
@ -40,13 +40,18 @@ export class FileGridComponent implements OnChanges, OnInit {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ngOnInit(): void {
|
|
|
|
public ngOnInit(): void {
|
|
|
|
this.gridEntries = this.files.map(file => {return {file, selected: false}});
|
|
|
|
this.gridEntries = this.files.map(file => {
|
|
|
|
|
|
|
|
return {file, selected: false}
|
|
|
|
|
|
|
|
});
|
|
|
|
this.setPartitionedGridEntries();
|
|
|
|
this.setPartitionedGridEntries();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
|
|
|
if (changes["files"]) {
|
|
|
|
if (changes["files"]) {
|
|
|
|
this.gridEntries = this.files.map(file => {return {file, selected: false}});
|
|
|
|
this.gridEntries = this.files.map(file => {
|
|
|
|
|
|
|
|
return {file, selected: false}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
this.refreshFileSelections();
|
|
|
|
this.setPartitionedGridEntries();
|
|
|
|
this.setPartitionedGridEntries();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -59,7 +64,9 @@ export class FileGridComponent implements OnChanges, OnInit {
|
|
|
|
const previousSelectionSize = this.selectedEntries.length;
|
|
|
|
const previousSelectionSize = this.selectedEntries.length;
|
|
|
|
|
|
|
|
|
|
|
|
if (!(this.shiftClicked || this.ctrlClicked) && this.selectedEntries.length > 0) {
|
|
|
|
if (!(this.shiftClicked || this.ctrlClicked) && this.selectedEntries.length > 0) {
|
|
|
|
this.selectedEntries.forEach(entry => {if (entry !== clickedEntry) entry.selected = false});
|
|
|
|
this.selectedEntries.forEach(entry => {
|
|
|
|
|
|
|
|
if (entry !== clickedEntry) entry.selected = false
|
|
|
|
|
|
|
|
});
|
|
|
|
this.selectedEntries = [];
|
|
|
|
this.selectedEntries = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.shiftClicked && this.selectedEntries.length > 0) {
|
|
|
|
if (this.shiftClicked && this.selectedEntries.length > 0) {
|
|
|
@ -76,24 +83,28 @@ export class FileGridComponent implements OnChanges, OnInit {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.selectedEntries.length == 1) {
|
|
|
|
if (this.selectedEntries.length == 1) {
|
|
|
|
this.fileSelectEvent.emit(this.selectedEntries.map(entry => entry.file)[0]);
|
|
|
|
this.fileSelectEvent.emit(
|
|
|
|
} else if (this.selectedEntries.length == 0 && previousSelectionSize == 1){
|
|
|
|
this.selectedEntries.map(entry => entry.file)[0]);
|
|
|
|
|
|
|
|
} else if (this.selectedEntries.length == 0 && previousSelectionSize == 1) {
|
|
|
|
this.fileSelectEvent.emit(undefined);
|
|
|
|
this.fileSelectEvent.emit(undefined);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
this.fileMultiselectEvent.emit(this.selectedEntries.map(entry => entry.file));
|
|
|
|
this.fileMultiselectEvent.emit(
|
|
|
|
|
|
|
|
this.selectedEntries.map(entry => entry.file));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private setPartitionedGridEntries() {
|
|
|
|
private setPartitionedGridEntries() {
|
|
|
|
this.partitionedGridEntries = [];
|
|
|
|
this.partitionedGridEntries = [];
|
|
|
|
this.selectedEntries = [];
|
|
|
|
|
|
|
|
let scrollToIndex = -1;
|
|
|
|
let scrollToIndex = -1;
|
|
|
|
let selectedEntry: GridEntry | undefined = undefined;
|
|
|
|
let selectedEntry: GridEntry | undefined = undefined;
|
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < (Math.ceil(this.gridEntries.length / this.columns)); i++) {
|
|
|
|
for (let i = 0; i < (Math.ceil(
|
|
|
|
const entries = this.gridEntries.slice(i * this.columns, Math.min(this.gridEntries.length, (i + 1) * this.columns));
|
|
|
|
this.gridEntries.length / this.columns)); i++) {
|
|
|
|
|
|
|
|
const entries = this.gridEntries.slice(i * this.columns,
|
|
|
|
|
|
|
|
Math.min(this.gridEntries.length, (i + 1) * this.columns));
|
|
|
|
this.partitionedGridEntries.push(entries);
|
|
|
|
this.partitionedGridEntries.push(entries);
|
|
|
|
const preselectedEntry = entries.find(e => e.file.hash == this.preselectedFile?.hash);
|
|
|
|
const preselectedEntry = entries.find(
|
|
|
|
|
|
|
|
e => e.file.hash == this.preselectedFile?.hash);
|
|
|
|
|
|
|
|
|
|
|
|
if (preselectedEntry) {
|
|
|
|
if (preselectedEntry) {
|
|
|
|
scrollToIndex = i;
|
|
|
|
scrollToIndex = i;
|
|
|
@ -106,13 +117,21 @@ export class FileGridComponent implements OnChanges, OnInit {
|
|
|
|
this.virtualScroll?.scrollToIndex(scrollToIndex);
|
|
|
|
this.virtualScroll?.scrollToIndex(scrollToIndex);
|
|
|
|
if (selectedEntry) {
|
|
|
|
if (selectedEntry) {
|
|
|
|
selectedEntry.selected = true;
|
|
|
|
selectedEntry.selected = true;
|
|
|
|
this.selectedEntries = [selectedEntry];
|
|
|
|
this.selectedEntries.push(selectedEntry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 0);
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private refreshFileSelections() {
|
|
|
|
|
|
|
|
const newSelection: GridEntry[] = this.gridEntries.filter(
|
|
|
|
|
|
|
|
entry => this.selectedEntries.findIndex(
|
|
|
|
|
|
|
|
e => e.file.id == entry.file.id) >= 0);
|
|
|
|
|
|
|
|
newSelection.forEach(entry => entry.selected = true);
|
|
|
|
|
|
|
|
this.selectedEntries = newSelection;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private handleShiftSelect(clickedEntry: GridEntry): void {
|
|
|
|
private handleShiftSelect(clickedEntry: GridEntry): void {
|
|
|
|
const lastEntry = this.selectedEntries[this.selectedEntries.length - 1];
|
|
|
|
const lastEntry = this.selectedEntries[this.selectedEntries.length - 1];
|
|
|
|
let found = false;
|
|
|
|
let found = false;
|
|
|
@ -140,16 +159,24 @@ export class FileGridComponent implements OnChanges, OnInit {
|
|
|
|
@HostListener("window:keydown", ["$event"])
|
|
|
|
@HostListener("window:keydown", ["$event"])
|
|
|
|
private handleKeydownEvent(event: KeyboardEvent) {
|
|
|
|
private handleKeydownEvent(event: KeyboardEvent) {
|
|
|
|
switch (event.key) {
|
|
|
|
switch (event.key) {
|
|
|
|
case "Shift": this.shiftClicked = true; break;
|
|
|
|
case "Shift":
|
|
|
|
case "Control": this.ctrlClicked = true; break;
|
|
|
|
this.shiftClicked = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "Control":
|
|
|
|
|
|
|
|
this.ctrlClicked = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@HostListener("window:keyup", ["$event"])
|
|
|
|
@HostListener("window:keyup", ["$event"])
|
|
|
|
private handleKeyupEvent(event: KeyboardEvent) {
|
|
|
|
private handleKeyupEvent(event: KeyboardEvent) {
|
|
|
|
switch (event.key) {
|
|
|
|
switch (event.key) {
|
|
|
|
case "Shift": this.shiftClicked = false; break;
|
|
|
|
case "Shift":
|
|
|
|
case "Control": this.ctrlClicked = false; break;
|
|
|
|
this.shiftClicked = false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "Control":
|
|
|
|
|
|
|
|
this.ctrlClicked = false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|