Skip to content

Commit

Permalink
feat: aligned board+port status bar with toolbar tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
Akos Kitta committed Aug 1, 2023
1 parent 20d99f5 commit f24aed6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
21 changes: 13 additions & 8 deletions arduino-ide-extension/src/browser/boards/boards-toolbar-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,18 @@ export class BoardsToolBarItem extends React.Component<
const boardLabel =
selectedBoard?.name ||
nls.localize('arduino/board/selectBoard', 'Select Board');
const selectedPortLabel = portLabel(selectedPort?.address);
const boardFqbn = selectedBoard?.fqbn;
const selectedItem: BoardListItem | undefined =
boardList[boardList.selectedIndex];
let tooltip = `${boardLabel}${boardFqbn ? ` (${boardFqbn})` : ''}${
selectedPort ? `\n${selectedPort.address}` : ''
}`;
if (selectedPort && !selectedItem) {
tooltip += ` ${nls.localize(
'arduino/common/notConnected',
'[not connected]'
)}`;
}

const isConnected = boardList.selectedIndex >= 0;
const protocolIcon = isConnected
Expand All @@ -321,7 +332,7 @@ export class BoardsToolBarItem extends React.Component<
<React.Fragment>
<div
className="arduino-boards-toolbar-item-container"
title={selectedPortLabel}
title={tooltip}
onClick={this.show}
>
{protocolIcon && <div className={protocolIconClassNames} />}
Expand Down Expand Up @@ -373,9 +384,3 @@ function iconNameFromProtocol(protocol: string): string {
return 'fa-arduino-technology-3dimensionscube';
}
}

function portLabel(portName?: string): string {
return portName
? nls.localize('arduino/board/portLabel', 'Port: {0}', portName)
: nls.localize('arduino/board/disconnected', 'Disconnected');
}
32 changes: 24 additions & 8 deletions arduino-ide-extension/src/browser/contributions/selected-board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {
} from '@theia/core/lib/browser/status-bar/status-bar';
import { nls } from '@theia/core/lib/common/nls';
import { inject, injectable } from '@theia/core/shared/inversify';
import type { BoardList } from '../../common/protocol/board-list';
import type {
BoardList,
BoardListItem,
} from '../../common/protocol/board-list';
import { BoardsServiceProvider } from '../boards/boards-service-provider';
import { Contribution } from './contribution';

Expand Down Expand Up @@ -38,17 +41,30 @@ export class SelectedBoard extends Contribution {
className: 'arduino-selected-board',
});
if (selectedBoard) {
const notConnectedLabel = nls.localize(
'arduino/common/notConnected',
'[not connected]'
);
let portLabel = notConnectedLabel;
if (selectedPort) {
portLabel = nls.localize(
'arduino/common/selectedOn',
'on {0}',
selectedPort.address
);
const selectedItem: BoardListItem | undefined =
boardList[boardList.selectedIndex];
if (!selectedItem) {
portLabel += ` ${notConnectedLabel}`; // append ` [not connected]` when the port is selected but it's not detected by the CLI
}
}
this.statusBar.setElement('arduino-selected-port', {
alignment: StatusBarAlignment.RIGHT,
text: selectedPort
? nls.localize(
'arduino/common/selectedOn',
'on {0}',
selectedPort.address
)
: nls.localize('arduino/common/notConnected', '[not connected]'),
text: portLabel,
className: 'arduino-selected-port',
});
} else {
this.statusBar.removeElement('arduino-selected-port');
}
}
}
2 changes: 0 additions & 2 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"boards": "boards",
"configDialog1": "Select both a Board and a Port if you want to upload a sketch.",
"configDialog2": "If you only select a Board you will be able to compile, but not to upload your sketch.",
"disconnected": "Disconnected",
"editBoardsConfig": "Edit Board and Port...",
"getBoardInfo": "Get Board Info",
"inSketchbook": " (in Sketchbook)",
Expand All @@ -29,7 +28,6 @@
"openBoardsConfig": "Select other board and port…",
"pleasePickBoard": "Please pick a board connected to the port you have selected.",
"port": "Port{0}",
"portLabel": "Port: {0}",
"ports": "ports",
"programmer": "Programmer",
"revertBoardsConfig": "Revert the selected '{0}' board to '{1}' detected on '{2}'",
Expand Down

0 comments on commit f24aed6

Please sign in to comment.