Esempio n. 1
0
void SSuperSearchBox::SuggestionSelectionChanged(TSharedPtr<FSearchEntry> NewValue)
{
	if(bIgnoreUIUpdate)
	{
		return;
	}

	if (NewValue.Get() == NULL || NewValue->bCategory)
	{
		return;
	}

	int32 CurrentCategory = INDEX_NONE;
	for(int32 i = 0; i < Suggestions.Num(); ++i)
	{
		if (Suggestions[i]->bCategory)
		{
			CurrentCategory = i;
		}

		if(NewValue == Suggestions[i])
		{
			SelectedSuggestion = i;
			MarkActiveSuggestion();

			FString const Category = CurrentCategory != INDEX_NONE ? Suggestions[CurrentCategory]->Title : FString();
			ActOnSuggestion(NewValue, Category);

			break;
		}
	}
}
Esempio n. 2
0
FReply SSuperSearchBox::OnKeyDown( const FGeometry& MyGeometry, const FKeyEvent& KeyEvent )
{
	if(SuggestionBox->IsOpen() && Suggestions.Num())
	{
		if(KeyEvent.GetKey() == EKeys::Up || KeyEvent.GetKey() == EKeys::Down)
		{
			if(KeyEvent.GetKey() == EKeys::Up)
			{
				//if we're at the top swing around
				if(SelectedSuggestion == 1)
				{
					SelectedSuggestion = Suggestions.Num() - 1;
				}
				else
				{
					// got one up
					--SelectedSuggestion;

					//make sure we're not selecting category
					if (Suggestions[SelectedSuggestion]->bCategory)
					{
						//we know that category is never shown empty so above us will be fine
						--SelectedSuggestion;
					}
				}
			}

			if(KeyEvent.GetKey() == EKeys::Down)
			{
				if(SelectedSuggestion < Suggestions.Num() - 1)
				{
					// go one down, possibly from edit control to top
					++SelectedSuggestion;

					//make sure we're not selecting category
					if (Suggestions[SelectedSuggestion]->bCategory)
					{
						//we know that category is never shown empty so below us will be fine
						++SelectedSuggestion;
					}
				}
				else
				{
					// back to edit control
					SelectedSuggestion = 1;
				}
			}

			MarkActiveSuggestion();

			return FReply::Handled();
		}
	}
	
	return FReply::Unhandled();
}
Esempio n. 3
0
void SSuperSearchBox::UpdateSuggestions()
{
	const FText & Query = InputText->GetText();
	FSearchResults * SearchResults = SearchResultsCache.Find(Query.ToString());

	//go through and build new suggestion list for list view widget
	ClearSuggestions();

	//still waiting on results for current query
	if (SearchResults == NULL)
	{
		return;
	}

	//first tutorials
	UpdateSuggestionHelper(NSLOCTEXT("SuperSearch", "tutorials", "Tutorials"), SearchResults->TutorialResults, Suggestions);

	//then docs
	UpdateSuggestionHelper(NSLOCTEXT("SuperSearch", "docs", "Documentation"), SearchResults->OnlineResults.FindOrAdd(TEXT("documentation")), Suggestions);

	//then api
	UpdateSuggestionHelper(NSLOCTEXT("SuperSearch", "API", "API"), SearchResults->OnlineResults.FindOrAdd(TEXT("api")), Suggestions);

	//then wiki
	UpdateSuggestionHelper(NSLOCTEXT("SuperSearch", "wiki", "Wiki"), SearchResults->OnlineResults.FindOrAdd(TEXT("wiki")), Suggestions);

	//then answerhub
	UpdateSuggestionHelper(NSLOCTEXT("SuperSearch", "answers", "Answerhub"), SearchResults->OnlineResults.FindOrAdd(TEXT("answers")), Suggestions);

	FSuperSearchModule& SuperSearchModule = FModuleManager::LoadModuleChecked< FSuperSearchModule >(TEXT("SuperSearch"));
	//Broadcast to anyone registered 
	SuperSearchModule.GetSearchTextChanged().Broadcast(InputText->GetText().ToString(),Suggestions);

	//finally add other category
	Suggestions.Add(OtherCategory);
	Suggestions.Add(AskQuestionEntry);

		SelectedSuggestion = 1;
		// Ideally if the selection box is open the output window is not changing it's window title (flickers)
		SuggestionBox->SetIsOpen(true, false);
		MarkActiveSuggestion();

		// Force the textbox back into focus.
	FSlateApplication::Get().SetKeyboardFocus(InputText.ToSharedRef(), EFocusCause::SetDirectly);
}
void SSuggestionTextBox::HandleSuggestionListViewSelectionChanged( TSharedPtr<FString> NewValue, ESelectInfo::Type SelectInfo )
{
	if (!IgnoreUIUpdate)
	{
		for (int32 i = 0; i < Suggestions.Num(); ++i)
		{
			if (NewValue == Suggestions[i])
			{
				SelectedSuggestion = i;

				MarkActiveSuggestion();
				FocusTextBox();

				break;
			}
		}
	}
}
FReply SSuggestionTextBox::OnKeyDown( const FGeometry& MyGeometry, const FKeyboardEvent& KeyboardEvent )
{
	const FString& InputTextStr = TextBox->GetText().ToString();

	if (MenuAnchor->IsOpen())
	{
		if (KeyboardEvent.GetKey() == EKeys::Up)
		{
			// backward navigate the list of suggestions
			if (SelectedSuggestion < 0)
			{
				SelectedSuggestion = Suggestions.Num() - 1;
			}
			else
			{
				--SelectedSuggestion;
			}

			MarkActiveSuggestion();

			return FReply::Handled();
		}
		else if(KeyboardEvent.GetKey() == EKeys::Down)
		{
			// forward navigate the list of suggestions
			if (SelectedSuggestion < Suggestions.Num() - 1)
			{
				++SelectedSuggestion;
			}
			else
			{
				SelectedSuggestion = -1;
			}

			MarkActiveSuggestion();

			return FReply::Handled();
		}
		else if (KeyboardEvent.GetKey() == EKeys::Tab)
		{
			// auto-complete the highlighted suggestion
			if (Suggestions.Num())
			{
				if ((SelectedSuggestion >= 0) && (SelectedSuggestion < Suggestions.Num()))
				{
					MarkActiveSuggestion();
					HandleTextBoxTextCommitted(TextBox->GetText(), ETextCommit::OnEnter);
				}
				else
				{
					SelectedSuggestion = 0;

					MarkActiveSuggestion();
				}
			}

			return FReply::Handled();
		}
	}
	else
	{
		if ((KeyboardEvent.GetKey() == EKeys::Up) || (KeyboardEvent.GetKey() == EKeys::Down))
		{
			// show the input history
			if (OnShowingHistory.IsBound())
			{
				TArray<FString> HistoryStrings;

				OnShowingHistory.ExecuteIfBound(HistoryStrings);

				if (HistoryStrings.Num() > 0)
				{
					SetSuggestions(HistoryStrings, true);

					if (KeyboardEvent.GetKey() == EKeys::Up)
					{
						SelectedSuggestion = HistoryStrings.Num() - 1;
					}
					else
					{
						SelectedSuggestion = 0;
					}

					MarkActiveSuggestion();
				}
			}

			return FReply::Handled();
		}
	}

	return FReply::Unhandled();
}