Skip to content

Commit

Permalink
tab-driven completion: realtime filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
elfmz committed Sep 24, 2016
1 parent 219fea7 commit 4198cd5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 51 deletions.
87 changes: 37 additions & 50 deletions far2l/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3000,6 +3000,40 @@ void EditControl::SetMenuPos(VMenu& menu)
}


static void FilteredAddToMenu(VMenu &menu, const FARString &filter, const FARString &text)
{
if (!StrCmpNI(text, filter, static_cast<int>(filter.GetLength())) && StrCmp(text, filter)) {
menu.AddItem(text);
}
}

void EditControl::PopulateCompletionMenu(VMenu &ComplMenu, const FARString &strFilter)
{
if (pCustomCompletionList)
{
for (const auto &possibility : *pCustomCompletionList)
FilteredAddToMenu(ComplMenu, strFilter, FARString(possibility));

if (ComplMenu.GetItemCount() < 10)
ComplMenu.AssignHighlights(0);
}
else
{
if(pHistory)
{
pHistory->GetAllSimilar(ComplMenu, strFilter);
}
else if(pList)
{
for(int i=0;i<pList->ItemsNumber;i++)
FilteredAddToMenu(ComplMenu, strFilter, pList->Items[i].Text);
}
if(ECFlags.Check(EC_ENABLEFNCOMPLETE))
EnumFiles(ComplMenu, strFilter);
}
}


int EditControl::AutoCompleteProc(bool Manual,bool DelBlock,int& BackKey)
{
int Result=0;
Expand All @@ -3010,38 +3044,8 @@ int EditControl::AutoCompleteProc(bool Manual,bool DelBlock,int& BackKey)
Reenter++;

VMenu ComplMenu(nullptr,nullptr,0,0);
FARString strTemp=Str;
if (pCustomCompletionList)
{
for (const auto &possibility : *pCustomCompletionList)
{
ComplMenu.AddItem(FARString(possibility));
}
if (pCustomCompletionList->size() < 10)
ComplMenu.AssignHighlights(0);
}
else
{
if(pHistory)
{
pHistory->GetAllSimilar(ComplMenu,strTemp);
}
else if(pList)
{
for(int i=0;i<pList->ItemsNumber;i++)
{
if (!StrCmpNI(pList->Items[i].Text, strTemp, static_cast<int>(strTemp.GetLength())) && StrCmp(pList->Items[i].Text, strTemp))
{
ComplMenu.AddItem(pList->Items[i].Text);
}
}
}

if(ECFlags.Check(EC_ENABLEFNCOMPLETE))
{
EnumFiles(ComplMenu,strTemp);
}
}
FARString strTemp = Str;
PopulateCompletionMenu(ComplMenu, strTemp);

if(ComplMenu.GetItemCount()>1 || (ComplMenu.GetItemCount()==1 && StrCmpI(strTemp,ComplMenu.GetItemPtr(0)->strName)))
{
Expand Down Expand Up @@ -3114,24 +3118,7 @@ int EditControl::AutoCompleteProc(bool Manual,bool DelBlock,int& BackKey)
PrevPos=0;
if(!strTemp.IsEmpty())
{
if(pHistory)
{
pHistory->GetAllSimilar(ComplMenu,strTemp);
}
else if(pList)
{
for(int i=0;i<pList->ItemsNumber;i++)
{
if (!StrCmpNI(pList->Items[i].Text, strTemp, static_cast<int>(strTemp.GetLength())) && StrCmp(pList->Items[i].Text, strTemp))
{
ComplMenu.AddItem(pList->Items[i].Text);
}
}
}
}
if(ECFlags.Check(EC_ENABLEFNCOMPLETE))
{
EnumFiles(ComplMenu,strTemp);
PopulateCompletionMenu(ComplMenu, strTemp);
}
if(ComplMenu.GetItemCount()>1 || (ComplMenu.GetItemCount()==1 && StrCmpI(strTemp,ComplMenu.GetItemPtr(0)->strName)))
{
Expand Down
2 changes: 1 addition & 1 deletion far2l/edit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class EditControl:public Edit

void SetMenuPos(VMenu& menu);
int AutoCompleteProc(bool Manual,bool DelBlock,int& BackKey);

void PopulateCompletionMenu(VMenu &ComplMenu, const FARString &strFilter);


public:
Expand Down

0 comments on commit 4198cd5

Please sign in to comment.