Skip to content

Commit

Permalink
address code review & make empty fields uncopyable
Browse files Browse the repository at this point in the history
  • Loading branch information
levkropp committed Jan 30, 2025
1 parent 8ff9e3e commit e4e0678
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
18 changes: 12 additions & 6 deletions src/client/gui/lib/copyable_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ class CopyableText extends StatefulWidget {

class _CopyableTextState extends State<CopyableText> {
bool _copied = false;
bool get _isCopyable => widget.text != '-';

void _copyToClipboard() async {
if (!_isCopyable) return;
await Clipboard.setData(ClipboardData(text: widget.text));
setState(() => _copied = true);
}
Expand All @@ -28,19 +30,23 @@ class _CopyableTextState extends State<CopyableText> {

@override
Widget build(BuildContext context) {
Widget text = Text(
widget.text,
style: widget.style,
maxLines: 1,
overflow: TextOverflow.ellipsis,
);

if (!_isCopyable) return text;

return MouseRegion(
cursor: SystemMouseCursors.click,
onExit: (_) => _resetCopied(),
child: GestureDetector(
onTap: _copyToClipboard,
child: Tooltip(
message: _copied ? 'Copied' : 'Click to copy',
child: Text(
widget.text,
style: widget.style,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
child: text,
),
),
);
Expand Down
30 changes: 10 additions & 20 deletions src/client/gui/lib/tooltip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,16 @@ class _TooltipState extends fl.State<Tooltip> {
fl.Widget build(fl.BuildContext context) {
return fl.TooltipVisibility(
visible: widget.visible,
child: _forceShow
? fl.Tooltip(
key: _key,
message: widget.message,
textAlign: fl.TextAlign.center,
decoration: fl.BoxDecoration(
color: const fl.Color(0xff111111),
borderRadius: fl.BorderRadius.circular(2),
),
child: widget.child,
)
: fl.Tooltip(
message: widget.message,
textAlign: fl.TextAlign.center,
decoration: fl.BoxDecoration(
color: const fl.Color(0xff111111),
borderRadius: fl.BorderRadius.circular(2),
),
child: widget.child,
),
child: fl.Tooltip(
key: _forceShow ? _key : null,
message: widget.message,
textAlign: fl.TextAlign.center,
decoration: fl.BoxDecoration(
color: const fl.Color(0xff111111),
borderRadius: fl.BorderRadius.circular(2),
),
child: widget.child,
),
);
}
}
3 changes: 2 additions & 1 deletion src/client/gui/lib/vm_details/ip_addresses.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class IpAddresses extends StatelessWidget {
? CopyableText(firstIp)
: Tooltip(
message: firstIp,
child: Text(firstIp.nonBreaking, overflow: TextOverflow.ellipsis),
child:
Text(firstIp.nonBreaking, overflow: TextOverflow.ellipsis),
),
),
if (restIps.isNotEmpty)
Expand Down

0 comments on commit e4e0678

Please sign in to comment.