diff options
| author | Nick Dedekind <nicholas.dedekind@gmail.com> | 2013-05-13 19:24:26 +0000 |
|---|---|---|
| committer | Tarmac <> | 2013-05-13 19:24:26 +0000 |
| commit | 56ab8702f006e7bb5347ade57068483571df0d44 (patch) | |
| tree | 121ba47a0b4991c39c89d13a5aa0cc4c0c24400a /dash | |
| parent | 310b1b34a2bd78749ed7232820ec6aaf4d56d872 (diff) | |
| parent | 7d2491cc2ee6d19550bca1926700ad566d212072 (diff) | |
Result preview activated on left single-click. Normal result activation on double-click.
Approved by Michal Hruby, PS Jenkins bot. (bzr r3008.2.133)
Diffstat (limited to 'dash')
| -rw-r--r-- | dash/ResultViewGrid.cpp | 69 | ||||
| -rw-r--r-- | dash/ResultViewGrid.h | 3 |
2 files changed, 59 insertions, 13 deletions
diff --git a/dash/ResultViewGrid.cpp b/dash/ResultViewGrid.cpp index abd201beb..146034b48 100644 --- a/dash/ResultViewGrid.cpp +++ b/dash/ResultViewGrid.cpp @@ -34,6 +34,7 @@ #include "unity-shared/UBusWrapper.h" #include "unity-shared/UBusMessages.h" #include "unity-shared/GraphicsUtils.h" +#include "unity-shared/UnitySettings.h" #include "ResultViewGrid.h" #include "math.h" @@ -51,6 +52,8 @@ namespace const float FOCUSED_GHOST_ICON_OPACITY_REF = 0.7f; const float FOCUSED_ICON_SATURATION_REF = 0.5f; + + const int DOUBLE_CLICK_SPEED = 500; //500 ms (double-click speed hardcoded to 400 ms in nux) } NUX_IMPLEMENT_OBJECT_TYPE(ResultViewGrid); @@ -74,6 +77,7 @@ ResultViewGrid::ResultViewGrid(NUX_FILE_LINE_DECL) , mouse_last_y_(-1) , extra_horizontal_spacing_(0) { + EnableDoubleClick(true); SetAcceptKeyNavFocusOnMouseDown(false); auto needredraw_lambda = [&](int value) { NeedRedraw(); }; @@ -92,6 +96,7 @@ ResultViewGrid::ResultViewGrid(NUX_FILE_LINE_DECL) key_down.connect(sigc::mem_fun(this, &ResultViewGrid::OnKeyDown)); mouse_move.connect(sigc::mem_fun(this, &ResultViewGrid::MouseMove)); mouse_click.connect(sigc::mem_fun(this, &ResultViewGrid::MouseClick)); + mouse_double_click.connect(sigc::mem_fun(this, &ResultViewGrid::MouseDoubleClick)); mouse_down.connect([&](int x, int y, unsigned long mouse_state, unsigned long button_state) { @@ -142,7 +147,7 @@ ResultViewGrid::ResultViewGrid(NUX_FILE_LINE_DECL) int current_index = GetIndexForLocalResult(activated_result_); if (nav_mode == -1) // left { - current_index--; + current_index--; } else if (nav_mode == 1) // right { @@ -164,7 +169,7 @@ ResultViewGrid::ResultViewGrid(NUX_FILE_LINE_DECL) { selected_index_ = active_index_ = current_index; activated_result_ = GetLocalResultForIndex(current_index); - LOG_DEBUG(logger) << "activating preview for index: " + LOG_DEBUG(logger) << "activating preview for index: " << "(" << current_index << ")" << " " << activated_result_.uri; Activate(activated_result_, current_index, ActivateType::PREVIEW); @@ -178,11 +183,12 @@ ResultViewGrid::ResultViewGrid(NUX_FILE_LINE_DECL) void ResultViewGrid::Activate(LocalResult const& local_result, int index, ResultView::ActivateType type) { + activate_timer_.reset(); unsigned num_results = GetNumResults(); int left_results = index; int right_results = num_results ? (num_results - index) - 1 : 0; - //FIXME - just uses y right now, needs to use the absolute position of the bottom of the result + //FIXME - just uses y right now, needs to use the absolute position of the bottom of the result // (jay) Here is the fix: Compute the y position of the row where the item is located. nux::Geometry abs_geo = GetAbsoluteGeometry(); int row_y = padding + abs_geo.y; @@ -242,7 +248,7 @@ void ResultViewGrid::QueueResultsChanged() SizeReallocate(); results_changed_idle_.reset(); lazy_load_source_.reset(); // no point doing this one as well. - + if (!all_results_preloaded_) { last_lazy_loaded_result_ = 0; // reset the lazy load index in case we got an insert @@ -289,7 +295,7 @@ bool ResultViewGrid::DoLazyLoad() else if (!lazy_load_source_) { lazy_load_source_.reset(new glib::Idle(glib::Source::Priority::DEFAULT)); - lazy_load_source_->Run(sigc::mem_fun(this, &ResultViewGrid::DoLazyLoad)); + lazy_load_source_->Run(sigc::mem_fun(this, &ResultViewGrid::DoLazyLoad)); } QueueDraw(); @@ -686,7 +692,7 @@ void ResultViewGrid::DrawRow(nux::GraphicsEngine& GfxContext, ResultListBounds c break; ResultRenderer::ResultRendererState state = ResultRenderer::RESULT_RENDERER_NORMAL; - + if (enable_texture_render() == false) { if (index == selected_index_) @@ -797,19 +803,56 @@ void ResultViewGrid::MouseClick(int x, int y, unsigned long button_flags, unsign Result result = *it; selected_index_ = index; focused_result_ = result; + activated_result_ = result; + - ActivateType type = nux::GetEventButton(button_flags) == nux::MouseButton::MOUSE_BUTTON3 ? ResultView::ActivateType::PREVIEW : - ResultView::ActivateType::DIRECT; + if (nux::GetEventButton(button_flags) == nux::NUX_MOUSE_BUTTON1) + { + if (unity::Settings::Instance().double_click_activate) + { + // delay activate for single left click. (for double click check) + activate_timer_.reset(new glib::Timeout(DOUBLE_CLICK_SPEED, [this, index]() { + Activate(activated_result_, index, ResultView::ActivateType::PREVIEW); + return false; + })); + } + else + { + Activate(activated_result_, index, ResultView::ActivateType::DIRECT); + } + } + else + { + Activate(activated_result_, index, ResultView::ActivateType::PREVIEW); + } + } +} + +void ResultViewGrid::MouseDoubleClick(int x, int y, unsigned long button_flags, unsigned long key_flags) +{ + if (unity::Settings::Instance().double_click_activate == false) + return; + + unsigned num_results = GetNumResults(); + unsigned index = GetIndexAtPosition(x, y); + mouse_over_index_ = index; + if (index < num_results && nux::GetEventButton(button_flags) == nux::NUX_MOUSE_BUTTON1) + { + // we got a click on a button so activate it + ResultIterator it(GetIteratorAtRow(index)); + Result result = *it; + selected_index_ = index; + focused_result_ = result; activated_result_ = result; - Activate(activated_result_, index, type); + Activate(activated_result_, index, ResultView::ActivateType::DIRECT); } } unsigned ResultViewGrid::GetIndexAtPosition(int x, int y) { - if (x < 0 || y < 0) - return -1; + if (x < 0 || y < 0) + return -1; unsigned items_per_row = GetItemsPerRow(); @@ -841,8 +884,8 @@ std::tuple<int, int> ResultViewGrid::GetResultPosition(const unsigned int& index if (G_UNLIKELY(index >= static_cast<unsigned>(GetNumResults()) || index < 0)) { LOG_ERROR(logger) << "index (" << index << ") does not exist in this category"; - return std::tuple<int, int>(0,0); - } // out of bounds. + return std::tuple<int, int>(0,0); + } // out of bounds. int items_per_row = GetItemsPerRow(); int column_size = renderer_->width + horizontal_spacing + extra_horizontal_spacing_; diff --git a/dash/ResultViewGrid.h b/dash/ResultViewGrid.h index c996905e3..04ee41952 100644 --- a/dash/ResultViewGrid.h +++ b/dash/ResultViewGrid.h @@ -63,6 +63,7 @@ public: protected: void MouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); void MouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags); + void MouseDoubleClick(int x, int y, unsigned long button_flags, unsigned long key_flags); virtual bool DndSourceDragBegin(); virtual nux::NBitmapData* DndSourceGetDragImage(); @@ -130,6 +131,8 @@ private: glib::Source::UniquePtr lazy_load_source_; glib::Source::UniquePtr results_changed_idle_; nux::Color background_color_; + + glib::Source::UniquePtr activate_timer_; }; } // namespace dash |
