Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename folder #563

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
"openFolder": "Open folder",
"renameButton": "RENAME",
"renameFile": "Rename file",
"renameFolder": "Rename folder",
"renameFrom": "from:",
"renameTitle": "Rename",
"renameTo": "to:",
Expand Down
8 changes: 8 additions & 0 deletions interfaces/shared-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,11 @@ export interface RenameFileResponse {
oldFileName: string;
errMsg?: string;
}

export interface RenameFolderResponse {
index: number;
success: boolean;
renameTo: string;
sourceFolder: string;
errMsg?: string;
}
62 changes: 50 additions & 12 deletions node/main-ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function setUpIpcMessages(ipc, win, pathToAppData, systemMessages) {
if (executablePath) {
event.sender.send('preferred-video-player-returning', executablePath);
}
}).catch(err => {});
}).catch(err => { });
});

/**
Expand Down Expand Up @@ -173,11 +173,11 @@ export function setUpIpcMessages(ipc, win, pathToAppData, systemMessages) {
*/
ipc.on('replace-thumbnail', (event, pathToIncomingJpg: string, item: ImageElement) => {
const fileToReplace: string = path.join(
GLOBALS.selectedOutputFolder,
'vha-' + GLOBALS.hubName,
'thumbnails',
item.hash + '.jpg'
);
GLOBALS.selectedOutputFolder,
'vha-' + GLOBALS.hubName,
'thumbnails',
item.hash + '.jpg'
);

const height: number = GLOBALS.screenshotSettings.height;

Expand All @@ -187,7 +187,7 @@ export function setUpIpcMessages(ipc, win, pathToAppData, systemMessages) {
event.sender.send('thumbnail-replaced');
}
})
.catch((err) => {});
.catch((err) => { });

});

Expand All @@ -203,7 +203,7 @@ export function setUpIpcMessages(ipc, win, pathToAppData, systemMessages) {
if (inputDirPath) {
event.sender.send('input-folder-chosen', inputDirPath);
}
}).catch(err => {});
}).catch(err => { });
});

/**
Expand All @@ -218,7 +218,7 @@ export function setUpIpcMessages(ipc, win, pathToAppData, systemMessages) {
if (inputDirPath) {
event.sender.send('old-folder-reconnected', inputSource, inputDirPath);
}
}).catch(err => {});
}).catch(err => { });
});

/**
Expand Down Expand Up @@ -273,7 +273,7 @@ export function setUpIpcMessages(ipc, win, pathToAppData, systemMessages) {
if (outputDirPath) {
event.sender.send('output-folder-chosen', outputDirPath);
}
}).catch(err => {});
}).catch(err => { });
});

/**
Expand Down Expand Up @@ -315,6 +315,44 @@ export function setUpIpcMessages(ipc, win, pathToAppData, systemMessages) {
event.sender.send('rename-file-response', index, success, renameTo, file, errMsg);
});

/**
* Try to rename the folder
*/
ipc.on('try-to-rename-this-folder', (event, sourceFolder: string, renameTo: string, file: string, index: number): void => {
console.log('renaming folder:');

const original: string = path.join(sourceFolder);
const newName: string = path.join(renameTo);

console.log(original);
console.log(newName);

let success = true;
let errMsg: string;

// check if already exists first
if (fs.existsSync(newName)) {
success = false;
errMsg = 'RIGHTCLICK.errorFileNameExists';
} else {
try {
fs.renameSync(original, newName);
} catch (err) {
success = false;
console.log(err);
if (err.code === 'ENOENT') {
// const pathObj = path.parse(err.path);
// console.log(pathObj);
errMsg = 'RIGHTCLICK.errorFileNotFound';
} else {
errMsg = 'RIGHTCLICK.errorSomeError';
}
}
}

event.sender.send('rename-folder-response', success, sourceFolder, renameTo, index, errMsg);
});

/**
* Close the window / quit / exit the app
*/
Expand Down Expand Up @@ -345,13 +383,13 @@ export function setUpIpcMessages(ipc, win, pathToAppData, systemMessages) {
writeVhaFileToDisk(finalObjectToSave, GLOBALS.currentlyOpenVhaFile, () => {
try {
BrowserWindow.getFocusedWindow().close();
} catch {}
} catch { }
});

} else {
try {
BrowserWindow.getFocusedWindow().close();
} catch {}
} catch { }
}
});
});
Expand Down
16 changes: 13 additions & 3 deletions src/app/components/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
class="right-click-menu"
@rightClickAnimation
>
<ul @rightClickContentAnimation>
<ul @rightClickContentAnimation *ngIf="currentRightClickedItem.cleanName !== '*FOLDER*'; else rightClickOnFolder">
<li
(click)="openRenameFileModal()"
[ngClass]="{ 'right-click-disabled': !rootFolderLive }"
Expand All @@ -98,6 +98,15 @@
class="right-click-delete"
>{{ 'RIGHTCLICK.delete' | translate }}</li>
</ul>

<ng-template #rightClickOnFolder>
<ul @rightClickContentAnimation>
<li
(click)="openRenameFileModal()"
[ngClass]="{ 'right-click-disabled': !rootFolderLive }"
>{{ 'RIGHTCLICK.renameFolder' | translate }}</li>
</ul>
</ng-template>
</div>

<!-- =========== Thumbnail Sheet Display =========== -->
Expand Down Expand Up @@ -146,6 +155,7 @@
[settingsButtons]="settingsButtons"

[renameResponse]="renameFileResponseBehaviorSubject"
[renameFolderResponse]="renameFolderresponseBehaviorSubject"
></app-rename-modal>

<!-- =========== AUTO-GENERATED TAGS MODAL =========== -->
Expand Down Expand Up @@ -732,8 +742,8 @@
<app-thumbnail
*ngFor="let item of scroll.viewPortItems"

(videoClick)=" (item.cleanName === '*FOLDER*') ? handleFolderIconClicked(item.partialPath) : handleClick($event, item)"
(rightClick)=" (item.cleanName === '*FOLDER*') ? doNothing() : rightMouseClicked($event.mouseEvent, $event.item)"
(videoClick)=" (item.cleanName === '*FOLDER*') ? handleFolderIconClicked(item.partialPath) : handleClick($event, item)"
(rightClick)=" rightMouseClicked($event.mouseEvent, $event.item)"

(sheetClick)="this.openThumbnailSheet(item)"
(drop)="droppedSomethingOverVideo($event, item)"
Expand Down
30 changes: 28 additions & 2 deletions src/app/components/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
AllSupportedViews,
HistoryItem,
RenameFileResponse,
RenameFolderResponse,
SupportedTrayView,
SupportedView,
VideoClickEmit,
Expand Down Expand Up @@ -300,6 +301,7 @@ export class HomeComponent implements OnInit, AfterViewInit {
numberScreenshotsDeletedBehaviorSubject: BehaviorSubject<number> = new BehaviorSubject(undefined);
oldFolderReconnectedBehaviorSubject: BehaviorSubject<{source: number, path: string}> = new BehaviorSubject(undefined);
renameFileResponseBehaviorSubject: BehaviorSubject<RenameFileResponse> = new BehaviorSubject(undefined);
renameFolderresponseBehaviorSubject:BehaviorSubject<RenameFolderResponse> = new BehaviorSubject(undefined);

// ========================================================================
// \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Expand Down Expand Up @@ -415,7 +417,29 @@ export class HomeComponent implements OnInit, AfterViewInit {
});
this.renameFileResponseBehaviorSubject.next(undefined); // allways remove right away

});
});

this.electronService.ipcRenderer.on(
'rename-folder-response', (
event,
success: boolean,
index: number,
renameTo: string,
sourceFolder: string,
errMsg?: string
) => {

this.renameFolderresponseBehaviorSubject.next({
index: index,
success: success,
renameTo: renameTo,
sourceFolder:sourceFolder,
errMsg: errMsg,
});
this.renameFolderresponseBehaviorSubject.next(undefined); // allways remove right away

});



// for statistics.component
Expand Down Expand Up @@ -1890,7 +1914,9 @@ export class HomeComponent implements OnInit, AfterViewInit {
this.currentRightClickedItem = item;
this.rightClickShowing = true;
}

ok(){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIP spandrel? 🙂

console.log("ok")
}
/**
* When in double-click mode and a video is clicked - `currentClickedItemName` updated
* @param item
Expand Down
29 changes: 19 additions & 10 deletions src/app/components/rename-file/rename-file.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,33 @@
[ngClass]="{ 'dark-mode-on': darkMode }"
>
<span class="hidden">{{ renamingWIP }}</span>
<span class="extension" *ngIf="renamingWIP.length > 0">.{{ renamingExtension }}</span>
<span class="extension"
*ngIf="renamingWIP.length > 0 && currentRightClickedItem.cleanName !== '*FOLDER*'">.{{ renamingExtension }}</span>
</span>
</div>

<span *ngIf="renameErrMsg !== ''" class="rename-err-msg">
{{ renameErrMsg | translate }}
</span>

<button
[disabled]="
(renamingWIP + '.' + renamingExtension) === currentRightClickedItem.fileName
|| nodeRenamingFile
|| renamingWIP.length === 0
"
class="wizard-button button-rename"
(click)="attemptToRename()"
>
<button *ngIf="currentRightClickedItem.cleanName !== '*FOLDER*' else submitFolder"
[disabled]="
(renamingWIP + '.' + renamingExtension) === currentRightClickedItem.fileName
|| nodeRenamingFile
|| renamingWIP.length === 0
"
class="wizard-button button-rename"
(click)="attemptToRename()">
{{ 'RIGHTCLICK.renameButton' | translate }}
</button>

<ng-template #submitFolder>
<button
[disabled]="renamingWIP=== currentRightClickedItem.fileName||nodeRenamingFile || renamingWIP.length === 0"
class="wizard-button button-rename"
(click)="attemptToRenameFoler()">
{{ 'RIGHTCLICK.renameButton' | translate }}
</button>
</ng-template>

</div>
52 changes: 47 additions & 5 deletions src/app/components/rename-file/rename-file.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ElectronService } from '../../providers/electron.service';
import { FilePathService } from '../views/file-path.service';

import { ImageElement } from '../../../../interfaces/final-object.interface';
import { RenameFileResponse } from '../../../../interfaces/shared-interfaces';
import { RenameFileResponse, RenameFolderResponse } from '../../../../interfaces/shared-interfaces';

@Component({
selector: 'app-rename-file',
Expand All @@ -25,14 +25,16 @@ export class RenameFileComponent implements OnInit, OnDestroy {
@Input() macVersion: boolean;
@Input() selectedSourceFolder: string;

@Input() renameResponse: Observable<RenameFileResponse>
@Input() renameResponse: Observable<RenameFileResponse>;
@Input() renameFolderResponse: Observable<RenameFolderResponse>;

renamingWIP: string;
renamingExtension: string;
nodeRenamingFile: boolean = false;
renameErrMsg: string = '';

responseSubscription: Subscription;
folderResponseSubscription: Subscription;

constructor(
public cd: ChangeDetectorRef,
Expand All @@ -41,27 +43,41 @@ export class RenameFileComponent implements OnInit, OnDestroy {
) { }

ngOnInit(): void {
this.renamingWIP = this.filePathService.getFileNameWithoutExtension(this.currentRightClickedItem.fileName);
if (this.currentRightClickedItem.cleanName === '*FOLDER*') {
this.renamingWIP = this.currentRightClickedItem.fileName;
}
else {
this.renamingWIP = this.filePathService.getFileNameWithoutExtension(this.currentRightClickedItem.fileName);
}
this.renamingExtension = this.filePathService.getFileNameExtension(this.currentRightClickedItem.fileName);

setTimeout(() => {
this.renameFileInput.nativeElement.focus();
}, 0);

this.responseSubscription = this.renameResponse.subscribe((data: RenameFileResponse) => {

if (data) {
console.log('WOW !!!');
console.log(data);

// just in case, make sure the message came back for the current file
if (this.currentRightClickedItem.index === data.index && !data.success) {
this.nodeRenamingFile = false;
this.renameErrMsg = data.errMsg;
this.cd.detectChanges();
} // if success, the `home.component` closes this component, no need to do anything else
}
});

this.folderResponseSubscription = this.renameFolderResponse.subscribe((data: RenameFolderResponse) => {
if (data) {
if (this.currentRightClickedItem.index === data.index && !data.success) {
//folder rename done.
console.log("folder rename")
this.nodeRenamingFile = false;
this.renameErrMsg = data.errMsg;
this.cd.detectChanges();
} // if success, the `home.component` closes this component, no need to do anything else
}
});
}

Expand Down Expand Up @@ -102,7 +118,33 @@ export class RenameFileComponent implements OnInit, OnDestroy {
}
}

attemptToRenameFoler() {
//calling try-to-rename-folder to update folder and then re-scan

this.nodeRenamingFile = true;
this.renameErrMsg = '';
const sourceFolder: string = this.selectedSourceFolder + this.currentRightClickedItem.partialPath;
const renameTo: string = sourceFolder.substring(0, sourceFolder.lastIndexOf("/")) + "/" + this.renamingWIP;

if (sourceFolder === renameTo) {
this.renameErrMsg = 'RIGHTCLICK.errorMustBeDifferent';
this.nodeRenamingFile = false;
} else if (this.renamingWIP.length === 0) {
this.renameErrMsg = 'RIGHTCLICK.errorMustNotBeEmpty';
this.nodeRenamingFile = false;
} else {
this.electronService.ipcRenderer.send(
'try-to-rename-this-folder',
sourceFolder,
renameTo,
this.renamingWIP,
this.currentRightClickedItem.index
);
}
}

ngOnDestroy() {
this.responseSubscription.unsubscribe();
this.folderResponseSubscription.unsubscribe();
}
}
Loading