Merge lp:~azzar1/unity/lp-1154364 into lp:unity

Proposed by Andrea Azzarone
Status: Needs review
Proposed branch: lp:~azzar1/unity/lp-1154364
Merge into: lp:unity
Diff against target: 52 lines (+16/-5)
1 file modified
unity-shared/SearchBar.cpp (+16/-5)
To merge this branch: bzr merge lp:~azzar1/unity/lp-1154364
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Unity Team Pending
Review via email: mp+281357@code.launchpad.net

Commit message

Propose a fix for bug #1154364. Patch originally proposed by Prasad Somwanshi.

Description of the change

Make search wait timeout depend on the search text length.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Mateusz Stachowski (stachowski-mateusz) :
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Add a new property for the max live search timeout and use live_search_wait() property instead of the default value.

In this way we can change tweak these values in other views, such as the SpreadFilter where we probably want to use different values (let's define good ones for that as well).

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Andrea, can you please check the comments here?

Unmerged revisions

4068. By Andrea Azzarone on 2015-12-26

Propose a fix for bug #1154364. Patch originally proposed by Prasad Somwanshi.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'unity-shared/SearchBar.cpp'
--- unity-shared/SearchBar.cpp 2015-06-27 04:44:51 +0000
+++ unity-shared/SearchBar.cpp 2015-12-26 09:30:45 +0000
@@ -48,6 +48,7 @@
48const double DEFAULT_SCALE = 1.0;48const double DEFAULT_SCALE = 1.0;
49const float DEFAULT_ICON_OPACITY = 1.0f;49const float DEFAULT_ICON_OPACITY = 1.0f;
50const int DEFAULT_LIVE_SEARCH_TIMEOUT = 40;50const int DEFAULT_LIVE_SEARCH_TIMEOUT = 40;
51const int MAX_LIVE_SEARCH_TIMEOUT = 250;
51const int SPINNER_TIMEOUT = 100;52const int SPINNER_TIMEOUT = 100;
52const int CORNER_RADIUS = 5;53const int CORNER_RADIUS = 5;
5354
@@ -357,10 +358,20 @@
357358
358void SearchBar::OnSearchChanged(nux::TextEntry* text_entry)359void SearchBar::OnSearchChanged(nux::TextEntry* text_entry)
359{360{
360 // We don't want to set a new search string on every new character, so we add a sma361 // We don't want to set a new search string on every new character, so we add a
361 // timeout to see if the user is typing a sentence. If more characters are added, we362 // timeout to see if the user is typing a sentence. If more characters are added, we
362 // keep restarting the timeout unti the user has actuay paused.363 // keep restarting the timeout until the user has actuay paused.
363 live_search_timeout_.reset(new glib::Timeout(live_search_wait()));364 auto search_wait = DEFAULT_LIVE_SEARCH_TIMEOUT;
365 const std::string& search_text = pango_entry_->GetText();
366 auto search_text_len = search_text.size();
367
368 if (search_text_len > 0)
369 {
370 search_wait = MAX_LIVE_SEARCH_TIMEOUT / search_text_len;
371 search_wait = std::max(search_wait, DEFAULT_LIVE_SEARCH_TIMEOUT);
372 }
373
374 live_search_timeout_.reset(new glib::Timeout(search_wait));
364 live_search_timeout_->Run(sigc::mem_fun(this, &SearchBar::OnLiveSearchTimeout));375 live_search_timeout_->Run(sigc::mem_fun(this, &SearchBar::OnLiveSearchTimeout));
365376
366 // Don't animate the spinner immediately, the searches are fast and377 // Don't animate the spinner immediately, the searches are fast and
@@ -368,14 +379,14 @@
368 start_spinner_timeout_.reset(new glib::Timeout(SPINNER_TIMEOUT));379 start_spinner_timeout_.reset(new glib::Timeout(SPINNER_TIMEOUT));
369 start_spinner_timeout_->Run(sigc::mem_fun(this, &SearchBar::OnSpinnerStartCb));380 start_spinner_timeout_->Run(sigc::mem_fun(this, &SearchBar::OnSpinnerStartCb));
370381
371 bool is_empty = pango_entry_->im_active() ? false : pango_entry_->GetText() == "";382 bool is_empty = pango_entry_->im_active() ? false : search_text_len == 0;
372 hint_->SetVisible(is_empty);383 hint_->SetVisible(is_empty);
373384
374 pango_entry_->QueueDraw();385 pango_entry_->QueueDraw();
375 hint_->QueueDraw();386 hint_->QueueDraw();
376 QueueDraw();387 QueueDraw();
377388
378 search_changed.emit(pango_entry_->GetText());389 search_changed.emit(search_text);
379}390}
380391
381bool SearchBar::OnLiveSearchTimeout()392bool SearchBar::OnLiveSearchTimeout()