void
BlogPositiveMainView::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case kRemoveCurrentBlog:
			RemoveBlog();
			break;
		case kBlogSelected:
		{
			int32 current = fListView->CurrentSelection();
			if (current == -1)
				break;
			BlogPositiveBlogListItem* blit =
				static_cast<BlogPositiveBlogListItem*>(fListView->ItemAt(current));
			BlogPositiveBlog* blog = blit->Blog();
			BlogPositivePluginLoader::FindPlugin(blog);
			fDelegate->OpenPostList(blog);
			break;
		}
		case kCreateNewBlog:
		{
			int32 index = message->GetInt32("ding", 0);
			PluginList* pluginList = BlogPositivePluginLoader::List();
			BlogPositiveBlogPlugin* plugin
				= dynamic_cast<BlogPositiveBlogPlugin*>(pluginList->ItemAt(index));
			if(plugin)
				plugin->OpenNewBlogWindow(this);
			break;
		}
		default:
			BView::MessageReceived(message);
			break;
	}
}
BlogPositiveMainView::BlogPositiveMainView(const char* name,
	BlogPositiveMainDelegate* del)
	:
	BView(name, 0)
{
	fDelegate = del;

	fListView = new BlogPositiveBlogListView();
	fListView->SetInvocationMessage(new BMessage(kBlogSelected));

	fMenuBar = new BMenuBar("MenuBar");

	fNewMenu = new BMenu(B_TRANSLATE("Add Blog"));
	fMenuBar->AddItem(fNewMenu);

	PluginList* pluginList = BlogPositivePluginLoader::List();

	fListView->Reload(gBlogList);

	for (int i = 0; i < pluginList->CountItems(); i++) {
		BlogPositivePlugin* pl = pluginList->ItemAt(i);
		if (dynamic_cast<BlogPositiveBlogPlugin*>(pl)) {
			BMessage* msg = new BMessage(kCreateNewBlog);
			msg->SetInt32("ding", i);
			msg->SetString("sendToView", Name());
			BMenuItem* mi = new BMenuItem(pl->Name(), msg);
			fNewMenu->AddItem(mi);
		}
	}

	BMessage* aMenuItemMessage = new BMessage(kRemoveCurrentBlog);
	fRemoveMenuItem = new BMenuItem(B_TRANSLATE("Remove blog"), aMenuItemMessage);
	fMenuBar->AddItem(fRemoveMenuItem);

	BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
		.Add(fMenuBar)
		.Add(new BScrollView("scroll_view", fListView, 0, false, true));
}