better new profile name handling - fixes #4325

This commit is contained in:
Eugene Pankov 2021-08-02 20:52:39 +02:00
parent c1a1f53707
commit ab8061ab39
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4
6 changed files with 32 additions and 3 deletions

View File

@ -46,6 +46,10 @@ export abstract class ProfileProvider<P extends Profile> {
abstract getNewTabParameters (profile: PartialProfile<P>): Promise<NewTabParameters<BaseTabComponent>>
getSuggestedName (profile: PartialProfile<P>): string|null {
return null
}
abstract getDescription (profile: PartialProfile<P>): string
quickConnect (query: string): PartialProfile<P>|null {

View File

@ -84,6 +84,10 @@ export class LocalProfilesService extends ProfileProvider<LocalProfile> {
}
}
getSuggestedName (profile: LocalProfile): string {
return this.getDescription(profile)
}
getDescription (profile: PartialProfile<LocalProfile>): string {
return profile.options?.command ?? ''
}

View File

@ -8,6 +8,7 @@ import { SerialProfileSettingsComponent } from './components/serialProfileSettin
import { SerialTabComponent } from './components/serialTab.component'
import { SerialService } from './services/serial.service'
import { BAUD_RATES, SerialProfile } from './api'
import { profileEnd } from 'console'
@Injectable({ providedIn: 'root' })
export class SerialProfilesService extends ProfileProvider<SerialProfile> {
@ -92,6 +93,10 @@ export class SerialProfilesService extends ProfileProvider<SerialProfile> {
}
}
getSuggestedName (profile: SerialProfile): string {
return this.getDescription(profile)
}
getDescription (profile: SerialProfile): string {
return profile.options.port
}

View File

@ -63,12 +63,20 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
})),
)
}
const profile = deepClone(base)
profile.id = null
profile.name = `${profile.name} copy`
const profile: PartialProfile<Profile> = deepClone(base)
delete profile.id
if (base.isTemplate) {
profile.name = ''
} else if (!base.isBuiltin) {
profile.name = `${base.name} copy`
}
profile.isBuiltin = false
profile.isTemplate = false
await this.editProfile(profile)
if (!profile.name) {
const cfgProxy = this.profilesService.getConfigProxyForProfile(profile)
profile.name = this.profilesService.providerForProfile(profile)?.getSuggestedName(cfgProxy) ?? `${base.name} copy`
}
profile.id = `${profile.type}:custom:${slugify(profile.name)}:${uuidv4()}`
this.config.store.profiles = [profile, ...this.config.store.profiles]
await this.config.save()

View File

@ -81,6 +81,10 @@ export class SSHProfilesService extends ProfileProvider<SSHProfile> {
}
}
getSuggestedName (profile: SSHProfile): string {
return `${profile.options.user}@${profile.options.host}:${profile.options.port}`
}
getDescription (profile: PartialProfile<SSHProfile>): string {
return profile.options?.host ?? ''
}

View File

@ -62,6 +62,10 @@ export class TelnetProfilesService extends ProfileProvider<TelnetProfile> {
}
}
getSuggestedName (profile: TelnetProfile): string|null {
return this.getDescription(profile) || null
}
getDescription (profile: TelnetProfile): string {
return profile.options.host ? `${profile.options.host}:${profile.options.port}` : ''
}