📄 fsnippets.pas
字号:
unit fSnippets;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, DockPanel, ImgList, ElXPThemedControl, ElTree, StrUtils,
Menus;
type
pData = ^data;
data = record
filename: string;
end;
TfrmSnippets = class(TDockableForm)
img: TImageList;
tvSnippets: TElTree;
popSnippets: TPopupMenu;
Delete1: TMenuItem;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure tvSnippetsItemExpanding(Sender: TObject; Item: TElTreeItem;
var CanProcess: Boolean);
procedure tvSnippetsDblClick(Sender: TObject);
procedure Delete1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure ListSnippets;
procedure ListSnippetsParentNode(Item: TElTreeItem);
end;
var
frmSnippets: TfrmSnippets;
implementation
uses fMain, dMain;
{$R *.dfm}
procedure TfrmSnippets.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
frmMain.SnippetsView1.Checked := false;
end;
procedure TfrmSnippets.FormCreate(Sender: TObject);
begin
ListSnippets;
end;
procedure TfrmSNippets.ListSnippets;
var
rec: TSearchRec;
tItem: TElTreeItem;
begin
tvSnippets.Items.Clear;
if findFirst(ExtractFilePath(Application.ExeName) + 'snippets\*.*', faDirectory, Rec) = 0 then begin
if LeftStr(rec.Name, 1) <> '.' then begin
tItem := tvSnippets.Items.Add(nil, PChar(Rec.Name));
tITem.ImageIndex :=2;
tItem.Data := Pointer(1);
tItem.ForceButtons := true;
end;
end;
While FindNext(rec) = 0 do
begin
if LeftStr(rec.Name, 1) <> '.' then begin
tItem := tvSnippets.Items.Add(nil, PChar(Rec.Name));
tITem.ImageIndex :=2;
tItem.ForceButtons := true;
tItem.Data := Pointer(1);
end;
end;
end;
procedure TfrmSnippets.ListSnippetsParentNode(Item: TElTreeItem);
var
rec: TSearchRec;
tItem: TElTreeItem;
s: String;
i: integer;
P: pdata;
begin
s := Item.Text;
s := ExtractFilePath(Application.ExeName) + 'snippets\' + s + '\';
for i := item.ChildrenCount - 1 downto 0 do begin
item.Children[i].Delete;
end;
if findFirst(s + '*.snp', faAnyFile, Rec) = 0 then begin
if LeftStr(rec.Name, 1) <> '.' then begin
tItem := tvSnippets.Items.AddChild(Item, PChar(Rec.Name));
tITem.ImageIndex :=3;
p := new(pData);
p.Filename := s + Rec.Name;
tItem.Data := Pointer(p);
end;
end;
While FindNext(rec) = 0 do
begin
if LeftStr(rec.Name, 1) <> '.' then begin
tItem := tvSnippets.Items.AddChild(Item, PChar(Rec.Name));
tITem.ImageIndex :=3;
p := new(pData);
p.Filename := s + Rec.Name;
tItem.Data := Pointer(p);
end;
end;
end;
procedure TfrmSnippets.tvSnippetsItemExpanding(Sender: TObject;
Item: TElTreeItem; var CanProcess: Boolean);
var
rec: TSearchRec;
tItem: TElTreeItem;
s: String;
i: integer;
P: pdata;
begin
s := Item.Text;
s := ExtractFilePath(Application.ExeName) + 'snippets\' + s + '\';
for i := item.ChildrenCount - 1 downto 0 do begin
item.Children[i].Delete;
end;
if findFirst(s + '*.snp', faAnyFile, Rec) = 0 then begin
if LeftStr(rec.Name, 1) <> '.' then begin
tItem := tvSnippets.Items.AddChild(Item, PChar(Rec.Name));
tITem.ImageIndex :=3;
p := new(pData);
p.Filename := s + Rec.Name;
tItem.Data := Pointer(p);
end;
end;
While FindNext(rec) = 0 do
begin
if LeftStr(rec.Name, 1) <> '.' then begin
tItem := tvSnippets.Items.AddChild(Item, PChar(Rec.Name));
tITem.ImageIndex :=3;
p := new(pData);
p.Filename := s + Rec.Name;
tItem.Data := Pointer(p);
end;
end;
end;
procedure TfrmSnippets.tvSnippetsDblClick(Sender: TObject);
var
Item: TElTreeItem;
stList: TStrings;
p: Pdata;
s: String;
i: integer;
begin
if dmMain.SelDoc = nil then exit;
if dmMain.selDoc.bHexMode then exit;
Item := tvSnippets.Selected;
if Item.ImageIndex = 2 then exit;
stList := TStringList.Create;
p := PData(Item.Data);
s := p.filename;
stList.LoadFromFile(s);
dmMain.SelDoc.sciMain.SelText := stList.Text;
WIndows.SetFocus(dmMain.seldoc.sciMain.handle);
dmMain.selDoc.sciMain.SetFocus;
stList.Free;
end;
procedure TfrmSnippets.Delete1Click(Sender: TObject);
var
s,l: String;
rec: TSearchRec;
begin
if tvSnippets.Selected.Parent = nil then
s := ExtractFilePath(Application.ExeName) + 'snippets\' + tvSnippets.Selected.Text
else begin
s := AnsiReplaceText(tvSnippets.Selected.Parent.Text, '\', '');
s := AnsiReplaceText(s, '/', '');
s := ExtractFilePath(Application.ExeName) + 'snippets\' + s + '\' + tvSnippets.Selected.Text;
end;
DeleteFile(s);
tvSNippets.Selected.Delete;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -