📄 mainunit.~pas
字号:
else
begin
FindDialog.Options:=ReplaceDialog.Options;
FindDialog.FindText:=ReplaceDialog.FindText;
FindDialogFind(Sender);
end;
end;
//****************************************************************
//节点改变前---------------------------------------------------------------
procedure TSrmForm.TreeViewChanging(Sender: TObject; Node: TTreeNode;
var AllowChange: Boolean);
var
Ps,UserPs:string;
begin
AllowChange:=true;
if Srm=nil then exit;
SaveItem;
if Node.Data=pointer(-1) then exit; //如果是新建节点则不检查口令
Ps:=Srm.GetItemPassword(integer(Node.Data)); //得要显示标题的口令
{ if Ps<>'' then //口令不为空时
begin
with TInpwForm.Create(self) do
begin
Caption:=csAppName;
InputLabel.Caption:=csPasswordTitle;
if ShowModal=mrCancel then
begin
AllowChange:=false;
end;
UserPs:=Edit.Text;
if Ps<>UserPs then //输入口令不对时
begin
if ModalResult<>mrCancel then //在口令输入框中没按Cancel按钮
Application.MessageBox(csPasswordError,csAppName,MB_OK);
AllowChange:=false; //不允许转移选择点
end;
Free;
end;
end; }
end;
//节点改变后---------------------------------------------------------------
procedure TSrmForm.TreeViewChange(Sender: TObject; Node: TTreeNode);
var
Ms:TMemoryStream;
begin
if Srm=nil then exit;
if ((Node=nil) or (integer(Node.Data)=-1)) then //无效节点或无内容
begin
ContextAuthorEdit.Text:='';
ContextPasswordEdit.Text:='';
ContextPubDateEdit.Text:=DateToStr(Date);
ContextIndexEdit.Text:='';
ContextTypeRadioGroup.ItemIndex:=1;
RichEdit.Text:='';
RichEdit.Modified:=false;
if Node<>nil then
begin
Srm.ItemHeadChanged:=true;
Srm.ItemDataChanged:=true;
end;
exit;
end;
Srm.ReadItemHead(integer(Node.Data)); //读入标题属性
case Srm.DataHead.Num of
0: //无内容
begin
RichEdit.Text:='';
end;
1:
begin
Ms:=TMemoryStream.Create;
Srm.ReadItemData(Ms);
RichEdit.PlainText:=true; //和3.2版兼容
RichEdit.SetTextBuf(Ms.Memory);
RichEdit.PlainText:=false;//和3.2版兼容
Ms.Free;
end;
end;
Node.SelectedIndex:=Node.ImageIndex; //设置标题属性
ContextAuthorEdit.Text:=string(Srm.DataHead.Author);
ContextPasswordEdit.Text:=String(Srm.DataHead.Password);
ContextPubDateEdit.Text:=DateToStr(Srm.DataHead.PubDate);
ContextIndexEdit.Text:=string(Srm.DataHead.SearchKey);
ContextTypeRadioGroup.ItemIndex:=Node.ImageIndex-1;
TitleLabel.Caption:=Node.Text;
StatusBar.Refresh;
RichEdit.Modified:=false;
Srm.ItemHeadChanged:=false;
Srm.ItemDataChanged:=false;
end;
//节点被编辑后------------------------------------------------------------
procedure TSrmForm.TreeViewEdited(Sender: TObject; Node: TTreeNode;
var S: String);
var
Id:integer;
begin
S:=FormatTreeNodeString(S);
if S='' then S:=csNewDefaultTitle;
if Node.Parent=nil then Id:=0 else Id:=integer(Node.Parent.ItemId);
PostMessage(TreeView.Handle,TVM_SORTCHILDREN,0,Id);
TitleLabel.Caption:=S;
Srm.IndexChanged:=true;
end;
//标题排序函数-------------------------------------------------------
procedure TSrmForm.TreeViewCompare(Sender: TObject; Node1,
Node2: TTreeNode; Data: Integer; var Compare: Integer);
begin
if Node1.ImageIndex<Node2.ImageIndex then Compare:=-1
else if Node1.ImageIndex>Node2.ImageIndex then begin Compare:=1 end
else comPare:=CompareText(Node1.Text,Node2.Text);
end;
//树形视图拖动过程----------------------------------------------------------
procedure TSrmForm.TreeViewDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
Var
NbPixels:Integer;
Info:TScrollInfo;
begin
if Source<>TreeView then
begin
Accept:=false;
exit;
end;
GetScrollInfo(TreeView.Handle,SB_VERT,Info);
if Info.nMin=Info.nMax then exit;
NbPixels:=Abs(TreeView.Font.Height);
if (Y<NbPixels) then
begin
TreeView.Perform(WM_VSCROLL,SB_LINEUP,0);
TreeView.Refresh;
end;
if (Y>TreeView.Height-NbPixels-16) then
begin
TreeView.Perform(WM_VSCROLL,SB_LINEDOWN,0);
TreeView.Refresh;
end;
end;
//树形视图拖动结束----------------------------------------------------------
procedure TSrmForm.TreeViewDragDrop(Sender, Source: TObject; X,
Y: Integer);
var
SNode,DNode:TTreeNode;
Id:integer;
begin
SNode:=TreeView.Selected; //得被拖动的标题
DNode:=TreeView.GetNodeAt(X,Y); //得坐标处标题
if DNode<>SNode then
if DNode=nil then
SNode.MoveTo(TreeView.Items.GetFirstNode,naAdd)
else
SNode.MoveTo(DNode,naAddChild);
if SNode.Parent=nil then Id:=0 else Id:=integer(SNode.Parent.ItemId);
SendMessage(TreeView.Handle,TVM_SORTCHILDREN,0,Id);
srm.IndexChanged:=true; //置索引改变为真
end;
//树形视图拖动结束----------------------------------------------------------
//节点被扩展前------------------------------------------------------------
procedure TSrmForm.TreeViewExpanding(Sender: TObject; Node: TTreeNode;
var AllowExpansion: Boolean);
var
ps,UserPs:string;
begin
AllowExpansion:=true;
if Node.Data=pointer(-1) then exit;
UserPs:=Srm.GetItemPassword(integer(Node.Data));
{if UserPs<>'' then
begin
with TInpwForm.Create(self) do
begin
Caption:=csAppName;
InputLabel.Caption:=csPasswordTitle;
if ShowModal=mrCancel then AllowExpansion:=false;
Ps:=Edit.Text;
if Ps<>UserPs then
begin
if ModalResult<>mrCancel then
MessageBox(Handle,csPasswordError,csAppName,MB_OK);
AllowExpansion:=false;
end;
Free;
end;
end; }
end;
//设为标题----------------------------------------------------------
procedure TSrmForm.SetTitlePopMenuItemClick(Sender: TObject);
begin
TreeView.Selected.Text:=FormatTreeNodeString(RichEdit.SelText);
Srm.IndexChanged:=true;
TitleLabel.Caption:=TreeView.Selected.Text;
end;
//设为作者----------------------------------------------------------
procedure TSrmForm.SetAuthorPopMenuItemClick(Sender: TObject);
begin
ContextAuthorEdit.Text:=RichEdit.SelText;
Srm.ItemHeadChanged:=true;
end;
//设为关键字--------------------------------------------------------
procedure TSrmForm.SetIndexPopMenuItemClick(Sender: TObject);
var
TmpStr:string;
p: pchar;
begin
TmpStr:=RichEdit.SelText;
if 51<Length(ContextIndexEdit.Text)+RichEdit.SelLength then
begin
Application.MessageBox(csIndexError,csAppName,MB_OK);
exit;
end;
p:=pchar(TmpStr);
while (p^<#33) and (P^<>#0) do inc(p);
if ContextIndexEdit.Text<>'' then
if ContextIndexEdit.Text[Length(ContextIndexEdit.Text)]<>'&' then
ContextIndexEdit.Text:=ContextIndexEdit.Text+'&';
ContextIndexEdit.Text:=ContextIndexEdit.Text+string(p);
Srm.ItemHeadChanged:=true;
end;
//编辑框菜单弹出时--------------------------------------------------
procedure TSrmForm.RichEditPopupMenuPopup(Sender: TObject);
begin
if Srm=nil then
begin
CutPopMenuItem.Enabled:=false;
CopyPopMenuItem.Enabled:=false;
PastePopMenuItem.Enabled:=false;
SetTitlePopMenuItem.Enabled:=false;
SetIndexPopMenuItem.Enabled:=false;
SelAllPopMenuItem.Enabled:=false;
SetAuthorPopMenuItem.Enabled:=false;
DelSpacePopMenuItem.Enabled:=false;
end
else
begin
OpenClipboard(Handle);
if GetClipboardData(CF_TEXT)=0 then //剪贴板中没有文本时
PastePopMenuItem.Enabled:=false
else
PastePopMenuItem.enabled:=true;
CloseClipboard;
if RichEdit.SelLength>=RichEdit.GetTextLen then
SelAllPopMenuItem.Enabled:=false
else
SelAllPopMenuItem.Enabled:=true;
if richEdit.SelLength<>0 then
begin
CutPopMenuItem.Enabled:=true;
CopyPopMenuItem.Enabled:=true;
SetTitlePopMenuItem.Enabled:=true;
SetIndexPopMenuItem.Enabled:=true;
SetAuthorPopMenuItem.Enabled:=true;
end
else
begin
CutPopMenuItem.Enabled:=false;
CopyPopMenuItem.Enabled:=false;
SetTitlePopMenuItem.Enabled:=false;
SetIndexPopMenuItem.Enabled:=false;
SetAuthorPopMenuItem.Enabled:=false;
end;
DelSpacePopMenuItem.Enabled:=(RichEdit.Text<>'');
end;
end;
//剪切标题----------------------------------------------------------
procedure TSrmForm.CutNodePopMenuItemClick(Sender: TObject);
begin
SrmClip.Cut(TreeView.Selected);
end;
//复制标题----------------------------------------------------------
procedure TSrmForm.CopyNodePopMenuItemClick(Sender: TObject);
begin
SrmClip.Copy(TreeView.Selected);
end;
//粘贴标题----------------------------------------------------------
procedure TSrmForm.PasteNodePopMenuItemClick(Sender: TObject);
begin
SrmClip.Paste(TreeView.Selected);
end;
//弹出菜单时的动作--------------------------------------------------------
procedure TSrmForm.TreeViewPopupMenuPopup(Sender: TObject);
begin
if Srm=nil then
begin
DelNodePopMenuItem.Enabled:=false;
EditNodePopMenuItem.Enabled:=false;
AddSubNodePopMenuItem.Enabled:=false;
AddNodePopMenuItem.Enabled:=false;
CutNodePopMenuItem.Enabled:=false;
CopyNodePopMenuItem.Enabled:=false;
PasteNodePopMenuItem.Enabled:=false;
exit;
end;
AddNodePopMenuItem.Enabled:=true;
if TreeView.Selected=nil then
begin
DelNodePopMenuItem.Enabled:=false;
EditNodePopMenuItem.Enabled:=false;
AddSubNodePopMenuItem.Enabled:=false;
CutNodePopMenuItem.Enabled:=false;
CopyNodePopMenuItem.Enabled:=false;
end
else
begin
DelNodePopMenuItem.Enabled:=true;
EditNodePopMenuItem.Enabled:=true;
AddSubNodePopMenuItem.Enabled:=true;
CutNodePopMenuItem.Enabled:=true;
CopyNodePopMenuItem.Enabled:=true;
end;
if SrmClip.Node=nil then
PasteNodePopMenuItem.Enabled:=false
else
PasteNodePopMenuItem.Enabled:=true;
end;
//****************************************************************
//---------------------------------------------------------------------
procedure TSrmForm.StatusBarDrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel; const Rect: TRect);
var
Text:string;
Rc:TRect;
begin
Rc:=Rect;
Rc.Left:=Rc.Left+3;
if Panel=StatusBar.Panels[0] then
begin
Text:=csPanel1Text+IntToStr(TreeView.Items.Count);
end;
if Panel=StatusBar.Panels[1] then
begin
Text:=csPanel2Text+IntToStr(RichEdit.GetTextLen);
end;
if Panel=StatusBar.Panels[2] then
begin
Text:=PanelHint;
end;
with StatusBar.Canvas do
begin
Brush.Style := bsClear;
Font := StatusBar.Font;
Font.Color := clWhite;
OffsetRect(Rc,5,1);
DrawText(Handle, PChar(Text), Length(Text), Rc,(DT_VCENTER or DT_SINGLELINE));
OffsetRect(Rc,-1,-1);
Font:=StatusBar.Font;
DrawText(Handle, PChar(Text), Length(Text), Rc,(DT_VCENTER or DT_SINGLELINE));
end;
end;
//****************************************************************
//新建数据文件-------------------------------------------------------------
procedure TSrmForm.NewMenuItemClick(Sender: TObject);
begin
with SaveDialog do
begin
DefaultExt:=csSrmExt;
Filter:=csSrmFilter;
Title:=csCreateTitle;
end;
if SaveDialog.Execute then
begin
if CloseSrmQuery then CloseSrm else exit;
Srm:=TSrmObject.Create(SaveDialog.FileName,fmCreate);
DbAuthorEdit.Text:='';
DbPasswordEdit.Text:='';
DbBuildDateEdit.Text:=DateToStr(Srm.FileHead.BuildDate);
DbeditDateEdit.Text:=DatetoStr(Srm.FileHead.EditDate);
Caption:=csAppName+' - '+SaveDialog.FileName;
Mru.Add(SaveDialog.FileName);
end;
end;
//打开数据文件------------------------------------------------------------
procedure TSrmForm.OpenMenuItemClick(Sender: TObject);
begin
with OpenDialog do
begin
DefaultExt:=csSrmExt;
Filter:=csSrmFilter;
Title:=csOpenTitle;
FileName:='';
end;
if OpenDialog.Execute then
begin
if CloseSrmQuery then CloseSrm else exit;
OpenSrm(OpenDialog.FileName);
if Srm=nil then
Caption:=csAppName
else
begin
Caption:=csAppName+' - '+OpenDialog.FileName;
Mru.Add(OpenDialog.FileName);
end;
end;
end;
//保存数据文件------------------------------------------------------------
procedure TSrmForm.SaveMenuItemClick(Sender: TObject);
begin
SaveSrm;
end;
//关闭数据文件------------------------------------------------------------
procedure TSrmForm.CloseMenuItemClick(Sender: TObject);
begin
if CloseSrmQuery then
begin
CloseSrm;
Caption:=csAppName;
end;
end;
//文件引入-----------------------------------------------------------------
procedure TSrmForm.FImportMenuItemClick(Sender: TObject);
var
Ps,UserPs:string;
Msh,Msd:TMemoryStream;
j:integer;
p:PTreeData;
AList: TStringList;
ALevel,AOldLevel:integer;
AParentNode:TTreeNode;
StrBuf:PChar;
ANode:TTreeNode;
i,n:integer;
Fn:string;
begin
with OpenDialog do
begin
DefaultExt:=csTxtExt;
Filter:=csTxtFilter+'|'+csSrmFilter;
Title:=csOpenTitle;
FileName:='';
end;
if OpenDialog.Execute then
if ExtractFileExt(OpenDialog.Files.Strings[0])='.txt' then
begin
n:=OpenDialog.Files.Count-1;
RichEdit.Perform(WM_SETREDRAW,0,0); //禁止重绘
for i:=0 to n do //循环读入多重选择文件
begin
Fn:=ExtractFileName(OpenDialog.Files.Strings[i]);
Delete(Fn,Length(Fn)-3,4);
ANode:=TreeView.Items.AddObjectFirst(TreeView.Selected,Fn,pointer(-1));
ANode.ImageIndex:=2;
with Srm.DataHead do
begin
DataType:=2;
Author[0]:=#0;
Password[0]:=#0;
end;
TreeView.Selected:=ANode;
RichEdit.Lines.LoadFromFile(OpenDialog.Files.Strings[i]);
end;
StatusBar.Refresh;
RichEdit.Perform(WM_SETREDRAW,-1,0); //允许重绘
Richedit.Refresh;
end
else
{
begin
Result:=true;
Application.ProcessMessages; //恢复原窗口
Srm:=TSrmObject.Create(Fn,fmOpenReadWrite);
{ if Srm.FileHead.Password[0]<>#0 then //密码保护
begin
InPwForm:=TInPwForm.Create(SrmForm);
with InPwForm do
begin
Caption:=csAppName;
InputLabel.Caption:=csPasswordTitle;
if ShowModal=mrCancel then
begin
Srm.Free;
Srm:=nil;
Free;
Result:=false;
Exit;
end;
Ps:=Edit.Text;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -