Add Local and Remote Branch
This commit is contained in:
107
main2.pb
107
main2.pb
@@ -593,7 +593,7 @@ EndProcedure
|
|||||||
|
|
||||||
; -----------------------------------------------------------------------------
|
; -----------------------------------------------------------------------------
|
||||||
; Tooltips & i18n
|
; Tooltips & i18n
|
||||||
; FR: Appeler après la création des gadgets, puis après tout changement de langue.
|
; FR: Appeler après la création des gadgets, puis après tout changement de langue
|
||||||
; EN: Call after creating gadgets, then after any language change.
|
; EN: Call after creating gadgets, then after any language change.
|
||||||
; -----------------------------------------------------------------------------
|
; -----------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -1033,6 +1033,102 @@ Procedure GetGitRemoteUrl(name.s="origin")
|
|||||||
EndIf
|
EndIf
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
Procedure GetGitLocalBranch()
|
||||||
|
If Git("branch")=0
|
||||||
|
ProcedureReturn #True
|
||||||
|
Else
|
||||||
|
ProcedureReturn #False
|
||||||
|
EndIf
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
|
Procedure.s RefreshLocalBranchesList(Gdt.i)
|
||||||
|
ClearGadgetItems(Gdt)
|
||||||
|
|
||||||
|
; Parser ligne par ligne
|
||||||
|
Protected n.l = CountString(main\Gitcall\output, #LF$) + 1
|
||||||
|
Protected i.l, line.s
|
||||||
|
|
||||||
|
For i = 1 To n
|
||||||
|
line = StringField(main\Gitcall\output, i, #LF$)
|
||||||
|
line = Trim(line)
|
||||||
|
|
||||||
|
If Len(line) = 0
|
||||||
|
Continue ; Ignorer les lignes vides
|
||||||
|
EndIf
|
||||||
|
Protected selectbranch.b=#False
|
||||||
|
If Left(line,1)="*"
|
||||||
|
selectbranch=#True
|
||||||
|
line=Trim(StringField(line,2," "))
|
||||||
|
EndIf
|
||||||
|
AddGadgetItem(Gdt,i-1,line)
|
||||||
|
If selectbranch=#True
|
||||||
|
SetGadgetState(Gdt,i-1)
|
||||||
|
EndIf
|
||||||
|
Next
|
||||||
|
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
|
Procedure GetGitRemoteBranch()
|
||||||
|
If Git("branch -r")=0
|
||||||
|
ProcedureReturn #True
|
||||||
|
Else
|
||||||
|
ProcedureReturn #False
|
||||||
|
EndIf
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
|
Procedure.s RefreshRemoteBranchesList(Gdt.i)
|
||||||
|
ClearGadgetItems(Gdt)
|
||||||
|
|
||||||
|
; Parser ligne par ligne
|
||||||
|
Protected n.l = CountString(main\Gitcall\output, #LF$) + 1
|
||||||
|
Protected i.l, line.s, cleanBranchName.s, defaultBranch.s
|
||||||
|
Protected itemIndex.l
|
||||||
|
|
||||||
|
; Trouver d'abord la branche par défaut
|
||||||
|
For i = 1 To n
|
||||||
|
line = StringField(main\Gitcall\output, i, #LF$)
|
||||||
|
line = Trim(line)
|
||||||
|
|
||||||
|
If FindString(line, "->", 1)
|
||||||
|
; Extraire la branche par défaut depuis "origin/HEAD -> origin/main"
|
||||||
|
defaultBranch = Trim(StringField(line, 2, "->"))
|
||||||
|
If Left(defaultBranch, 8) = "remotes/"
|
||||||
|
defaultBranch = Right(defaultBranch, Len(defaultBranch) - 8)
|
||||||
|
EndIf
|
||||||
|
Break
|
||||||
|
EndIf
|
||||||
|
Next
|
||||||
|
|
||||||
|
; Ajouter les branches
|
||||||
|
For i = 1 To n
|
||||||
|
line = StringField(main\Gitcall\output, i, #LF$)
|
||||||
|
line = Trim(line)
|
||||||
|
|
||||||
|
If Len(line) = 0
|
||||||
|
Continue ; Ignorer les lignes vides
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
; Ignorer la ligne origin/HEAD -> origin/main
|
||||||
|
If FindString(line, "->", 1)
|
||||||
|
Continue
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
; Nettoyer le nom de la branche (enlever "remotes/" si présent)
|
||||||
|
cleanBranchName = line
|
||||||
|
If Left(cleanBranchName, 8) = "remotes/"
|
||||||
|
cleanBranchName = Right(cleanBranchName, Len(cleanBranchName) - 8)
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
itemIndex = CountGadgetItems(Gdt)
|
||||||
|
AddGadgetItem(Gdt, itemIndex, cleanBranchName)
|
||||||
|
|
||||||
|
; Sélectionner la branche par défaut
|
||||||
|
If cleanBranchName = defaultBranch
|
||||||
|
SetGadgetState(Gdt, itemIndex)
|
||||||
|
EndIf
|
||||||
|
Next
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
; --- Helper interne : scanne un dossier et alimente la liste
|
; --- Helper interne : scanne un dossier et alimente la liste
|
||||||
Procedure _ScanFiles(path$, root$="")
|
Procedure _ScanFiles(path$, root$="")
|
||||||
If root$="":root$=path$:EndIf
|
If root$="":root$=path$:EndIf
|
||||||
@@ -1085,14 +1181,19 @@ Procedure RefreshFiles()
|
|||||||
ClearList(main\Files())
|
ClearList(main\Files())
|
||||||
readDirectory()
|
readDirectory()
|
||||||
If main\IsRepository And GetGitVersion()
|
If main\IsRepository And GetGitVersion()
|
||||||
|
GetGitLocalBranch()
|
||||||
|
RefreshLocalBranchesList(#GID_CbLocalBranch)
|
||||||
GetGitStatusPocelaine()
|
GetGitStatusPocelaine()
|
||||||
ParseStatusPorcelaine(main\gitCall\output)
|
ParseStatusPorcelaine(main\gitCall\output)
|
||||||
If GetGitRemoteUrl()
|
If GetGitRemoteUrl()
|
||||||
SetGadgetText(#GID_EdRemote,SupTrim(main\gitCall\output))
|
SetGadgetText(#GID_EdRemote,SupTrim(main\gitCall\output))
|
||||||
main\hasRemoteUrl=#True
|
main\hasRemoteUrl=#True
|
||||||
|
GetGitRemoteBranch()
|
||||||
|
RefreshRemoteBranchesList(#GID_CbRemoteBranch)
|
||||||
Else
|
Else
|
||||||
SetGadgetText(#GID_EdRemote,"")
|
SetGadgetText(#GID_EdRemote,"")
|
||||||
main\hasRemoteUrl=#False
|
main\hasRemoteUrl=#False
|
||||||
|
ClearGadgetItems(#GID_CbRemoteBranch)
|
||||||
EndIf
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
Protected n.l=n-1
|
Protected n.l=n-1
|
||||||
@@ -1243,8 +1344,8 @@ EndProcedure
|
|||||||
Main()
|
Main()
|
||||||
|
|
||||||
; IDE Options = PureBasic 6.21 (Windows - x64)
|
; IDE Options = PureBasic 6.21 (Windows - x64)
|
||||||
; CursorPosition = 591
|
; CursorPosition = 1191
|
||||||
; FirstLine = 521
|
; FirstLine = 1159
|
||||||
; Folding = ------
|
; Folding = ------
|
||||||
; EnableXP
|
; EnableXP
|
||||||
; DPIAware
|
; DPIAware
|
Reference in New Issue
Block a user