Skip to content

Commit

Permalink
Display all instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreSi committed Jan 9, 2025
1 parent 65ce2bf commit 4b2c3ab
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const moveDeprecatedInstructionsDown = (
};

export interface TreeViewItemContent {
applySearch: boolean;
getName(): string | React.Node;
getDescription(): string | null;
getId(): string;
Expand All @@ -103,6 +104,7 @@ export interface TreeViewItemContent {
}

export class ObjectGroupTreeViewItemContent implements TreeViewItemContent {
applySearch = true;
group: gdObjectGroup;

constructor(group: gdObjectGroup) {
Expand Down Expand Up @@ -135,17 +137,24 @@ export class ObjectGroupTreeViewItemContent implements TreeViewItemContent {
}

getThumbnail(): ?string {
return null;
return 'res/ribbon_default/objectsgroups64.png';
}
}
export class ObjectGroupObjectTreeViewItemContent
implements TreeViewItemContent {
applySearch = true;
object: gdObject;
props: ObjectTreeViewItemProps;
groupPrefix: string;

constructor(object: gdObject, props: ObjectTreeViewItemProps) {
constructor(
object: gdObject,
props: ObjectTreeViewItemProps,
groupPrefix: string
) {
this.object = object;
this.props = props;
this.groupPrefix = groupPrefix;
}

getObject(): gdObject | null {
Expand All @@ -160,11 +169,11 @@ export class ObjectGroupObjectTreeViewItemContent
}

getId(): string {
return getObjectTreeViewItemId(this.object);
return `${this.groupPrefix}-${getObjectTreeViewItemId(this.object)}`;
}

getHtmlId(index: number): ?string {
return `object-item-${index}`;
return `${this.groupPrefix}-object-item-${index}`;
}

getDataSet(): ?HTMLDataset {
Expand Down Expand Up @@ -236,7 +245,8 @@ class GroupTreeViewItem implements TreeViewItem {
return new LeafTreeViewItem(
new ObjectGroupObjectTreeViewItemContent(
object,
this.objectTreeViewItemProps
this.objectTreeViewItemProps,
this.content.getId()
)
);
})
Expand All @@ -261,6 +271,7 @@ class RootTreeViewItem implements TreeViewItem {

class InstructionTreeViewItemContent implements TreeViewItemContent {
instructionMetadata: EnumeratedInstructionMetadata;
applySearch = false;
constructor(instructionMetadata) {
this.instructionMetadata = instructionMetadata;
}
Expand Down Expand Up @@ -291,6 +302,7 @@ class InstructionTreeViewItemContent implements TreeViewItemContent {
class LabelTreeViewItemContent implements TreeViewItemContent {
id: string;
label: string | React.Node;
applySearch = true;

constructor(id: string, label: string | React.Node) {
this.id = id;
Expand Down Expand Up @@ -605,6 +617,7 @@ export default class InstructionOrObjectSelector extends React.PureComponent<
};

getTreeViewItemName = (item: TreeViewItem) => item.content.getName();
shouldApplySearchToItem = (item: TreeViewItem) => item.content.applySearch;
getTreeViewItemDescription = (item: TreeViewItem) =>
item.content.getDescription();
getTreeViewItemId = (item: TreeViewItem) => item.content.getId();
Expand Down Expand Up @@ -804,7 +817,7 @@ export default class InstructionOrObjectSelector extends React.PureComponent<
})
)
: null,
displayedInstructionsList
displayedInstructionsList.length > 0
? new RootTreeViewItem(
new LabelTreeViewItemContent(
'instructions',
Expand Down Expand Up @@ -889,8 +902,9 @@ export default class InstructionOrObjectSelector extends React.PureComponent<
<ReadOnlyTreeView
height={height}
items={getTreeViewItems(i18n)}
getItemHeight={() => (isSearching ? 40 : 32)}
getItemHeight={() => (isSearching ? 44 : 32)}
getItemName={this.getTreeViewItemName}
shouldApplySearchToItem={this.shouldApplySearchToItem}
getItemDescription={this.getTreeViewItemDescription}
getItemId={this.getTreeViewItemId}
getItemHtmlId={this.getTreeViewItemHtmlId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const getObjectFolderTreeViewItemId = (
export class ObjectFolderTreeViewItemContent implements TreeViewItemContent {
objectFolder: gdObjectFolderOrObject;
props: ObjectFolderTreeViewItemProps;
applySearch = true;

constructor(
objectFolder: gdObjectFolderOrObject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type ObjectTreeViewItemProps = {|
export class ObjectTreeViewItemContent implements TreeViewItemContent {
object: gdObjectFolderOrObject;
props: ObjectTreeViewItemProps;
applySearch = true;

constructor(
object: gdObjectFolderOrObject,
Expand Down
12 changes: 10 additions & 2 deletions newIDE/app/src/UI/TreeView/ReadOnlyTreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type Props<Item> = {|
width?: number,
items: Item[],
getItemHeight: () => number,
shouldApplySearchToItem: Item => boolean,
getItemName: Item => string | React.Node,
getItemDescription?: Item => string,
getItemId: Item => string,
Expand Down Expand Up @@ -113,6 +114,7 @@ const ReadOnlyTreeView = <Item: ItemBaseAttributes>(
items,
searchText,
getItemHeight,
shouldApplySearchToItem,
getItemName,
getItemDescription,
getItemId,
Expand Down Expand Up @@ -180,10 +182,13 @@ const ReadOnlyTreeView = <Item: ItemBaseAttributes>(
}

const name = getItemName(item);
const description = getItemDescription ? getItemDescription(item) : undefined;
const description = getItemDescription
? getItemDescription(item)
: undefined;
const dataset = getItemDataset ? getItemDataset(item) : undefined;
const extraClass =
animatedItemId && id === animatedItemId ? classes.animate : '';
const applySearch = shouldApplySearchToItem(item);

/*
* Append node to result if either:
Expand All @@ -197,7 +202,9 @@ const ReadOnlyTreeView = <Item: ItemBaseAttributes>(
!searchText ||
forceAllOpened ||
forceOpen ||
(typeof name === 'string' && name.toLowerCase().includes(searchText)) ||
(!applySearch ||
(typeof name === 'string' &&
name.toLowerCase().includes(searchText))) ||
flattenedChildren.length > 0
) {
const thumbnailSrc = getItemThumbnail ? getItemThumbnail(item) : null;
Expand Down Expand Up @@ -241,6 +248,7 @@ const ReadOnlyTreeView = <Item: ItemBaseAttributes>(
[
getItemId,
getItemChildren,
shouldApplySearchToItem,
forceAllOpened,
openedNodeIds,
openedDuringSearchNodeIds,
Expand Down
2 changes: 1 addition & 1 deletion newIDE/app/src/UI/TreeView/ReadOnlyTreeViewRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const TreeViewRow = <Item: ItemBaseAttributes>(props: Props<Item>) => {

const onDoubleClickItem = React.useCallback(
e => {
if (!node || !node.hasChildren) return;
if (!node || !node.hasChildren || node.disableCollapse) return;
onOpen(node);
},
[node, onOpen]
Expand Down
1 change: 1 addition & 0 deletions newIDE/app/src/UI/TreeView/TreeView.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@

.itemTextContainer {
display: inline-grid;
gap: 2px;
}

.itemName {
Expand Down
2 changes: 1 addition & 1 deletion newIDE/app/src/UI/TreeView/TreeViewRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ const TreeViewRow = <Item: ItemBaseAttributes>(props: Props<Item>) => {

const onDoubleClickItem = React.useCallback(
e => {
if (!node || !node.hasChildren) return;
if (!node || !node.hasChildren || node.disableCollapse) return;
onOpen(node);
},
[node, onOpen]
Expand Down

0 comments on commit 4b2c3ab

Please sign in to comment.