Changeset View
Changeset View
Standalone View
Standalone View
src/ProfileList.cpp
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | 42 | { | |||
---|---|---|---|---|---|
44 | _group = new QActionGroup(this); | 44 | _group = new QActionGroup(this); | ||
45 | 45 | | |||
46 | // Even when there are no favorite profiles, allow user to | 46 | // Even when there are no favorite profiles, allow user to | ||
47 | // create new tabs using the default profile from the menu | 47 | // create new tabs using the default profile from the menu | ||
48 | _emptyListAction = new QAction(i18n("Default profile"), _group); | 48 | _emptyListAction = new QAction(i18n("Default profile"), _group); | ||
49 | 49 | | |||
50 | // TODO - Handle re-sorts when user changes profile names | 50 | // TODO - Handle re-sorts when user changes profile names | ||
51 | ProfileManager* manager = ProfileManager::instance(); | 51 | ProfileManager* manager = ProfileManager::instance(); | ||
52 | QList<Profile::Ptr> favoriteProfiles = manager->sortedFavorites(); | | |||
53 | 52 | | |||
54 | foreach(const Profile::Ptr& profile, favoriteProfiles) { | 53 | for (const auto& profile : manager->sortedFavorites()) { | ||
55 | favoriteChanged(profile, true); | 54 | favoriteChanged(profile, true); | ||
56 | } | 55 | } | ||
57 | 56 | | |||
58 | connect(_group, &QActionGroup::triggered, this, &Konsole::ProfileList::triggered); | 57 | connect(_group, &QActionGroup::triggered, this, &Konsole::ProfileList::triggered); | ||
59 | 58 | | |||
60 | // listen for future changes to the profiles | 59 | // listen for future changes to the profiles | ||
61 | connect(manager, &Konsole::ProfileManager::favoriteStatusChanged, this, &Konsole::ProfileList::favoriteChanged); | 60 | connect(manager, &Konsole::ProfileManager::favoriteStatusChanged, this, &Konsole::ProfileList::favoriteChanged); | ||
62 | connect(manager, &Konsole::ProfileManager::shortcutChanged, this, &Konsole::ProfileList::shortcutChanged); | 61 | connect(manager, &Konsole::ProfileManager::shortcutChanged, this, &Konsole::ProfileList::shortcutChanged); | ||
63 | connect(manager, &Konsole::ProfileManager::profileChanged, this, &Konsole::ProfileList::profileChanged); | 62 | connect(manager, &Konsole::ProfileManager::profileChanged, this, &Konsole::ProfileList::profileChanged); | ||
64 | } | 63 | } | ||
65 | void ProfileList::updateEmptyAction() | 64 | void ProfileList::updateEmptyAction() | ||
66 | { | 65 | { | ||
67 | Q_ASSERT(_group); | 66 | Q_ASSERT(_group); | ||
68 | Q_ASSERT(_emptyListAction); | 67 | Q_ASSERT(_emptyListAction); | ||
69 | 68 | | |||
70 | // show this action only when it is the only action in the group | 69 | // show this action only when it is the only action in the group | ||
71 | const bool showEmptyAction = (_group->actions().count() == 1); | 70 | const bool showEmptyAction = (_group->actions().count() == 1); | ||
72 | 71 | | |||
73 | if (showEmptyAction != _emptyListAction->isVisible()) { | 72 | if (showEmptyAction != _emptyListAction->isVisible()) { | ||
74 | _emptyListAction->setVisible(showEmptyAction); | 73 | _emptyListAction->setVisible(showEmptyAction); | ||
75 | } | 74 | } | ||
76 | } | 75 | } | ||
77 | QAction* ProfileList::actionForProfile(const Profile::Ptr &profile) const | 76 | QAction* ProfileList::actionForProfile(const Profile::Ptr &profile) const | ||
78 | { | 77 | { | ||
79 | foreach(QAction* action, _group->actions()) { | 78 | for (auto *action : _group->actions()) { | ||
80 | if (action->data().value<Profile::Ptr>() == profile) { | 79 | if (action->data().value<Profile::Ptr>() == profile) { | ||
81 | return action; | 80 | return action; | ||
82 | } | 81 | } | ||
83 | } | 82 | } | ||
84 | return nullptr; // not found | 83 | return nullptr; // not found | ||
85 | } | 84 | } | ||
86 | 85 | | |||
87 | void ProfileList::profileChanged(const Profile::Ptr &profile) | 86 | void ProfileList::profileChanged(const Profile::Ptr &profile) | ||
Show All 28 Lines | |||||
116 | { | 115 | { | ||
117 | if (!sync) { | 116 | if (!sync) { | ||
118 | _registeredWidgets.remove(widget); | 117 | _registeredWidgets.remove(widget); | ||
119 | return; | 118 | return; | ||
120 | } | 119 | } | ||
121 | 120 | | |||
122 | _registeredWidgets.insert(widget); | 121 | _registeredWidgets.insert(widget); | ||
123 | 122 | | |||
124 | const QList<QAction*> currentActions = widget->actions(); | 123 | for (auto *currentAction : widget->actions()) { | ||
125 | foreach(QAction * currentAction, currentActions) { | | |||
126 | widget->removeAction(currentAction); | 124 | widget->removeAction(currentAction); | ||
127 | } | 125 | } | ||
128 | 126 | | |||
129 | widget->addActions(_group->actions()); | 127 | widget->addActions(_group->actions()); | ||
130 | } | 128 | } | ||
131 | 129 | | |||
132 | void ProfileList::addShortcutAction(const Profile::Ptr &profile) | 130 | void ProfileList::addShortcutAction(const Profile::Ptr &profile) | ||
133 | { | 131 | { | ||
134 | ProfileManager* manager = ProfileManager::instance(); | 132 | ProfileManager* manager = ProfileManager::instance(); | ||
135 | 133 | | |||
136 | auto action = new QAction(_group); | 134 | auto action = new QAction(_group); | ||
137 | action->setData(QVariant::fromValue(profile)); | 135 | action->setData(QVariant::fromValue(profile)); | ||
138 | 136 | | |||
139 | if (_addShortcuts) { | 137 | if (_addShortcuts) { | ||
140 | action->setShortcut(manager->shortcut(profile)); | 138 | action->setShortcut(manager->shortcut(profile)); | ||
141 | } | 139 | } | ||
142 | 140 | | |||
143 | updateAction(action, profile); | 141 | updateAction(action, profile); | ||
144 | 142 | | |||
145 | foreach(QWidget * widget, _registeredWidgets) { | 143 | for (auto *widget : _registeredWidgets) { | ||
146 | widget->addAction(action); | 144 | widget->addAction(action); | ||
147 | } | 145 | } | ||
148 | emit actionsChanged(_group->actions()); | 146 | emit actionsChanged(_group->actions()); | ||
149 | 147 | | |||
150 | updateEmptyAction(); | 148 | updateEmptyAction(); | ||
151 | } | 149 | } | ||
152 | 150 | | |||
153 | void ProfileList::removeShortcutAction(const Profile::Ptr &profile) | 151 | void ProfileList::removeShortcutAction(const Profile::Ptr &profile) | ||
154 | { | 152 | { | ||
155 | QAction* action = actionForProfile(profile); | 153 | QAction* action = actionForProfile(profile); | ||
156 | 154 | | |||
157 | if (action != nullptr) { | 155 | if (action != nullptr) { | ||
158 | _group->removeAction(action); | 156 | _group->removeAction(action); | ||
159 | foreach(QWidget * widget, _registeredWidgets) { | 157 | for (QWidget * widget : _registeredWidgets) { | ||
160 | widget->removeAction(action); | 158 | widget->removeAction(action); | ||
161 | } | 159 | } | ||
162 | emit actionsChanged(_group->actions()); | 160 | emit actionsChanged(_group->actions()); | ||
163 | } | 161 | } | ||
164 | updateEmptyAction(); | 162 | updateEmptyAction(); | ||
165 | } | 163 | } | ||
166 | 164 | | |||
167 | void ProfileList::favoriteChanged(const Profile::Ptr &profile, bool isFavorite) | 165 | void ProfileList::favoriteChanged(const Profile::Ptr &profile, bool isFavorite) | ||
Show All 18 Lines |