this.onBlur()}
onKeyPress={e => this.onKeyPress(e)}
/>
}
private onBlur() {
this.props.editFinished(this.ref_div.current.textContent);
}
private onKeyPress(event: React.KeyboardEvent) {
if (event.key === "Enter") {
event.preventDefault();
this.onBlur();
}
}
}
export interface ClientEntryProperties {
client: ClientEntryController;
depth: number;
offset: number;
}
export interface ClientEntryState {
rename: boolean;
renameInitialName?: string;
}
@ReactEventHandler
(e => e.props.client.events)
@BatchUpdateAssignment(BatchUpdateType.CHANNEL_TREE)
export class ClientEntry extends TreeEntry {
shouldComponentUpdate(nextProps: Readonly, nextState: Readonly, nextContext: any): boolean {
return nextState.rename !== this.state.rename ||
nextProps.offset !== this.props.offset ||
nextProps.client !== this.props.client ||
nextProps.depth !== this.props.depth;
}
render() {
return (
this.onDoubleClick()}
onMouseUp={e => this.onMouseUp(e)}
onContextMenu={e => this.onContextMenu(e)}
>
{this.state.rename ?
this.onEditFinished(name)}
initialName={this.state.renameInitialName || this.props.client.properties.client_nickname}/> :
[,
]}
)
}
private onDoubleClick() {
const client = this.props.client;
if (client.channelTree.selection.is_multi_select()) return;
if (this.props.client instanceof LocalClientEntry) {
this.props.client.openRename();
} else if (this.props.client instanceof MusicClientEntry) {
/* no action defined yet */
} else {
this.props.client.open_text_chat();
}
}
private onEditFinished(new_name?: string) {
if (!(this.props.client instanceof LocalClientEntry))
throw "Only local clients could be renamed";
if (new_name && new_name !== this.state.renameInitialName) {
const client = this.props.client;
client.renameSelf(new_name).then(result => {
if (!result)
this.setState({rename: true, renameInitialName: new_name}); //TODO: Keep last name?
});
}
this.setState({rename: false});
}
private onMouseUp(event: React.MouseEvent) {
if (event.button !== 0) return; /* only left mouse clicks */
const tree = this.props.client.channelTree;
if (tree.isClientMoveActive()) return;
tree.events.fire("action_select_entries", {entries: [this.props.client], mode: "auto"});
}
private onContextMenu(event: React.MouseEvent) {
if (settings.static(Settings.KEY_DISABLE_CONTEXT_MENU))
return;
event.preventDefault();
const client = this.props.client;
if (client.channelTree.selection.is_multi_select() && client.isSelected()) return;
client.channelTree.events.fire("action_select_entries", {
entries: [client],
mode: "exclusive"
});
client.showContextMenu(event.pageX, event.pageY);
}
@EventHandler("notify_select_state_change")
private handleSelectChangeState() {
this.forceUpdate();
}
}