~sethj/ubuntu/wily/unity/fix-for-1445595

« back to all changes in this revision

Viewing changes to UnityCore/Scopes.cpp

New libunity scope API.

Show diffs side-by-side

added added

removed removed

Lines of Context:
240
240
  return pimpl->GetScopeForShortcut(scope_shortcut);
241
241
}
242
242
 
 
243
void Scopes::AppendScope(std::string const& scope_id)
 
244
{
 
245
  InsertScope(scope_id, pimpl->scopes_.size());
 
246
}
 
247
 
243
248
void Scopes::InsertScope(std::string const& scope_id, unsigned index)
244
249
{
245
250
  if (!pimpl->scopes_reader_)
248
253
  ScopeData::Ptr scope_data(pimpl->scopes_reader_->GetScopeDataById(scope_id));
249
254
  if (scope_data)
250
255
    pimpl->InsertScope(scope_data, index);
 
256
 
 
257
  // Fallback - manually create and insert the scope.
 
258
  auto scope_data_position = std::find_if(pimpl->scopes_.begin(),
 
259
                                     pimpl->scopes_.end(),
 
260
                                     [scope_id](Scope::Ptr const& scope) { return scope->id() == scope_id; });
 
261
  if (scope_data_position == pimpl->scopes_.end())
 
262
  {
 
263
    glib::Error error;
 
264
    ScopeData::Ptr scope_data(ScopeData::ReadProtocolDataForId(scope_id, error));
 
265
    // manually created scopes are not visible.
 
266
    scope_data->visible = false;
 
267
    if (scope_data && !error)
 
268
    {
 
269
      pimpl->InsertScope(scope_data, index);
 
270
    }
 
271
  }
251
272
}
252
273
 
253
274
void Scopes::RemoveScope(std::string const& scope_id)