using namespace std;
-CommandFinder::CommandFinder(std::string &text, std::list<std::shared_ptr<ClickableItem>>& commands) :
+CommandFinder::CommandFinder(std::string &text, int index, bool isIndex, std::list<std::shared_ptr<ClickableItem>> &commands) :
__WORD_MATCHING_RATE(0.3), __CHAR_MATCHING_RATE(0.25), __MIN_WORD_SIZE(3), __commands(commands)
{
- _I("[CommandFinder] Initiate command searcher. text(%s)", text.c_str());
+ _I("[CommandFinder] Initiate command searcher. text(%s) index(%d), isIndex(%d)", text.c_str(), index, isIndex);
__loweredText = StringUtil::makeLowerCase(text);
__splitText = StringUtil::splitText(__loweredText, ' ');
- __index = -1;
- __isLabel = true;
-}
-
-CommandFinder::CommandFinder(int index, std::list<std::shared_ptr<ClickableItem>>& commands) :
- __WORD_MATCHING_RATE(0.3), __CHAR_MATCHING_RATE(0.25), __MIN_WORD_SIZE(3), __commands(commands)
-{
- _I("[CommandFinder] Initiate command searcher. index(%d)", index);
-
__index = index;
- __isLabel = false;
+ __isIndex = isIndex;
}
ClickableItem* CommandFinder::findCommand()
{
ClickableItem* result = nullptr;
- if (__isLabel) {
+ if (__isIndex) {
+ _I("[CommandFinder] Find command by index. index(%d)", __index);
+ result = findCommandByIndex();
+ } else {
_I("[CommandFinder] Find command by label text. text(%s)", __loweredText.c_str());
result = findCommandByText();
if (result != nullptr) {
if (result != nullptr) {
return result;
}
- } else {
- _I("[CommandFinder] Find command by index. index(%d)", __index);
+
+ _I("[CommandFinder] Fail to get command from text. Find command by index. index(%d)", __index);
result = findCommandByIndex();
+ if (result == nullptr || result->label != to_string(result->index)) {
+ _D("[CommandFinder] The result is null or not number label");
+ return nullptr;
+ }
}
return result;
class CommandFinder {
public:
- CommandFinder(std::string &text, std::list<std::shared_ptr<ClickableItem>> &__commands);
- CommandFinder(int index, std::list<std::shared_ptr<ClickableItem>> &__commands);
+ CommandFinder(std::string &text, int index, bool isIndex, std::list<std::shared_ptr<ClickableItem>> &commands);
ClickableItem* findCommand();
std::string __loweredText;
int __index;
- bool __isLabel;
+ bool __isIndex;
};
#endif /* __TIZEN_UIX_MMI_IU_COMMAND_FINDER_H__ */
\ No newline at end of file
return nullptr;
}
- unique_ptr<CommandFinder> finder;
- if (isIndex) {
- finder = make_unique<CommandFinder>(index, __commands);
- } else {
- finder = make_unique<CommandFinder>(text, __commands);
- }
-
+ auto finder = make_unique<CommandFinder>(text, index, isIndex, __commands);
auto command = finder->findCommand();
if (command != nullptr) {
_I("[CommandManager] Find command. text(%s). command(%s)", text.c_str(), command->label.c_str());
}
provider.setOutputEvent(MMI_KEY_UI_CLICKABLE_OBJECT);
- provider.setUiClickableObject(resultType, tooltipType, __itemList.size(), timestamp);
+ provider.setUiClickableObject(resultType, tooltipType, itemList->size(), timestamp);
provider.setGridDepth(__currentGridInfo.currentStep + 1);
for (auto &item : *itemList) {
- auto label = (item.label.empty() ? to_string(item.index) : item.label);
- provider.addInfoClickableObject(item.index, item.coordX, item.coordY, item.width, item.height, label.c_str());
+ if (item.label.empty()) {
+ item.label = to_string(item.index);
+ }
+ provider.addInfoClickableObject(item.index, item.coordX, item.coordY, item.width, item.height, item.label.c_str());
}
}
TEST_F(CommandFinderTest, utc_CommandFinder_Constructor)
{
string target = "test1";
- auto finder1 = new(nothrow) CommandFinder(target, commands);
- auto finder2 = new(nothrow) CommandFinder(1, commands);
+ auto finder = new(nothrow) CommandFinder(target, 1, false, commands);
- EXPECT_NE(finder1, nullptr);
- EXPECT_NE(finder2, nullptr);
+ EXPECT_NE(finder, nullptr);
- delete finder1;
- delete finder2;
+ delete finder;
}
TEST_F(CommandFinderTest, utc_CommandFinder_findCommand_p)
{
string target = "test1";
- auto finder_p = new(nothrow) CommandFinder(target, commands);
+ auto finder_p = new(nothrow) CommandFinder(target, -1, false, commands);
ASSERT_NE(finder_p, nullptr);
auto command = finder_p->findCommand();
TEST_F(CommandFinderTest, utc_CommandFinder_findCommand_p2)
{
string target = "text1";
- auto finder_p = new(nothrow) CommandFinder(target, commands);
+ auto finder_p = new(nothrow) CommandFinder(target, -1, false, commands);
ASSERT_NE(finder_p, nullptr);
auto command = finder_p->findCommand();
TEST_F(CommandFinderTest, utc_CommandFinder_findCommand_p3)
{
- auto finder_p = new(nothrow) CommandFinder(1, commands);
+ string target = "";
+ auto finder_p = new(nothrow) CommandFinder(target, 1, true, commands);
ASSERT_NE(finder_p, nullptr);
auto command = finder_p->findCommand();
TEST_F(CommandFinderTest, utc_CommandFinder_findCommand_n)
{
string target = "no matched text";
- auto finder_n = new(nothrow) CommandFinder(target, commands);
+ auto finder_n = new(nothrow) CommandFinder(target, -1, false, commands);
ASSERT_NE(finder_n, nullptr);
auto command = finder_n->findCommand();
TEST_F(CommandFinderTest, utc_CommandFinder_findCommand_n2)
{
- auto finder_n = new(nothrow) CommandFinder(-1, commands);
+ string target = "";
+ auto finder_n = new(nothrow) CommandFinder(target, -1, true, commands);
ASSERT_NE(finder_n, nullptr);
auto command = finder_n->findCommand();