Пример #1
0
bool CQueueItem::TryRemoveAll()
{
	const int oldVisibleOffspring = m_visibleOffspring;
	std::vector<CQueueItem*>::iterator iter;
	std::vector<CQueueItem*> keepChildren;
	m_visibleOffspring = 0;
	for (iter = m_children.begin() + m_removed_at_front; iter != m_children.end(); iter++)
	{
		CQueueItem* pItem = *iter;
		if (pItem->TryRemoveAll())
			delete pItem;
		else
		{
			keepChildren.push_back(pItem);
			m_visibleOffspring++;
			m_visibleOffspring += pItem->GetChildrenCount(true);
		}
	}
	m_children = keepChildren;
	m_maxCachedIndex = -1;
	m_removed_at_front = 0;

	CQueueItem* parent = GetParent();
	while (parent)
	{
		parent->m_maxCachedIndex = -1;
		parent->m_visibleOffspring -= oldVisibleOffspring - m_visibleOffspring;
		parent = parent->GetParent();
	}

	return m_children.empty();
}
Пример #2
0
bool CQueueItem::RemoveChild(CQueueItem* pItem, bool destroy /*=true*/)
{
	int oldVisibleOffspring = m_visibleOffspring;
	std::vector<CQueueItem*>::iterator iter;
	bool deleted = false;
	for (iter = m_children.begin(); iter != m_children.end(); iter++)
	{
		if (*iter == pItem)
		{
			m_visibleOffspring -= 1;
			m_visibleOffspring -= pItem->m_visibleOffspring;
			if (destroy)
				delete pItem;
			m_children.erase(iter);

			deleted = true;
			break;
		}

		int visibleOffspring = (*iter)->m_visibleOffspring;
		if ((*iter)->RemoveChild(pItem, destroy))
		{
			m_visibleOffspring -= visibleOffspring - (*iter)->m_visibleOffspring;
			if (!(*iter)->m_children.size())
			{
				m_visibleOffspring -= 1;
				delete *iter;
				m_children.erase(iter);
			}

			deleted = true;
			break;
		}
	}
	if (!deleted)
		return false;

	m_maxCachedIndex = -1;

	// Propagate new children count to parent
	CQueueItem* parent = GetParent();
	while (parent)
	{
		parent->m_maxCachedIndex = -1;
		parent->m_visibleOffspring -= oldVisibleOffspring - m_visibleOffspring;
		parent = parent->GetParent();
	}

	return true;
}
Пример #3
0
CQueueItem* CQueueItem::GetTopLevelItem()
{
    if (!m_parent)
        return this;

    CQueueItem* newParent = m_parent;
    CQueueItem* parent = 0;
    while (newParent) {
        parent = newParent;
        newParent = newParent->GetParent();
    }

    return parent;
}
Пример #4
0
void CQueueItem::AddChild(CQueueItem* item)
{
	item->m_indent = m_indent + _T("  ");
	m_children.push_back(item);

	m_visibleOffspring += 1 + item->m_visibleOffspring;
	m_maxCachedIndex = -1;
	CQueueItem* parent = GetParent();
	while (parent)
	{
		parent->m_visibleOffspring += 1 + item->m_visibleOffspring;
		parent->m_maxCachedIndex = -1;
		parent = parent->GetParent();
	}
}
Пример #5
0
void CQueueItem::AddChild(CQueueItem* item)
{
	if (m_removed_at_front)
	{
		m_children.erase(m_children.begin(), m_children.begin() + m_removed_at_front);
		m_removed_at_front = 0;
	}
	item->m_indent = m_indent + _T("  ");
	m_children.push_back(item);

	m_visibleOffspring += 1 + item->m_visibleOffspring;
	m_maxCachedIndex = -1;
	CQueueItem* parent = GetParent();
	while (parent)
	{
		parent->m_visibleOffspring += 1 + item->m_visibleOffspring;
		parent->m_maxCachedIndex = -1;
		parent = parent->GetParent();
	}
}
Пример #6
0
void CQueueItem::AddChild(CQueueItem* item)
{
    wxASSERT(GetType() != QueueItemType::Folder);
    wxASSERT(GetType() != QueueItemType::Status);

    if (m_removed_at_front) {
        m_children.erase(m_children.begin(), m_children.begin() + m_removed_at_front);
        m_removed_at_front = 0;
    }
    m_children.push_back(item);

    CQueueItem* parent = GetParent();
    while (parent) {
        if (parent->GetType() == QueueItemType::Server) {
            static_cast<CServerItem*>(parent)->m_visibleOffspring += 1 + item->GetChildrenCount(true);
            static_cast<CServerItem*>(parent)->m_maxCachedIndex = -1;
        }
        parent = parent->GetParent();
    }
}
Пример #7
0
bool CServerItem::TryRemoveAll()
{
	const int oldVisibleOffspring = m_visibleOffspring;
	std::vector<CQueueItem*>::iterator iter;
	std::vector<CQueueItem*> keepChildren;
	m_visibleOffspring = 0;
	for (iter = m_children.begin() + m_removed_at_front; iter != m_children.end(); iter++)
	{
		CQueueItem* pItem = *iter;
		if (pItem->TryRemoveAll())
		{
			if (pItem->GetType() == QueueItemType_File || pItem->GetType() == QueueItemType_Folder)
			{
				CFileItem* pFileItem = reinterpret_cast<CFileItem*>(pItem);
				RemoveFileItemFromList(pFileItem);
			}
			delete pItem;
		}
		else
		{
			keepChildren.push_back(pItem);
			m_visibleOffspring++;
			m_visibleOffspring += pItem->GetChildrenCount(true);
		}
	}
	m_children = keepChildren;
	m_removed_at_front = 0;

	CQueueItem* parent = GetParent();
	while (parent)
	{
		parent->m_visibleOffspring -= oldVisibleOffspring - m_visibleOffspring;
		parent = parent->GetParent();
	}

	return m_children.empty();
}
Пример #8
0
bool CQueueItem::RemoveChild(CQueueItem* pItem, bool destroy /*=true*/)
{
	int oldVisibleOffspring = m_visibleOffspring;
	std::vector<CQueueItem*>::iterator iter;
	bool deleted = false;
	for (iter = m_children.begin() + m_removed_at_front; iter != m_children.end(); iter++)
	{
		if (*iter == pItem)
		{
			m_visibleOffspring -= 1;
			m_visibleOffspring -= pItem->m_visibleOffspring;
			if (destroy)
				delete pItem;

			if (iter - m_children.begin() - m_removed_at_front <= 10)
			{
				m_removed_at_front++;
				unsigned int end = iter - m_children.begin();
				int c = 0;
				for (int i = end; i >= m_removed_at_front; i--, c++)
					m_children[i] = m_children[i - 1];
			}
			else
				m_children.erase(iter);

			deleted = true;
			break;
		}

		int visibleOffspring = (*iter)->m_visibleOffspring;
		if ((*iter)->RemoveChild(pItem, destroy))
		{
			m_visibleOffspring -= visibleOffspring - (*iter)->m_visibleOffspring;
			if (!((*iter)->m_children.size() - (*iter)->m_removed_at_front))
			{
				m_visibleOffspring -= 1;
				delete *iter;

				if (iter - m_children.begin() - m_removed_at_front <= 10)
				{
					m_removed_at_front++;
					unsigned int end = iter - m_children.begin();
					for (int i = end; i >= m_removed_at_front; i--)
						m_children[i] = m_children[i - 1];
				}
				else
					m_children.erase(iter);
			}

			deleted = true;
			break;
		}
	}

	if (!deleted)
		return false;

	m_maxCachedIndex = -1;

	// Propagate new children count to parent
	CQueueItem* parent = GetParent();
	while (parent)
	{
		parent->m_maxCachedIndex = -1;
		parent->m_visibleOffspring -= oldVisibleOffspring - m_visibleOffspring;
		parent = parent->GetParent();
	}

	return true;
}
Пример #9
0
bool CQueueItem::RemoveChild(CQueueItem* pItem, bool destroy, bool forward)
{
    int const oldVisibleOffspring = GetChildrenCount(true);
    int visibleOffspring = oldVisibleOffspring;

    bool deleted = false;

    auto doRemove = [&](std::vector<CQueueItem*>::iterator iter) {
        if (*iter == pItem) {
            visibleOffspring -= 1;
            visibleOffspring -= pItem->GetChildrenCount(true);
            if (destroy)
                delete pItem;

            if (iter - m_children.begin() - m_removed_at_front <= 10) {
                ++m_removed_at_front;
                unsigned int end = iter - m_children.begin();
                int c = 0;
                for (int i = end; i >= m_removed_at_front; i--, c++)
                    m_children[i] = m_children[i - 1];
            }
            else
                m_children.erase(iter);

            deleted = true;
            return;
        }

        int childVisibleOffspring = (*iter)->GetChildrenCount(true);
        if ((*iter)->RemoveChild(pItem, destroy)) {
            visibleOffspring -= childVisibleOffspring - (*iter)->GetChildrenCount(true);
            if (!((*iter)->m_children.size() - (*iter)->m_removed_at_front)) {
                visibleOffspring -= 1;
                delete *iter;

                if (iter - m_children.begin() - m_removed_at_front <= 10) {
                    ++m_removed_at_front;
                    unsigned int end = iter - m_children.begin();
                    for (int i = end; i >= m_removed_at_front; i--)
                        m_children[i] = m_children[i - 1];
                }
                else
                    m_children.erase(iter);
            }

            deleted = true;
        }
    };

    if (forward) {
        for (auto iter = m_children.begin() + m_removed_at_front; iter != m_children.end(); ++iter ) {
            doRemove(iter);
            if (deleted) {
                break;
            }
        }
    }
    else {
        for (auto iter = m_children.rbegin(); iter != m_children.rend() - m_removed_at_front; ++iter ) {
            doRemove(iter.base() - 1);
            if (deleted) {
                break;
            }
        }
    }

    if (!deleted)
        return false;

    if (GetType() == QueueItemType::Server) {
        static_cast<CServerItem*>(this)->m_visibleOffspring = visibleOffspring;
    }

    // Propagate new children count to parent
    CQueueItem* parent = GetParent();
    while (parent) {
        if (parent->GetType() == QueueItemType::Server) {
            static_cast<CServerItem*>(parent)->m_maxCachedIndex = -1;
            static_cast<CServerItem*>(parent)->m_visibleOffspring -= oldVisibleOffspring - visibleOffspring;
        }
        parent = parent->GetParent();
    }

    return true;
}