-
Notifications
You must be signed in to change notification settings - Fork 6
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
Core 617 orphan collection #215
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import vscode from 'vscode' | ||
import { type TocsTreeProvider, type BookOrTocNode } from './book-tocs' | ||
import { type TocModification, TocModificationKind, type TocModificationParams, TocNodeKind, BookRootNode, type CreatePageEvent, type CreateSubbookEvent, type CreateAncillaryEvent } from '../../common/src/toc' | ||
import { type TocsTreeProvider, type BookOrTocNode, ClientOnlyTocKinds } from './book-tocs' | ||
import { type TocModification, TocModificationKind, type TocModificationParams, TocNodeKind, BookRootNode, type CreatePageEvent, type CreateSubbookEvent, type CreateAncillaryEvent, isClientTocNode } from '../../common/src/toc' | ||
import { ExtensionServerRequest } from '../../common/src/requests' | ||
import { expect, getRootPathUri } from './utils' | ||
import { type ExtensionHostContext } from './panel' | ||
|
@@ -17,6 +17,8 @@ export const validateTitle = (title: string) => { | |
|
||
export const XFER_ITEM_ID = 'application/vnd.code.tree.tocTrees' | ||
|
||
type TocEvent = TocModification | CreateSubbookEvent | CreatePageEvent | CreateAncillaryEvent | ||
|
||
export class TocsEventHandler implements vscode.TreeDragAndDropController<BookOrTocNode> { | ||
constructor( | ||
private readonly tocTreesProvider: TocsTreeProvider, | ||
|
@@ -30,7 +32,7 @@ export class TocsEventHandler implements vscode.TreeDragAndDropController<BookOr | |
return expect(getRootPathUri(), 'Could not get root path uri').toString() | ||
} | ||
|
||
private async fireEvent(event: TocModification | CreateSubbookEvent | CreatePageEvent | CreateAncillaryEvent) { | ||
private async fireEvent(event: TocEvent) { | ||
const workspaceUri = this.workspaceUri | ||
const params: TocModificationParams = { workspaceUri, event } | ||
await this.context.client.sendRequest( | ||
|
@@ -126,41 +128,43 @@ export class TocsEventHandler implements vscode.TreeDragAndDropController<BookOr | |
} | ||
} | ||
} | ||
if (nodeType === TocNodeKind.Page) { | ||
const event: CreatePageEvent = { | ||
type: TocNodeKind.Page, | ||
title, | ||
bookIndex, | ||
parentNodeToken | ||
} | ||
await this.fireEvent(event) | ||
} else if (nodeType === TocNodeKind.Subbook) { | ||
const event: CreateSubbookEvent = { | ||
type: TocNodeKind.Subbook, | ||
title, | ||
slug, | ||
bookIndex, | ||
parentNodeToken | ||
} | ||
await this.fireEvent(event) | ||
} else if (nodeType === TocNodeKind.Ancillary) { | ||
const event: CreateAncillaryEvent = { | ||
type: TocNodeKind.Ancillary, | ||
title, | ||
bookIndex, | ||
parentNodeToken | ||
} | ||
await this.fireEvent(event) | ||
let event: CreatePageEvent | CreateSubbookEvent | CreateAncillaryEvent | ||
switch (nodeType) { | ||
case TocNodeKind.Page: | ||
event = { | ||
type: TocNodeKind.Page, | ||
title, | ||
bookIndex, | ||
parentNodeToken | ||
} | ||
break | ||
case TocNodeKind.Subbook: | ||
event = { | ||
type: TocNodeKind.Subbook, | ||
title, | ||
slug, | ||
bookIndex, | ||
parentNodeToken | ||
} | ||
break | ||
case TocNodeKind.Ancillary: | ||
event = { | ||
type: TocNodeKind.Ancillary, | ||
title, | ||
bookIndex, | ||
parentNodeToken | ||
} | ||
break | ||
} | ||
await this.fireEvent(event) | ||
} | ||
|
||
async renameNode(node: BookOrTocNode) { | ||
// TODO Implement the rename functionality using inline editing (wait for the API to be available) | ||
// https://github.com/microsoft/vscode/issues/97190 | ||
// https://stackoverflow.com/questions/70594061/change-an-existing-label-name-in-tree-view-vscode-extension | ||
let oldTitle: string | undefined = '' | ||
if (node.type !== BookRootNode.Singleton && 'title' in node.value) { | ||
/* istanbul ignore next */ | ||
if (isClientTocNode(node)) { | ||
oldTitle = node.value.title | ||
} | ||
const newTitle = await this.askTitle(oldTitle) | ||
|
@@ -204,10 +208,18 @@ export class TocsEventHandler implements vscode.TreeDragAndDropController<BookOr | |
|
||
async handleDrop(target: BookOrTocNode | undefined, dataTransfer: vscode.DataTransfer): Promise<void> { | ||
const dragging: BookOrTocNode | undefined = dataTransfer.get(XFER_ITEM_ID)?.value | ||
if (dragging?.type === undefined) throw new Error('BUG: Bad drag target') | ||
if (target === undefined) throw new Error('BUG: Bad drop target') | ||
if (target !== dragging && dragging.type !== BookRootNode.Singleton) { | ||
await this.moveNode(dragging, target) | ||
if (dragging?.type === undefined) { throw new Error('BUG: Bad drag target') } | ||
if (target === undefined) { throw new Error('BUG: Bad drop target') } | ||
if ( | ||
target !== dragging && | ||
dragging.type !== ClientOnlyTocKinds.OrphanCollection && | ||
dragging.type !== BookRootNode.Singleton | ||
) { | ||
if (target.type === ClientOnlyTocKinds.OrphanCollection) { | ||
await this.removeNode(dragging) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So they never get put in the OrphanCollection, they just go under it somehow? How does the OrphanCollection actually gets elements, like in your screenshot? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
So the language server is telling the client which modules are orphaned and the client renders them under the orphan collection. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, here's a video instead of a screenshot. Screen.Recording.2025-01-14.at.5.06.57.PM.mov |
||
} else { | ||
await this.moveNode(dragging, target) | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming seems a bit confusing because
isClientTocNode
andClientOnlyTocKinds
seem to mean opposite things. MaybeisServerTocNode
? OrisClientOnlyTocNode
and invert the logic?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
isTocLeafNode
? The function is for checking if the node can be moved/renamed/deleted (leaf nodes).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this was a little confusing. My goal was to illustrate that the orphan collection is something that is specific to the tree view. I did not want to entangle it with the
ClientTocNode
. I replaced theClientOnlyTocKinds
enum with anOrphanCollectionKind
constant in hopes of making the difference more clear.