| 1 | // Aseprite
|
| 2 | // Copyright (C) 2001-2015 David Capello
|
| 3 | //
|
| 4 | // This program is distributed under the terms of
|
| 5 | // the End-User License Agreement for Aseprite.
|
| 6 |
|
| 7 | #ifndef APP_FIND_WIDGET_H_INCLUDED
|
| 8 | #define APP_FIND_WIDGET_H_INCLUDED
|
| 9 | #pragma once
|
| 10 |
|
| 11 | #include "app/widget_not_found.h"
|
| 12 | #include "ui/widget.h"
|
| 13 |
|
| 14 | namespace app {
|
| 15 |
|
| 16 | template<class T>
|
| 17 | inline T* find_widget(ui::Widget* parent, const char* childId) {
|
| 18 | T* child = parent->findChildT<T>(childId);
|
| 19 | if (!child)
|
| 20 | throw WidgetNotFound(childId);
|
| 21 |
|
| 22 | return child;
|
| 23 | }
|
| 24 |
|
| 25 | class finder {
|
| 26 | public:
|
| 27 | finder(ui::Widget* parent) : m_parent(parent) {
|
| 28 | }
|
| 29 |
|
| 30 | finder& operator>>(const char* id) {
|
| 31 | m_lastId = id;
|
| 32 | return *this;
|
| 33 | }
|
| 34 |
|
| 35 | finder& operator>>(const std::string& id) {
|
| 36 | m_lastId = id;
|
| 37 | return *this;
|
| 38 | }
|
| 39 |
|
| 40 | template<typename T>
|
| 41 | finder& operator>>(T*& child) {
|
| 42 | child = app::find_widget<T>(m_parent, m_lastId.c_str());
|
| 43 | return *this;
|
| 44 | }
|
| 45 |
|
| 46 | private:
|
| 47 | ui::Widget* m_parent;
|
| 48 | std::string m_lastId;
|
| 49 | };
|
| 50 |
|
| 51 | } // namespace app
|
| 52 |
|
| 53 | #endif
|
| 54 | |