unit uMain;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls,uTreeView, Data.DB,
  Datasnap.DBClient, SimpleDS, Data.SqlExpr,uEtcetra,uSelectionOptions, Vcl.ExtCtrls, Vcl.Grids,
  Vcl.DBGrids, Vcl.AppEvnts, udmActionManager1;

type
  TMainForm = class(TForm)
    bTest: TButton;
    bInsertFolder: TButton;
    bInsertFile: TButton;
    NodeUp: TButton;
    NodeDown: TButton;
    bInitialUpdate: TButton;
    bDelete: TButton;
    bCopy: TButton;
    bPaste: TButton;
    bCut: TButton;
    bEditNodeText: TButton;
    Bevel1: TBevel;
    Bevel2: TBevel;
    DBGrid1: TDBGrid;
    eSearch: TEdit;
    bUncheckCheckboxes: TButton;
    ApplicationEvents: TApplicationEvents;
    DBTreeView1: TDBTreeView;
    Button1: TButton;





    procedure FormCreate(Sender: TObject);
    procedure bInsertFolderClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure bInsertFileClick(Sender: TObject);
    procedure NodeUpClick(Sender: TObject);
    procedure NodeDownClick(Sender: TObject);
    procedure bInitialUpdateClick(Sender: TObject);
    procedure bDeleteClick(Sender: TObject);
    procedure bCopyClick(Sender: TObject);
    procedure bPasteClick(Sender: TObject);
    procedure bCutClick(Sender: TObject);
    procedure bEditNodeTextClick(Sender: TObject);
    procedure eSearchChange(Sender: TObject);
    procedure bUncheckCheckboxesClick(Sender: TObject);
    procedure ApplicationEventsMessage(var Msg: tagMSG; var Handled: Boolean);
    procedure eSearchClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure bTestClick(Sender: TObject);

  private

    dmActionManager1:TDMActionManager;

    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

{$R *.dfm}

procedure TMainForm.ApplicationEventsMessage(var Msg: tagMSG;
  var Handled: Boolean);

//Внимание!!! Обработку сообщений лучше делать в самой программе, использующей
// DBTReeView, добавив компонент ApplicationEvents и обработав OnMessage

//Эта процедура помогает прокручивать мышку при Drag&Drop

var iPos:integer; i:Integer;
begin

if Msg.message=WM_Mousewheel then
 begin

 i:=HiWord(Msg.wParam);

 //Если колесо движется от пользователя
 if i=120 then
         begin
             iPos := GetScrollPos(DBTreeView1.Handle, SB_VERT);
             SetScrollPos(DBTreeView1.Handle, SB_VERT, iPos -1, True);
             DBTreeView1.TopItem := DBTreeView1.TopItem.GetPrevVisible;

         end else

 //Если колесо движется к пользователю
         begin
             iPos := GetScrollPos(DBTreeView1.Handle, SB_VERT);
             SetScrollPos(MainForm.DBTreeView1.Handle, SB_VERT, iPos +1, True);
             DBTreeView1.TopItem := DBTreeView1.TopItem.GetNextVisible;
         end;

 end;
end;

procedure TMainForm.bCopyClick(Sender: TObject);
begin
//DBTreeView1.CopyNodes;
end;

procedure TMainForm.bCutClick(Sender: TObject);
begin
//DBTreeView1.CutNodes;
end;

procedure TMainForm.bDeleteClick(Sender: TObject);
//var fSelectionOptions2:TfSelectionOptions;
begin
//DBTreeView1.DeleteNodes;
end;

procedure TMainForm.bEditNodeTextClick(Sender: TObject);
begin
DBTreeView1.EditNodeText;
end;

procedure TMainForm.bInitialUpdateClick(Sender: TObject);
var DMEtcetra:TDMEtcetra;
begin

{
//Очистка дерева
DMEtcetra:=TDMEtcetra.Create(Self);
DMEtcetra.ClearTree(DBTreeView1);
FreeAndNil(DMEtcetra);
}
//Первоначальное заполнение
//DBTreeView1.InitialUpdate;

end;

procedure TMainForm.bInsertFileClick(Sender: TObject);
begin
//DBTreeView1.InsertFile;
end;

procedure TMainForm.bInsertFolderClick(Sender: TObject);
begin
//DBTreeView1.InsertFolder;

end;

procedure TMainForm.bUncheckCheckboxesClick(Sender: TObject);
begin
DBTreeView1.ClearCheckBoxes;
end;



procedure TMainForm.eSearchChange(Sender: TObject);
begin

if eSearch.Text='' then exit;

DBTreeView1.Search(eSearch.text);
DBGrid1.DataSource:=DBTreeView1.DataSource;

end;

procedure TMainForm.eSearchClick(Sender: TObject);
begin
if eSearch.Text='Search...' then
eSearch.Text:='';
end;

procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);

begin

DBTreeView1.ClearPointers;

end;


procedure TMainForm.FormCreate(Sender: TObject);

begin

DBTreeView1.InitialUpdate;
DBTreeView1.ClearCheckBoxes;
ReportMemoryLeaksOnShutdown:=true;

dmActionManager1:=TDMActionManager.create(Self);
dmActionManager1.DBTreeView:=DBTreeView1;//  DBTreeView3;

end;


procedure TMainForm.FormDestroy(Sender: TObject);
begin
FreeAndNil(dmActionManager1);
end;

procedure TMainForm.NodeUpClick(Sender: TObject);
begin
//DBTreeView1.NodeUp;
end;

procedure TMainForm.bPasteClick(Sender: TObject);
begin
//DBTreeView1.PasteNodes;
end;

procedure TMainForm.bTestClick(Sender: TObject);
begin
DBTreeView1.Connect;
end;

procedure TMainForm.NodeDownClick(Sender: TObject);
begin
//DBTreeView1.NodeDown;
end;


end.
