Skip to content

Commit

Permalink
fix(client): check disabled for actions, fix #255
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 31, 2024
1 parent eafc280 commit 498e486
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/client/client/plugins/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export default class ActionService extends Service {
ctx.internal.activeMenus = reactive([])

ctx.addEventListener('keydown', (event) => {
const scope = this.createScope()
for (const action of Object.values(ctx.internal.actions)) {
if (!action.shortcut) continue
const keys = action.shortcut.split('+').map(key => key.toLowerCase().trim())
Expand All @@ -108,8 +109,9 @@ export default class ActionService extends Service {
if (shiftKey !== event.shiftKey) continue
if (metaKey !== event.metaKey) continue
if (code !== event.key.toLowerCase()) continue
if (action.disabled?.(scope)) continue
event.preventDefault()
action.action(this.createScope())
action.action(scope)
}
})
}
Expand Down
1 change: 1 addition & 0 deletions packages/client/client/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { markRaw } from 'vue'
import * as cordis from 'cordis'
import { Context } from './context'

export type Service = cordis.Service<Context>
export const Service = cordis.Service<Context>

export interface Ordered {
Expand Down
1 change: 1 addition & 0 deletions plugins/config/client/components/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ function checkConfig(name: string) {
ctx.action('config.tree.save', {
shortcut: 'ctrl+s',
disabled: (scope) => !scope?.config?.tree || !['config'].includes(router.currentRoute.value?.meta?.activity.id),
action: async ({ config: { tree } }) => {
const { disabled, path } = tree
if (!disabled && !checkConfig(tree.name)) return
Expand Down
1 change: 1 addition & 0 deletions plugins/config/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default class ConfigWriter extends Service {
})

ctx.page({
id: 'config',
path: '/plugins/:name*',
name: '插件配置',
icon: 'activity:plugin',
Expand Down
1 change: 1 addition & 0 deletions plugins/explorer/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default (ctx: Context) => {
})

ctx.page({
id: 'files',
path: '/files/:name*',
name: '资源管理器',
icon: 'activity:explorer',
Expand Down
3 changes: 2 additions & 1 deletion plugins/explorer/client/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const trigger = useMenu('explorer.tree')
ctx.action('explorer.save', {
shortcut: 'ctrl+s',
disabled: () => files[active.value]?.newValue === files[active.value]?.oldValue,
disabled: () => files[active.value]?.newValue === files[active.value]?.oldValue || !['files'].includes(router.currentRoute.value?.meta?.activity.id),
action: async () => {
const content = files[active.value].newValue
await send('explorer/write', active.value, content)
Expand All @@ -113,6 +113,7 @@ ctx.action('explorer.save', {
ctx.action('explorer.refresh', {
shortcut: 'ctrl+r',
disabled: () => !['files'].includes(router.currentRoute.value?.meta?.activity.id),
action: () => send('explorer/refresh'),
})
Expand Down
2 changes: 2 additions & 0 deletions plugins/market/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export default (ctx: Context) => {
})

ctx.page({
id: 'dependencies',
path: '/dependencies',
name: '依赖管理',
icon: 'activity:deps',
Expand All @@ -115,6 +116,7 @@ export default (ctx: Context) => {

ctx.action('market.refresh', {
shortcut: 'ctrl+r',
disabled: () => !['market', 'dependencies'].includes(router.currentRoute.value?.meta?.activity.id),
action: (scope) => send('market/refresh'),
})

Expand Down

0 comments on commit 498e486

Please sign in to comment.