-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Language server integration in code editor - Rename Resources (#1155)
* LS integration for Rename Resources * typo
- Loading branch information
Showing
59 changed files
with
1,442 additions
and
1,362 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<script lang="ts"> | ||
export interface IRenameTarget { | ||
name: string | ||
validateName(newName: string): LocaleMessage | null | undefined | ||
setName(newName: string): Promise<void> | ||
inputTip: LocaleMessage | ||
} | ||
</script> | ||
|
||
<script setup lang="ts"> | ||
import { useI18n, type LocaleMessage } from '@/utils/i18n' | ||
import { UIFormModal, UIButton, UITextInput, UIForm, UIFormItem, useForm } from '@/components/ui' | ||
import { useMessageHandle } from '@/utils/exception' | ||
const props = defineProps<{ | ||
visible: boolean | ||
target: IRenameTarget | ||
}>() | ||
const emit = defineEmits<{ | ||
resolved: [void] | ||
cancelled: [] | ||
}>() | ||
const { t } = useI18n() | ||
const form = useForm({ | ||
name: [props.target.name, validateName] | ||
}) | ||
const handleSubmit = useMessageHandle( | ||
async () => { | ||
if (form.value.name !== props.target.name) { | ||
await props.target.setName(form.value.name) | ||
} | ||
emit('resolved') | ||
}, | ||
{ | ||
en: 'Failed to rename', | ||
zh: '重命名失败' | ||
} | ||
) | ||
function validateName(name: string) { | ||
if (name === props.target.name) return | ||
return t(props.target.validateName(name) ?? null) | ||
} | ||
</script> | ||
|
||
<template> | ||
<UIFormModal | ||
class="rename-modal" | ||
style="width: 512px" | ||
:title="$t({ en: 'Rename', zh: '重命名' })" | ||
:visible="visible" | ||
@update:visible="emit('cancelled')" | ||
> | ||
<UIForm :form="form" has-success-feedback @submit="handleSubmit.fn"> | ||
<UIFormItem path="name"> | ||
<UITextInput v-model:value="form.value.name" /> | ||
<template #tip>{{ $t(target.inputTip) }}</template> | ||
</UIFormItem> | ||
<footer class="footer"> | ||
<UIButton type="boring" @click="emit('cancelled')"> | ||
{{ $t({ en: 'Cancel', zh: '取消' }) }} | ||
</UIButton> | ||
<UIButton type="primary" html-type="submit" :loading="handleSubmit.isLoading.value"> | ||
{{ $t({ en: 'Confirm', zh: '确认' }) }} | ||
</UIButton> | ||
</footer> | ||
</UIForm> | ||
</UIFormModal> | ||
</template> | ||
|
||
<style lang="scss" scoped> | ||
.footer { | ||
margin-top: 40px; | ||
display: flex; | ||
gap: var(--ui-gap-middle); | ||
justify-content: flex-end; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.