(assistant: Assistant)
| 151 | } |
| 152 | |
| 153 | #createViewForAssistant(assistant: Assistant) { |
| 154 | // Create a button in sidebar. |
| 155 | const button = new ToggleButton(assistant.service.icon.getImage()); |
| 156 | button.view.setTooltip(assistant.service.name); |
| 157 | button.view.setStyle({ |
| 158 | width: style.buttonSize, |
| 159 | height: style.buttonSize, |
| 160 | }); |
| 161 | this.#sidebar.addItemAt(button, -1); |
| 162 | // Create the service's view. |
| 163 | const mainView = new assistant.viewClass(); |
| 164 | mainView.view.setVisible(false); |
| 165 | mainView.view.setStyle({flex: 1}); |
| 166 | mainView.loadService(assistant.service); |
| 167 | this.contentView.addChildView(mainView.view); |
| 168 | // Save them. |
| 169 | const view = {assistant, button, mainView}; |
| 170 | this.views.push(view); |
| 171 | button.onClick = this.#onSelect.bind(this, view); |
| 172 | button.onContextMenu = this.#onContextMenu.bind(this, view); |
| 173 | // Update button image and title on change. |
| 174 | mainView.connections.add(mainView.onNewTitle.connect(() => { |
| 175 | this.#onNewTitle(view); |
| 176 | })); |
| 177 | mainView.connections.add(assistant.service.onChangeName.connect(() => { |
| 178 | button.view.setTooltip(assistant.service.name); |
| 179 | this.#onNewTitle(view); |
| 180 | })); |
| 181 | mainView.connections.add(assistant.service.onChangeIcon.connect(() => { |
| 182 | button.setImage(assistant.service.icon.getImage()); |
| 183 | })); |
| 184 | } |
| 185 | |
| 186 | #removeViewForAssistant(assistant: Assistant) { |
| 187 | const index = this.views.findIndex(v => v.assistant == assistant); |
no test coverage detected