From 1b9944f73376fbbef5b4f838aed873e3cf8f7267 Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Wed, 11 Jul 2018 16:26:35 +0200 Subject: [PATCH] add project menu items for git branche checlout and git pull --- icons/other/git.png | Bin 0 -> 468 bytes icons/other/git24.png | Bin 0 -> 617 bytes icons/other/git32.png | Bin 0 -> 868 bytes lazproj/coedit.lpi | 5 +- src/ce_main.lfm | 19 ++++++ src/ce_main.pas | 155 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 icons/other/git.png create mode 100644 icons/other/git24.png create mode 100644 icons/other/git32.png diff --git a/icons/other/git.png b/icons/other/git.png new file mode 100644 index 0000000000000000000000000000000000000000..ea7dc00eeb97bf5a075bf93522bc7688b61082f6 GIT binary patch literal 468 zcmV;_0W1EAP)&DmHv;e zy6a!)sy{$*}#(Rl^VSAvDm|4h)O~CYRBQ+L&TyFrhE2V3UVyGPt!T@F~_m$H6 zQ_*o&I~Ifo8sZyprIaSlmKmP}%cD*_cCUuu5tT(E&XW#D^QZMZ=y2eqm&Rv~NHXDn zu^3P3ZGSe_8YG2YdF08CiJSjQM0{_5cz1#E`Kg6ww`1D|@NiJbrD{k_oS?m!CD3!bTD+XTU_c*` z#-9+Pwg%D&K~nn{Y}UjGS+o?l*@>c}ph(gvC~hVpU}Q7*ScHuGF|%`%)6Lv_p6AYc zxFa}Lr(T>C<2@Cni|BNr5wuw0A(caqON@Yw4jF(cvi z()qJ%?H{Uk9#tJ!9tUZLez|fiL8o4v%!&CF-m1)vEw4XT)w$zH5+mx%Tvb8t7oN2j zL%&ot$VCeeK`!;Sq{THPNEj%ns#SY+eEIEbfUs7+h9|EETazSx5hcO_M8w0Kil1$F z!!@p0kP1Ki2*bke&CBNi3ajtGp*(PrhzmSExYgSx>b{X&uAXlMOFQ-QJu5syWH9PD zE^&p&0wXO{zlboKZv;!BU#c207p&@h(%@ywuY4Dn$b$C?;47*smMi&{pal^6r7D=0 zz55m2G@^7};6o)M81g-^-$Ppv?*yXLAWdNWs1AjNomyqn()|l&abS5{BApR{gQ;gr z`XU-#+Y;%G{7TR=00);tr+`jchoC>j>IeC=x238ZE^z3%2U(KHGCTHs{at?TV+WPH zF7Q4C1Le)Zpg=eO#?SyU%HjrKlA0n9pEdZ%dYo$z-I2g05}QG zky7Cl#_^yv4NQZMFFT#~&Vxp_h~8K4E>~5Bf!T_r>aO@J^}RN^QcV{ju92?k&7% zEcI5i@w{5$Edt3TG{5F`W9#QvZp{I_@}HFnJM$6nfIxf+yZYg!zwb9^pH}WXMNB4z zhYG}zkoY9za@e(w@U{X`5@y==xK#M2Ie)S%w@pUK>$Wo-Vtf;N#r&Ww - + @@ -390,6 +390,9 @@ + + + diff --git a/src/ce_main.lfm b/src/ce_main.lfm index 47bdceb4..76898de6 100644 --- a/src/ce_main.lfm +++ b/src/ce_main.lfm @@ -1713,6 +1713,15 @@ object CEMainForm: TCEMainForm object MenuItem110: TMenuItem Action = actProjTest end + object MenuItem115: TMenuItem + Caption = '-' + end + object mnuGitBranch: TMenuItem + Caption = 'Git branch...' + end + object MenuItem116: TMenuItem + Action = actProjGitPull + end end object MenuItem100: TMenuItem Caption = 'Projects group' @@ -2287,6 +2296,16 @@ object CEMainForm: TCEMainForm Caption = 'New project dialog...' OnExecute = actProjNewDialogExecute end + object actProjGitBranchesUpd: TAction + Category = 'Project' + Caption = 'Update list' + OnExecute = actProjGitBranchesUpdExecute + end + object actProjGitPull: TAction + Category = 'Project' + Caption = 'Git pull' + OnExecute = actProjGitPullExecute + end end object ApplicationProperties1: TApplicationProperties OnActivate = ApplicationProperties1Activate diff --git a/src/ce_main.pas b/src/ce_main.pas index 018b21a6..bd4bdead 100644 --- a/src/ce_main.pas +++ b/src/ce_main.pas @@ -117,6 +117,8 @@ type actFileCloseAll: TAction; actFileNewClip: TAction; actEdFormat: TAction; + actProjGitPull: TAction; + actProjGitBranchesUpd: TAction; actProjNewDialog: TAction; actProjStopComp: TAction; actProjTest: TAction; @@ -178,6 +180,9 @@ type MenuItem112: TMenuItem; MenuItem113: TMenuItem; MenuItem114: TMenuItem; + MenuItem115: TMenuItem; + MenuItem116: TMenuItem; + mnuGitBranch: TMenuItem; mnuItemDubDialog: TMenuItem; mnuItemHelp: TMenuItem; mnuItemAbout: TMenuItem; @@ -304,6 +309,8 @@ type procedure actNewGroupExecute(Sender: TObject); procedure actProjAddToGroupExecute(Sender: TObject); procedure actProjDscanExecute(Sender: TObject); + procedure actProjGitBranchesUpdExecute(Sender: TObject); + procedure actProjGitPullExecute(Sender: TObject); procedure actProjGroupCompileCustomSyncExecute(Sender: TObject); procedure actProjGroupCompileExecute(Sender: TObject); procedure actProjGroupCompileSyncExecute(Sender: TObject); @@ -377,6 +384,7 @@ type private + fGitIconIndex: integer; fImages: TImageList; fOptionCategories: TCEEditableOptionsSubject; fRunnablesOptions: TCEEditableRunnableOptions; @@ -527,6 +535,9 @@ type procedure layoutSaveToFile(const fname: string); procedure layoutUpdateMenu; + // git + procedure gitBranchMenuItemClick(sender: TObject); + public constructor create(aOwner: TComponent); override; destructor destroy; override; @@ -1517,6 +1528,14 @@ begin i := loadIcon('CROSS'); actProjStopComp.ImageIndex:=i; + + i := loadIcon('GIT'); + fGitIconIndex := i; + mnuGitBranch.ImageIndex:=i; + actProjGitPull.ImageIndex:=i; + + i := loadIcon('AROOW_UPDATE'); + actProjGitBranchesUpd.ImageIndex:=i; end; procedure TCEMainForm.InitWidgets; @@ -2427,6 +2446,9 @@ begin else if project = fFreeProj then fFreeProj := nil; + if assigned(fProject) then + actProjGitBranchesUpdExecute(nil); + showProjTitle; end; @@ -3993,6 +4015,139 @@ begin end; end; +procedure TCEMainForm.actProjGitPullExecute(Sender: TObject); +var + p: TProcess; + r: TStringList; + i: integer; + b: string; +begin + p := TProcess.Create(nil); + r := TStringList.Create; + try + p.Executable := exeFullName('git' + exeExt); + if p.Executable.fileExists then + begin + p.Options := [poUsePipes, poNoConsole]; + p.ShowWindow:= swoHIDE; + p.Parameters.Add('pull'); + //p.Parameters.Add('&&'); + //p.Parameters.Add('git'); + //p.Parameters.Add('submodule'); + //p.Parameters.Add('--update'); + //p.Parameters.Add('--init'); + //p.Parameters.Add('--recursive'); + p.CurrentDirectory:= fProject.basePath; + p.Execute; + processOutputToStrings(p,r); + for i := 0 to r.Count-1 do + fMsgs.message(r[i], fProject, amcProj, amkInf); + r.Clear; + r.LoadFromStream(p.Stderr); + for i := 0 to r.Count-1 do + fMsgs.message(r[i], fProject, amcProj, amkErr); + end; + finally; + actProjGitBranchesUpd.Execute; + p.Free; + r.Free; + end; +end; + + +procedure TCEMainForm.gitBranchMenuItemClick(sender: TObject); +var + p: TProcess; + r: TStringList; + i: integer; + b: string; +begin + p := TProcess.Create(nil); + r := TStringList.Create; + b := TMenuItem(sender).Caption; + try + p.Executable := exeFullName('git' + exeExt); + if p.Executable.fileExists then + begin + p.Options := [poUsePipes, poNoConsole]; + p.ShowWindow:= swoHIDE; + p.Parameters.Add('checkout'); + p.Parameters.Add(b); + p.CurrentDirectory:= fProject.basePath; + p.Execute; + processOutputToStrings(p,r); + r.Clear; + r.LoadFromStream(p.Stderr); + // git bug ? even on success they write the switch in stderr + if r.Count > 1 then + begin + for i := 0 to r.Count-1 do + fMsgs.message(r[i], fProject, amcProj, amkErr); + end + else + begin + fMsgs.message('now on branch `' + b + '`', fProject, amcProj, amkInf); + end; + end; + finally; + actProjGitBranchesUpd.Execute; + p.Free; + r.Free; + end; +end; + +procedure TCEMainForm.actProjGitBranchesUpdExecute(Sender: TObject); +var + p: TProcess; + r: TStringList; + i: integer; + m: TMenuItem; +begin + mnuGitBranch.Clear; + p := TProcess.Create(nil); + r := TStringList.Create; + try + p.Executable := exeFullName('git' + exeExt); + if p.Executable.fileExists then + begin + p.Options := [poUsePipes, poNoConsole]; + p.ShowWindow:= swoHIDE; + p.Parameters.Add('branch'); + p.Parameters.Add('--list'); + p.CurrentDirectory:= fProject.basePath; + p.Execute; + processOutputToStrings(p,r); + m := TMenuItem.Create(mnuGitBranch); + m.action := actProjGitBranchesUpd; + mnuGitBranch.Add(m); + mnuGitBranch.AddSeparator; + for i:= 0 to r.Count-1 do + begin + m := TMenuItem.Create(mnuGitBranch); + m.GroupIndex := 45; + m.RadioItem:= true; + m.ImageIndex:=fGitIconIndex; + m.OnClick:= @gitBranchMenuItemClick; + if r[i][1] = '*' then + begin + m.Caption:= Trim(r[i][2..r[i].length]); + m.Checked:= true; + end + else m.Caption:= Trim(r[i][1..r[i].length]); + mnuGitBranch.Add(m); + end; + r.Clear; + r.LoadFromStream(p.Stderr); + if r.Count <> 0 then + for i := 0 to r.Count-1 do + fMsgs.message(r[i], fProject, amcProj, amkErr); + end; + finally + p.Free; + r.Free; + end; +end; + procedure TCEMainForm.actProjOpenGroupExecute(Sender: TObject); begin if fProjectGroup.groupModified then