mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
feat(plugin-sql-editor): CB-2029 script renaming extension
This commit is contained in:
+18
-2
@@ -117,7 +117,14 @@ export class ResourceSqlDataSource extends BaseSqlDataSource {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !!this.actions && !!this.nodeInfo && !this.isOutdated() && this.saved && name.trim().length > 0;
|
||||
name = name.trim();
|
||||
|
||||
return (
|
||||
!!this.actions
|
||||
&& !!this.nodeInfo
|
||||
&& this.saved
|
||||
&& name.length > 0
|
||||
);
|
||||
}
|
||||
|
||||
setScript(script: string): void {
|
||||
@@ -143,10 +150,19 @@ export class ResourceSqlDataSource extends BaseSqlDataSource {
|
||||
async rename(name: string | null) {
|
||||
await this.write();
|
||||
|
||||
if (!this.actions || !this.nodeInfo || !this.saved || !name?.trim()) {
|
||||
if (
|
||||
!this.actions
|
||||
|| !this.nodeInfo
|
||||
|| !this.saved
|
||||
|| !name?.trim()
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!name.toLowerCase().endsWith('.sql')) {
|
||||
name += '.sql';
|
||||
}
|
||||
|
||||
this.lastAction = this.rename.bind(this, name);
|
||||
this.loading = true;
|
||||
this.message = 'Renaming script...';
|
||||
|
||||
@@ -130,18 +130,18 @@ export class SqlEditorBootstrap extends Bootstrap {
|
||||
const connection = this.connectionInfoResource.get(dataSource.executionContext?.connectionId ?? '');
|
||||
|
||||
const name = getSqlEditorName(state, dataSource, connection);
|
||||
const regexp = /^(.*?)(\.\w+)$/ig.exec(name);
|
||||
|
||||
const result = await this.commonDialogService.open(RenameDialog, {
|
||||
value: name,
|
||||
value: regexp?.[1] ?? name,
|
||||
objectName: name,
|
||||
icon: '/icons/sql_script_m.svg',
|
||||
validation: name => (
|
||||
!this.sqlEditorTabService.sqlEditorTabs.some(tab => (
|
||||
tab.handlerState.order !== state.order
|
||||
&& this.sqlEditorService.getName(tab.handlerState) === name.trim()
|
||||
)
|
||||
&& this.sqlEditorService.getName(tab.handlerState) === name.trim()
|
||||
))
|
||||
&& dataSource.canRename(name)
|
||||
)
|
||||
),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user