summaryrefslogtreecommitdiff
path: root/apps/windoze/CBuilder4/BibleCS/searchfrm.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'apps/windoze/CBuilder4/BibleCS/searchfrm.cpp')
-rw-r--r--apps/windoze/CBuilder4/BibleCS/searchfrm.cpp192
1 files changed, 192 insertions, 0 deletions
diff --git a/apps/windoze/CBuilder4/BibleCS/searchfrm.cpp b/apps/windoze/CBuilder4/BibleCS/searchfrm.cpp
new file mode 100644
index 0000000..afc45c0
--- /dev/null
+++ b/apps/windoze/CBuilder4/BibleCS/searchfrm.cpp
@@ -0,0 +1,192 @@
+//---------------------------------------------------------------------------
+#include <vcl\vcl.h>
+#pragma hdrstop
+
+#include "searchfrm.h"
+#include <listkey.h>
+#include "mainfrm.h"
+#include <regex.h>
+#include "RangeMaintFrm.h"
+
+
+//---------------------------------------------------------------------------
+#pragma resource "*.dfm"
+TForm2 *Form2;
+//---------------------------------------------------------------------------
+__fastcall TForm2::TForm2(TComponent* Owner)
+ : TForm(Owner) {
+ pvrtf = new SWDispRTF(this);
+
+ pvrtf->Parent = plPreview;
+ pvrtf->Align = alClient;
+ pvrtf->ScrollBars = ssVertical;
+ pvrtf->ReadOnly = true;
+ SearchText->Align = alClient;
+// pvrtf->PopupMenu = PopupMenu2;
+
+// mod->Disp(*displays.insert(displays.begin(), new RTFDisp(newrtf)));
+// mod->SetKey(DefaultVSKey);
+// return 0;
+}
+//---------------------------------------------------------------------------
+void __fastcall TForm2::Button1Click(TObject *Sender)
+{
+// ModMap::iterator target;
+ class TWaitCursor {
+ public:
+ TWaitCursor() : oldc(Screen->Cursor) { Screen->Cursor = crHourGlass; }
+ ~TWaitCursor() { Screen->Cursor = oldc; }
+ private:
+ TCursor oldc;
+ } wait; // show hourglass
+
+ if (!SearchText->Text.Length())
+ return;
+
+
+ int index = SearchText->Items->IndexOf(SearchText->Text);
+ SearchText->Items->Insert(0, SearchText->Text);
+
+ if (index >= 0)
+ SearchText->Items->Delete(index+1);
+
+ SearchText->ItemIndex = 0;
+
+ Caption = "";
+
+ targetpc = Form1->PageControl1;
+
+ if ((Form1->ActiveControl == Form1->PageControl2) || (IsChild(Form1->PageControl2->Handle, Form1->ActiveControl->Handle)))
+ targetpc = Form1->PageControl2;
+ if ((Form1->ActiveControl == Form1->PageControl3) || (IsChild(Form1->PageControl3->Handle, Form1->ActiveControl->Handle)))
+ targetpc = Form1->PageControl3;
+
+
+ target = Form1->mainmgr->Modules.find(targetpc->ActivePage->Caption.c_str());
+ if (target != Form1->mainmgr->Modules.end()) {
+ Caption = Caption + "Searching [" + (*target).first.c_str() + "]...";
+ ListBox1->Clear();
+ int searchType;
+ switch (searchTypeGroup->ItemIndex) {
+ case 0: searchType = -2; break;
+ case 1: searchType = -1; break;
+ case 2: searchType = 0; break;
+ }
+ int searchOptions = (CheckBox2->Checked) ? 0 : REG_ICASE;
+ Button1->Caption = "Halt";
+ Button1->OnClick = TerminateSearch;
+ SWKey *scope = 0;
+ switch (scopeGroup->ItemIndex) {
+ case 2:
+ if (ComboBox1->ItemIndex < 0)
+ results = VerseKey().ParseVerseList(ComboBox1->Text.c_str(), "", true);
+ else {
+ TCustomRange *rs = (TCustomRange *)ComboBox1->Items->Objects[ComboBox1->ItemIndex];
+ results = VerseKey().ParseVerseList(rs->text.c_str(), "", true);
+ }
+ case 1: scope = &results; break;
+ }
+ searchThread = new TSearchThread(this, SearchText->Text.c_str(), searchType, searchOptions, scope);
+ }
+ else Caption = "Error finding target module";
+}
+
+
+void __fastcall TForm2::TerminateSearch(TObject *Sender)
+{
+ (*target).second->terminateSearch = true;
+}
+
+//---------------------------------------------------------------------------
+void __fastcall TForm2::ListBox1DblClick(TObject *Sender)
+{
+ if (targetpc == Form1->PageControl3) {
+ Form1->DictKeyEdit->Text = ListBox1->Items->Strings[ListBox1->ItemIndex].c_str();
+ }
+ else {
+ Form1->DefaultVSKey = ListBox1->Items->Strings[ListBox1->ItemIndex].c_str();
+ Form1->TextKeyChanged();
+ }
+}
+//---------------------------------------------------------------------------
+void __fastcall TForm2::ListBox1Click(TObject *Sender)
+{
+ if (target != Form1->mainmgr->Modules.end()) {
+ SWKey *savekey = *(*target).second;
+ (*target).second->SetKey(ListBox1->Items->Strings[ListBox1->ItemIndex].c_str());
+ pvrtf->Display(*(*target).second);
+ (*target).second->SetKey(*savekey);
+ }
+}
+//---------------------------------------------------------------------------
+
+__fastcall TForm2::TSearchThread::TSearchThread(TForm2 *parent, string searchText, int searchType, int searchOptions, SWKey *scope, bool CreateSuspended)
+ : TThread(CreateSuspended)
+{
+ this->parent = parent;
+ this->searchText = searchText;
+ this->searchType = searchType;
+ this->searchOptions = searchOptions;
+ this->scope = scope;
+ Priority = tpNormal;
+ FreeOnTerminate = true;
+}
+//---------------------------------------------------------------------------
+void __fastcall TForm2::TSearchThread::FillListBox(void)
+{
+ for (results = TOP; !results.Error(); results++) {
+ parent->ListBox1->Items->Add((const char *)results);
+ }
+// ListBox1->Items->Pack(); // so Count is set correctly (per helpfile)
+ parent->Caption = "";
+ parent->Caption = parent->Caption + "Results from [" + (*(parent->target)).first.c_str() + "] (" + parent->ListBox1->Items->Count + ((parent->ListBox1->Items->Count == 1) ? " match)" : " matches)");
+ parent->Button1->Caption = "Search";
+ parent->Button1->OnClick = parent->Button1Click;
+}
+
+void __fastcall TForm2::TSearchThread::Execute()
+{
+ results = (*(parent->target)).second->Search(searchText.c_str(), searchType, searchOptions, scope);
+
+ Synchronize((TThreadMethod)&FillListBox);
+ parent->results = results;
+}
+
+
+
+
+void __fastcall TForm2::scopeGroupClick(TObject *Sender) {
+ bool enabled = (scopeGroup->ItemIndex == 2);
+
+ Button2->Enabled = enabled;
+ ComboBox1->Enabled = enabled;
+}
+//---------------------------------------------------------------------------
+
+void __fastcall TForm2::Button2Click(TObject *Sender)
+{
+ RangeMaintForm->ShowModal();
+ populateRanges();
+}
+//---------------------------------------------------------------------------
+
+void TForm2::populateRanges() {
+ ConfigEntMap::iterator loop, end;
+ SWConfig config("./options.conf");
+ ComboBox1->Clear();
+ loop = config.Sections["CustomRanges"].begin();
+ end = config.Sections["CustomRanges"].end();
+ while (loop != end) {
+ TCustomRange *rs = new TCustomRange(loop->first.c_str(), loop->second.c_str());
+ ComboBox1->Items->AddObject(rs->name.c_str(), rs);
+ loop++;
+ }
+}
+
+
+void __fastcall TForm2::FormShow(TObject *Sender)
+{
+ populateRanges();
+}
+//---------------------------------------------------------------------------
+