Skip to content

Commit

Permalink
Optimize toolbar and result view components
Browse files Browse the repository at this point in the history
Added toolbar tips using reactive variable and optimized redundant code in result view. Improved toolbar aesthetics with shadow support and made minor refactoring.
  • Loading branch information
qianlifeng committed Sep 9, 2024
1 parent 7a5c62e commit b9f55f8
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 43 deletions.
1 change: 0 additions & 1 deletion Wox.UI.Flutter/wox/lib/components/wox_list_item_view.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:from_css_color/from_css_color.dart';
import 'package:get/get.dart';
import 'package:hotkey_manager/hotkey_manager.dart';
import 'package:uuid/v4.dart';
import 'package:wox/components/wox_image_view.dart';
import 'package:wox/entity/wox_image.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,27 @@ class WoxLauncherView extends GetView<WoxLauncherController> {
},
child: Column(
children: [
Padding(
padding: EdgeInsets.only(
top: controller.woxTheme.value.appPaddingTop.toDouble(),
right: controller.woxTheme.value.appPaddingRight.toDouble(),
bottom: controller.woxTheme.value.appPaddingBottom.toDouble(),
left: controller.woxTheme.value.appPaddingLeft.toDouble(),
),
child: const Column(
children: [
WoxQueryBoxView(),
WoxQueryResultView(),
],
Expanded(
child: Padding(
padding: EdgeInsets.only(
top: controller.woxTheme.value.appPaddingTop.toDouble(),
right: controller.woxTheme.value.appPaddingRight.toDouble(),
bottom: controller.woxTheme.value.appPaddingBottom.toDouble(),
left: controller.woxTheme.value.appPaddingLeft.toDouble(),
),
child: const Column(
children: [
WoxQueryBoxView(),
Expanded(child: WoxQueryResultView()),
],
),
),
),
controller.results.isNotEmpty ? const WoxQueryToolbarView() : const SizedBox(),
if (controller.results.isNotEmpty)
const SizedBox(
height: 40,
child: WoxQueryToolbarView(),
),
],
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class WoxQueryResultView extends GetView<WoxLauncherController> {
itemBuilder: (context, index) {
WoxResultAction woxResultAction = controller.geActionByIndex(index);
return WoxListItemView(
key: ValueKey(woxResultAction.id),
woxTheme: controller.woxTheme.value,
icon: woxResultAction.icon,
title: woxResultAction.name,
Expand Down Expand Up @@ -95,12 +96,7 @@ class WoxQueryResultView extends GetView<WoxLauncherController> {
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Actions", style: TextStyle(color: fromCssColor(controller.woxTheme.value.actionContainerHeaderFontColor), fontSize: 16.0)),
const Divider(),
getActionListView(),
getActionQueryBox()
],
children: [Text("Actions", style: TextStyle(color: fromCssColor(controller.woxTheme.value.actionContainerHeaderFontColor), fontSize: 16.0)), const Divider(), getActionListView(), getActionQueryBox()],
),
),
),
Expand Down Expand Up @@ -190,12 +186,10 @@ class WoxQueryResultView extends GetView<WoxLauncherController> {
controller.toggleActionPanel(const UuidV4().generate());
return KeyEventResult.handled;
case LogicalKeyboardKey.arrowDown:
controller.changeActionScrollPosition(
const UuidV4().generate(), WoxEventDeviceTypeEnum.WOX_EVENT_DEVEICE_TYPE_KEYBOARD.code, WoxDirectionEnum.WOX_DIRECTION_DOWN.code);
controller.changeActionScrollPosition(const UuidV4().generate(), WoxEventDeviceTypeEnum.WOX_EVENT_DEVEICE_TYPE_KEYBOARD.code, WoxDirectionEnum.WOX_DIRECTION_DOWN.code);
return KeyEventResult.handled;
case LogicalKeyboardKey.arrowUp:
controller.changeActionScrollPosition(
const UuidV4().generate(), WoxEventDeviceTypeEnum.WOX_EVENT_DEVEICE_TYPE_KEYBOARD.code, WoxDirectionEnum.WOX_DIRECTION_UP.code);
controller.changeActionScrollPosition(const UuidV4().generate(), WoxEventDeviceTypeEnum.WOX_EVENT_DEVEICE_TYPE_KEYBOARD.code, WoxDirectionEnum.WOX_DIRECTION_UP.code);
return KeyEventResult.handled;
case LogicalKeyboardKey.enter:
controller.executeActiveAction(const UuidV4().generate());
Expand All @@ -206,12 +200,10 @@ class WoxQueryResultView extends GetView<WoxLauncherController> {
if (event is KeyRepeatEvent) {
switch (event.logicalKey) {
case LogicalKeyboardKey.arrowDown:
controller.changeActionScrollPosition(
const UuidV4().generate(), WoxEventDeviceTypeEnum.WOX_EVENT_DEVEICE_TYPE_KEYBOARD.code, WoxDirectionEnum.WOX_DIRECTION_DOWN.code);
controller.changeActionScrollPosition(const UuidV4().generate(), WoxEventDeviceTypeEnum.WOX_EVENT_DEVEICE_TYPE_KEYBOARD.code, WoxDirectionEnum.WOX_DIRECTION_DOWN.code);
return KeyEventResult.handled;
case LogicalKeyboardKey.arrowUp:
controller.changeActionScrollPosition(
const UuidV4().generate(), WoxEventDeviceTypeEnum.WOX_EVENT_DEVEICE_TYPE_KEYBOARD.code, WoxDirectionEnum.WOX_DIRECTION_UP.code);
controller.changeActionScrollPosition(const UuidV4().generate(), WoxEventDeviceTypeEnum.WOX_EVENT_DEVEICE_TYPE_KEYBOARD.code, WoxDirectionEnum.WOX_DIRECTION_UP.code);
return KeyEventResult.handled;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ class WoxQueryToolbarView extends GetView<WoxLauncherController> {
const WoxQueryToolbarView({super.key});

Widget leftTip() {
return const SizedBox();
return Obx(() {
final tipText = controller.toolbarTip.value;
if (tipText.isEmpty) {
return const SizedBox();
}
return Text(
tipText,
style: TextStyle(color: fromCssColor(controller.woxTheme.value.toolbarFontColor)),
);
});
}

Widget rightTip() {
Expand Down Expand Up @@ -42,7 +51,13 @@ class WoxQueryToolbarView extends GetView<WoxLauncherController> {
child: Container(
decoration: BoxDecoration(
color: fromCssColor(controller.woxTheme.value.toolbarBackgroundColor),
//add some shadow to the top of the toolbar
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
blurRadius: 4,
offset: Offset(0, 2),
),
],
),
child: Padding(
padding: EdgeInsets.only(left: controller.woxTheme.value.toolbarPaddingLeft.toDouble(), right: controller.woxTheme.value.toolbarPaddingRight.toDouble()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class WoxLauncherController extends GetxController {
final isInSettingView = false.obs;
var positionBeforeOpenSetting = const Offset(0, 0);

/// toolbar related variables
final toolbarTip = ''.obs;

/// Triggered when received query results from the server.
void onReceivedQueryResults(List<WoxQueryResult> receivedResults) {
if (receivedResults.isEmpty) {
Expand Down Expand Up @@ -424,9 +427,7 @@ class WoxLauncherController extends GetxController {
if (activeResultIndex.value < prevResultIndex) {
resultScrollerController.jumpTo(0);
} else {
bool shouldJump = deviceType == WoxEventDeviceTypeEnum.WOX_EVENT_DEVEICE_TYPE_KEYBOARD.code
? isResultItemAtBottom(activeResultIndex.value - 1)
: !isResultItemAtBottom(results.length - 1);
bool shouldJump = deviceType == WoxEventDeviceTypeEnum.WOX_EVENT_DEVEICE_TYPE_KEYBOARD.code ? isResultItemAtBottom(activeResultIndex.value - 1) : !isResultItemAtBottom(results.length - 1);
if (shouldJump) {
resultScrollerController.jumpTo(resultScrollerController.offset.ceil() + WoxThemeUtil.instance.getResultItemHeight() * (activeResultIndex.value - prevResultIndex).abs());
}
Expand Down Expand Up @@ -519,8 +520,7 @@ class WoxLauncherController extends GetxController {
RenderBox? renderBox = resultGlobalKeys[index].currentContext?.findRenderObject() as RenderBox?;
if (renderBox == null) return false;

if (renderBox.localToGlobal(Offset.zero).dy.ceil() >=
WoxThemeUtil.instance.getQueryBoxHeight() + WoxThemeUtil.instance.getResultListViewHeightByCount(MAX_LIST_VIEW_ITEM_COUNT - 1)) {
if (renderBox.localToGlobal(Offset.zero).dy.ceil() >= WoxThemeUtil.instance.getQueryBoxHeight() + WoxThemeUtil.instance.getResultListViewHeightByCount(MAX_LIST_VIEW_ITEM_COUNT - 1)) {
return true;
}
return false;
Expand Down Expand Up @@ -898,4 +898,8 @@ class WoxLauncherController extends GetxController {

queryIcon.value = WoxImage.empty();
}

void showToolbarTips(String tip) {
toolbarTip.value = tip;
}
}
9 changes: 5 additions & 4 deletions Wox/plugin/system/indicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package system
import (
"context"
"fmt"
"github.com/google/uuid"
"github.com/samber/lo"
"wox/i18n"
"wox/plugin"
"wox/share"

"github.com/google/uuid"
"github.com/samber/lo"
)

var indicatorIcon = plugin.NewWoxImageBase64(`data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAACXBIWXMAAAsTAAALEwEAmpwYAAACVklEQVR4nO2cQUrdUBSG30aae1Md5RZUcFSecCaOWtfRtw+ltHYB2g2cXWgp4kTX4CKqzlOS+AqVQqG+l//05fvgzIQcv48kjwzubAYAAAAAAAAAAAAAAAAAsBZSbq5TXdoXTy5Xm7SLjJUIqIfZpF1kLP+Bt8ff/3nSioNE2EVGJAkp0C4yIklIgXaREUlCCrSLjEgSUqBdZESSkALtIiOShBRol7Xyqi5HVd18S3XzuMrf+um/muaxqpvLqi7vpTGqXD7qZZRQU+XmRHZn9Ets77S7iy/t/PymNb+b5MzPb9rdxWnvoo+iuFOGx1TpF1ELsSCzt/g83Cm5XIweJOXy0F384OutXIQFmc7F8Ngq9+MHeXpmqiVYsFl6CRVka/9w9Jfp1v7hX/d4/jcv2fNP1wsbZMqTCHInj0AQ14sniOtlE8T1ggnieqkECSDSCKKXZwTRCzOC6CUZQfRijCB6GRZg+HTi+ggEcb14grheNkFcL5ggrpdKkAAijSB6eUYQvTAjiF6SEUQvxgiil2EBhk8nro9AENeLJ4jrZRPE9YIJ4nqpBAkg0giil2cE0QszguglGUH0YowgehkWYPh04voIBHG9eIK4XjZBXC+YIK6XSpAAIm2TgygODkgBDioIG2TKk2RBng6fmfKxTPZs5me/Dp/5MXqQ7gS17uLdkURqERZk9j580h3P1B3S1V98e6ePMuU7ZX52O8RYHmD2+s270YP0UXJzon65pnDTHEti/Han5HKxfKdMcnJ56BzI7gwAAAAAAAAAAAAAAAAAAJitgZ+lmGHcVGx/0gAAAABJRU5ErkJggg==`)
Expand Down Expand Up @@ -62,7 +63,7 @@ func (i *IndicatorPlugin) Query(ctx context.Context, query plugin.Query) []plugi
Icon: pluginInstance.Metadata.GetIconOrDefault(pluginInstance.PluginDirectory, indicatorIcon),
Actions: []plugin.QueryResultAction{
{
Name: "activate",
Name: "i18n:plugin_indicator_activate",
PreventHideAfterAction: true,
Action: func(ctx context.Context, actionContext plugin.ActionContext) {
i.api.ChangeQuery(ctx, share.PlainQuery{
Expand All @@ -84,7 +85,7 @@ func (i *IndicatorPlugin) Query(ctx context.Context, query plugin.Query) []plugi
Icon: pluginInstance.Metadata.GetIconOrDefault(pluginInstance.PluginDirectory, indicatorIcon),
Actions: []plugin.QueryResultAction{
{
Name: "activate",
Name: "i18n:plugin_indicator_activate",
PreventHideAfterAction: true,
Action: func(ctx context.Context, actionContext plugin.ActionContext) {
i.api.ChangeQuery(ctx, share.PlainQuery{
Expand Down
3 changes: 2 additions & 1 deletion Wox/resource/lang/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"plugin_clipboard_primary_action": "Primary action",
"plugin_clipboard_primary_action_copy_to_clipboard": "Copy to clipboard",
"plugin_clipboard_primary_action_paste_to_active_app": "Paste to active app",
"plugin_indicator_activate_plugin": "Activate %s plugin",
"plugin_indicator_activate": "Activate",
"plugin_indicator_activate_plugin": "Activate the %s plugin",
"plugin_sys_empty_trash": "Empty Trash",
"plugin_sys_lock_computer": "Lock PC",
"plugin_sys_execute": "Execute",
Expand Down
1 change: 1 addition & 0 deletions Wox/resource/lang/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"plugin_clipboard_primary_action": "主要操作",
"plugin_clipboard_primary_action_copy_to_clipboard": "复制到剪贴板",
"plugin_clipboard_primary_action_paste_to_active_app": "粘贴到活动应用程序",
"plugin_indicator_activate": "激活",
"plugin_indicator_activate_plugin": "激活%s插件",
"plugin_sys_empty_trash": "清空回收站",
"plugin_sys_lock_computer": "锁定电脑",
Expand Down
7 changes: 4 additions & 3 deletions Wox/ui/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/olahol/melody"
"github.com/rs/cors"
"github.com/samber/lo"
"net/http"
"strings"
"wox/plugin"
"wox/setting/definition"
"wox/ui/dto"
"wox/util"

"github.com/olahol/melody"
"github.com/rs/cors"
"github.com/samber/lo"
)

var m *melody.Melody
Expand Down

0 comments on commit b9f55f8

Please sign in to comment.