Auto Disable / Enable Gadget
This commit is contained in:
148
main.pb
148
main.pb
@@ -505,6 +505,43 @@ Procedure.i RunExe(*call.RunProgramCall)
|
||||
ProcedureReturn *call\exitcode
|
||||
EndProcedure
|
||||
|
||||
; ---- Helpers ---------------------------------------------------------------
|
||||
|
||||
Procedure.s _JoinPath(base$, sub$)
|
||||
Protected out$ = Trim(base$)
|
||||
If out$ = "" : ProcedureReturn sub$ : EndIf
|
||||
If Right(out$, 1) <> "\" And Right(out$, 1) <> "/" : out$ + "/" : EndIf
|
||||
ProcedureReturn out$ + sub$
|
||||
EndProcedure
|
||||
|
||||
Procedure.b _RepoIsInitialized(workdir$)
|
||||
ProcedureReturn Bool(FileSize(_JoinPath(workdir$, ".git")) = -2)
|
||||
EndProcedure
|
||||
|
||||
Procedure.i _CountCheckedItems(listID)
|
||||
Protected i, n = CountGadgetItems(listID), c
|
||||
For i = 0 To n - 1
|
||||
If GetGadgetItemState(listID, i) & #PB_ListIcon_Checked
|
||||
c + 1
|
||||
EndIf
|
||||
Next
|
||||
ProcedureReturn c
|
||||
EndProcedure
|
||||
|
||||
Procedure.i _CountSelectedItems(listID)
|
||||
Protected i, n = CountGadgetItems(listID), c
|
||||
For i = 0 To n - 1
|
||||
If GetGadgetItemState(listID, i) & #PB_ListIcon_Selected
|
||||
c + 1
|
||||
EndIf
|
||||
Next
|
||||
ProcedureReturn c
|
||||
EndProcedure
|
||||
|
||||
Procedure.b _HasRemote()
|
||||
ProcedureReturn Bool(Trim(GetGadgetText(#GdtFieldRemote)) <> "")
|
||||
EndProcedure
|
||||
|
||||
Procedure Max(nb1, nb2)
|
||||
If nb1 > nb2
|
||||
Result = nb1
|
||||
@@ -1262,7 +1299,7 @@ Procedure DoLsFilesByType( includeType.s = "CDOI")
|
||||
Protected status.s=""
|
||||
; Construire les arguments selon les types demandés
|
||||
If FindString(includeType, "C") > 0
|
||||
args + " --cached --stage"
|
||||
args + " -s --cached --stage"
|
||||
status =".."
|
||||
EndIf
|
||||
If FindString(includeType, "D") > 0
|
||||
@@ -1573,6 +1610,103 @@ Procedure UpdateHelp(txt.s)
|
||||
SetGadgetItemText(#GdtHelp,#PB_Web_HtmlCode,txt.s)
|
||||
EndProcedure
|
||||
|
||||
Procedure _SetTooltips()
|
||||
; Dépôt
|
||||
GadgetToolTip(#GdtBtnInit, T("tip.init", "Initialiser un dépôt Git ici"))
|
||||
GadgetToolTip(#GdtBtnRefresh, T("tip.refresh", "Rafraîchir la liste des fichiers et l’état Git"))
|
||||
GadgetToolTip(#GgtFieldRepo, T("tip.repo.path", "Chemin du dossier projet (workdir)"))
|
||||
|
||||
; Remote / Branch
|
||||
GadgetToolTip(#GdtFieldRemote, T("tip.remote", "URL du remote (ex.: https://... ou git@host:org/repo.git)"))
|
||||
GadgetToolTip(#GdtSlctBranch, T("tip.branch.select","Choisir la branche active"))
|
||||
GadgetToolTip(#GdtBtnNewBranch,T("tip.branch.new", "Créer une nouvelle branche"))
|
||||
GadgetToolTip(#GdtBtnClone, T("tip.clone", "Cloner depuis l’URL remote"))
|
||||
GadgetToolTip(#GdtBtnPull, T("tip.pull", "Récupérer et fusionner depuis le remote"))
|
||||
GadgetToolTip(#GdtBtnPush, T("tip.push", "Envoyer vos commits sur le remote"))
|
||||
|
||||
; Fichiers & actions locales
|
||||
GadgetToolTip(#GdtListStatus, T("tip.files.list", "Fichiers du dépôt : cochez pour préparer un commit, sélectionnez pour agir"))
|
||||
GadgetToolTip(#GdtBtnRestore, T("tip.restore", "Restaurer les fichiers sélectionnés"))
|
||||
GadgetToolTip(#GdtBtnRename, T("tip.rename", "Renommer les fichiers sélectionnés"))
|
||||
GadgetToolTip(#GdtBtnDelete, T("tip.delete", "Supprimer les fichiers sélectionnés"))
|
||||
GadgetToolTip(#GdtBtnIgnore, T("tip.ignore", "Ajouter/retirer les fichiers sélectionnés dans .gitignore"))
|
||||
|
||||
; Commit
|
||||
GadgetToolTip(#GdtFieldMessage,T("tip.message", "Message du commit"))
|
||||
GadgetToolTip(#GdtBtnCommit, T("tip.commit", "Committer tous les fichiers cochés avec le message"))
|
||||
|
||||
; History
|
||||
GadgetToolTip(#GdtListHistory, T("tip.history", "Historique des commits"))
|
||||
GadgetToolTip(#GdtBtnRestoreCommit,T("tip.history.restore","Restaurer/checkout le commit sélectionné"))
|
||||
|
||||
; .gitignore
|
||||
GadgetToolTip(#GdtTxtGitIgnore, T("tip.gitignore.edit","Éditeur du .gitignore"))
|
||||
GadgetToolTip(#GdtBtnSaveGitIgnore,T("tip.gitignore.save","Sauvegarder le .gitignore"))
|
||||
|
||||
; Config
|
||||
GadgetToolTip(#GdtFieldUserName, T("tip.cfg.username","Nom d’utilisateur Git (user.name)"))
|
||||
GadgetToolTip(#GdtFieldUserEmail,T("tip.cfg.useremail","Email Git (user.email)"))
|
||||
GadgetToolTip(#GdtSlctScope, T("tip.cfg.scope", "Portée de la configuration (Local/Global/System)"))
|
||||
GadgetToolTip(#GdtBtnSaveCfg, T("tip.cfg.save", "Enregistrer la configuration Git"))
|
||||
EndProcedure
|
||||
|
||||
; ---- Procédure principale ---------------------------------------------------
|
||||
|
||||
Procedure InitGadget()
|
||||
Protected hasGit.b = main\info\isGit
|
||||
Protected workdir$ = Trim(GetGadgetText(#GgtFieldRepo))
|
||||
Protected repoDirOK.b = Bool(workdir$ <> "" And FileSize(workdir$) = -2)
|
||||
Protected isInit.b = Bool(repoDirOK And _RepoIsInitialized(workdir$))
|
||||
Protected hasRemote.b = _HasRemote()
|
||||
Protected selCount.i = _CountSelectedItems(#GdtListStatus)
|
||||
Protected checkedCount.i = _CountCheckedItems(#GdtListStatus)
|
||||
Protected haveHistorySel.b = Bool(GetGadgetState(#GdtListHistory) >= 0)
|
||||
Protected userName$ = Trim(GetGadgetText(#GdtFieldUserName))
|
||||
Protected userEmail$ = Trim(GetGadgetText(#GdtFieldUserEmail))
|
||||
|
||||
; Mémoriser l’état init global
|
||||
main\info\isInit = isInit
|
||||
|
||||
; ---- Zone Dépôt ----------------------------------------------------------
|
||||
DisableGadget(#GdtBtnInit, Bool(Not (hasGit And repoDirOK And Not isInit)))
|
||||
DisableGadget(#GdtBtnRefresh, Bool(Not (hasGit And repoDirOK)))
|
||||
DisableGadget(#GgtFieldRepo, Bool(Not hasGit))
|
||||
|
||||
; ---- Remote / Branch -----------------------------------------------------
|
||||
DisableGadget(#GdtFieldRemote, Bool(Not (hasGit And repoDirOK)))
|
||||
DisableGadget(#GdtSlctBranch, Bool(Not (hasGit And isInit)))
|
||||
DisableGadget(#GdtBtnNewBranch,Bool(Not (hasGit And isInit)))
|
||||
|
||||
; Règle demandée : Clone/Pull/Push uniquement si une remote est définie
|
||||
DisableGadget(#GdtBtnClone, Bool(Not (hasGit And repoDirOK And hasRemote)))
|
||||
DisableGadget(#GdtBtnPull, Bool(Not (hasGit And isInit And hasRemote)))
|
||||
DisableGadget(#GdtBtnPush, Bool(Not (hasGit And isInit And hasRemote)))
|
||||
|
||||
; ---- Fichiers & actions locales -----------------------------------------
|
||||
; Restaurer / Renommer / Supprimer / Ignorer : uniquement si des fichiers sont sélectionnés
|
||||
DisableGadget(#GdtBtnRestore, Bool(selCount = 0))
|
||||
DisableGadget(#GdtBtnRename, Bool(selCount = 0))
|
||||
DisableGadget(#GdtBtnDelete, Bool(selCount = 0))
|
||||
DisableGadget(#GdtBtnIgnore, Bool(selCount = 0))
|
||||
|
||||
; Commit : uniquement si des fichiers sont cochés
|
||||
DisableGadget(#GdtBtnCommit, Bool(Not (hasGit And isInit And checkedCount > 0)))
|
||||
|
||||
; ---- Onglet History ------------------------------------------------------
|
||||
DisableGadget(#GdtBtnRestoreCommit, Bool(Not (hasGit And isInit And haveHistorySel)))
|
||||
|
||||
; ---- .gitignore ----------------------------------------------------------
|
||||
; On autorise la sauvegarde si le repo est initialisé (fichier créé si besoin)
|
||||
DisableGadget(#GdtBtnSaveGitIgnore, Bool(Not (hasGit And isInit)))
|
||||
|
||||
; ---- Config --------------------------------------------------------------
|
||||
; Le bouton "Enregistrer" actif si au moins un champ non vide
|
||||
DisableGadget(#GdtBtnSaveCfg, Bool(userName$ = "" And userEmail$ = ""))
|
||||
|
||||
|
||||
EndProcedure
|
||||
|
||||
|
||||
Procedure OpenGUI()
|
||||
Protected argCount.l=CountProgramParameters(), w.l,a$
|
||||
If CountProgramParameters() <> 0
|
||||
@@ -1733,13 +1867,16 @@ Procedure OpenGUI()
|
||||
|
||||
SetGadgetText(#GgtFieldRepo,main\GitCall\workdir)
|
||||
CreateThread(@RefreshFileList(),0)
|
||||
InitGadget()
|
||||
_SetTooltips()
|
||||
If FileSize(".git")=-2:main\info\isInit=#True:EndIf
|
||||
If main\info\isInit=#True
|
||||
GetRemoteUrl("origin")
|
||||
GetCommitHistory()
|
||||
EndIf
|
||||
|
||||
GetBranchesList()
|
||||
GetCommitHistory()
|
||||
|
||||
; =================== EVENT LOOP / BOUCLE ÉVÉNEMENTS ===================
|
||||
Quit=#False
|
||||
Repeat
|
||||
@@ -1808,6 +1945,7 @@ Procedure OpenGUI()
|
||||
|
||||
|
||||
EndSelect
|
||||
InitGadget()
|
||||
EndSelect
|
||||
Until Quit=#True
|
||||
End
|
||||
@@ -1819,9 +1957,9 @@ OpenGUI()
|
||||
|
||||
|
||||
; IDE Options = PureBasic 6.21 (Windows - x64)
|
||||
; CursorPosition = 1158
|
||||
; FirstLine = 1152
|
||||
; Folding = -------
|
||||
; CursorPosition = 1947
|
||||
; FirstLine = 1906
|
||||
; Folding = --------
|
||||
; Optimizer
|
||||
; EnableThread
|
||||
; EnableXP
|
||||
|
Reference in New Issue
Block a user