⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainunit.pas

📁 初次上传,不太会规类.这是一个电子文档收集的软件.支持从浏览器窗口中托拽到本地窗口中.个人以为比网文快抓,webcollecter之类的好.小,绿色,适用.
💻 PAS
📖 第 1 页 / 共 5 页
字号:
      RichEdit.SelLength := Length(ReplaceDialog.FindText);
      RichEdit.SelText := ReplaceDialog.ReplaceText;
      RichEdit.SelStart := FoundAt;
      RichEdit.SelLength := Length(ReplaceDialog.ReplaceText);
    end
    else
    begin
      Application.MessageBox(csFindError,csAppName,MB_OK or MB_ICONWARNING);
    end;
  end
  else if frReplaceAll in ReplaceDialog.Options then
  begin
    StartPos:=0;
    FoundAt:=0;
    while FoundAt<>-1 do
    begin
      FoundAt:=RichEdit.FindText(ReplaceDialog.FindText,StartPos,ToEnd,
                                 SearchFlag);
      if FoundAt<>-1 then
      begin
        RichEdit.SetFocus;
        RichEdit.SelStart := FoundAt;
        RichEdit.SelLength:=Length(ReplaceDialog.FindText);
        RichEdit.SelText:=ReplaceDialog.ReplaceText;
        StartPos:=FoundAt+Length(ReplaceDialog.Findtext);
        ToEnd:=Length(RichEdit.Text)-StartPos;
      end
      else
      begin
        Application.MessageBox(csReplaceSucess,csAppName,0);
        break;
      end;
    end;
  end
  else
  begin
    FindDialog.Options:=ReplaceDialog.Options;
    FindDialog.FindText:=ReplaceDialog.FindText;
    FindDialogFind(Sender);
  end;
end;


//****************************************************************
//节点改变前---------------------------------------------------------------
procedure TSrmForm.TreeViewChanging(Sender: TObject; Node: TTreeNode;
  var AllowChange: Boolean);
begin
{  Ps:=GetItem
  if Srm.FileHead.Password[0]<>#0 then   //密码保护
  begin
    Ps:=InputBox(csAppName,csPasswordTitle,'');
    UserPs:=string(Srm.FileHead.Password);
    if Ps<>UserPs then
    begin
      Application.MessageBox(csAppName,csPasswordError,MB_OK);
      Srm.Free;
      Srm:=nil;
      exit;
    end;
  end;}
end;
//节点改变后---------------------------------------------------------------
procedure TSrmForm.TreeViewChange(Sender: TObject; Node: TTreeNode);
var
  Ms:TMemoryStream;
  Ps,UserPs:string;
begin
  SaveData;  //保存更改
  if ((Node=nil) or (integer(Node.Data)=-1)) then  //无效节点或无内容
  begin
    RichEdit.Text:='';
    ContextAuthorEdit.Text:='';
    ContextPasswordEdit.Text:='';
    ContextPubDateEdit.Text:='';
    ContextIndexEdit.Text:='';
    ContextTypeRadioGroup.ItemIndex:=1;
    ActiveNode:=Node;
    DataChange:=true;
    exit;
  end
  else
  begin
    Srm.ReadItemHead(integer(Node.Data));
    if Srm.DataHead.Password[0]<>#0 then   //密码保护
    begin
      Ps:=InputBox(csAppName,csPasswordTitle,'');
      UserPs:=string(Srm.DataHead.Password);
      if Ps<>UserPs then
      begin
        Application.MessageBox(csPasswordError,csAppName,MB_OK);
        if ActiveNode=nil then
          PostMessage(TreeView.Handle,TVM_SELECTITEM,TVGN_CARET,LPARAM(0))
        else
          PostMessage(TreeView.Handle,TVM_SELECTITEM,TVGN_CARET,LPARAM(ActiveNode.ItemID));
        DataChange:=false;
        exit;
      end;
    end;

    Ms:=TMemoryStream.Create;
    case Srm.DataHead.Num of
      0:                //无内容
      begin
        RichEdit.Text:='';
      end;
      1:
      begin
        Srm.ReadItemData(Ms);
        RichEdit.SetTextBuf(Ms.Memory);
        Ms.Free;
      end;
    end;
    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;
  end;
  TitleLabel.Caption:=Node.Text;
  ActiveNode:=Node;  //置当前激活节点
  RichEdit.Modified:=false;
  DataChange:=false;
end;
//节点被扩展前------------------------------------------------------------
procedure TSrmForm.TreeViewExpanding(Sender: TObject; Node: TTreeNode;
  var AllowExpansion: Boolean);
var
  ps,UserPs:string;
begin
  if Node.Data=pointer(-1) then exit;
  UserPs:=Srm.GetItemPassword(integer(Node.Data));
  AllowExpansion:=true;
  if UserPs<>'' then
  begin
    Ps:=InputBox(csAppName,csPasswordTitle,'');
    if Ps<>UserPs then
    begin
      Application.MessageBox(csPasswordError,csAppName,MB_OK);
      AllowExpansion:=false;
    end;
  end;
end;
//节点被编辑后------------------------------------------------------------
procedure TSrmForm.TreeViewEdited(Sender: TObject; Node: TTreeNode;
  var S: String);
var
  Ap:Pchar;
  Id:integer;
begin
  Ap:=pchar(s);
  while Ap^ in [#1..#32] do inc(Ap);
  S:=string(Ap);
  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);
  IndexChange:=true;
end;
//设为标题----------------------------------------------------------
procedure TSrmForm.SetTitlePopMenuItemClick(Sender: TObject);
var
  TmpStr:string;
  p: pchar;
begin
  TmpStr:=RichEdit.SelText;
  p:=pchar(TmpStr);
  while p^<chr(33) do inc(p);
  TreeView.Selected.Text:=string(p);
  Indexchange:=true;
end;
//设为作者----------------------------------------------------------
procedure TSrmForm.SetAuthorPopMenuItemClick(Sender: TObject);
var
  TmpStr:string;
  p: pchar;
begin
  TmpStr:=RichEdit.SelText;
  p:=pchar(TmpStr);
  while p^<chr(33) do inc(p);
  ContextAuthorEdit.Text:=string(p);
  DataChange:=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);
  DataChange:=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.TreeViewDragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  if Source=TreeView then
    Accept:=true;
  if Y<TreeView.Height-15 then
    SendMessage(TreeView.Handle,WM_VSCROLL,SB_LINEUP,0);
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);
  IndexChange:=true;      //置索引改变为真  }
end;
//拖动结束----------------------------------------------------------
procedure TSrmForm.TreeViewEndDrag(Sender, Target: 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);
  IndexChange:=true;      //置索引改变为真
end;
//剪切标题----------------------------------------------------------
procedure TSrmForm.CutNodePopMenuItemClick(Sender: TObject);
begin
  CcpNode:=TreeView.Selected;
  CcpMode:=1;
end;
//复制标题----------------------------------------------------------
procedure TSrmForm.CopyNodePopMenuItemClick(Sender: TObject);
begin
  CcpNode:=TreeView.Selected;
  CcpMode:=2;
end;
//粘贴标题----------------------------------------------------------
procedure TSrmForm.PasteNodePopMenuItemClick(Sender: TObject);
var
  ANode:TTreeNode;
  Ms:TMemoryStream;
  Id:integer;
begin
  if CcpMode=0 then Exit;
  ANode:=nil;
  if CcpMode=1 then        //剪切时
  begin
    CcpNode.MoveTo(TreeView.Selected,naAddChildFirst);
    ANode:=CcpNode;
    TreeView.Selected:=ANode;
    IndexChange:=true;
  end
  else if CcpMode=2 then         //复制时
  begin
    ANode:=TreeView.Items.AddChildObjectFirst
           (TreeView.Selected,CcpNode.Text,pointer(-1));
    ANode.ImageIndex:=CcpNode.ImageIndex;
    TreeView.Selected:=ANode;
    Srm.ReadItemHead(integer(CcpNode.Data));
    Ms:=TMemoryStream.Create;
    Srm.ReadItemData(Ms);
    RichEdit.Lines.LoadFromStream(Ms);
    Ms.Free;
  end;
  CcpNode:=nil;
  if ANode.Parent=nil then Id:=0 else Id:=integer(ANode.Parent.ItemId);
  SendMessage(TreeView.Handle,TVM_SORTCHILDREN,0,Id);
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 CcpNode=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, 1, 1);
    DrawText(Handle, PChar(Text), Length(Text), Rc,(DT_VCENTER or DT_SINGLELINE));
    OffsetRect(Rc, -1, -1);
    Font.Color := clBlack;
    DrawText(Handle, PChar(Text), Length(Text), Rc,(DT_VCENTER or DT_SINGLELINE));
  end;
end;

//****************************************************************
//新建数据文件-------------------------------------------------------------
procedure TSrmForm.NewMenuItemClick(Sender: TObject);
begin
  with SaveDialog do

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -