Changeset View
Changeset View
Standalone View
Standalone View
plugins/externalscript/externalscriptplugin.cpp
Show First 20 Lines • Show All 160 Lines • ▼ Show 20 Line(s) | 160 | { | |||
---|---|---|---|---|---|
161 | return m_self; | 161 | return m_self; | ||
162 | } | 162 | } | ||
163 | 163 | | |||
164 | ExternalScriptPlugin::~ExternalScriptPlugin() | 164 | ExternalScriptPlugin::~ExternalScriptPlugin() | ||
165 | { | 165 | { | ||
166 | m_self = nullptr; | 166 | m_self = nullptr; | ||
167 | } | 167 | } | ||
168 | 168 | | |||
169 | KDevelop::ContextMenuExtension ExternalScriptPlugin::contextMenuExtension( KDevelop::Context* context ) | 169 | KDevelop::ContextMenuExtension ExternalScriptPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) | ||
170 | { | 170 | { | ||
171 | m_urls.clear(); | 171 | m_urls.clear(); | ||
172 | 172 | | |||
173 | int folderCount = 0; | 173 | int folderCount = 0; | ||
174 | 174 | | |||
175 | if ( context->type() == KDevelop::Context::FileContext ) { | 175 | if ( context->type() == KDevelop::Context::FileContext ) { | ||
176 | KDevelop::FileContext* filectx = static_cast<KDevelop::FileContext*>(context); | 176 | KDevelop::FileContext* filectx = static_cast<KDevelop::FileContext*>(context); | ||
177 | m_urls = filectx->urls(); | 177 | m_urls = filectx->urls(); | ||
Show All 9 Lines | 178 | } else if ( context->type() == KDevelop::Context::ProjectItemContext ) { | |||
187 | } | 187 | } | ||
188 | } else if ( context->type() == KDevelop::Context::EditorContext ) { | 188 | } else if ( context->type() == KDevelop::Context::EditorContext ) { | ||
189 | KDevelop::EditorContext* econtext = static_cast<KDevelop::EditorContext*>(context); | 189 | KDevelop::EditorContext* econtext = static_cast<KDevelop::EditorContext*>(context); | ||
190 | m_urls << econtext->url(); | 190 | m_urls << econtext->url(); | ||
191 | } | 191 | } | ||
192 | 192 | | |||
193 | if ( !m_urls.isEmpty() ) { | 193 | if ( !m_urls.isEmpty() ) { | ||
194 | KDevelop::ContextMenuExtension ext; | 194 | KDevelop::ContextMenuExtension ext; | ||
195 | QMenu* menu = new QMenu(); | 195 | QMenu* menu = nullptr; | ||
196 | menu->setTitle( i18n("External Scripts") ); | | |||
197 | 196 | | |||
198 | for ( int row = 0; row < m_model->rowCount(); ++row ) { | 197 | for ( int row = 0; row < m_model->rowCount(); ++row ) { | ||
199 | ExternalScriptItem* item = dynamic_cast<ExternalScriptItem*>( m_model->item( row ) ); | 198 | ExternalScriptItem* item = dynamic_cast<ExternalScriptItem*>( m_model->item( row ) ); | ||
200 | Q_ASSERT( item ); | 199 | Q_ASSERT( item ); | ||
201 | 200 | | |||
202 | if (context->type() != KDevelop::Context::EditorContext) { | 201 | if (context->type() != KDevelop::Context::EditorContext) { | ||
203 | // filter scripts that depend on an opened document | 202 | // filter scripts that depend on an opened document | ||
204 | // if the context menu was not requested inside the editor | 203 | // if the context menu was not requested inside the editor | ||
Show All 14 Lines | 214 | (!item->command().contains(QStringLiteral("%d")) || | |||
219 | item->command().contains(QStringLiteral("%b")) || | 218 | item->command().contains(QStringLiteral("%b")) || | ||
220 | item->command().contains(QStringLiteral("%n")) | 219 | item->command().contains(QStringLiteral("%n")) | ||
221 | ) | 220 | ) | ||
222 | ) { | 221 | ) { | ||
223 | continue; | 222 | continue; | ||
224 | } | 223 | } | ||
225 | } | 224 | } | ||
226 | 225 | | |||
227 | QAction* scriptAction = new QAction( item->text(), this ); | 226 | if (!menu) { | ||
227 | menu = new QMenu(i18n("External Scripts"), parent); | ||||
228 | } | ||||
229 | | ||||
230 | QAction* scriptAction = new QAction(item->text(), menu); | ||||
228 | scriptAction->setData( QVariant::fromValue<ExternalScriptItem*>( item )); | 231 | scriptAction->setData( QVariant::fromValue<ExternalScriptItem*>( item )); | ||
229 | connect( scriptAction, &QAction::triggered, this, &ExternalScriptPlugin::executeScriptFromContextMenu ); | 232 | connect( scriptAction, &QAction::triggered, this, &ExternalScriptPlugin::executeScriptFromContextMenu ); | ||
230 | menu->addAction( scriptAction ); | 233 | menu->addAction( scriptAction ); | ||
231 | } | 234 | } | ||
232 | 235 | | |||
233 | if (!menu->actions().isEmpty()) | 236 | if (menu) { | ||
234 | ext.addAction( KDevelop::ContextMenuExtension::ExtensionGroup, menu->menuAction() ); | 237 | ext.addAction( KDevelop::ContextMenuExtension::ExtensionGroup, menu->menuAction() ); | ||
238 | } | ||||
235 | 239 | | |||
236 | return ext; | 240 | return ext; | ||
237 | } | 241 | } | ||
238 | 242 | | |||
239 | return KDevelop::IPlugin::contextMenuExtension( context ); | 243 | return KDevelop::IPlugin::contextMenuExtension(context, parent); | ||
240 | } | 244 | } | ||
241 | 245 | | |||
242 | void ExternalScriptPlugin::unload() | 246 | void ExternalScriptPlugin::unload() | ||
243 | { | 247 | { | ||
244 | core()->uiController()->removeToolView( m_factory ); | 248 | core()->uiController()->removeToolView( m_factory ); | ||
245 | KDevelop::IPlugin::unload(); | 249 | KDevelop::IPlugin::unload(); | ||
246 | } | 250 | } | ||
247 | 251 | | |||
▲ Show 20 Lines • Show All 125 Lines • Show Last 20 Lines |