feat: Improved mouse support for selecting events

pull/524/head
krille-chan 2 years ago
parent 56c7c72f92
commit 6e9d3627cc
No known key found for this signature in database

@ -816,6 +816,17 @@ class ChatController extends State<ChatPageWithRoom> {
return true; return true;
} }
bool get canPinSelectedEvents {
if (isArchived ||
!room.canChangeStateEvent(EventTypes.RoomPinnedEvents) ||
selectedEvents.length != 1 ||
!selectedEvents.single.status.isSent) {
return false;
}
return currentRoomBundle
.any((cl) => selectedEvents.first.senderId == cl!.userID);
}
bool get canEditSelectedEvents { bool get canEditSelectedEvents {
if (isArchived || if (isArchived ||
selectedEvents.length != 1 || selectedEvents.length != 1 ||

@ -54,17 +54,18 @@ class ChatView extends StatelessWidget {
onPressed: () => controller.saveSelectedEvent(context), onPressed: () => controller.saveSelectedEvent(context),
), ),
), ),
if (controller.canPinSelectedEvents)
IconButton(
icon: const Icon(Icons.push_pin_outlined),
onPressed: controller.pinEvent,
tooltip: L10n.of(context)!.pinMessage,
),
if (controller.canRedactSelectedEvents) if (controller.canRedactSelectedEvents)
IconButton( IconButton(
icon: const Icon(Icons.delete_outlined), icon: const Icon(Icons.delete_outlined),
tooltip: L10n.of(context)!.redactMessage, tooltip: L10n.of(context)!.redactMessage,
onPressed: controller.redactEventsAction, onPressed: controller.redactEventsAction,
), ),
IconButton(
icon: const Icon(Icons.push_pin_outlined),
onPressed: controller.pinEvent,
tooltip: L10n.of(context)!.pinMessage,
),
if (controller.selectedEvents.length == 1) if (controller.selectedEvents.length == 1)
PopupMenuButton<_EventContextAction>( PopupMenuButton<_EventContextAction>(
onSelected: (action) { onSelected: (action) {

@ -117,7 +117,10 @@ class Message extends StatelessWidget {
: Theme.of(context).colorScheme.primaryContainer; : Theme.of(context).colorScheme.primaryContainer;
} }
final rowChildren = <Widget>[ final row = Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: rowMainAxisAlignment,
children: [
sameSender || ownMessage sameSender || ownMessage
? SizedBox( ? SizedBox(
width: Avatar.defaultSize, width: Avatar.defaultSize,
@ -141,7 +144,8 @@ class Message extends StatelessWidget {
: FutureBuilder<User?>( : FutureBuilder<User?>(
future: event.fetchSenderUser(), future: event.fetchSenderUser(),
builder: (context, snapshot) { builder: (context, snapshot) {
final user = snapshot.data ?? event.senderFromMemoryOrFallback; final user =
snapshot.data ?? event.senderFromMemoryOrFallback;
return Avatar( return Avatar(
mxContent: user.avatarUrl, mxContent: user.avatarUrl,
name: user.calcDisplayname(), name: user.calcDisplayname(),
@ -187,13 +191,6 @@ class Message extends StatelessWidget {
color: noBubble ? Colors.transparent : color, color: noBubble ? Colors.transparent : color,
borderRadius: borderRadius, borderRadius: borderRadius,
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
child: InkWell(
onHover: (b) => useMouse = true,
onTap: !useMouse && longPressSelect
? () {}
: () => onSelect!(event),
onLongPress: !longPressSelect ? null : () => onSelect!(event),
borderRadius: borderRadius,
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: borderRadius:
@ -292,15 +289,10 @@ class Message extends StatelessWidget {
), ),
), ),
), ),
),
], ],
), ),
), ),
]; ],
final row = Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: rowMainAxisAlignment,
children: rowChildren,
); );
Widget container; Widget container;
if (event.hasAggregatedEvents(timeline, RelationshipTypes.reaction) || if (event.hasAggregatedEvents(timeline, RelationshipTypes.reaction) ||
@ -400,12 +392,19 @@ class Message extends StatelessWidget {
direction: SwipeDirection.endToStart, direction: SwipeDirection.endToStart,
onSwipe: onSwipe, onSwipe: onSwipe,
child: Center( child: Center(
child: MouseRegion(
onEnter: (_) => useMouse = true,
onExit: (_) => useMouse = false,
child: InkWell(
onTap: longPressSelect || useMouse ? () => onSelect!(event) : null,
onLongPress: () => onSelect!(event),
child: Container( child: Container(
color: selected color: selected
? Theme.of(context).primaryColor.withAlpha(100) ? Theme.of(context).primaryColor.withAlpha(100)
: Theme.of(context).primaryColor.withAlpha(0), : Theme.of(context).primaryColor.withAlpha(0),
constraints: constraints: const BoxConstraints(
const BoxConstraints(maxWidth: FluffyThemes.columnWidth * 2.5), maxWidth: FluffyThemes.columnWidth * 2.5,
),
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
horizontal: 8.0, horizontal: 8.0,
vertical: 4.0, vertical: 4.0,
@ -413,6 +412,8 @@ class Message extends StatelessWidget {
child: container, child: container,
), ),
), ),
),
),
); );
} }
} }

Loading…
Cancel
Save