Skip to content

Commit

Permalink
copy from folder to desktop using cntxt menu works
Browse files Browse the repository at this point in the history
  • Loading branch information
chinonso098 committed Aug 8, 2024
1 parent dd5b335 commit a28e357
Show file tree
Hide file tree
Showing 11 changed files with 309 additions and 197 deletions.
23 changes: 9 additions & 14 deletions src/app/shared/system-component/menu/menu.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Input, OnChanges, SimpleChanges, OnDestroy } from '@angular/core';
import {DesktopMenu, GeneralMenu } from './menu.item';
import {NestedMenu, GeneralMenu } from './menu.item';
import { MenuService } from '../../system-service/menu.services';
import { Subscription } from 'rxjs';

Expand All @@ -11,33 +11,32 @@ import { Subscription } from 'rxjs';
export class MenuComponent implements OnChanges, OnDestroy{

@Input() generalMenu: GeneralMenu[] = [];
@Input() desktopMenu: DesktopMenu[] = [];
@Input() desktopMenu: NestedMenu[] = [];
@Input() menuType = '';

private _menuService:MenuService;
private _storeDataSub!:Subscription;
isPasteActive!:boolean;

menuOption = '';
fileExplrMngrMenuOption = "file-explorer-file-manager-menu";
tskBarMenuOption = "taskbar-menu";
deskTopMenuOption = "desktop-menu";
keys: string[] = [];
data = 'NOPATH';
paste = 'Paste';
actions:string[]=[];

isPasteActive!:boolean;

constructor(menuService:MenuService) {
this._menuService = menuService;

this.isPasteActive = this._menuService.getPasteState();
this._storeDataSub = this._menuService.storeData.subscribe(p => {
this.data = p[0];
p.shift();
this.actions = [...p]

this._menuService.setPasteState(this.activatePaste());
const path = p[0];
const actions = p[1];

this._menuService.setPath(path);
this._menuService.setActions(actions);
this._menuService.setPasteState(true);
})
}

Expand All @@ -57,8 +56,4 @@ export class MenuComponent implements OnChanges, OnDestroy{
this.keys = Object.keys(obj);
}

activatePaste():boolean{
return (this.data === 'NOPATH')? false: true;
}

}
6 changes: 3 additions & 3 deletions src/app/shared/system-component/menu/menu.item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ export interface GeneralMenu {
action: () => void;
}

export interface DesktopMenu{
export interface NestedMenu{
icon1: string;
icon2: string;
label: string;
nest: DesktopMenuItem[];
nest: NestedMenuItem[];
action: () => void;
emptyline: boolean;
}

export interface DesktopMenuItem {
export interface NestedMenuItem {
icon:string;
label: string;
action: () => void;
Expand Down
130 changes: 126 additions & 4 deletions src/app/shared/system-service/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,47 @@ export class FileService{
});
}

public async copyHandler(arg0:string, sourcePathArg:string, destinationArg:string):Promise<boolean>{

const checkIfDirResult = await this.checkIfDirectory(`${sourcePathArg}`);
if(checkIfDirResult){
const folderName = this.getFileName(sourcePathArg);
const createFolderResult = await this.createFolderAsync(destinationArg, folderName);
if(createFolderResult){
const loadedDirectoryEntries = await this.getEntriesFromDirectoryAsync(sourcePathArg);
for(const directoryEntry of loadedDirectoryEntries){
const checkIfDirResult = await this.checkIfDirectory(`${sourcePathArg}/${directoryEntry}`);
if(checkIfDirResult){
const result = await this.copyHandler(arg0,`${sourcePathArg}/${directoryEntry}`,`${destinationArg}/${folderName}`);
if(!result){
console.log(`Failed to copy directory: ${sourcePathArg}/${directoryEntry}`);
return false;
}
}else{
const result = await this.copyFileAsync(`${sourcePathArg}/${directoryEntry}`, `${destinationArg}/${folderName}`);
if(result){
console.log(`file:${sourcePathArg}/${directoryEntry} successfully copied to destination:${destinationArg}/${folderName}`);
}else{
console.log(`file:${sourcePathArg}/${directoryEntry} failed to copy to destination:${destinationArg}/${folderName}`)
return false
}
}
}
}
}else{
const result = await this.copyFileAsync(`${sourcePathArg}`, `${destinationArg}`);
if(result){
console.log(`file:${sourcePathArg} successfully copied to destination:${destinationArg}`);
}else{
console.log(`file:${sourcePathArg} failed to copy to destination:${destinationArg}`)
return false
}
}

return true
}


public async createFolderAsync(directory:string, fileName:string):Promise<boolean>{
return new Promise<boolean>((resolve, reject) =>{
this._fileSystem.mkdir(`${directory}/${fileName}`,0o777,(err) =>{
Expand Down Expand Up @@ -489,6 +530,48 @@ export class FileService{
});
}

public async movehandler(destinationArg:string, folderQueue:string[]):Promise<boolean>{

if(folderQueue.length === 0)
return true;

const sourcePath = folderQueue.shift() || '';
const folderName = this.getFileName(sourcePath);

const checkIfDirResult = await this.checkIfDirectory(`${sourcePath}`);
if(checkIfDirResult){
const loadedDirectoryEntries = await this.getEntriesFromDirectoryAsync(sourcePath);
const moveFolderResult = await this.createFolderAsync(destinationArg,folderName);
if(moveFolderResult){
for(const directoryEntry of loadedDirectoryEntries){
const checkIfDirResult = await this.checkIfDirectory(`${sourcePath}/${directoryEntry}`);
if(checkIfDirResult){
folderQueue.push(`${sourcePath}/${directoryEntry}`);
}else{
const result = await this.moveFileAsync(`${sourcePath}/${directoryEntry}`, `${destinationArg}/${folderName}`);
if(result){
console.log(`file:${sourcePath}/${directoryEntry} successfully moved to destination:${destinationArg}/${folderName}`);
}else{
console.log(`file:${sourcePath}/${directoryEntry} failed to move to destination:${destinationArg}/${folderName}`)
}
}
}
}else{
console.log(`folder:${destinationArg}/${folderName} creation failed`);
return false;
}
}else{
const result = await this.moveFileAsync(`${sourcePath}`,`${destinationArg}`);
if(result){
console.log(`file:${sourcePath} successfully moved to destination:${destinationArg}`);
}else{
console.log(`file:${sourcePath} failed to move to destination:${destinationArg}`)
}
}

return this.movehandler(`${destinationArg}/${folderName}`, folderQueue);
}

public async writeFilesAsync(directory:string, files:File[]):Promise<boolean>{

return new Promise<boolean>((resolve, reject) =>{
Expand Down Expand Up @@ -542,6 +625,45 @@ export class FileService{
});
}


public async removeHandler(arg0: string, sourceArg: string): Promise<boolean> {
const loadedDirectoryEntries = await this.getEntriesFromDirectoryAsync(sourceArg);

for (const directoryEntry of loadedDirectoryEntries) {
const entryPath = `${sourceArg}/${directoryEntry}`;
const checkIfDirectory = await this.checkIfDirectory(entryPath);

if (checkIfDirectory) {
// Recursively call the rm_dir_handler for the subdirectory
const success = await this.removeHandler(arg0, entryPath);
if (!success) {
console.log(`Failed to delete directory: ${entryPath}`);
return false;
}
} else {
const result = await this.deleteFileAsync(entryPath);
if (result) {
console.log(`File: ${directoryEntry} in ${entryPath} deleted successfully`);
} else {
console.log(`File: ${directoryEntry} in ${entryPath} failed deletion`);
return false;
}
}
}

// Delete the current directory after all its contents have been deleted
console.log(`folder to delete: ${sourceArg}`);
const result = await this.deleteFolderAsync(`${sourceArg}`);

if (result) {
console.log(`Directory: ${sourceArg} deleted successfully`);
return true;
} else {
console.log(`Failed to delete directory: ${sourceArg}`);
return false;
}
}

public async renameAsync(path:string, newFileName:string, isFile:boolean): Promise<boolean> {

return new Promise<boolean>((resolve, reject) =>{
Expand All @@ -566,6 +688,10 @@ export class FileService{
});
}

public resetDirectoryFiles(){
this._directoryFileEntires=[]
}

//virtual filesystem, use copy and then delete
public async moveFileAsync(currentPath:string, newPath:string): Promise<boolean> {

Expand Down Expand Up @@ -613,10 +739,6 @@ export class FileService{
return `${dirname(path)}/${filename} (${count})${extension}`;
}

public resetDirectoryFiles(){
this._directoryFileEntires=[]
}

public async setFolderValuesAsync(path: string):Promise<ShortCut>{
return new Promise<ShortCut>((resolve, reject) =>{

Expand Down
20 changes: 19 additions & 1 deletion src/app/shared/system-service/menu.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { Process } from "src/app/system-files/process";

export class MenuService{

private _isPasteActive = false
private _isPasteActive = false;
private _path = 'NOPATH';
private _actions = '';

pinToTaskBar: Subject<FileInfo> = new Subject<FileInfo>();
unPinFromTaskBar: Subject<FileInfo> = new Subject<FileInfo>();
Expand All @@ -32,4 +34,20 @@ export class MenuService{
getPasteState():boolean{
return this._isPasteActive;
}

setPath(path:string):void{
this._path = path;
}

getPath():string{
return this._path;
}

setActions(action:string):void{
this._actions = action;
}

getActions():string{
return this._actions;
}
}
Loading

0 comments on commit a28e357

Please sign in to comment.