dernière version
This commit is contained in:
677
PBIDE-GitTool.pb
677
PBIDE-GitTool.pb
@@ -1,31 +1,90 @@
|
|||||||
; PBIDE-GitTool.pb — Outil externe Git pour l’IDE PureBasic
|
; PBIDE-GitTool.pb — Outil externe Git pour l’IDE PureBasic
|
||||||
; Gère init, status, add+commit, push/pull avec paramètres simples
|
; - Init, Status, Add+Commit (sélectif), Push/Pull
|
||||||
; PureBasic 6.x, multiplateforme
|
; - UI : liste avec cases à cocher + actions Inclure/Exclure/Tout
|
||||||
; ------------------------------------------------------------
|
; - Fenêtre "Avancé…" : switch/restore de branche
|
||||||
|
; - Assistant d’installation IDE si lancé sans paramètre
|
||||||
|
; Contraintes respectées : pas d'underscore dans nos identifiants,
|
||||||
|
; Protected uniquement dans les procédures, pas de IIf, déclarations = implémentations,
|
||||||
|
; comparaisons uniquement dans If/While/Until/For, etc.
|
||||||
|
|
||||||
EnableExplicit
|
EnableExplicit
|
||||||
|
|
||||||
; ====== Debug global ======
|
|
||||||
#EnableDebug = #True
|
#EnableDebug = #True
|
||||||
|
|
||||||
; ====== Séparateur de chemin (portable) ======
|
; ====== Séparateur de chemin (portable) ======
|
||||||
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
|
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
|
||||||
#PathSep$ = "\"
|
#PathSep$ = "\"
|
||||||
; Chemin Git forcé pour Windows (proposé) :
|
; Chemin Git forcé pour Windows :
|
||||||
#GitExe$ = "C:\Program Files\Git\cmd\git.exe"
|
#GitExe$ = "C:\Program Files\Git\cmd\git.exe"
|
||||||
CompilerElse
|
CompilerElse
|
||||||
#PathSep$ = "/"
|
#PathSep$ = "/"
|
||||||
; Sur macOS/Linux on garde 'git' dans le PATH
|
; Sur macOS/Linux on garde 'git' dans le PATH :
|
||||||
#GitExe$ = "git"
|
#GitExe$ = "git"
|
||||||
CompilerEndIf
|
CompilerEndIf
|
||||||
|
|
||||||
; ====== Structure d'appel Git ======
|
; ====== IDs UI (placer ce bloc AVANT toutes les procédures) ======
|
||||||
|
|
||||||
|
; Fenêtre principale
|
||||||
|
#GWindow = 1
|
||||||
|
#GLabelRepo = 10
|
||||||
|
#GStringRepo = 11
|
||||||
|
#GButtonBrowse = 12
|
||||||
|
#GListStatus = 13
|
||||||
|
#GRefresh = 14
|
||||||
|
#GLabelMsg = 15
|
||||||
|
#GStringMsg = 16
|
||||||
|
#GCheckPush = 17
|
||||||
|
#GLabelRemote = 18
|
||||||
|
#GStringRemote = 19
|
||||||
|
#GLabelBranch = 20
|
||||||
|
#GComboBranch = 21
|
||||||
|
#GSavePrefs = 22
|
||||||
|
#GInit = 23
|
||||||
|
#GCommit = 24
|
||||||
|
#GPull = 25
|
||||||
|
#GPush = 26
|
||||||
|
#GInclude = 27
|
||||||
|
#GExclude = 28
|
||||||
|
#GIncludeAll = 29
|
||||||
|
#GExcludeAll = 30
|
||||||
|
#GAdvanced = 31
|
||||||
|
|
||||||
|
; Fenêtre avancée (branches)
|
||||||
|
#WAdv = 200
|
||||||
|
#GAdvLabel = 210
|
||||||
|
#GAdvCombo = 211
|
||||||
|
#GAdvSwitch = 212
|
||||||
|
#GAdvRestore = 213
|
||||||
|
#GAdvClose = 214
|
||||||
|
|
||||||
|
; Assistant d’installation
|
||||||
|
#WInstall = 100
|
||||||
|
#GLabelIde = 110
|
||||||
|
#GStringIde = 111
|
||||||
|
#GButtonIde = 112
|
||||||
|
#GLabelTools = 113
|
||||||
|
#GStringTools = 114
|
||||||
|
#GButtonTools = 115
|
||||||
|
#GLabelTheme = 116
|
||||||
|
#GStringTheme = 117
|
||||||
|
#GButtonTheme = 118
|
||||||
|
#GInstallGo = 119
|
||||||
|
#GInstallCancel = 120
|
||||||
|
#GInstallNote = 121
|
||||||
|
|
||||||
|
|
||||||
|
; ====== Structures ======
|
||||||
Structure GitCall
|
Structure GitCall
|
||||||
args.s ; ex: "status --porcelain"
|
args.s
|
||||||
workdir.s ; répertoire de travail
|
workdir.s
|
||||||
output.s ; stdout complet
|
output.s
|
||||||
errors.s ; stderr complet
|
errors.s
|
||||||
exitcode.i ; code retour
|
exitcode.i
|
||||||
|
EndStructure
|
||||||
|
|
||||||
|
Structure FileRow
|
||||||
|
stat.s ; 2 lettres porcelain (" M", "A ", "??", etc.)
|
||||||
|
file.s ; chemin relatif
|
||||||
|
include.i ; 1=coché (inclus), 0=exclu
|
||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
; ====== Déclarations ======
|
; ====== Déclarations ======
|
||||||
@@ -43,12 +102,19 @@ Declare.i DoCommit(repoDir$, message$, doPush.i, remote$, branch$)
|
|||||||
Declare.i DoPush(repoDir$, remote$, branch$)
|
Declare.i DoPush(repoDir$, remote$, branch$)
|
||||||
Declare.i DoPull(repoDir$, remote$, branch$)
|
Declare.i DoPull(repoDir$, remote$, branch$)
|
||||||
Declare.i ListBranches(repoDir$, List branchesList.s())
|
Declare.i ListBranches(repoDir$, List branchesList.s())
|
||||||
|
Declare.i LoadStatusRows(repoDir$, List rows.FileRow())
|
||||||
|
Declare.i FillStatusList(List rows.FileRow())
|
||||||
|
Declare.i ToggleIncludeAt(index.i, List rows.FileRow())
|
||||||
|
Declare.i CollectIncludedFiles(List rows.FileRow(), List files.s())
|
||||||
|
Declare.i DoCommitSelected(repoDir$, message$, doPush.i, remote$, branch$, List files.s())
|
||||||
|
Declare.i OpenAdvancedWindow(repoDir$)
|
||||||
|
Declare.i SwitchToBranch(repoDir$, branch$)
|
||||||
|
Declare.i RestoreFromBranch(repoDir$, branch$)
|
||||||
Declare.i InstallPBGitInIDE(ideExe$, toolsPrefs$, themeZip$)
|
Declare.i InstallPBGitInIDE(ideExe$, toolsPrefs$, themeZip$)
|
||||||
Declare.i OpenInstallWizard()
|
Declare.i OpenInstallWizard()
|
||||||
|
|
||||||
; ====== Utils ======
|
; ====== Utils ======
|
||||||
Procedure.s TrimNewlines(text$)
|
Procedure.s TrimNewlines(text$)
|
||||||
; Supprime \r et \n en fin de chaîne
|
|
||||||
Protected s$ = text$
|
Protected s$ = text$
|
||||||
While Right(s$, 1) = #LF$ Or Right(s$, 1) = #CR$
|
While Right(s$, 1) = #LF$ Or Right(s$, 1) = #CR$
|
||||||
s$ = Left(s$, Len(s$)-1)
|
s$ = Left(s$, Len(s$)-1)
|
||||||
@@ -56,20 +122,17 @@ Procedure.s TrimNewlines(text$)
|
|||||||
ProcedureReturn s$
|
ProcedureReturn s$
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
; Exécute git avec une structure d'appel passée par pointeur
|
; Exécute git avec capture stdout/stderr (structure passée par pointeur)
|
||||||
; Remplit *call\output, *call\errors, *call\exitcode
|
|
||||||
Procedure.i RunGit(*call.GitCall)
|
Procedure.i RunGit(*call.GitCall)
|
||||||
Protected prg.i, line$
|
Protected prg.i, line$, out$, err$
|
||||||
Protected out$, err$
|
|
||||||
|
|
||||||
If #EnableDebug
|
If #EnableDebug
|
||||||
Debug "[RunGit] exe=" + #GitExe$ + " args=" + *call\args + " wd=" + *call\workdir
|
Debug "[RunGit] " + #GitExe$ + " " + *call\args + " (wd=" + *call\workdir + ")"
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
prg = RunProgram(#GitExe$, *call\args, *call\workdir, #PB_Program_Open | #PB_Program_Read | #PB_Program_Error | #PB_Program_Hide)
|
prg = RunProgram(#GitExe$, *call\args, *call\workdir, #PB_Program_Open | #PB_Program_Read | #PB_Program_Error | #PB_Program_Hide)
|
||||||
If prg = 0
|
If prg = 0
|
||||||
*call\output = ""
|
*call\output = ""
|
||||||
*call\errors = "Impossible de lancer '" + #GitExe$ + "'."
|
*call\errors = "Impossible de lancer '" + #GitExe$ + "'."
|
||||||
*call\exitcode = -1
|
*call\exitcode = -1
|
||||||
ProcedureReturn *call\exitcode
|
ProcedureReturn *call\exitcode
|
||||||
EndIf
|
EndIf
|
||||||
@@ -77,34 +140,20 @@ Procedure.i RunGit(*call.GitCall)
|
|||||||
While ProgramRunning(prg)
|
While ProgramRunning(prg)
|
||||||
While AvailableProgramOutput(prg)
|
While AvailableProgramOutput(prg)
|
||||||
line$ = ReadProgramString(prg)
|
line$ = ReadProgramString(prg)
|
||||||
If line$ <> ""
|
If line$ <> "" : out$ + line$ + #LF$ : EndIf
|
||||||
out$ + line$ + #LF$
|
|
||||||
EndIf
|
|
||||||
Wend
|
Wend
|
||||||
|
line$ = ReadProgramError(prg) ; renvoie "" si rien à lire (non bloquant)
|
||||||
; ReadProgramError() renvoie "" s'il n'y a rien (non bloquant)
|
If line$ <> "" : err$ + line$ + #LF$ : EndIf
|
||||||
line$ = ReadProgramError(prg)
|
|
||||||
If line$ <> ""
|
|
||||||
err$ + line$ + #LF$
|
|
||||||
EndIf
|
|
||||||
|
|
||||||
Delay(5)
|
Delay(5)
|
||||||
Wend
|
Wend
|
||||||
|
|
||||||
; Vidange finale stdout
|
|
||||||
While AvailableProgramOutput(prg)
|
While AvailableProgramOutput(prg)
|
||||||
line$ = ReadProgramString(prg)
|
line$ = ReadProgramString(prg)
|
||||||
If line$ <> ""
|
If line$ <> "" : out$ + line$ + #LF$ : EndIf
|
||||||
out$ + line$ + #LF$
|
|
||||||
EndIf
|
|
||||||
Wend
|
Wend
|
||||||
|
|
||||||
; Vidange finale stderr (jusqu'à chaîne vide)
|
|
||||||
Repeat
|
Repeat
|
||||||
line$ = ReadProgramError(prg)
|
line$ = ReadProgramError(prg)
|
||||||
If line$ = ""
|
If line$ = "" : Break : EndIf
|
||||||
Break
|
|
||||||
EndIf
|
|
||||||
err$ + line$ + #LF$
|
err$ + line$ + #LF$
|
||||||
ForEver
|
ForEver
|
||||||
|
|
||||||
@@ -123,9 +172,8 @@ Procedure.i RunGit(*call.GitCall)
|
|||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.s DetectRepoRoot(startDir$)
|
Procedure.s DetectRepoRoot(startDir$)
|
||||||
; Renvoie le toplevel git si présent, sinon startDir$
|
|
||||||
Protected gc.GitCall
|
Protected gc.GitCall
|
||||||
gc\args = "rev-parse --show-toplevel"
|
gc\args = "rev-parse --show-toplevel"
|
||||||
gc\workdir = startDir$
|
gc\workdir = startDir$
|
||||||
If RunGit(@gc) = 0
|
If RunGit(@gc) = 0
|
||||||
ProcedureReturn TrimNewlines(gc\output)
|
ProcedureReturn TrimNewlines(gc\output)
|
||||||
@@ -169,20 +217,16 @@ Procedure.i EnsureGitAvailable()
|
|||||||
If RunGit(@gc) = 0 And FindString(LCase(gc\output), "git version", 1)
|
If RunGit(@gc) = 0 And FindString(LCase(gc\output), "git version", 1)
|
||||||
ProcedureReturn 1
|
ProcedureReturn 1
|
||||||
EndIf
|
EndIf
|
||||||
MessageRequester("PBIDE-GitTool", "Git n'est pas détecté à l'emplacement prévu : " + #GitExe$, #PB_MessageRequester_Warning)
|
MessageRequester("PBIDE-GitTool", "Git n'est pas détecté à l’emplacement prévu : " + #GitExe$, #PB_MessageRequester_Warning)
|
||||||
ProcedureReturn 0
|
ProcedureReturn 0
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
; Détermine un répertoire pertinent (project → env → --repo → exe)
|
||||||
Procedure.s DirFromArgOrFallback()
|
Procedure.s DirFromArgOrFallback()
|
||||||
; 1) --project "<dir>" si fourni (via %PROJECT)
|
|
||||||
; 2) PB_TOOL_Project -> GetPathPart()
|
|
||||||
; 3) --repo "<dir>" ou 1er argument libre
|
|
||||||
; 4) dossier de l'exécutable
|
|
||||||
Protected n.i = CountProgramParameters()
|
Protected n.i = CountProgramParameters()
|
||||||
Protected gotNextProject.i = 0
|
Protected gotNextProject.i = 0
|
||||||
Protected gotNextRepo.i = 0
|
Protected gotNextRepo.i = 0
|
||||||
Protected dir$ = ""
|
Protected dir$ = "", i.i, p$
|
||||||
Protected i.i, p$
|
|
||||||
|
|
||||||
For i = 0 To n - 1
|
For i = 0 To n - 1
|
||||||
p$ = ProgramParameter(i)
|
p$ = ProgramParameter(i)
|
||||||
@@ -202,7 +246,7 @@ Procedure.s DirFromArgOrFallback()
|
|||||||
Next
|
Next
|
||||||
|
|
||||||
If dir$ <> ""
|
If dir$ <> ""
|
||||||
If #EnableDebug : Debug "[DirFromArgOrFallback] from args: " + dir$ : EndIf
|
If #EnableDebug : Debug "[Dir] from args: " + dir$ : EndIf
|
||||||
ProcedureReturn dir$
|
ProcedureReturn dir$
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
@@ -210,23 +254,23 @@ Procedure.s DirFromArgOrFallback()
|
|||||||
If projFile$ <> ""
|
If projFile$ <> ""
|
||||||
Protected projDir$ = GetPathPart(projFile$)
|
Protected projDir$ = GetPathPart(projFile$)
|
||||||
If projDir$ <> ""
|
If projDir$ <> ""
|
||||||
If #EnableDebug : Debug "[DirFromArgOrFallback] from PB_TOOL_Project: " + projDir$ : EndIf
|
If #EnableDebug : Debug "[Dir] from PB_TOOL_Project: " + projDir$ : EndIf
|
||||||
ProcedureReturn projDir$
|
ProcedureReturn projDir$
|
||||||
EndIf
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
dir$ = GetPathPart(ProgramFilename())
|
dir$ = GetPathPart(ProgramFilename())
|
||||||
If #EnableDebug : Debug "[DirFromArgOrFallback] fallback exe dir: " + dir$ : EndIf
|
If #EnableDebug : Debug "[Dir] fallback exe dir: " + dir$ : EndIf
|
||||||
ProcedureReturn dir$
|
ProcedureReturn dir$
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
; ====== Opérations Git de base ======
|
; ====== Opérations Git de base ======
|
||||||
Procedure.i DoInitRepo(repoDir$)
|
Procedure.i DoInitRepo(repoDir$)
|
||||||
Protected gc.GitCall
|
Protected gc.GitCall
|
||||||
gc\args = "init"
|
gc\args = "init"
|
||||||
gc\workdir = repoDir$
|
gc\workdir = repoDir$
|
||||||
If RunGit(@gc) = 0
|
If RunGit(@gc) = 0
|
||||||
MessageRequester("Git init", "Répertoire initialisé comme dépôt Git." + #LF$ + TrimNewlines(gc\output), #PB_MessageRequester_Info)
|
MessageRequester("Git init", "Répertoire initialisé." + #LF$ + TrimNewlines(gc\output), #PB_MessageRequester_Info)
|
||||||
ProcedureReturn 1
|
ProcedureReturn 1
|
||||||
EndIf
|
EndIf
|
||||||
MessageRequester("Git init", "Échec: " + #LF$ + TrimNewlines(gc\errors), #PB_MessageRequester_Error)
|
MessageRequester("Git init", "Échec: " + #LF$ + TrimNewlines(gc\errors), #PB_MessageRequester_Error)
|
||||||
@@ -235,7 +279,7 @@ EndProcedure
|
|||||||
|
|
||||||
Procedure.i DoStatus(repoDir$, out$)
|
Procedure.i DoStatus(repoDir$, out$)
|
||||||
Protected gc.GitCall
|
Protected gc.GitCall
|
||||||
gc\args = "status --porcelain"
|
gc\args = "status --porcelain"
|
||||||
gc\workdir = repoDir$
|
gc\workdir = repoDir$
|
||||||
If RunGit(@gc) <> 0
|
If RunGit(@gc) <> 0
|
||||||
out$ = ""
|
out$ = ""
|
||||||
@@ -247,23 +291,21 @@ Procedure.i DoStatus(repoDir$, out$)
|
|||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.i DoCommit(repoDir$, message$, doPush.i, remote$, branch$)
|
Procedure.i DoCommit(repoDir$, message$, doPush.i, remote$, branch$)
|
||||||
Protected gc.GitCall
|
Protected gc.GitCall, code.i
|
||||||
|
|
||||||
; add -A
|
|
||||||
gc\args = "add -A"
|
|
||||||
gc\workdir = repoDir$
|
gc\workdir = repoDir$
|
||||||
If RunGit(@gc) <> 0
|
|
||||||
|
gc\args = "add -A"
|
||||||
|
code = RunGit(@gc)
|
||||||
|
If code <> 0
|
||||||
MessageRequester("Git add", "Échec: " + #LF$ + TrimNewlines(gc\errors), #PB_MessageRequester_Error)
|
MessageRequester("Git add", "Échec: " + #LF$ + TrimNewlines(gc\errors), #PB_MessageRequester_Error)
|
||||||
ProcedureReturn 0
|
ProcedureReturn 0
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
; commit
|
|
||||||
gc\args = "commit -m " + Chr(34) + message$ + Chr(34)
|
gc\args = "commit -m " + Chr(34) + message$ + Chr(34)
|
||||||
If RunGit(@gc) <> 0
|
code = RunGit(@gc)
|
||||||
|
If code <> 0
|
||||||
MessageRequester("Git commit", "Échec ou rien à valider: " + #LF$ + TrimNewlines(gc\errors) + #LF$ + TrimNewlines(gc\output), #PB_MessageRequester_Warning)
|
MessageRequester("Git commit", "Échec ou rien à valider: " + #LF$ + TrimNewlines(gc\errors) + #LF$ + TrimNewlines(gc\output), #PB_MessageRequester_Warning)
|
||||||
If doPush = 0
|
If doPush = 0 : ProcedureReturn 0 : EndIf
|
||||||
ProcedureReturn 0
|
|
||||||
EndIf
|
|
||||||
Else
|
Else
|
||||||
MessageRequester("Git commit", "OK:" + #LF$ + TrimNewlines(gc\output), #PB_MessageRequester_Info)
|
MessageRequester("Git commit", "OK:" + #LF$ + TrimNewlines(gc\output), #PB_MessageRequester_Info)
|
||||||
EndIf
|
EndIf
|
||||||
@@ -271,13 +313,12 @@ Procedure.i DoCommit(repoDir$, message$, doPush.i, remote$, branch$)
|
|||||||
If doPush
|
If doPush
|
||||||
ProcedureReturn DoPush(repoDir$, remote$, branch$)
|
ProcedureReturn DoPush(repoDir$, remote$, branch$)
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
ProcedureReturn 1
|
ProcedureReturn 1
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.i DoPush(repoDir$, remote$, branch$)
|
Procedure.i DoPush(repoDir$, remote$, branch$)
|
||||||
Protected gc.GitCall
|
Protected gc.GitCall
|
||||||
gc\args = "push " + remote$ + " " + branch$
|
gc\args = "push " + remote$ + " " + branch$
|
||||||
gc\workdir = repoDir$
|
gc\workdir = repoDir$
|
||||||
If RunGit(@gc) = 0
|
If RunGit(@gc) = 0
|
||||||
MessageRequester("Git push", "OK:" + #LF$ + TrimNewlines(gc\output), #PB_MessageRequester_Info)
|
MessageRequester("Git push", "OK:" + #LF$ + TrimNewlines(gc\output), #PB_MessageRequester_Info)
|
||||||
@@ -289,7 +330,7 @@ EndProcedure
|
|||||||
|
|
||||||
Procedure.i DoPull(repoDir$, remote$, branch$)
|
Procedure.i DoPull(repoDir$, remote$, branch$)
|
||||||
Protected gc.GitCall
|
Protected gc.GitCall
|
||||||
gc\args = "pull " + remote$ + " " + branch$
|
gc\args = "pull " + remote$ + " " + branch$
|
||||||
gc\workdir = repoDir$
|
gc\workdir = repoDir$
|
||||||
If RunGit(@gc) = 0
|
If RunGit(@gc) = 0
|
||||||
MessageRequester("Git pull", "OK:" + #LF$ + TrimNewlines(gc\output), #PB_MessageRequester_Info)
|
MessageRequester("Git pull", "OK:" + #LF$ + TrimNewlines(gc\output), #PB_MessageRequester_Info)
|
||||||
@@ -300,11 +341,9 @@ Procedure.i DoPull(repoDir$, remote$, branch$)
|
|||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.i ListBranches(repoDir$, List branchesList.s())
|
Procedure.i ListBranches(repoDir$, List branchesList.s())
|
||||||
; Remplit la liste 'branchesList()' avec les noms de branches
|
|
||||||
ClearList(branchesList())
|
ClearList(branchesList())
|
||||||
|
|
||||||
Protected gc.GitCall
|
Protected gc.GitCall
|
||||||
gc\args = "branch --list --format='%(refname:short)'"
|
gc\args = "branch --list --format='%(refname:short)'"
|
||||||
gc\workdir = repoDir$
|
gc\workdir = repoDir$
|
||||||
|
|
||||||
If RunGit(@gc) <> 0
|
If RunGit(@gc) <> 0
|
||||||
@@ -322,12 +361,198 @@ Procedure.i ListBranches(repoDir$, List branchesList.s())
|
|||||||
branchesList() = b$
|
branchesList() = b$
|
||||||
EndIf
|
EndIf
|
||||||
Next i
|
Next i
|
||||||
|
|
||||||
ProcedureReturn 1
|
ProcedureReturn 1
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
; ====== Interface simple ======
|
; ====== Status → lignes et gestion des coches ======
|
||||||
; Gadgets IDs (sans underscores)
|
Procedure.i LoadStatusRows(repoDir$, List rows.FileRow())
|
||||||
|
Protected gc.GitCall, text$, line$, n.i, i.i
|
||||||
|
gc\args = "status --porcelain"
|
||||||
|
gc\workdir = repoDir$
|
||||||
|
If RunGit(@gc) <> 0
|
||||||
|
MessageRequester("Git status", "Échec: " + #LF$ + TrimNewlines(gc\errors), #PB_MessageRequester_Error)
|
||||||
|
ProcedureReturn 0
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
text$ = gc\output
|
||||||
|
n = CountString(text$, #LF$) + 1
|
||||||
|
For i = 1 To n
|
||||||
|
line$ = Trim(StringField(text$, i, #LF$))
|
||||||
|
If line$ <> ""
|
||||||
|
AddElement(rows())
|
||||||
|
rows()\stat = Left(line$, 2)
|
||||||
|
rows()\file = Trim(Mid(line$, 4))
|
||||||
|
rows()\include = 0
|
||||||
|
EndIf
|
||||||
|
Next i
|
||||||
|
ProcedureReturn ListSize(rows())
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
|
Procedure.i FillStatusList(List rows.FileRow())
|
||||||
|
ClearGadgetItems(#GListStatus)
|
||||||
|
Protected idx.i = 0
|
||||||
|
ForEach rows()
|
||||||
|
AddGadgetItem(#GListStatus, -1, rows()\stat + #LF$ + rows()\file)
|
||||||
|
If rows()\include
|
||||||
|
SetGadgetItemState(#GListStatus, idx, #PB_ListIcon_Checked)
|
||||||
|
Else
|
||||||
|
SetGadgetItemState(#GListStatus, idx, 0)
|
||||||
|
EndIf
|
||||||
|
idx + 1
|
||||||
|
Next
|
||||||
|
ProcedureReturn CountGadgetItems(#GListStatus)
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
|
Procedure.i ToggleIncludeAt(index.i, List rows.FileRow())
|
||||||
|
If index < 0 : ProcedureReturn 0 : EndIf
|
||||||
|
Protected c.i = CountGadgetItems(#GListStatus)
|
||||||
|
If index >= c : ProcedureReturn 0 : EndIf
|
||||||
|
|
||||||
|
Protected state.i = GetGadgetItemState(#GListStatus, index)
|
||||||
|
Protected want.i
|
||||||
|
If state & #PB_ListIcon_Checked : want = 1 : Else : want = 0 : EndIf
|
||||||
|
|
||||||
|
Protected j.i = 0
|
||||||
|
ForEach rows()
|
||||||
|
If j = index
|
||||||
|
rows()\include = want
|
||||||
|
Break
|
||||||
|
EndIf
|
||||||
|
j + 1
|
||||||
|
Next
|
||||||
|
ProcedureReturn 1
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
|
Procedure.i CollectIncludedFiles(List rows.FileRow(), List files.s())
|
||||||
|
ClearList(files())
|
||||||
|
ForEach rows()
|
||||||
|
If rows()\include
|
||||||
|
AddElement(files())
|
||||||
|
files() = rows()\file
|
||||||
|
EndIf
|
||||||
|
Next
|
||||||
|
ProcedureReturn ListSize(files())
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
|
; Commit sélectif si des fichiers sont cochés
|
||||||
|
Procedure.i DoCommitSelected(repoDir$, message$, doPush.i, remote$, branch$, List files.s())
|
||||||
|
If ListSize(files()) = 0
|
||||||
|
ProcedureReturn DoCommit(repoDir$, message$, doPush, remote$, branch$)
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
Protected gc.GitCall, code.i, argsAdd$, q$
|
||||||
|
gc\workdir = repoDir$
|
||||||
|
q$ = Chr(34)
|
||||||
|
|
||||||
|
argsAdd$ = "add"
|
||||||
|
ForEach files()
|
||||||
|
argsAdd$ + " " + q$ + files() + q$
|
||||||
|
Next
|
||||||
|
gc\args = argsAdd$
|
||||||
|
code = RunGit(@gc)
|
||||||
|
If code <> 0
|
||||||
|
MessageRequester("Git add", "Échec: " + #LF$ + TrimNewlines(gc\errors), #PB_MessageRequester_Error)
|
||||||
|
ProcedureReturn 0
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
gc\args = "commit -m " + Chr(34) + message$ + Chr(34)
|
||||||
|
code = RunGit(@gc)
|
||||||
|
If code <> 0
|
||||||
|
MessageRequester("Git commit", "Échec ou rien à valider: " + #LF$ + TrimNewlines(gc\errors) + #LF$ + TrimNewlines(gc\output), #PB_MessageRequester_Warning)
|
||||||
|
If doPush = 0 : ProcedureReturn 0 : EndIf
|
||||||
|
Else
|
||||||
|
MessageRequester("Git commit", "OK:" + #LF$ + TrimNewlines(gc\output), #PB_MessageRequester_Info)
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
If doPush
|
||||||
|
ProcedureReturn DoPush(repoDir$, remote$, branch$)
|
||||||
|
EndIf
|
||||||
|
ProcedureReturn 1
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
|
; ====== Fenêtre Avancé… (branches) ======
|
||||||
|
#WAdv = 200
|
||||||
|
#GAdvLabel = 210
|
||||||
|
#GAdvCombo = 211
|
||||||
|
#GAdvSwitch = 212
|
||||||
|
#GAdvRestore = 213
|
||||||
|
#GAdvClose = 214
|
||||||
|
|
||||||
|
Procedure.i OpenAdvancedWindow(repoDir$)
|
||||||
|
Protected b$
|
||||||
|
NewList blist.s()
|
||||||
|
ListBranches(repoDir$, blist())
|
||||||
|
|
||||||
|
If OpenWindow(#WAdv, 0, 0, 440, 160, "Actions avancées — Branches", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
|
||||||
|
TextGadget(#GAdvLabel, 10, 14, 140, 24, "Branche :")
|
||||||
|
ComboBoxGadget(#GAdvCombo, 160, 12, 270, 24)
|
||||||
|
ForEach blist() : AddGadgetItem(#GAdvCombo, -1, blist()) : Next
|
||||||
|
GadgetToolTip(#GAdvCombo, "Sélectionnez la branche cible.")
|
||||||
|
|
||||||
|
ButtonGadget(#GAdvSwitch, 10, 60, 170, 30, "Basculer sur la branche")
|
||||||
|
GadgetToolTip(#GAdvSwitch, "git switch <branche> (ou git checkout).")
|
||||||
|
|
||||||
|
ButtonGadget(#GAdvRestore, 190, 60, 170, 30, "Restaurer depuis la branche")
|
||||||
|
GadgetToolTip(#GAdvRestore, "git restore --source <branche> -- . (remplace le contenu de travail).")
|
||||||
|
|
||||||
|
ButtonGadget(#GAdvClose, 370, 60, 60, 30, "Fermer")
|
||||||
|
|
||||||
|
Repeat
|
||||||
|
Protected ev.i = WaitWindowEvent()
|
||||||
|
If ev = #PB_Event_Gadget
|
||||||
|
Select EventGadget()
|
||||||
|
Case #GAdvSwitch
|
||||||
|
b$ = GetGadgetText(#GAdvCombo)
|
||||||
|
If b$ <> ""
|
||||||
|
If SwitchToBranch(repoDir$, b$)
|
||||||
|
MessageRequester("Branche", "Basculé sur '" + b$ + "'.", #PB_MessageRequester_Info)
|
||||||
|
EndIf
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
Case #GAdvRestore
|
||||||
|
b$ = GetGadgetText(#GAdvCombo)
|
||||||
|
If b$ <> ""
|
||||||
|
If MessageRequester("Restauration", "Cette action va restaurer le contenu depuis '" + b$ + "'." + #LF$ + "Continuer ?", #PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
|
||||||
|
If RestoreFromBranch(repoDir$, b$)
|
||||||
|
MessageRequester("Restauration", "Contenu restauré depuis '" + b$ + "'.", #PB_MessageRequester_Info)
|
||||||
|
EndIf
|
||||||
|
EndIf
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
Case #GAdvClose
|
||||||
|
CloseWindow(#WAdv)
|
||||||
|
ProcedureReturn 1
|
||||||
|
EndSelect
|
||||||
|
EndIf
|
||||||
|
Until ev = #PB_Event_CloseWindow
|
||||||
|
|
||||||
|
ProcedureReturn 1
|
||||||
|
EndIf
|
||||||
|
ProcedureReturn 0
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
|
Procedure.i SwitchToBranch(repoDir$, branch$)
|
||||||
|
Protected gc.GitCall
|
||||||
|
gc\workdir = repoDir$
|
||||||
|
gc\args = "switch " + Chr(34) + branch$ + Chr(34)
|
||||||
|
If RunGit(@gc) = 0 : ProcedureReturn 1 : EndIf
|
||||||
|
gc\args = "checkout " + Chr(34) + branch$ + Chr(34) ; fallback versions anciennes
|
||||||
|
If RunGit(@gc) = 0 : ProcedureReturn 1 : EndIf
|
||||||
|
MessageRequester("Branche", "Échec: " + #LF$ + TrimNewlines(gc\errors), #PB_MessageRequester_Error)
|
||||||
|
ProcedureReturn 0
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
|
Procedure.i RestoreFromBranch(repoDir$, branch$)
|
||||||
|
Protected gc.GitCall
|
||||||
|
gc\workdir = repoDir$
|
||||||
|
gc\args = "restore --source " + Chr(34) + branch$ + Chr(34) + " -- ."
|
||||||
|
If RunGit(@gc) = 0 : ProcedureReturn 1 : EndIf
|
||||||
|
MessageRequester("Restauration", "Échec: " + #LF$ + TrimNewlines(gc\errors), #PB_MessageRequester_Error)
|
||||||
|
ProcedureReturn 0
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
|
; ====== UI principale ======
|
||||||
|
; Gadgets IDs (inclut les NOUVEAUX boutons)
|
||||||
#GWindow = 1
|
#GWindow = 1
|
||||||
#GLabelRepo = 10
|
#GLabelRepo = 10
|
||||||
#GStringRepo = 11
|
#GStringRepo = 11
|
||||||
@@ -346,81 +571,87 @@ EndProcedure
|
|||||||
#GCommit = 24
|
#GCommit = 24
|
||||||
#GPull = 25
|
#GPull = 25
|
||||||
#GPush = 26
|
#GPush = 26
|
||||||
|
#GInclude = 27
|
||||||
|
#GExclude = 28
|
||||||
|
#GIncludeAll = 29
|
||||||
|
#GExcludeAll = 30
|
||||||
|
#GAdvanced = 31
|
||||||
|
|
||||||
Procedure.i OpenGUI(initialDir$, prefsPath$)
|
Procedure.i OpenGUI(initialDir$, prefsPath$)
|
||||||
Protected repoDir$ = DetectRepoRoot(initialDir$)
|
Protected repoDir$ = DetectRepoRoot(initialDir$)
|
||||||
Protected remote$ = "", branch$ = ""
|
Protected remote$ = "", branch$ = ""
|
||||||
LoadPrefs(prefsPath$, remote$, branch$)
|
LoadPrefs(prefsPath$, remote$, branch$)
|
||||||
|
|
||||||
If OpenWindow(#GWindow, 0, 0, 680, 520, "PBIDE-GitTool — Git simplifié pour PureBasic", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
|
If OpenWindow(#GWindow, 0, 0, 740, 560, "PBIDE-GitTool — Git simplifié pour PureBasic", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
|
||||||
TextGadget(#GLabelRepo, 10, 12, 60, 22, "Dépôt :")
|
TextGadget(#GLabelRepo, 10, 12, 60, 22, "Dépôt :")
|
||||||
StringGadget(#GStringRepo, 80, 10, 480, 24, repoDir$)
|
StringGadget(#GStringRepo, 80, 10, 540, 24, repoDir$)
|
||||||
ButtonGadget(#GButtonBrowse, 570, 10, 100, 24, "Parcourir…")
|
ButtonGadget(#GButtonBrowse, 630, 10, 100, 24, "Parcourir…")
|
||||||
|
|
||||||
ListViewGadget(#GListStatus, 10, 46, 660, 250)
|
; Liste avec cases à cocher
|
||||||
ButtonGadget(#GRefresh, 10, 302, 90, 26, "Rafraîchir")
|
ListIconGadget(#GListStatus, 10, 46, 720, 280, "Statut", 100, #PB_ListIcon_CheckBoxes | #PB_ListIcon_FullRowSelect)
|
||||||
ButtonGadget(#GInit, 110, 302, 90, 26, "Init repo")
|
AddGadgetColumn(#GListStatus, 1, "Fichier", 600)
|
||||||
|
|
||||||
TextGadget(#GLabelMsg, 10, 342, 100, 22, "Message :")
|
ButtonGadget(#GRefresh, 10, 332, 90, 26, "Rafraîchir")
|
||||||
StringGadget(#GStringMsg, 110, 340, 560, 24, "")
|
ButtonGadget(#GInit, 110, 332, 90, 26, "Init repo")
|
||||||
CheckBoxGadget(#GCheckPush, 10, 372, 120, 22, "Pousser après")
|
ButtonGadget(#GInclude, 210, 332, 90, 26, "Inclure")
|
||||||
|
ButtonGadget(#GExclude, 310, 332, 90, 26, "Exclure")
|
||||||
|
ButtonGadget(#GIncludeAll, 410, 332, 110, 26, "Tout inclure")
|
||||||
|
ButtonGadget(#GExcludeAll, 530, 332, 110, 26, "Tout exclure")
|
||||||
|
ButtonGadget(#GAdvanced, 650, 332, 80, 26, "Avancé…")
|
||||||
|
|
||||||
|
TextGadget(#GLabelMsg, 10, 372, 100, 22, "Message :")
|
||||||
|
StringGadget(#GStringMsg, 110, 370, 620, 24, "")
|
||||||
|
CheckBoxGadget(#GCheckPush, 10, 402, 120, 22, "Pousser après")
|
||||||
SetGadgetState(#GCheckPush, #True)
|
SetGadgetState(#GCheckPush, #True)
|
||||||
|
|
||||||
TextGadget(#GLabelRemote, 150, 372, 60, 22, "Remote :")
|
TextGadget(#GLabelRemote, 150, 402, 60, 22, "Remote :")
|
||||||
StringGadget(#GStringRemote, 210, 370, 120, 24, remote$)
|
StringGadget(#GStringRemote, 210, 400, 120, 24, remote$)
|
||||||
TextGadget(#GLabelBranch, 340, 372, 60, 22, "Branche :")
|
TextGadget(#GLabelBranch, 340, 402, 60, 22, "Branche :")
|
||||||
ComboBoxGadget(#GComboBranch, 400, 370, 150, 24)
|
ComboBoxGadget(#GComboBranch, 400, 400, 170, 24)
|
||||||
ButtonGadget(#GSavePrefs, 560, 370, 110, 24, "Sauver défauts")
|
ButtonGadget(#GSavePrefs, 580, 400, 150, 24, "Sauver défauts")
|
||||||
|
|
||||||
ButtonGadget(#GCommit, 10, 410, 120, 30, "Add + Commit")
|
ButtonGadget(#GCommit, 10, 440, 120, 30, "Add + Commit")
|
||||||
ButtonGadget(#GPush, 140, 410, 120, 30, "Push")
|
ButtonGadget(#GPush, 140, 440, 120, 30, "Push")
|
||||||
ButtonGadget(#GPull, 270, 410, 120, 30, "Pull")
|
ButtonGadget(#GPull, 270, 440, 120, 30, "Pull")
|
||||||
|
|
||||||
; --------- Infobulles (tooltips) ---------
|
; Infobulles
|
||||||
GadgetToolTip(#GStringRepo, "Dossier du dépôt Git. Utilisez 'Parcourir…' pour le sélectionner.")
|
GadgetToolTip(#GStringRepo, "Dossier du dépôt Git. Utilisez 'Parcourir…' pour le sélectionner.")
|
||||||
GadgetToolTip(#GButtonBrowse, "Choisir le répertoire du dépôt.")
|
GadgetToolTip(#GButtonBrowse, "Choisir le répertoire du dépôt.")
|
||||||
GadgetToolTip(#GListStatus, "État des fichiers (git status --porcelain).")
|
GadgetToolTip(#GListStatus, "Cochez pour inclure un fichier dans le prochain commit. Colonnes : Statut / Fichier.")
|
||||||
GadgetToolTip(#GRefresh, "Rafraîchir l’état du dépôt.")
|
GadgetToolTip(#GRefresh, "Rafraîchir l’état du dépôt (git status --porcelain).")
|
||||||
GadgetToolTip(#GInit, "Initialiser un dépôt Git ici (git init).")
|
GadgetToolTip(#GInit, "Initialiser un dépôt Git ici (git init).")
|
||||||
|
GadgetToolTip(#GInclude, "Inclure l’élément sélectionné.")
|
||||||
|
GadgetToolTip(#GExclude, "Exclure l’élément sélectionné.")
|
||||||
|
GadgetToolTip(#GIncludeAll, "Inclure tous les éléments de la liste.")
|
||||||
|
GadgetToolTip(#GExcludeAll, "Exclure tous les éléments de la liste.")
|
||||||
|
GadgetToolTip(#GAdvanced, "Ouvrir les actions avancées (branches, restauration…).")
|
||||||
GadgetToolTip(#GStringMsg, "Message de commit.")
|
GadgetToolTip(#GStringMsg, "Message de commit.")
|
||||||
GadgetToolTip(#GCheckPush, "Activer pour pousser après le commit (git push).")
|
GadgetToolTip(#GCheckPush, "Activer pour pousser après le commit (git push).")
|
||||||
GadgetToolTip(#GStringRemote, "Nom du remote (ex: origin).")
|
GadgetToolTip(#GStringRemote, "Nom du remote (ex: origin).")
|
||||||
GadgetToolTip(#GLabelRemote, "Nom du remote par défaut.")
|
|
||||||
GadgetToolTip(#GComboBranch, "Branche cible (ex: main).")
|
GadgetToolTip(#GComboBranch, "Branche cible (ex: main).")
|
||||||
GadgetToolTip(#GSavePrefs, "Sauver remote/branche comme valeurs par défaut.")
|
GadgetToolTip(#GSavePrefs, "Sauver remote/branche comme valeurs par défaut.")
|
||||||
GadgetToolTip(#GCommit, "git add -A puis git commit -m "+Chr(34)+"message"+Chr(34)+" (et push si coché).")
|
GadgetToolTip(#GCommit, ~"git add (fichiers cochés ou -A si aucun coché) puis git commit -m \"message\" (et push si coché).")
|
||||||
GadgetToolTip(#GPush, "Pousser la branche (git push).")
|
GadgetToolTip(#GPush, "Pousser la branche (git push).")
|
||||||
GadgetToolTip(#GPull, "Récupérer les changements distants (git pull).")
|
GadgetToolTip(#GPull, "Récupérer les changements distants (git pull).")
|
||||||
|
|
||||||
; Remplir branches via la LISTE
|
; Branches et status
|
||||||
NewList branchItems.s()
|
NewList branchItems.s()
|
||||||
ListBranches(repoDir$, branchItems())
|
ListBranches(repoDir$, branchItems())
|
||||||
ClearGadgetItems(#GComboBranch)
|
ClearGadgetItems(#GComboBranch)
|
||||||
ForEach branchItems()
|
ForEach branchItems() : AddGadgetItem(#GComboBranch, -1, branchItems()) : Next
|
||||||
AddGadgetItem(#GComboBranch, -1, branchItems())
|
If branch$ <> "" : SetGadgetText(#GComboBranch, branch$) : EndIf
|
||||||
Next
|
|
||||||
If branch$ <> ""
|
|
||||||
SetGadgetText(#GComboBranch, branch$)
|
|
||||||
EndIf
|
|
||||||
|
|
||||||
; Status initial
|
NewList rows.FileRow()
|
||||||
Protected stat$, line$, n.i, i.i
|
LoadStatusRows(repoDir$, rows())
|
||||||
If DoStatus(repoDir$, stat$)
|
FillStatusList(rows())
|
||||||
ClearGadgetItems(#GListStatus)
|
|
||||||
n = CountString(stat$, #LF$) + 1
|
|
||||||
For i = 1 To n
|
|
||||||
line$ = StringField(stat$, i, #LF$)
|
|
||||||
If Trim(line$) <> ""
|
|
||||||
AddGadgetItem(#GListStatus, -1, line$)
|
|
||||||
EndIf
|
|
||||||
Next i
|
|
||||||
EndIf
|
|
||||||
|
|
||||||
|
; Boucle
|
||||||
Repeat
|
Repeat
|
||||||
Protected ev.i = WaitWindowEvent()
|
Protected ev.i = WaitWindowEvent()
|
||||||
Select ev
|
Select ev
|
||||||
Case #PB_Event_Gadget
|
Case #PB_Event_Gadget
|
||||||
Select EventGadget()
|
Select EventGadget()
|
||||||
|
|
||||||
Case #GButtonBrowse
|
Case #GButtonBrowse
|
||||||
Protected newDir$ = PathRequester("Choisir le répertoire du dépôt", repoDir$)
|
Protected newDir$ = PathRequester("Choisir le répertoire du dépôt", repoDir$)
|
||||||
If newDir$ <> ""
|
If newDir$ <> ""
|
||||||
@@ -429,27 +660,55 @@ Procedure.i OpenGUI(initialDir$, prefsPath$)
|
|||||||
ClearList(branchItems())
|
ClearList(branchItems())
|
||||||
ListBranches(repoDir$, branchItems())
|
ListBranches(repoDir$, branchItems())
|
||||||
ClearGadgetItems(#GComboBranch)
|
ClearGadgetItems(#GComboBranch)
|
||||||
ForEach branchItems()
|
ForEach branchItems() : AddGadgetItem(#GComboBranch, -1, branchItems()) : Next
|
||||||
AddGadgetItem(#GComboBranch, -1, branchItems())
|
ClearList(rows())
|
||||||
Next
|
LoadStatusRows(repoDir$, rows())
|
||||||
|
FillStatusList(rows())
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
Case #GRefresh
|
Case #GRefresh
|
||||||
repoDir$ = GetGadgetText(#GStringRepo)
|
repoDir$ = GetGadgetText(#GStringRepo)
|
||||||
If DoStatus(repoDir$, stat$)
|
ClearList(rows())
|
||||||
ClearGadgetItems(#GListStatus)
|
LoadStatusRows(repoDir$, rows())
|
||||||
n = CountString(stat$, #LF$) + 1
|
FillStatusList(rows())
|
||||||
For i = 1 To n
|
|
||||||
line$ = StringField(stat$, i, #LF$)
|
|
||||||
If Trim(line$) <> ""
|
|
||||||
AddGadgetItem(#GListStatus, -1, line$)
|
|
||||||
EndIf
|
|
||||||
Next i
|
|
||||||
EndIf
|
|
||||||
|
|
||||||
Case #GInit
|
Case #GInit
|
||||||
repoDir$ = GetGadgetText(#GStringRepo)
|
repoDir$ = GetGadgetText(#GStringRepo)
|
||||||
DoInitRepo(repoDir$)
|
DoInitRepo(repoDir$)
|
||||||
|
ClearList(rows())
|
||||||
|
LoadStatusRows(repoDir$, rows())
|
||||||
|
FillStatusList(rows())
|
||||||
|
|
||||||
|
Case #GInclude
|
||||||
|
Protected idx.i = GetGadgetState(#GListStatus)
|
||||||
|
If idx >= 0
|
||||||
|
SetGadgetItemState(#GListStatus, idx, #PB_ListIcon_Checked)
|
||||||
|
ToggleIncludeAt(idx, rows())
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
Case #GExclude
|
||||||
|
idx = GetGadgetState(#GListStatus)
|
||||||
|
If idx >= 0
|
||||||
|
SetGadgetItemState(#GListStatus, idx, 0)
|
||||||
|
ToggleIncludeAt(idx, rows())
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
Case #GIncludeAll
|
||||||
|
Protected c.i = CountGadgetItems(#GListStatus)
|
||||||
|
For idx = 0 To c - 1 : SetGadgetItemState(#GListStatus, idx, #PB_ListIcon_Checked) : Next
|
||||||
|
ForEach rows() : rows()\include = 1 : Next
|
||||||
|
|
||||||
|
Case #GExcludeAll
|
||||||
|
c = CountGadgetItems(#GListStatus)
|
||||||
|
For idx = 0 To c - 1 : SetGadgetItemState(#GListStatus, idx, 0) : Next
|
||||||
|
ForEach rows() : rows()\include = 0 : Next
|
||||||
|
|
||||||
|
Case #GAdvanced
|
||||||
|
repoDir$ = GetGadgetText(#GStringRepo)
|
||||||
|
OpenAdvancedWindow(repoDir$)
|
||||||
|
ClearList(rows())
|
||||||
|
LoadStatusRows(repoDir$, rows())
|
||||||
|
FillStatusList(rows())
|
||||||
|
|
||||||
Case #GSavePrefs
|
Case #GSavePrefs
|
||||||
remote$ = GetGadgetText(#GStringRemote)
|
remote$ = GetGadgetText(#GStringRemote)
|
||||||
@@ -468,7 +727,16 @@ Procedure.i OpenGUI(initialDir$, prefsPath$)
|
|||||||
If Trim(msg$) = ""
|
If Trim(msg$) = ""
|
||||||
MessageRequester("Commit", "Merci de saisir un message.", #PB_MessageRequester_Warning)
|
MessageRequester("Commit", "Merci de saisir un message.", #PB_MessageRequester_Warning)
|
||||||
Else
|
Else
|
||||||
DoCommit(repoDir$, msg$, GetGadgetState(#GCheckPush), remote$, branch$)
|
NewList files.s()
|
||||||
|
CollectIncludedFiles(rows(), files())
|
||||||
|
If ListSize(files()) > 0
|
||||||
|
DoCommitSelected(repoDir$, msg$, GetGadgetState(#GCheckPush), remote$, branch$, files())
|
||||||
|
Else
|
||||||
|
DoCommit(repoDir$, msg$, GetGadgetState(#GCheckPush), remote$, branch$)
|
||||||
|
EndIf
|
||||||
|
ClearList(rows())
|
||||||
|
LoadStatusRows(repoDir$, rows())
|
||||||
|
FillStatusList(rows())
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
Case #GPush
|
Case #GPush
|
||||||
@@ -483,78 +751,21 @@ Procedure.i OpenGUI(initialDir$, prefsPath$)
|
|||||||
branch$ = GetGadgetText(#GComboBranch)
|
branch$ = GetGadgetText(#GComboBranch)
|
||||||
DoPull(repoDir$, remote$, branch$)
|
DoPull(repoDir$, remote$, branch$)
|
||||||
|
|
||||||
|
Case #GListStatus
|
||||||
|
idx = GetGadgetState(#GListStatus)
|
||||||
|
If idx >= 0 : ToggleIncludeAt(idx, rows()) : EndIf
|
||||||
|
|
||||||
EndSelect
|
EndSelect
|
||||||
EndSelect
|
EndSelect
|
||||||
|
|
||||||
Until ev = #PB_Event_CloseWindow
|
Until ev = #PB_Event_CloseWindow
|
||||||
|
|
||||||
ProcedureReturn 1
|
ProcedureReturn 1
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
ProcedureReturn 0
|
ProcedureReturn 0
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
; ------------------------------------------------------------------
|
; ====== Installation IDE ======
|
||||||
; Installe l’intégration dans l’IDE PureBasic :
|
; Fenêtre assistant
|
||||||
; - copie le thème d’icônes (zip) dans <IDE>\Themes\
|
|
||||||
; - lance l’IDE avec /A "<fichier_tools>" pour importer les outils
|
|
||||||
; Retourne 1 si OK, 0 sinon.
|
|
||||||
; ------------------------------------------------------------------
|
|
||||||
Procedure.i InstallPBGitInIDE(ideExe$, toolsPrefs$, themeZip$)
|
|
||||||
Protected ok.i = 1
|
|
||||||
Protected ideHome$, themesDir$, destZip$, args$, prg.i, copyOk.i
|
|
||||||
|
|
||||||
If FileSize(ideExe$) <= 0 Or FileSize(toolsPrefs$) <= 0 Or FileSize(themeZip$) <= 0
|
|
||||||
MessageRequester("Installation", "Chemins invalides. Merci de sélectionner PureBasic.exe, le fichier d’outils et le thème.", #PB_MessageRequester_Error)
|
|
||||||
ProcedureReturn 0
|
|
||||||
EndIf
|
|
||||||
|
|
||||||
ideHome$ = GetPathPart(ideExe$)
|
|
||||||
themesDir$ = ideHome$ + "Themes" + #PathSep$
|
|
||||||
destZip$ = themesDir$ + GetFilePart(themeZip$)
|
|
||||||
|
|
||||||
; Créer le dossier Themes si besoin
|
|
||||||
If FileSize(themesDir$) <> -2
|
|
||||||
If CreateDirectory(themesDir$) = 0
|
|
||||||
MessageRequester("Installation", "Impossible de créer le dossier Themes : " + themesDir$, #PB_MessageRequester_Error)
|
|
||||||
ProcedureReturn 0
|
|
||||||
EndIf
|
|
||||||
EndIf
|
|
||||||
|
|
||||||
; Copier le thème
|
|
||||||
copyOk = CopyFile(themeZip$, destZip$)
|
|
||||||
If copyOk = 0
|
|
||||||
MessageRequester("Installation", "Échec de copie du thème vers : " + destZip$, #PB_MessageRequester_Error)
|
|
||||||
ok = 0
|
|
||||||
EndIf
|
|
||||||
|
|
||||||
; Importer les outils via /A "<toolsPrefs$>"
|
|
||||||
If ok
|
|
||||||
args$ = "/A " + Chr(34) + toolsPrefs$ + Chr(34)
|
|
||||||
prg = RunProgram(ideExe$, args$, "", #PB_Program_Hide | #PB_Program_Wait)
|
|
||||||
If prg = 0
|
|
||||||
MessageRequester("Installation", "Échec de l’import des outils (/A).", #PB_MessageRequester_Error)
|
|
||||||
ok = 0
|
|
||||||
EndIf
|
|
||||||
EndIf
|
|
||||||
|
|
||||||
If ok
|
|
||||||
MessageRequester("Installation", "Intégration importée !" + #LF$ +
|
|
||||||
"- Thème copié dans: " + destZip$ + #LF$ +
|
|
||||||
"- Outils importés via /A", #PB_MessageRequester_Info)
|
|
||||||
EndIf
|
|
||||||
|
|
||||||
ProcedureReturn ok
|
|
||||||
EndProcedure
|
|
||||||
|
|
||||||
; ------------------------------------------------------------------
|
|
||||||
; Assistant d’installation graphique quand PBIDE-GitTool est lancé sans paramètre.
|
|
||||||
; - Permet de choisir PureBasic.exe, git_tools.prefs et PBGitTheme.zip
|
|
||||||
; - Appelle InstallPBGitInIDE()
|
|
||||||
; Retourne 1 si installation OK, 0 sinon.
|
|
||||||
; ------------------------------------------------------------------
|
|
||||||
|
|
||||||
; Gadgets de la fenêtre d'installation (évite toute collision avec l’UI principale)
|
|
||||||
#WInstall = 100
|
#WInstall = 100
|
||||||
#GLabelIde = 110
|
#GLabelIde = 110
|
||||||
#GStringIde = 111
|
#GStringIde = 111
|
||||||
@@ -569,6 +780,48 @@ EndProcedure
|
|||||||
#GInstallCancel = 120
|
#GInstallCancel = 120
|
||||||
#GInstallNote = 121
|
#GInstallNote = 121
|
||||||
|
|
||||||
|
Procedure.i InstallPBGitInIDE(ideExe$, toolsPrefs$, themeZip$)
|
||||||
|
Protected ok.i = 1, ideHome$, themesDir$, destZip$, args$, prg.i, copyok.i
|
||||||
|
|
||||||
|
If FileSize(ideExe$) <= 0 Or FileSize(toolsPrefs$) <= 0 Or FileSize(themeZip$) <= 0
|
||||||
|
MessageRequester("Installation", "Chemins invalides. Sélectionnez PureBasic.exe, le fichier d’outils et le thème.", #PB_MessageRequester_Error)
|
||||||
|
ProcedureReturn 0
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
ideHome$ = GetPathPart(ideExe$)
|
||||||
|
themesDir$ = ideHome$ + "Themes" + #PathSep$
|
||||||
|
destZip$ = themesDir$ + GetFilePart(themeZip$)
|
||||||
|
|
||||||
|
If FileSize(themesDir$) <> -2
|
||||||
|
If CreateDirectory(themesDir$) = 0
|
||||||
|
MessageRequester("Installation", "Impossible de créer le dossier Themes : " + themesDir$, #PB_MessageRequester_Error)
|
||||||
|
ProcedureReturn 0
|
||||||
|
EndIf
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
copyok = CopyFile(themeZip$, destZip$)
|
||||||
|
If copyok = 0
|
||||||
|
MessageRequester("Installation", "Échec de copie du thème vers : " + destZip$, #PB_MessageRequester_Error)
|
||||||
|
ok = 0
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
If ok
|
||||||
|
args$ = "/A " + Chr(34) + toolsPrefs$ + Chr(34)
|
||||||
|
prg = RunProgram(ideExe$, args$, "", #PB_Program_Hide | #PB_Program_Wait)
|
||||||
|
If prg = 0
|
||||||
|
MessageRequester("Installation", "Échec de l’import des outils (/A).", #PB_MessageRequester_Error)
|
||||||
|
ok = 0
|
||||||
|
EndIf
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
If ok
|
||||||
|
MessageRequester("Installation", "Intégration importée !" + #LF$ +
|
||||||
|
"- Thème copié : " + destZip$ + #LF$ +
|
||||||
|
"- Outils importés via /A", #PB_MessageRequester_Info)
|
||||||
|
EndIf
|
||||||
|
ProcedureReturn ok
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
Procedure.i OpenInstallWizard()
|
Procedure.i OpenInstallWizard()
|
||||||
Protected exeDefault$ = ""
|
Protected exeDefault$ = ""
|
||||||
Protected dirExe$ = GetPathPart(ProgramFilename())
|
Protected dirExe$ = GetPathPart(ProgramFilename())
|
||||||
@@ -592,10 +845,9 @@ Procedure.i OpenInstallWizard()
|
|||||||
ButtonGadget(#GInstallCancel, 530, 150, 140, 30, "Annuler")
|
ButtonGadget(#GInstallCancel, 530, 150, 140, 30, "Annuler")
|
||||||
|
|
||||||
TextGadget(#GInstallNote, 10, 190, 660, 40,
|
TextGadget(#GInstallNote, 10, 190, 660, 40,
|
||||||
"Conseil : placez 'git_tools.prefs' et 'PBGitTheme.zip' à côté de PBIDE-GitTool.exe pour auto-renseignement." + #LF$ +
|
"Astuce : placez 'git_tools.prefs' et 'PBGitTheme.zip' à côté de PBIDE-GitTool.exe pour auto-renseignement." + #LF$ +
|
||||||
"Après import, choisissez le thème dans Préférences → General → Themes, puis ajoutez des boutons 'Run tool' dans la Toolbar.")
|
"Ensuite choisissez le thème (Préférences → Themes) et ajoutez les boutons 'Run tool' dans la Toolbar.")
|
||||||
|
|
||||||
; Infobulles de l’assistant
|
|
||||||
GadgetToolTip(#GStringIde, "Chemin de PureBasic.exe (IDE).")
|
GadgetToolTip(#GStringIde, "Chemin de PureBasic.exe (IDE).")
|
||||||
GadgetToolTip(#GButtonIde, "Parcourir pour sélectionner l’exécutable de l’IDE PureBasic.")
|
GadgetToolTip(#GButtonIde, "Parcourir pour sélectionner l’exécutable de l’IDE PureBasic.")
|
||||||
GadgetToolTip(#GStringTools, "Fichier d’outils externes à importer (/A).")
|
GadgetToolTip(#GStringTools, "Fichier d’outils externes à importer (/A).")
|
||||||
@@ -623,10 +875,7 @@ Procedure.i OpenInstallWizard()
|
|||||||
|
|
||||||
Case #GInstallGo
|
Case #GInstallGo
|
||||||
Protected ok.i = InstallPBGitInIDE(GetGadgetText(#GStringIde), GetGadgetText(#GStringTools), GetGadgetText(#GStringTheme))
|
Protected ok.i = InstallPBGitInIDE(GetGadgetText(#GStringIde), GetGadgetText(#GStringTools), GetGadgetText(#GStringTheme))
|
||||||
If ok
|
If ok : CloseWindow(#WInstall) : ProcedureReturn 1 : EndIf
|
||||||
CloseWindow(#WInstall)
|
|
||||||
ProcedureReturn 1
|
|
||||||
EndIf
|
|
||||||
|
|
||||||
Case #GInstallCancel
|
Case #GInstallCancel
|
||||||
CloseWindow(#WInstall)
|
CloseWindow(#WInstall)
|
||||||
@@ -637,21 +886,18 @@ Procedure.i OpenInstallWizard()
|
|||||||
|
|
||||||
ProcedureReturn 0
|
ProcedureReturn 0
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
ProcedureReturn 0
|
ProcedureReturn 0
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
; ====== Entrée ======
|
; ====== Entrée ======
|
||||||
|
; On ne coupe pas si Git manque, pour permettre l’assistant d’installation
|
||||||
If EnsureGitAvailable() = 0
|
If EnsureGitAvailable() = 0
|
||||||
; On n’arrête pas forcément l’outil si Git manque, pour l’assistant d’installation
|
; Averti, mais continue.
|
||||||
; Mais on avertit : Git sera requis pour les opérations.
|
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
; Emplacement prefs locale de l’outil
|
; Préférences locales de l’outil
|
||||||
Define baseDoc$ = GetUserDirectory(#PB_Directory_Documents)
|
Define baseDoc$ = GetUserDirectory(#PB_Directory_Documents)
|
||||||
If Right(baseDoc$, 1) <> #PathSep$
|
If Right(baseDoc$, 1) <> #PathSep$ : baseDoc$ + #PathSep$ : EndIf
|
||||||
baseDoc$ + #PathSep$
|
|
||||||
EndIf
|
|
||||||
Define prefsDir$ = baseDoc$ + "PBIDE-GitTool" + #PathSep$
|
Define prefsDir$ = baseDoc$ + "PBIDE-GitTool" + #PathSep$
|
||||||
If FileSize(prefsDir$) <> -2 : CreateDirectory(prefsDir$) : EndIf
|
If FileSize(prefsDir$) <> -2 : CreateDirectory(prefsDir$) : EndIf
|
||||||
Define prefsPath$ = prefsDir$ + "settings.prefs"
|
Define prefsPath$ = prefsDir$ + "settings.prefs"
|
||||||
@@ -663,7 +909,7 @@ Define repoArg$ = "", msgArg$ = "", remoteArg$ = "", branchArg$ = ""
|
|||||||
Define wantStatus.i = 0, wantInit.i = 0, wantCommit.i = 0, wantPush.i = 0, wantPull.i = 0
|
Define wantStatus.i = 0, wantInit.i = 0, wantCommit.i = 0, wantPush.i = 0, wantPull.i = 0
|
||||||
Define w.i
|
Define w.i
|
||||||
|
|
||||||
; --- Si aucun paramètre : proposer l’installation IDE ---
|
; Si aucun paramètre : proposer l’installation IDE
|
||||||
If argCount = 0
|
If argCount = 0
|
||||||
If MessageRequester("PBIDE-GitTool", "Aucun paramètre détecté." + #LF$ + "Souhaitez-vous installer l’intégration IDE (outils + thème) maintenant ?", #PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
|
If MessageRequester("PBIDE-GitTool", "Aucun paramètre détecté." + #LF$ + "Souhaitez-vous installer l’intégration IDE (outils + thème) maintenant ?", #PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
|
||||||
OpenInstallWizard()
|
OpenInstallWizard()
|
||||||
@@ -671,10 +917,10 @@ If argCount = 0
|
|||||||
EndIf
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
; Parsing arguments
|
|
||||||
For w = 0 To argCount - 1
|
For w = 0 To argCount - 1
|
||||||
Define a$ = ProgramParameter(w)
|
Define a$ = ProgramParameter(w)
|
||||||
Select LCase(a$)
|
Select LCase(a$)
|
||||||
|
Case "--project" : If w + 1 < argCount : repoArg$ = ProgramParameter(w + 1) : EndIf
|
||||||
Case "--repo" : If w + 1 < argCount : repoArg$ = ProgramParameter(w + 1) : EndIf
|
Case "--repo" : If w + 1 < argCount : repoArg$ = ProgramParameter(w + 1) : EndIf
|
||||||
Case "--status" : wantStatus = 1 : useGui = 0
|
Case "--status" : wantStatus = 1 : useGui = 0
|
||||||
Case "--init" : wantInit = 1 : useGui = 0
|
Case "--init" : wantInit = 1 : useGui = 0
|
||||||
@@ -683,7 +929,6 @@ For w = 0 To argCount - 1
|
|||||||
Case "--pull" : wantPull = 1 : useGui = 0
|
Case "--pull" : wantPull = 1 : useGui = 0
|
||||||
Case "--remote" : If w + 1 < argCount : remoteArg$ = ProgramParameter(w + 1) : EndIf
|
Case "--remote" : If w + 1 < argCount : remoteArg$ = ProgramParameter(w + 1) : EndIf
|
||||||
Case "--branch" : If w + 1 < argCount : branchArg$ = ProgramParameter(w + 1) : EndIf
|
Case "--branch" : If w + 1 < argCount : branchArg$ = ProgramParameter(w + 1) : EndIf
|
||||||
Case "--project" : If w + 1 < argCount : repoArg$ = ProgramParameter(w + 1) : EndIf
|
|
||||||
EndSelect
|
EndSelect
|
||||||
Next w
|
Next w
|
||||||
|
|
||||||
@@ -692,7 +937,7 @@ If useGui
|
|||||||
If dir$ = "" : dir$ = DirFromArgOrFallback() : EndIf
|
If dir$ = "" : dir$ = DirFromArgOrFallback() : EndIf
|
||||||
OpenGUI(dir$, prefsPath$)
|
OpenGUI(dir$, prefsPath$)
|
||||||
Else
|
Else
|
||||||
; Exécution non interactive
|
; Mode non interactif
|
||||||
Define remote$ = "", branch$ = ""
|
Define remote$ = "", branch$ = ""
|
||||||
LoadPrefs(prefsPath$, remote$, branch$)
|
LoadPrefs(prefsPath$, remote$, branch$)
|
||||||
If remoteArg$ <> "" : remote$ = remoteArg$ : EndIf
|
If remoteArg$ <> "" : remote$ = remoteArg$ : EndIf
|
||||||
@@ -703,8 +948,8 @@ Else
|
|||||||
baseDir$ = DetectRepoRoot(baseDir$)
|
baseDir$ = DetectRepoRoot(baseDir$)
|
||||||
|
|
||||||
If wantStatus
|
If wantStatus
|
||||||
Define st$, ok.i = DoStatus(baseDir$, st$)
|
Define st$, okstat.i = DoStatus(baseDir$, st$)
|
||||||
If ok : PrintN(st$) : EndIf
|
If okstat : PrintN(st$) : EndIf
|
||||||
ElseIf wantInit
|
ElseIf wantInit
|
||||||
DoInitRepo(baseDir$)
|
DoInitRepo(baseDir$)
|
||||||
ElseIf wantCommit
|
ElseIf wantCommit
|
||||||
@@ -718,9 +963,9 @@ Else
|
|||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
; IDE Options = PureBasic 6.21 (Windows - x64)
|
; IDE Options = PureBasic 6.21 (Windows - x64)
|
||||||
; CursorPosition = 390
|
; CursorPosition = 632
|
||||||
; FirstLine = 386
|
; FirstLine = 628
|
||||||
; Folding = ---
|
; Folding = -----
|
||||||
; EnableXP
|
; EnableXP
|
||||||
; DPIAware
|
; DPIAware
|
||||||
; Executable = ..\PBIDE-GitTool.exe
|
; Executable = ..\PBIDE-GitTool.exe
|
||||||
|
Binary file not shown.
Reference in New Issue
Block a user