-
Notifications
You must be signed in to change notification settings - Fork 3
/
SongDetails.pas
308 lines (279 loc) · 8.59 KB
/
SongDetails.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
unit SongDetails;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, SBZipUtils, ShellAPI;
type
TFSongDetails = class(TForm)
P4: TPanel;
LKey: TLabel;
LCapo: TLabel;
LTempo: TLabel;
LC1: TLabel;
LC2: TLabel;
Label1: TLabel;
LAuto: TLabel;
Label3: TLabel;
Label4: TLabel;
CKey: TComboBox;
CMM: TComboBox;
CCapo: TComboBox;
CTempo: TComboBox;
ECop1: TEdit;
ECop2: TEdit;
ENotes: TEdit;
CBC1: TCheckBox;
CBC2: TCheckBox;
LBLinks: TListBox;
BAddLink: TButton;
BShowLink: TButton;
BExtract: TButton;
BRenLink: TButton;
BDelLink: TButton;
P2: TPanel;
LMus: TLabel;
LTune: TLabel;
Larr1: TLabel;
Larr2: TLabel;
LPub: TLabel;
LIsbn: TLabel;
CPhoto: TCheckBox;
EMus: TEdit;
EISBN: TEdit;
ETune: TEdit;
EArr: TEdit;
SaveDialog1: TSaveDialog;
procedure EMusKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure EMusExit(Sender: TObject);
procedure LBLinksClick(Sender: TObject);
procedure BAddLinkClick(Sender: TObject);
procedure BDelLinkClick(Sender: TObject);
procedure BRenLinkClick(Sender: TObject);
procedure BShowLinkClick(Sender: TObject);
procedure BExtractClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure EMusChange(Sender: TObject);
private
{ Private declarations }
// Used to keep this window off the projection screen
procedure WMWindowPosChanging(var hMsg: TWMWindowPosChanging); message WM_WINDOWPOSCHANGING;
public
{ Public declarations }
PosX,PosY : integer;
end;
var
FSongDetails: TFSongDetails;
implementation
uses SBMain, LinkForm, LinkDesc, EditProj;
{$R *.dfm}
procedure TFSongDetails.EMusKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
var S,I,T : string;
R : integer;
begin
if (Key>64) and (Key<91) and (lengtH(FSongbase.ECopyRight.Text)>0) then begin
T:=copy(EMus.Text,1,EMus.SelStart);
FSongbase.LookupPhotoHistory(T,S,I,PhotoFile);
R:=EMus.SelStart;
if S<>'' then begin
EMus.Text:=S;
EMus.SelStart:=R;
EMus.Sellength:=length(S);
end;
end;
end;
procedure TFSongDetails.EMusExit(Sender: TObject);
var T,S,I : string;
begin
T:=EMus.Text;
FSongbase.LookupPhotoHistory(T,S,I,PhotoFile);
if (I<>'') and (EISBN.TexT='') then EISBN.Text:=I;
end;
procedure TFSongDetails.LBLinksClick(Sender: TObject);
begin
BShowLink.Enabled:=(LBLinks.ItemIndex>=0);
BDelLink.Enabled:=BShowLink.Enabled;
BExtract.Enabled:=BDelLink.Enabled;
end;
procedure TFSongDetails.BAddLinkClick(Sender: TObject);
var StoreFile : string;
extend : string;
SrcFile : string;
begin
FLinkForm.Mode:=1; // Add Link Flag
FLinkForm.showModal;
if (FLinkForm.Description<>'') and (FLinkForm.Location<>'') then begin
StoreFile:=FLinkForm.Location;
extend:='';
while (pos('.',StoreFile)>0) do begin
extend:=Storefile[length(Storefile)]+extend;
Storefile:=copy(Storefile,1,length(Storefile)-1);
end;
str(LinkNextID,StoreFile);
StoreFile:=FSongBase.EID.Text+'-'+StoreFile+'L'+extend;
SrcFile:=FLinkForm.Location;
CopyFile(PChar(SrcFile),PChar(StoreFile),FALSE);
AddFileToZip(StoreFile,OHPFile,false);
DeleteFile(StoreFile);
inc(LinkNextID);
LinkDescriptions:=LinkDescriptions+FLinkForm.Description+chr129;
LinkFiles:=LinkFiles+StoreFile+chr129;
LBLinks.Items.Add(FLinkForm.Description);
FSongBase.SaveRec;
end;
end;
procedure TFSongDetails.BRenLinkClick(Sender: TObject);
var i : integer;
s,d1 : string;
begin
FLinkDesc.Description:=LBLinks.Items.Strings[LBLinks.ItemIndex];
FLinkDesc.showmodal;
LBLinks.Items.Strings[LBLinks.ItemIndex]:=FLinkDesc.Description;
i:=0;
s:='';
D1:=LinkDescriptions;
while (i<LBLinks.Itemindex) do begin
s:=s+copy(d1,1,pos(chr129,d1));
d1:=copy(d1,pos(chr129,d1)+1,length(d1));
end;
d1:=copy(d1,pos(chr129,d1)+1,length(d1));
s:=s+FLinkDesc.Description+chr129+d1;
LinkDescriptions:=s;
end;
procedure TFSongDetails.BDelLinkClick(Sender: TObject);
var found : boolean;
NewDescs : String;
NewFiles : String;
D1,F1 : string;
begin
if (messagedlg(FSongbase.SCheckDelete,mtWarning,[mbOK,mbCancel],0)=mrOK) then begin
Found:=false;
if pos(chr129,LinkDescriptions)=0 then LinkDescriptions:=LinkDescriptions+chr129;
if pos(chr129,LinkFiles)=0 then LinkFiles:=LinkFiles+chr129;
while (not Found) do begin
D1:=copy(LinkDescriptions,1,pos(chr129,LinkDescriptions)-1);
F1:=copy(LinkFiles,1,pos(chr129,LinkFiles)-1);
LinkDescriptions:=copy(LinkDescriptions,pos(chr129,LinkDescriptions)+1,length(LinkDescriptions));
LinkFiles:=copy(LinkFiles,pos(chr129,LinkFiles)+1,length(LinkFiles));
if (D1=LBLinks.Items.Strings[LbLinks.ItemIndex]) then begin
found:=true;
NewDescs:=NewDescs+LinkDescriptions;
NewFiles:=NewFiles+LinkFiles;
LBLinks.Items.Delete(LBLinks.ItemIndex);
DeleteFileFromZip(OHPFile,F1);
FSongBase.SaveRec;
end else begin
NewDescs:=NewDescs+D1;
NewFiles:=NewFiles+F1;
end;
end;
LinkDescriptions:=NewDescs;
LinkFiles:=NewFiles;
LbLinks.ItemIndex:=-1;
BDelLink.Enabled:=false;
BShowLink.Enabled:=false;
BExtract.Enabled:=false;
end;
end;
procedure TFSongDetails.BExtractClick(Sender: TObject);
var i : integer;
s : string;
ext,F1,D1 : string;
begin
i:=0;
s:='';
F1:=LinkFiles;
d1:=LinkDescriptions;
while (i<LBLinks.Itemindex) do begin
f1:=copy(f1,pos(chr129,f1)+1,length(f1));
d1:=copy(d1,pos(chr129,d1)+1,length(d1));
inc(i);
end;
f1:=copy(f1,1,pos(chr129,f1)-1);
d1:=copy(d1,1,pos(chr129,d1)-1);
i:=length(f1);
ext:='';
while (f1[i]<>'.') do begin
ext:=f1[i]+ext;
dec(i);
end;
d1:=d1+'.'+ext;
SaveDialog1.FileName:=d1;
SaveDialog1.Title:='Extract '+d1;
SaveDialog1.Options:=[ofOverWritePrompt];
if savedialog1.execute then begin
ExtractFileFromZip(OHPFile,f1,TempDir);
d1:=savedialog1.filename;
renamefile(TempDir+f1,d1);
end;
end;
procedure TFSongDetails.BShowLinkClick(Sender: TObject);
var i : integer;
s,F1 : string;
begin
i:=0;
s:='';
F1:=LinkFiles;
while (i<LBLinks.Itemindex) do begin
f1:=copy(f1,pos(chr129,f1)+1,length(f1));
inc(i);
end;
f1:=copy(f1,1,pos(chr129,f1)-1);
ExtractFileFromZip(OHPFile,f1,TempDir);
shellexecute(Application.handle,nil,pchar(TempDir+f1),nil,nil,SW_SHOW);
end;
procedure TFSongDetails.FormShow(Sender: TObject);
begin
top:=PosY;
left:=PosX;
end;
procedure TFSongDetails.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
PosY := top;
PosX := left;
end;
procedure TFSongDetails.WMWindowPosChanging(var hMsg: TWMWindowPosChanging);
var rBadRect, rCurRect : TRect;
var ptBadCentre : TPoint;
begin
// Only restrict access once projection form is visible
if FSongbase.BProjectReady and FProjWin.Visible then begin
// Get the desktop rectangle that we don't want to let this screen have
// any intersections with.
rBadRect := Rect( FSongBase.ptDisplayOrigin.X,
FSongBase.ptDisplayOrigin.Y,
FSongBase.ptDisplayOrigin.X + FSongBase.szDisplaySize.cx,
FSongBase.ptDisplayOrigin.Y + FSongBase.szDisplaySize.cy );
rCurRect := Rect( hMsg.WindowPos.x, hMsg.WindowPos.y,
hMsg.WindowPos.x + Width, hMsg.WindowPos.y + Height );
// Work out centre of 'illegal' area so we can work out which side to push off
ptBadCentre.X := FSongBase.ptDisplayOrigin.X + (FSongBase.szDisplaySize.cx div 2);
ptBadCentre.Y := FSongBase.ptDisplayOrigin.Y + (FSongBase.szDisplaySize.cy div 2);
// And do the logic to prevent overlap in X
if (rCurRect.Right < ptBadCentre.X) and (rCurRect.Right > rBadRect.Left) then begin
rCurRect.Left := rBadRect.Left - (rCurRect.Right - rCurRect.Left);
rCurRect.Right := rBadRect.Left;
end;
if (rCurRect.Left > ptBadCentre.X) and (rCurRect.Left < rBadRect.Right) then begin
rCurRect.Right := rBadRect.Right + (rCurRect.Right - rCurRect.Left);
rCurRect.Left := rBadRect.Right;
end;
hMsg.WindowPos.x := rCurRect.Left;
hMsg.WindowPos.y := rCurRect.Top;
end;
inherited;
end;
procedure TFSongDetails.EMusChange(Sender: TObject);
begin
if not FSongbase.bDisableEvents then begin
FSongbase.CurrentSongIsReadable( true );
Unsaved := true;
FSongbase.LUnsaved.visible:=true;
FSongbase.SaveChanges1.Enabled:=true;
FSongbase.BEditSong.Enabled := true;
end;
end;
end.