Browse Source

better new profile name handling - fixes #4325

Eugene Pankov 4 years ago
parent
commit
ab8061ab39

+ 4 - 0
tabby-core/src/api/profileProvider.ts

@@ -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 {

+ 4 - 0
tabby-local/src/profiles.ts

@@ -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 ?? ''
     }

+ 5 - 0
tabby-serial/src/profiles.ts

@@ -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
     }

+ 11 - 3
tabby-settings/src/components/profilesSettingsTab.component.ts

@@ -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()

+ 4 - 0
tabby-ssh/src/profiles.ts

@@ -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 ?? ''
     }

+ 4 - 0
tabby-telnet/src/profiles.ts

@@ -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}` : ''
     }