📄 jvqid3v2editorform.pas
字号:
for I := Items.Count - 1 downto 0 do
if Selected[I] then
TJvID3Frame(Items.Objects[I]).Free;
finally
FFSDesigner.EndDesign;
Designer.Modified;
end;
finally
UpdateDisplay;
end;
if Focused <> -1 then
begin
Focused := Min(Focused, FrameListBox.Items.Count - 1);
FrameListBox.ItemIndex := Focused;
FrameListBox.Selected[Focused] := True;
UpdateSelection;
end;
FrameListBox.SetFocus;
end;
procedure TJvID3FramesEditor.RestoreSelection(var Selection: TStringList;
ItemIndex, TopIndex: Integer; RestoreUpdate: Boolean);
var
I: Integer;
begin
try
with FrameListBox do
for I := 0 to Items.Count - 1 do
Selected[I] := Selection.IndexOf(TComponent(Items.Objects[I]).Name) <> -1;
if TopIndex <> -1 then
FrameListBox.TopIndex := TopIndex;
if ItemIndex <> -1 then
FrameListBox.ItemIndex := ItemIndex;
finally
if RestoreUpdate then
FrameListBox.Items.EndUpdate;
FrameListBox.Invalidate;
Selection.Free;
Selection := nil;
UpdateSelection;
end;
end;
procedure TJvID3FramesEditor.SaveSelection(var Selection: TStringList;
var ItemIndex, TopIndex: Integer; NoUpdate: Boolean);
var
I: Integer;
begin
{ Name of a frame is unique, thus fill Selection with these names
of frames that are selected }
Selection := TStringList.Create;
try
ItemIndex := FrameListBox.ItemIndex;
TopIndex := FrameListBox.TopIndex;
with FrameListBox do
for I := 0 to Items.Count - 1 do
if Selected[I] then
Selection.Add(TComponent(Items.Objects[I]).Name);
if NoUpdate then
FrameListBox.Items.BeginUpdate;
except
Selection.Free;
Selection := nil;
end;
end;
procedure TJvID3FramesEditor.SelectAll;
var
I: Integer;
begin
with FrameListBox do
for I := 0 to Items.Count - 1 do
Selected[I] := True;
end;
procedure TJvID3FramesEditor.SelectionChanged(const ADesigner: IDesigner;
const ASelection: IDesignerSelections);
var
I: Integer;
S: Boolean;
function InSelection(Component: TComponent): Boolean;
var
I: Integer;
begin
Result := True;
if ASelection <> nil then
with ASelection do
for I := 0 to Count - 1 do
if Component = Items[I] then
Exit;
Result := False;
end;
begin
with FrameListBox do
for I := 0 to Items.Count - 1 do
begin
S := InSelection(TComponent(Items.Objects[I]));
if Selected[I] <> S then
Selected[I] := S;
end;
end;
procedure TJvID3FramesEditor.SetController(Value: TJvID3Controller);
begin
if FController <> Value then
begin
if FController <> nil then
FreeAndNil(FFSDesigner);
FController := Value;
if FController <> nil then
begin
FFSDesigner := TFSDesigner.Create(Value);
FFSDesigner.FFramesEditor := Self;
UpdateDisplay;
end
else
begin
if not (csDestroying in ComponentState) then
Release;
end;
end;
end;
function TJvID3FramesEditor.UniqueName(Component: TComponent): string;
var
FrameName: string;
begin
if Component is TJvID3Frame then
FrameName := TJvID3Frame(Component).FrameName
else
FrameName := '';
Result := CreateUniqueName(Controller, FrameName,
TJvID3FrameClass(Component.ClassType), Component)
end;
procedure TJvID3FramesEditor.UpdateCaption;
const
cFrameEditor = '%s%s%s';
var
NewCaption: string;
begin
if (Controller <> nil) and (Controller.Owner <> nil) then
NewCaption := Format(cFrameEditor,
[Controller.Owner.Name, '.', Controller.Name]);
if Caption <> NewCaption then
Caption := NewCaption;
end;
procedure TJvID3FramesEditor.UpdateDisplay;
begin
UpdateFrameList;
UpdateCaption;
UpdateSelection;
end;
procedure TJvID3FramesEditor.UpdateFrameList;
var
ItemIndex, TopIndex: Integer;
Selection: TStringList;
EnableList: Boolean;
I: Integer;
Frame: TJvID3Frame;
FrameName: string;
begin
SaveSelection(Selection, ItemIndex, TopIndex, True);
try
FrameListBox.Clear;
EnableList := False;
try
if Controller = nil then
Exit;
for I := 0 to Controller.Frames.Count - 1 do
begin
Frame := Controller.Frames[I];
if not (csDestroying in Frame.ComponentState) then
begin
FrameName := Frame.FrameName;
if FrameName = '' then
FrameName := Format('<%s>', [Controller.Frames[I].Name]);
FrameName := FrameName + ' - ' + cFrameDescriptions[Frame.FrameID];
FrameListBox.Items.AddObject(FrameName, Frame);
end;
end;
EnableList := True;
finally
FrameListBox.Enabled := EnableList;
end;
finally
RestoreSelection(Selection, ItemIndex, TopIndex, True)
end;
end;
procedure TJvID3FramesEditor.UpdateSelection;
var
I: Integer;
Frame: TJvID3Frame;
ComponentList: IDesignerSelections;
begin
if Active then
begin
ComponentList := TDesignerSelections.Create;
try
with FrameListBox do
for I := 0 to Items.Count - 1 do
if Selected[I] then
begin
Frame := TJvID3Frame(Items.Objects[I]);
if Frame <> nil then
ComponentList.Add(Frame);
end;
if ComponentList.Count = 0 then
ComponentList.Add(Controller);
except
raise;
end;
Designer.SetSelections(ComponentList);
end;
end;
(*
procedure TJvID3FramesEditor.WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo);
begin
inherited;
with Msg.MinMaxInfo^.ptMinTrackSize do
begin
X := FMinWidth;
Y := FMinHeight;
end;
end;
*)
//=== { TJvID3ControllerEditor } =============================================
procedure TJvID3ControllerEditor.Commit;
begin
if MessageDlg(RsCommit, mtConfirmation, mbOKCancel, 0) = mrOk then
TJvID3Controller(Component).Commit;
end;
procedure TJvID3ControllerEditor.ExecuteVerb(Index: Integer);
begin
case Index of
0:
ShowFramesEditor(Designer, TJvID3Controller(Component));
1:
RemoveTag;
2:
ShowFileInfo(TJvID3Controller(Component));
3:
Commit;
end;
end;
function TJvID3ControllerEditor.GetVerb(Index: Integer): string;
begin
case Index of
0:
Result := RSID3FrameEditorTag;
1:
Result := RSID3RemoveTag;
2:
Result := RSID3FileInfoTag;
3:
Result := RSID3CommitTag;
end;
end;
function TJvID3ControllerEditor.GetVerbCount: Integer;
begin
Result := 3;
with TJvID3Controller(Component) do
if Active and Modified then
Inc(Result);
end;
procedure TJvID3FramesEditor.FormCreate(Sender: TObject);
begin
FMinWidth := Width;
FMinHeight := Height;
end;
procedure TJvID3ControllerEditor.RemoveTag;
begin
with TJvID3Controller(Component) do
begin
if FileName = '' then
begin
MessageDlg(RsID3Err_NoFileSpecified, mtError, [mbOK], 0);
Exit;
end;
if not FileExists(FileName) then
begin
MessageDlg(Format(RSID3Err_FileDoesNotExists, [FileName]), mtError, [mbOK], 0);
Exit;
end;
if MessageDlg(RSID3RemoveTagConfirmation, mtConfirmation, mbOKCancel, 0) = mrOk then
Erase;
end;
end;
//=== { TFSDesigner } ========================================================
destructor TFSDesigner.Destroy;
var
F: TJvID3FramesEditor;
begin
if FFramesEditor <> nil then
begin
F := FFramesEditor;
FFramesEditor := nil;
F.FFSDesigner := nil;
{ (rb) DSDesign.pas uses Release, but that gave problems, with recompiling }
F.Free;
end;
inherited Destroy;
end;
procedure TJvID3FramesEditor.ListBoxClick(Sender: TObject);
begin
UpdateSelection;
end;
function TFSDesigner.GetFrameDescription(const FrameID: TJvID3FrameID): string;
begin
Result := cFrameDescriptions[FrameID];
end;
procedure TFSDesigner.ID3Event(Event: TJvID3Event; Info: Longint);
begin
if Event in [ideFrameListChange, ideID3Change] then
FFramesEditor.UpdateFrameList;
end;
procedure TJvID3FramesEditor.ListBoxKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
VK_INSERT:
NewFrameClick(Self);
VK_DELETE:
RemoveFrames;
VK_UP:
if (ssCtrl in Shift) and (Sender = FrameListBox) then
MoveFrames(-1)
else
Exit;
VK_DOWN:
if (ssCtrl in Shift) and (Sender = FrameListBox) then
MoveFrames(1)
else
Exit;
else
Exit;
end;
Key := 0;
end;
procedure TJvID3FramesEditor.ListBoxDragDrop(Sender, Source: TObject;
X, Y: Integer);
var
F: TJvID3Frame;
I: Integer;
begin
try
FFSDesigner.BeginDesign;
try
with FrameListBox do
begin
F := TJvID3Frame(Items.Objects[ItemAtPos(Point(X, Y), True)]);
for I := 0 to Items.Count - 1 do
if Selected[I] then
TJvID3Frame(Items.Objects[I]).Index := F.Index;
end;
finally
FFSDesigner.EndDesign;
end;
finally
UpdateDisplay;
Designer.Modified;
end;
end;
procedure TJvID3FramesEditor.ListBoxDragOver(Sender, Source: TObject;
X, Y: Integer; State: TDragState; var Accept: Boolean);
var
Item: Integer;
procedure DrawRect(Item: Integer);
begin
if Item <> -1 then
with FrameListBox do
Canvas.DrawFocusRect(ItemRect(Item));
FFocusRectItem := Item;
end;
begin
Item := FrameListBox.ItemAtPos(Point(X, Y), False);
Accept := (Source = FrameListBox) and
(Item >= 0) and (Item < FrameListBox.Items.Count) and
not FrameListBox.Selected[Item];
if State = dsDragEnter then
FFocusRectItem := -1;
if (State = dsDragLeave) or not Accept then
Item := -1;
DrawRect(FFocusRectItem);
DrawRect(Item);
end;
procedure TJvID3FramesEditor.FormDestroy(Sender: TObject);
begin
if FFSDesigner <> nil then
begin
{ Destroy the designer if the editor is destroyed }
FFSDesigner.FFramesEditor := nil;
FFSDesigner.Free;
FFSDesigner := nil;
end;
end;
procedure TJvID3FramesEditor.NewFrameClick(Sender: TObject);
var
Selection: TStringList;
Frame: TJvID3Frame;
begin
Frame := DoNewFrame;
if Frame <> nil then
begin
Selection := TStringList.Create;
try
Selection.Add(Frame.Name);
finally
RestoreSelection(Selection, -1, -1, False);
end;
end;
FrameListBox.SetFocus;
end;
procedure TJvID3FramesEditor.DeleteClick(Sender: TObject);
begin
RemoveFrames;
end;
procedure TJvID3FramesEditor.SelectAllClick(Sender: TObject);
begin
SelectAll;
UpdateSelection;
end;
//=== { TJvID3FileInfoEditor } ===============================================
procedure TJvID3FileInfoEditor.Edit;
var
P: TPersistent;
begin
P := TPersistent(GetComponent(0));
if P is TJvID3Controller then
ShowFileInfo(TJvID3Controller(P));
end;
function TJvID3FileInfoEditor.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog];
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -