2 * Copyright 2013 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * Nick Dedekind <nick.dedekind@canonical.com>
20#include "modelactionrootstate.h"
21#include "indicators.h"
23#include <unitymenumodel.h>
32ModelActionRootState::ModelActionRootState(QObject *parent)
33 : RootStateObject(parent),
38ModelActionRootState::~ModelActionRootState()
42UnityMenuModel* ModelActionRootState::menu() const
47void ModelActionRootState::setMenu(UnityMenuModel* menu)
50 bool wasValid = valid();
53 m_menu->disconnect(this);
58 connect(m_menu, &UnityMenuModel::rowsInserted, this, &ModelActionRootState::onModelRowsAdded);
59 connect(m_menu, &UnityMenuModel::rowsRemoved, this, &ModelActionRootState::onModelRowsRemoved);
60 connect(m_menu, &UnityMenuModel::dataChanged, this, &ModelActionRootState::onModelDataChanged);
62 connect(m_menu, &UnityMenuModel::destroyed, this, &ModelActionRootState::reset);
67 if (wasValid != valid())
68 Q_EMIT validChanged();
72bool ModelActionRootState::valid() const
74 return !currentState().empty();
77void ModelActionRootState::onModelRowsAdded(const QModelIndex& parent, int start, int end)
80 if (start == 0 && end >= 0) {
85void ModelActionRootState::onModelRowsRemoved(const QModelIndex& parent, int start, int end)
88 if (start == 0 && end >= 0) {
93void ModelActionRootState::onModelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles)
96 if (!topLeft.isValid() || !bottomRight.isValid()) {
100 if (topLeft.row() <= 0 && bottomRight.row() >= 0) {
105void ModelActionRootState::reset()
109 Q_EMIT menuChanged();
110 setCurrentState(QVariantMap());
113void ModelActionRootState::updateActionState()
115 if (m_menu && m_menu->rowCount() > 0) {
116 ActionStateParser* oldParser = m_menu->actionStateParser();
117 m_menu->setActionStateParser(&m_parser);
119 QVariantMap state = m_menu->get(0, "actionState").toMap();
121 m_menu->setActionStateParser(oldParser);
123 setCurrentState(state);
124 } else if (!m_menu) {
125 setCurrentState(QVariantMap());
127 // else if m_menu->rowCount() == 0, let's leave existing cache in place
128 // until the new menu comes in, to avoid flashing the UI empty for a moment
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list