Unit Unit9;

{$mode objfpc}{$H+}

Interface

Uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  ExtCtrls, StdCtrls, PairSplitter, Buttons, ComCtrls, LCLType, CADEngine;

Type

  { TSearchForm }

  TSearchForm = Class(TForm)
    OpenInInspectorSpeedButton: TSpeedButton;
    CountLabel: TLabel;
    AddToSelectionSpeedButton: TSpeedButton;
    SearchFilterCheckGroup: TCheckGroup;
    ActionGroupBox: TGroupBox;
    SearchListBox: TListBox;
    Panel2: TPanel;
    ProgressBar: TProgressBar;
    SearchEdit: TEdit;
    SearchSubjectGroupBox: TGroupBox;
    Panel1: TPanel;
    SearchResultGroupBox: TGroupBox;
    DoSearchSpeedButton: TSpeedButton;
    AutoSearchSpeedButton: TSpeedButton;
    SpeedButton1: TSpeedButton;
    NavigateToSpeedButton: TSpeedButton;
    Splitter1: TSplitter;
    Splitter2: TSplitter;
    Procedure DoSearchSpeedButtonClick(Sender: TObject);
    Procedure SearchEditKeyUp(Sender: TObject; Var Key: Word; Shift: TShiftState
      );
    Procedure SearchListBoxDblClick(Sender: TObject);
    Procedure SpeedButton1Click(Sender: TObject);
  Private
    { private declarations }
  Public
    { public declarations }
  End;

Var
  SearchForm: TSearchForm;

Implementation
Uses Unit1;
{ TSearchForm }

Procedure TSearchForm.DoSearchSpeedButtonClick(Sender: TObject);
Var I:Longint;Tmp:String;
    Callout:TVCallout;
begin
        Tmp:=SearchEdit.Text;
        SearchListBox.Items.Clear;
        If SearchFilterCheckGroup.Checked[0] Then
          If Scene.VObjectList.Count>0 Then
            For I:=0 To Scene.VObjectList.Count-1 Do Begin
              ProgressBar.Position:=Round(I/Scene.VObjectList.Count)*100;
              If Pos(Tmp,Scene.VObjectList[I])>0 Then
                SearchListBox.Items.Add(Scene.VObjectList[I]);
            End;
        If SearchFilterCheckGroup.Checked[3] then
          If Scene.VCurlList.Count>0 Then
            For I:=0 To Scene.VCurlList.Count-1 Do Begin
              ProgressBar.Position:=Round(I/Scene.VCurlList.Count)*100;
              If Pos(Tmp,Scene.VCurlList[I])>0 Then
                SearchListBox.Items.Add(Scene.VCurlList[I]);
            End;
        If SearchFilterCheckGroup.Checked[2] then
          If Scene.VConnectionList.Count>0 Then
              For I:=0 To Scene.VConnectionList.Count-1 Do Begin
                ProgressBar.Position:=Round(I/Scene.VConnectionList.Count)*100;
                If Pos(Tmp,Scene.VConnectionList[I])>0 Then
                  SearchListBox.Items.Add(Scene.VConnectionList[I]);
              End;
        If SearchFilterCheckGroup.Checked[1] then
          If Scene.VCalloutList.Count>0 Then
            For I:=0 To Scene.VCalloutList.Count-1 Do Begin
              ProgressBar.Position:=Round(I/Scene.VCalloutList.Count)*100;
              If Pos(Tmp,Scene.VCalloutList[I])>0 Then
                SearchListBox.Items.Add(Scene.VCalloutList[I])
            End;
        If SearchFilterCheckGroup.Checked[4] then
          If Scene.VCalloutList.Count>0 Then
            For I:=0 To Scene.VCalloutList.Count-1 Do Begin
              ProgressBar.Position:=Round(I/Scene.VCalloutList.Count)*100;
              // if fulltext search
              Callout:=Scene.VCalloutList.Objects[I] As TVCallout;
              If Pos(Tmp,Callout.Text)>0 Then SearchListBox.Items.Add(Scene.VCalloutList[I]);
            End;
       SearchEdit.SelStart:=Length(SearchEdit.Text);
       CountLabel.Caption:='Total found:'+IntToStr(SearchListBox.Count);
end;

Procedure TSearchForm.SearchEditKeyUp(Sender: TObject; Var Key: Word; Shift: TShiftState);
Begin
        If (Key=VK_return) Or (Key=VK_Left) Or (Key=VK_Right) Or (Key=VK_Tab) Then Exit;
        If (Key=VK_Up) Then Begin
          If SearchListBox.Items.Count>0 Then Begin
            If SearchListBox.ItemIndex<0 Then SearchListBox.ItemIndex:=0;
            If SearchListBox.ItemIndex=0 Then SearchListBox.ItemIndex:=SearchListBox.Items.Count-1
            Else SearchListBox.ItemIndex:=SearchListBox.ItemIndex-1;
          end;
          SearchEdit.Text:=SearchListBox.Items[SearchListBox.ItemIndex];
          Exit;
        End;
        If (Key=VK_Down) Then Begin
          If SearchListBox.Items.Count>0 Then Begin
            If SearchListBox.ItemIndex<0 Then SearchListBox.ItemIndex:=0 Else
            If SearchListBox.ItemIndex=SearchListBox.Items.Count-1 Then SearchListBox.ItemIndex:=0
            Else SearchListBox.ItemIndex:=SearchListBox.ItemIndex+1;
          end;
          SearchEdit.Text:=SearchListBox.Items[SearchListBox.ItemIndex];
          Exit;
        End;

  If AutoSearchSpeedButton.Down Then
    SearchForm.DoSearchSpeedButtonClick(Nil);
end;

Procedure TSearchForm.SearchListBoxDblClick(Sender: TObject);
Var Obj:TVObject;
    Callout:TVCallout;
    Connection:TVConnection;
    I:Longint;
    CurrentItem:String;
Begin
  If SearchListBox.Items.Count<=0 Then Exit;
  CurrentItem:=SearchListBox.Items[SearchListBox.ItemIndex];
  If NavigateToSpeedButton.Down Then Begin
       If SearchListBox.Count>1 Then Begin
         Unit1.UnselectAllBut('');
           AddItemToSelection(CurrentItem);
         If Pos('zoom',LowerCase(NavigationMode))>0 Then
           NavigateTo(ComputeSelectionZoomDST)
         Else
           NavigateTo(ComputeSelectionDST);
         If EditMode='edit' Then UpdateMultiSelection;
       End Else Begin
         If (Pos('zoom',LowerCase(NavigationMode))>0)Or(NavigationMode='Fly') Then
           NavigateTo(ComputeItemZoomDST(SearchEdit.Text))
         Else
           NavigateTo(ComputeItemDST(SearchEdit.Text));
       end;
    End;
    If AddToSelectionSpeedButton.Down Then Begin
       If SearchListBox.Count>1 Then Begin
         UnselectAllBut('');
         AddItemToSelection(CurrentItem);
         If EditMode='edit' Then UpdateMultiSelection;
       End Else begin
         UnselectAllBut('');
         AddItemToSelection(CurrentItem);
       end;
    End;
    If OpenInInspectorSpeedButton.Down Then begin
       Case Scene.GetTypeByName(CurrentItem) of
       'object': Begin Obj:=Scene.VObjectList.Objects[Scene.VObjectList.IndexOf(CurrentItem)] As TVObject;
                       PrepareObjectPropEdit(Obj);
                 End;
       'callout': Begin Callout:=Scene.VCalloutList.Objects[Scene.VCalloutList.IndexOf(CurrentItem)] As TVCallout;
                       PrepareCalloutPropEdit(Callout);
                  End;
       'connection': Begin
                       Connection:=Scene.VConnectionList.Objects[Scene.VConnectionList.IndexOf(CurrentItem)] As TVConnection;
                       PrepareConnectionPropEdit(Connection);
                     End;
       end;
    end;

end;

Procedure TSearchForm.SpeedButton1Click(Sender: TObject);
Var Obj:TVObject;
    Callout:TVCallout;
    Connection:TVConnection;
    I:Longint;
begin
  If SearchListBox.ItemIndex<0 Then Exit;

  If NavigateToSpeedButton.Down Then Begin
     If SearchListBox.Count>1 Then Begin
       Unit1.UnselectAllBut('');
       For I:=0 To SearchListBox.Count-1 Do
         AddItemToSelection(SearchListBox.Items[I]);
       If Pos('zoom',LowerCase(NavigationMode))>0 Then
         NavigateTo(ComputeSelectionZoomDST)
       Else
         NavigateTo(ComputeSelectionDST);
       If EditMode='edit' Then UpdateMultiSelection;
     End Else Begin
       If (Pos('zoom',LowerCase(NavigationMode))>0)Or(NavigationMode='Fly') Then
         NavigateTo(ComputeItemZoomDST(SearchEdit.Text))
       Else
         NavigateTo(ComputeItemDST(SearchEdit.Text));
     end;
  End;
  If AddToSelectionSpeedButton.Down Then Begin
     If SearchListBox.Count>1 Then Begin
       UnselectAllBut('');
       For I:=0 To SearchListBox.Count-1 Do
         AddItemToSelection(SearchListBox.Items[I]);
       If EditMode='edit' Then UpdateMultiSelection;
     End Else begin
       UnselectAllBut('');
       AddItemToSelection(SearchEdit.Text);
     end;
  End;
  If OpenInInspectorSpeedButton.Down Then begin
     Case Scene.GetTypeByName(SearchEdit.Text) of
     'object': Begin Obj:=Scene.VObjectList.Objects[Scene.VObjectList.IndexOf(SearchEdit.Text)] As TVObject;
                     PrepareObjectPropEdit(Obj);
               End;
     'callout': Begin Callout:=Scene.VCalloutList.Objects[Scene.VCalloutList.IndexOf(SearchEdit.Text)] As TVCallout;
                     PrepareCalloutPropEdit(Callout);
                End;
     'connection': Begin
                     Connection:=Scene.VConnectionList.Objects[Scene.VConnectionList.IndexOf(SearchEdit.Text)] As TVConnection;
                     PrepareConnectionPropEdit(Connection);
                   End;
     end;
  end;
end;




Initialization
  {$I unit9.lrs}

End.

