1 { Copyright (C) 2008 Darius Blaszijk
2 
3   This source is free software; you can redistribute it and/or modify it under
4   the terms of the GNU General Public License as published by the Free
5   Software Foundation; either version 2 of the License, or (at your option)
6   any later version.
7 
8   This code is distributed in the hope that it will be useful, but WITHOUT ANY
9   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
11   details.
12 
13   A copy of the GNU General Public License is available on the World Wide Web
14   at <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing
15   to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
16   Boston, MA 02110-1335, USA.
17 }
18 
19 unit LazSVNIntf;
20 
21 {$mode objfpc}{$H+}
22 
23 interface
24 
25 uses
26   SysUtils, LCLtype, LResources, LCLProc;
27 
28 procedure ProcSVNLog(Sender: TObject);
29 procedure ProcSVNCommit(Sender: TObject);
30 procedure ProcSVNUpdate(Sender: TObject);
31 procedure ProcSVNDiff(Sender: TObject);
32 procedure ProcSVNDiffPrev(Sender: TObject);
33 procedure ProcSVNDiffHead(Sender: TObject);
34 procedure ProcSVNSettings(Sender: TObject);
35 procedure Register;
36 
37 implementation
38 
39 {$R lazsvnpkg_images.res}
40 
41 uses
42   MenuIntf, IDECommands, Controls, Forms, Dialogs,
43   SVNLogForm, SVNUpdateForm, SVNDiffForm, SVNStatusForm, LazIDEIntf, SVNClasses,
44   SVNAddProjectForm, SrcEditorIntf;
45 
46 var
47   CmdSVNLog : TIDECommand;
48   CmdSVNCommit : TIDECommand;
49   CmdSVNUpdate : TIDECommand;
50   CmdSVNDiff : TIDECommand;
51   CmdSVNDiffPrev : TIDECommand;
52   CmdSVNDiffHead : TIDECommand;
53   CmdSVNSettings : TIDECommand;
54 
55 procedure Register;
56 var
57   Key: TIDEShortCut;
58   Cat: TIDECommandCategory;
59   mnuSVNSection : TIDEMenuSection;
60 begin
61   Key:=IDEShortCut(VK_UNKNOWN,[],VK_UNKNOWN,[]);
62 
63   {$ifndef USECustomCategory}
64     Cat:=IDECommandList.CreateCategory(nil, 'SVN', rsSVNTools, IDECmdScopeSrcEditOnly);
65   {$else}
66     Cat:=nil;
67   {$endif}
68 
69   CmdSVNLog:=RegisterIDECommand(Cat, 'SVNLog', rsShowLog, Key, nil, @ProcSVNLog);
70   CmdSVNCommit:=RegisterIDECommand(Cat, 'SVNCommit', rsCommit, Key, nil, @ProcSVNCommit);
71   CmdSVNUpdate:=RegisterIDECommand(Cat, 'SVNUpdate', rsUpdate, Key, nil, @ProcSVNUpdate);
72   CmdSVNDiff:=RegisterIDECommand(Cat, 'SVNDiff', rsShowDiffBase, Key, nil, @ProcSVNDiff);
73   CmdSVNDiffPrev:=RegisterIDECommand(Cat, 'SVNDiffPrev', rsShowDiffPrev, Key, nil, @ProcSVNDiffPrev);
74   CmdSVNDiffHead:=RegisterIDECommand(Cat, 'SVNDiffHead', rsShowDiffHead, Key, nil, @ProcSVNDiffHead);
75   CmdSVNSettings:=RegisterIDECommand(Cat, 'SVNSettings', rsSVNSettings, Key, nil, @ProcSVNSettings);
76 
77   mnuSVNSection:=RegisterIDESubMenu(itmSecondaryTools, 'SVN', 'SVN', nil, nil, 'menu_svn');
78   RegisterIDEMenuCommand(mnuSVNSection, 'SVNLog', rsShowLog, nil, nil,
79     CmdSVNLog, 'menu_svn_log');
80   RegisterIDEMenuCommand(mnuSVNSection, 'SVNCommit', rsCommit, nil, nil,
81     CmdSVNCommit, 'menu_svn_commit');
82   RegisterIDEMenuCommand(mnuSVNSection, 'SVNUpdate', rsUpdate, nil, nil,
83     CmdSVNUpdate, 'menu_svn_update');
84   RegisterIDEMenuCommand(mnuSVNSection, 'SVNDiff', rsShowDiffBase, nil, nil,
85     CmdSVNDiff, 'menu_svn_diff');
86   RegisterIDEMenuCommand(mnuSVNSection, 'SVNDiffPrev', rsShowDiffPrev, nil, nil,
87     CmdSVNDiffPrev, 'menu_svn_diff');
88   RegisterIDEMenuCommand(mnuSVNSection, 'SVNDiffHead', rsShowDiffHead, nil, nil,
89     CmdSVNDiffHead, 'menu_svn_diff');
90   RegisterIDEMenuCommand(mnuSVNSection, 'SVNSettings', rsSettings, nil, nil,
91     CmdSVNSettings, 'menu_environment_options');
92 end;
93 
94 procedure ProcSVNLog(Sender: TObject);
95 var
96   Repo: string;
97   IsActive: boolean;
98   sBool: string;
99 begin
100   If Assigned(LazarusIDE) and Assigned(LazarusIDE.ActiveProject) then
101   begin
102     Repo := LazarusIDE.ActiveProject.CustomSessionData.Values[SVN_REPOSITORY];
103     sBool := LazarusIDE.ActiveProject.CustomSessionData.Values[SVN_ACTIVE];
104     if sBool <> '' then
105       IsActive := StrToBool(sBool)
106     else
107       IsActive := False;
108 
109     if IsActive and (Repo <> '') then
110       ShowSVNLogFrm(Repo)
111     else
112       ShowMessage(rsProjectIsNotActiveInSVNSettingsPleaseActivateFirst);
113   end;
114 end;
115 
116 procedure ProcSVNCommit(Sender: TObject);
117 var
118   Repo: string;
119   IsActive: boolean;
120   sBool: string;
121 begin
122   If Assigned(LazarusIDE) and Assigned(LazarusIDE.ActiveProject) then
123   begin
124     Repo := LazarusIDE.ActiveProject.CustomSessionData.Values[SVN_REPOSITORY];
125     sBool := LazarusIDE.ActiveProject.CustomSessionData.Values[SVN_ACTIVE];
126     if sBool <> '' then
127       IsActive := StrToBool(sBool)
128     else
129       IsActive := False;
130 
131     if IsActive and (Repo <> '') then
132       ShowSVNStatusFrm(Repo)
133     else
134       ShowMessage(rsProjectIsNotActiveInSVNSettingsPleaseActivateFirst);
135   end;
136 end;
137 
138 procedure ProcSVNUpdate(Sender: TObject);
139 var
140   Repo: string;
141   IsActive: boolean;
142   sBool: string;
143 begin
144   If Assigned(LazarusIDE) and Assigned(LazarusIDE.ActiveProject) then
145   begin
146     Repo := LazarusIDE.ActiveProject.CustomSessionData.Values[SVN_REPOSITORY];
147     sBool := LazarusIDE.ActiveProject.CustomSessionData.Values[SVN_ACTIVE];
148     if sBool <> '' then
149       IsActive := StrToBool(sBool)
150     else
151       IsActive := False;
152 
153     debugln('ProcSVNUpdate repo='+Repo+' isactive='+sBool);
154 
155     if IsActive and (Repo <> '') then
156       ShowSVNUpdateFrm(Repo)
157     else
158       ShowMessage(rsProjectIsNotActiveInSVNSettingsPleaseActivateFirst);
159   end;
160 end;
161 
162 procedure DoSVNDiff(ASwitches: String);
163 var
164   Repo: string;
165   IsActive: boolean;
166   SrcFile: string;
167   sBool: string;
168 begin
169   If Assigned(LazarusIDE) and Assigned(LazarusIDE.ActiveProject) then
170   begin
171     Repo := LazarusIDE.ActiveProject.CustomSessionData.Values[SVN_REPOSITORY];
172     sBool := LazarusIDE.ActiveProject.CustomSessionData.Values[SVN_ACTIVE];
173     if sBool <> '' then
174       IsActive := StrToBool(sBool)
175     else
176       IsActive := False;
177 
178     if IsActive and (Repo <> '') then
179     begin
180       SrcFile := SourceEditorManagerIntf.ActiveEditor.FileName;
181       ShowSVNDiffFrm(ASwitches, SrcFile);
182     end
183     else
184       ShowMessage(rsProjectIsNotActiveInSVNSettingsPleaseActivateFirst);
185   end;
186 end;
187 
188 procedure ProcSvnDiff(Sender: TObject);
189 begin
190   DoSvnDiff('-r BASE');
191 end;
192 
193 procedure ProcSvnDiffHead(Sender: TObject);
194 begin
195   DoSvnDiff('-r HEAD');
196 end;
197 
198 procedure ProcSvnDiffPrev(Sender: TObject);
199 begin
200   DoSvnDiff('-r PREV');
201 end;
202 
203 procedure ProcSVNSettings(Sender: TObject);
204 begin
205   ShowSVNAddProjectFrm;
206 end;
207 
208 end.
209