import React from "react"; import { action, computed, makeObservable, observable } from "mobx"; import { observer } from "mobx-react"; import classNames from "classnames"; import { HorizontalHeaderWithBody, VerticalHeaderWithBody, Header, Body } from "eez-studio-ui/header-with-body"; import { Navigation } from "instrument/window/navigation"; import { ButtonAction, IconAction } from "eez-studio-ui/action"; import { AlertDanger } from "eez-studio-ui/alert"; import { Loader } from "eez-studio-ui/loader"; import { Toolbar } from "eez-studio-ui/toolbar"; import { Dialog, showDialog } from "eez-studio-ui/dialog"; import { PropertyList, TextInputProperty } from "eez-studio-ui/properties"; import type { InstrumentAppStore } from "instrument/window/app-store"; import type { INavigationItem } from "instrument/window/navigation"; import type { InstrumentObject } from "instrument/instrument-object"; import { Icon } from "eez-studio-ui/icon"; import { settingsController } from "home/settings"; //////////////////////////////////////////////////////////////////////////////// export const EditInstrumentLabelDialog = observer( class EditInstrumentLabelDialog extends React.Component<{ instrument: InstrumentObject; size?: "small" | "medium" | "large"; }> { label: string; constructor(props: any) { super(props); this.label = this.props.instrument.label || ""; makeObservable(this, { label: observable }); } render() { return ( { this.props.instrument.setLabel(this.label.trim()); return true; }} size={this.props.size} > (this.label = value))} /> ); } } ); //////////////////////////////////////////////////////////////////////////////// export const AppBar = observer( class AppBar extends React.Component< { appStore: InstrumentAppStore; selectedItem: INavigationItem | undefined; }, {} > { get instrument() { return this.props.appStore.instrument; } handleConnectClick = () => { this.instrument.openConnectDialog(); }; handleDisconnectClick = () => { this.instrument.connection.disconnect(); }; onEditInstrumentLabel = () => { showDialog( ); }; render() { let recordHistoryButton = ( ); let connectionStatus; if (this.instrument.connection.isIdle) { connectionStatus = (
{recordHistoryButton}
); } else if (this.instrument.connection.isConnected) { connectionStatus = (
{this.instrument.connection.interfaceInfo}
{recordHistoryButton}
); } else { connectionStatus = (
{recordHistoryButton}
); } let sendFile; if ( this.instrument.sendFileToInstrumentHandler && this.instrument.connection.isConnected ) { if (this.props.appStore.history.sendFileStatus) { if ( this.props.appStore.navigationStore .mainNavigationSelectedItem != this.props.appStore.navigationStore .terminalNavigationItem && this.props.appStore.navigationStore .mainNavigationSelectedItem != this.props.appStore.navigationStore .startPageNavigationItem ) { sendFile = this.props.appStore.history.sendFileStatus; } } else { sendFile = ( ); } } let toolbarButtons = this.props.selectedItem && this.props.selectedItem.renderToolbarButtons(); return (
{" "}
[{this.instrument.id}] {this.instrument.name}
{connectionStatus}
{sendFile}
{toolbarButtons}
); } } ); //////////////////////////////////////////////////////////////////////////////// export const App = observer( class App extends React.Component<{ appStore: InstrumentAppStore }> { constructor(props: any) { super(props); makeObservable(this, { appBar: computed }); } renderedItems = new Set(); renderContent(item: INavigationItem) { this.renderedItems.add(item.id); return item.renderContent(); } renderContentIfRenderedBefore(item: INavigationItem) { if (!this.renderedItems.has(item.id)) { return null; } return item.renderContent(); } onSelectionChange = (item: INavigationItem) => { this.props.appStore.navigationStore.changeMainNavigationSelectedItem( item ); }; get appBar() { const instrument = this.props.appStore.instrument; if (!instrument) { return undefined; } return (
{instrument.connection.error && ( instrument.connection.dismissError() } > {instrument.connection.error} )} { }
); } render() { const navigationItems = this.props.appStore.navigationStore.navigationItems; const selectedItem = this.props.appStore.navigationStore.mainNavigationSelectedItem; const appBar = this.appBar; return (
{appBar}
{navigationItems.map(item => ( {item === selectedItem ? this.renderContent(item) : this.renderContentIfRenderedBefore( item )} ))}
); } } );