Shows an effect or command dialog so the user can specify settings for later ! It is used when defining a macro. It does not invoke the effect or command. */
| 251 | It is used when defining a macro. It does not invoke the effect or command. |
| 252 | */ |
| 253 | bool EffectAndCommandPluginManager::PromptUser( |
| 254 | const PluginID& ID, AudacityProject& project, DialogInvoker dialogInvoker) |
| 255 | { |
| 256 | bool result = false; |
| 257 | if (auto effect = dynamic_cast<Effect*>(EffectManager::Get().GetEffect(ID))) |
| 258 | { |
| 259 | auto empty = TrackList::Create(nullptr); |
| 260 | auto pEffectBase = dynamic_cast<EffectBase*>(effect); |
| 261 | if (pEffectBase) |
| 262 | // This allows effects to call Init() safely |
| 263 | pEffectBase->SetTracks(empty.get()); |
| 264 | Finally Do([&] { |
| 265 | // reverse the side-effect |
| 266 | if (pEffectBase) |
| 267 | pEffectBase->SetTracks(nullptr); |
| 268 | }); |
| 269 | |
| 270 | std::shared_ptr<EffectInstance> pInstance; |
| 271 | //! Show the effect dialog, only so that the user can choose settings, |
| 272 | //! for instance to define a macro. |
| 273 | if (const auto pSettings = EffectManager::Get().GetDefaultSettings(ID)) |
| 274 | result = dialogInvoker(*effect, *pSettings, pInstance); |
| 275 | return result; |
| 276 | } |
| 277 | |
| 278 | AudacityCommand* command = GetAudacityCommand(ID); |
| 279 | |
| 280 | if (command) |
| 281 | { |
| 282 | result = command->PromptUser(project); |
| 283 | return result; |
| 284 | } |
| 285 | |
| 286 | return result; |
| 287 | } |