feat:新增文档集修改名称的功能
This commit is contained in:
@ -198,3 +198,16 @@ export function deleteDocumentSet(id: string, panel: vscode.WebviewPanel) {
|
||||
documentSets: documentSets,
|
||||
});
|
||||
}
|
||||
|
||||
export function changeDocumentSetName(id: string, newName: string, panel: vscode.WebviewPanel) {
|
||||
const docSet = documentSets.find(ds => ds.id === id);
|
||||
if (docSet) {
|
||||
docSet.name = newName;
|
||||
docSet.updatedAt = new Date().toISOString();
|
||||
persistDocumentSets();
|
||||
panel.webview.postMessage({
|
||||
command: "documentSetSaved",
|
||||
documentSets: documentSets,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -382,6 +382,11 @@ export async function handleWebviewMessage(
|
||||
deleteDocumentSet(message.id, panel);
|
||||
break;
|
||||
|
||||
case "changeDocumentSetName":
|
||||
const { changeDocumentSetName } = await import("./contextHelper");
|
||||
changeDocumentSetName(message.id, message.newName, panel);
|
||||
break;
|
||||
|
||||
case "openContextSettings":
|
||||
panel.webview.postMessage({
|
||||
command: "openSettingsTab",
|
||||
|
||||
@ -48,6 +48,16 @@ export function getDocsetDialogContent(): string {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="rename-dialog" id="renameDialog">
|
||||
<div class="rename-content">
|
||||
<div class="rename-title">修改名称</div>
|
||||
<input type="text" id="renameInput" class="rename-input" placeholder="输入新名称" />
|
||||
<div class="rename-actions">
|
||||
<button class="docset-btn-cancel" onclick="closeRenameDialog()">取消</button>
|
||||
<button class="docset-btn-confirm" onclick="confirmRename()">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
@ -209,7 +219,7 @@ export function getDocsetDialogStyles(): string {
|
||||
background: var(--vscode-button-hoverBackground);
|
||||
}
|
||||
|
||||
.docset-delete-btn {
|
||||
.docset-delete-btn, .docset-change-btn {
|
||||
position: relative;
|
||||
background: transparent;
|
||||
border: none;
|
||||
@ -219,11 +229,11 @@ export function getDocsetDialogStyles(): string {
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.docset-delete-btn:hover {
|
||||
.docset-delete-btn:hover, .docset-change-btn:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.docset-delete-btn:hover::after {
|
||||
.docset-delete-btn:hover::after, .docset-change-btn:hover::after {
|
||||
content: attr(data-tooltip);
|
||||
position: absolute;
|
||||
bottom: 100%;
|
||||
@ -291,6 +301,64 @@ export function getDocsetDialogStyles(): string {
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.rename-dialog {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.4);
|
||||
z-index: 10000;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.rename-dialog.active {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.rename-content {
|
||||
background: var(--vscode-editor-background);
|
||||
border: 1px solid var(--vscode-panel-border);
|
||||
border-radius: 6px;
|
||||
padding: 20px;
|
||||
min-width: 300px;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
.rename-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.rename-input {
|
||||
width: 100%;
|
||||
padding: 8px 12px;
|
||||
background: var(--vscode-input-background);
|
||||
border: 1px solid var(--vscode-input-border);
|
||||
border-radius: 4px;
|
||||
color: var(--vscode-input-foreground);
|
||||
font-size: 13px;
|
||||
box-sizing: border-box;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.rename-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.rename-actions button {
|
||||
padding: 6px 16px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
@ -392,16 +460,23 @@ export function getDocsetDialogScript(): string {
|
||||
<div class="docset-item">
|
||||
<div class="docset-name">\${ds.name}</div>
|
||||
<div class="docset-meta">更新于 \${new Date(ds.updatedAt).toLocaleString('zh-CN')}</div>
|
||||
<button class="docset-change-btn" data-tooltip="修改名称" onclick="changeDocsetName('\${ds.id}', '\${ds.name}')">
|
||||
<svg t="1773883957219" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7170" width="14" height="14">
|
||||
<path d="M745.76 369.86l-451 537.48a18.693 18.693 0 0 1-8.46 5.74l-136.58 45.27c-13.24 4.39-26.46-6.71-24.43-20.5l20.86-142.36c0.5-3.44 1.95-6.67 4.19-9.33l451-537.48c6.65-7.93 18.47-8.96 26.4-2.31l115.71 97.1c7.92 6.64 8.96 18.46 2.31 26.39zM894.53 192.56l-65.9 78.53c-6.65 7.93-18.47 8.96-26.4 2.31l-115.71-97.1c-7.93-6.65-8.96-18.47-2.31-26.4l65.9-78.53c6.65-7.93 18.47-8.96 26.4-2.31l115.71 97.1c7.93 6.65 8.96 18.47 2.31 26.4z" fill="currentColor" p-id="7171"></path>
|
||||
</svg>
|
||||
</button>
|
||||
<button class="docset-delete-btn" data-tooltip="删除" onclick="showDeleteConfirm('\${ds.id}', '\${ds.name}')">
|
||||
<svg width="14" height="14" viewBox="0 0 16 16" fill="currentColor">
|
||||
<path d="M10 3h3v1h-1v9l-1 1H4l-1-1V4H2V3h3V2a1 1 0 0 1 1-1h3a1 1 0 0 1 1 1v1zM9 2H6v1h3V2zM4 13h7V4H4v9zm2-8H5v7h1V5zm1 0h1v7H7V5zm2 0h1v7H9V5z"/>
|
||||
</svg>
|
||||
</button>
|
||||
</button>
|
||||
</div>
|
||||
\`).join('');
|
||||
}
|
||||
|
||||
let deleteTargetId = null;
|
||||
let renameTargetId = null;
|
||||
let renameOriginalName = null;
|
||||
|
||||
window.showDeleteConfirm = function(id, name) {
|
||||
deleteTargetId = id;
|
||||
@ -409,11 +484,25 @@ export function getDocsetDialogScript(): string {
|
||||
document.getElementById('deleteConfirmDialog').classList.add('active');
|
||||
};
|
||||
|
||||
window.changeDocsetName = function(id, name) {
|
||||
renameTargetId = id;
|
||||
renameOriginalName = name;
|
||||
document.getElementById('renameInput').value = name;
|
||||
document.getElementById('renameDialog').classList.add('active');
|
||||
setTimeout(() => document.getElementById('renameInput').focus(), 100);
|
||||
};
|
||||
|
||||
window.closeDeleteConfirm = function() {
|
||||
document.getElementById('deleteConfirmDialog').classList.remove('active');
|
||||
deleteTargetId = null;
|
||||
};
|
||||
|
||||
window.closeRenameDialog = function() {
|
||||
document.getElementById('renameDialog').classList.remove('active');
|
||||
renameTargetId = null;
|
||||
renameOriginalName = null;
|
||||
};
|
||||
|
||||
window.confirmDelete = function() {
|
||||
if (deleteTargetId) {
|
||||
vscode.postMessage({ command: 'deleteDocumentSet', id: deleteTargetId });
|
||||
@ -421,6 +510,18 @@ export function getDocsetDialogScript(): string {
|
||||
}
|
||||
};
|
||||
|
||||
window.confirmRename = function() {
|
||||
const newName = document.getElementById('renameInput').value.trim();
|
||||
if (!newName) {
|
||||
alert('请输入名称');
|
||||
return;
|
||||
}
|
||||
if (newName !== renameOriginalName) {
|
||||
vscode.postMessage({ command: 'changeDocumentSetName', id: renameTargetId, newName: newName });
|
||||
}
|
||||
closeRenameDialog();
|
||||
};
|
||||
|
||||
window.addEventListener('message', event => {
|
||||
const message = event.data;
|
||||
if (message.command === 'filesSelectedForDocset') {
|
||||
|
||||
Reference in New Issue
Block a user