Skip to content

Service unvailable in new tab or window #214

@maforget

Description

@maforget

Describe the bug
Some functions are not available when lists are open in a new tab or window. Things like removing books are disabled.

Exact Steps to Reproduce
Steps to reproduce the behavior:

  1. Open a List in a new tab
  2. Go back to the Library tab and switch lists
  3. Go to the previous list in the new tab
  4. The Remove entry in the context menu is grayed out.

Version/Commit (check the about page, next to the version, for the string between brackets):

Additional context
When UpdateBookList is called

private void UpdateBookList()
{
updateTimer.Stop();
using (new WaitCursor())
{
if (tvQueries.SelectedNode != null)
{
BookList = tvQueries.SelectedNode.Tag as IComicBookListProvider;
}
}
}

It sets the BookList, but when the list differ, it disconnects the ServiceRequest from the old one.

protected set
{
if (bookList != value)
{
IComicBookListProvider comicBookListProvider = bookList;
bookList = value;
if (bookList != null)
{
bookList.ServiceRequest += bookList_ServiceRequest;
}
OnBookListChanged();
if (comicBookListProvider != null)
{
comicBookListProvider.ServiceRequest -= bookList_ServiceRequest;
}
history.AddAtCursor(bookList);
}
}

So things that use QueryService might not work. When the QueryService is called it execute the OnServiceRequest. But since it is disconnected it won't trigger.

public virtual T QueryService<T>() where T : class
{
ServiceRequestEventArgs serviceRequestEventArgs = new ServiceRequestEventArgs(typeof(T), this as T);
OnServiceRequest(serviceRequestEventArgs);
return serviceRequestEventArgs.Service as T;
}
protected virtual void OnServiceRequest(ServiceRequestEventArgs e)
{
if (this.ServiceRequest != null)
{
this.ServiceRequest(this, e);
}
}

if (e.Service == null && e.ServiceType == typeof(IRemoveBooks))
{
e.Service = new RemoveBookHandler(this, Library, senderList);
}

But it seems to be a problem specifically with IRemoveBooks. Usually when BookList.QueryService<IRemoveBooks>() is called, if the caller (in this case a ComicIdListItem or ComicSmartListItem or any type of lists) doesn't implement IRemoveBooks then the Service becomes null, thus no allowing it to work with CanRemoveBooks or RemoveBooks.

public void RemoveBooks(IEnumerable<ComicBook> books)
{
IRemoveBooks removeBooks = BookList.QueryService<IRemoveBooks>();
if (removeBooks != null)
{
ItemView.BeginUpdate();
try
{
removeBooks.RemoveBooks(books, Control.ModifierKeys != Keys.Control);
}
finally
{
ItemView.EndUpdate();
}
}
}
private bool CanRemoveBooks()
{
if (itemView.InplaceEditItem == null && ComicEditMode.CanDeleteComics() && BookList != null)
{
return BookList.QueryService<IRemoveBooks>() != null;
}
return false;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions