From 1feed03272490e3b09be63323d55090f8f860a77 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Wed, 26 May 2021 13:45:14 +0200 Subject: [PATCH] Fixed some bookmark related stuff and updated the ChangeLog.md --- ChangeLog.md | 5 ++ shared/js/Bookmarks.ts | 4 ++ shared/js/ui/modal/bookmarks/Controller.ts | 34 ++++++++++++-- shared/js/ui/modal/bookmarks/Definitions.ts | 4 +- shared/js/ui/modal/bookmarks/Renderer.tsx | 51 ++++++++++++--------- 5 files changed, 72 insertions(+), 26 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 18c7e89a..242bdba3 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,4 +1,9 @@ # Changelog: +* **26.05.21** + - Fixed automated builds + - Fixed the bookmark UI popout window + - Added a context menu for the general bookmark container + * **05.05.21** - Reworked the icon modal - Fixed some minor icon and avatar related issues diff --git a/shared/js/Bookmarks.ts b/shared/js/Bookmarks.ts index 55d6e99b..e8bf474e 100644 --- a/shared/js/Bookmarks.ts +++ b/shared/js/Bookmarks.ts @@ -300,6 +300,10 @@ export class BookmarkManager { this.doEditBookmark(uniqueId, newValues); } + directoryContents(uniqueId: string) : BookmarkEntry[] { + return this.registeredBookmarks.filter(bookmark => bookmark.parentEntry === uniqueId); + } + deleteEntry(uniqueId: string) { const index = this.registeredBookmarks.findIndex(entry => entry.uniqueId === uniqueId); if(index === -1) { diff --git a/shared/js/ui/modal/bookmarks/Controller.ts b/shared/js/ui/modal/bookmarks/Controller.ts index 8557d6bd..f88cafd7 100644 --- a/shared/js/ui/modal/bookmarks/Controller.ts +++ b/shared/js/ui/modal/bookmarks/Controller.ts @@ -17,7 +17,9 @@ import {server_connections} from "tc-shared/ConnectionManager"; import {ConnectionHandler, ConnectionState} from "tc-shared/ConnectionHandler"; import {LocalClientEntry} from "tc-shared/tree/Client"; import _ from "lodash"; -import {LogCategory, logError} from "tc-shared/log"; +import {LogCategory, logError, logWarn} from "tc-shared/log"; +import {promptYesNo} from "tc-shared/ui/modal/yes-no/Controller"; +import {tra} from "tc-shared/i18n/localize"; class BookmarkModalController { readonly events: Registry; @@ -194,7 +196,30 @@ class BookmarkModalController { })); /* events */ - this.events.on("action_delete_bookmark", event => bookmarks.deleteEntry(event.uniqueId)); + this.events.on("action_delete_bookmark", event => { + const entry = bookmarks.findBookmark(event.uniqueId); + if(!entry) { + logWarn(LogCategory.GENERAL, tr("Tried to delete an unknown bookmark entry %s."), event.uniqueId); + return; + } + + const children = bookmarks.directoryContents(entry.uniqueId); + if(!event.force && entry.type === "directory" && children.length > 0) { + promptYesNo({ + title: tr("Are you sure?"), + question: tra("Do you really want to delete the directory \"{0}\"?\nThe directory contains {1} entries.", entry.displayName, children.length) + }).then(result => { + if(!result) { + return; + } + + this.events.fire("action_delete_bookmark", { uniqueId: entry.uniqueId, force: true }); + }); + return; + } + + bookmarks.deleteEntry(event.uniqueId); + }); this.events.on("action_create_bookmark", event => { if(!event.displayName) { return; @@ -215,10 +240,13 @@ class BookmarkModalController { } case "selected": - default: parentBookmark = this.selectedBookmark?.parentEntry; previousBookmark = this.selectedBookmark?.previousEntry; break; + + case "end": + default: + break; } if(event.entryType === "bookmark") { diff --git a/shared/js/ui/modal/bookmarks/Definitions.ts b/shared/js/ui/modal/bookmarks/Definitions.ts index 4d4ac18e..11151f2b 100644 --- a/shared/js/ui/modal/bookmarks/Definitions.ts +++ b/shared/js/ui/modal/bookmarks/Definitions.ts @@ -55,11 +55,13 @@ export interface ModalBookmarkEvents { entry: string } | { type: "selected", + } | { + type: "end" }, displayName: string | undefined }, action_duplicate_bookmark: { uniqueId: string, displayName: string | undefined, originalName: string }, - action_delete_bookmark: { uniqueId: string }, + action_delete_bookmark: { uniqueId: string, force: boolean }, action_connect: { uniqueId: string, newTab: boolean, closeModal: boolean }, diff --git a/shared/js/ui/modal/bookmarks/Renderer.tsx b/shared/js/ui/modal/bookmarks/Renderer.tsx index 7fb6a4f8..58fb5ca5 100644 --- a/shared/js/ui/modal/bookmarks/Renderer.tsx +++ b/shared/js/ui/modal/bookmarks/Renderer.tsx @@ -31,8 +31,6 @@ import ServerInfoImage from "./serverinfo.png"; import {IconTooltip} from "tc-shared/ui/react-elements/Tooltip"; import {CountryCode} from "tc-shared/ui/react-elements/CountryCode"; import {downloadTextAsFile, requestFileAsText} from "tc-shared/file/Utils"; -import {promptYesNo} from "tc-shared/ui/modal/yes-no/Controller"; -import {tra} from "tc-shared/i18n/localize"; const EventContext = React.createContext>(undefined); const VariableContext = React.createContext>(undefined); @@ -53,23 +51,6 @@ const BookmarkListEntryRenderer = React.memo((props: { entry: BookmarkListEntry const events = useContext(EventContext); const selectedItem = variables.useVariable("bookmarkSelected", undefined, undefined); - const tryDelete = () => { - if(props.entry.type === "directory" && props.entry.childCount > 0) { - promptYesNo({ - title: tr("Are you sure?"), - question: tra("Do you really want to delete the directory \"{0}\"?\nThe directory contains {1} entries.", props.entry.displayName, props.entry.childCount) - }).then(result => { - if(!result) { - return; - } - - events.fire("action_delete_bookmark", { uniqueId: props.entry.uniqueId }); - }); - } else { - events.fire("action_delete_bookmark", { uniqueId: props.entry.uniqueId }); - } - }; - let icon; if(props.entry.icon) { icon = ; @@ -98,7 +79,9 @@ const BookmarkListEntryRenderer = React.memo((props: { entry: BookmarkListEntry ); } buttons.push( -
+
{ + events.fire("action_delete_bookmark", { uniqueId: props.entry.uniqueId, force: false }); + }}>
); @@ -184,7 +167,7 @@ const BookmarkListEntryRenderer = React.memo((props: { entry: BookmarkListEntry type: "normal", label: props.entry.type === "bookmark" ? tr("Delete bookmark") : tr("Delete directory"), icon: ClientIcon.BookmarkRemove, - click: tryDelete + click: () => events.fire("action_delete_bookmark", { uniqueId: props.entry.uniqueId, force: false }) } ]); }} @@ -209,7 +192,31 @@ const BookmarkList = React.memo(() => { const bookmarks = bookmarksInfo.status === "loaded" ? bookmarksInfo.value : []; return ( -
+
{ + event.preventDefault(); + + if(bookmarks.length === 0) { + return; + } + + spawnContextMenu({ pageX: event.pageX, pageY: event.pageY }, [ + { + type: "normal", + label: tr("Add bookmark"), + icon: ClientIcon.BookmarkAdd, + click: () => events.fire("action_create_bookmark", { entryType: "bookmark", order: { type: "end" }, displayName: undefined }) + }, + { + type: "normal", + label: tr("Add directory"), + icon: ClientIcon.BookmarkAddFolder, + click: () => events.fire("action_create_bookmark", { entryType: "directory", order: { type: "end" }, displayName: undefined }) + }, + ]); + }} + > {bookmarks.map(entry => )}
loading