⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resorgsymbolslistview.cpp

📁 ResOrg 图形化管理Vc项目的资源ID的工具的源代码。 ResOrg - Manage and Renumber Resource Symbol IDs Introduction The
💻 CPP
📖 第 1 页 / 共 3 页
字号:

	ASSERT(NULL != pMap);

	POSITION pos = pMap->GetStartPosition();

	// Zoom through the map...
	CString sKey;
	CResourceSymbol* pSymbol = NULL;
	while (NULL != pos)
	{
		pMap->GetNextAssoc(pos, sKey, (LPVOID&)pSymbol );

		if (NULL != pSymbol)
		{
			LV_FINDINFO FindInfo;
			FindInfo.flags = LVFI_PARAM;
			FindInfo.lParam = (DWORD)pSymbol;
			int nItem = GetListCtrl().FindItem(&FindInfo);
			if (nItem >= 0)
			{
				GetListCtrl().SetItemState(nItem, /*LVIS_FOCUSED |*/ LVIS_SELECTED, 0xff);
			}
		}
	}
#endif
}


void CResOrgSymbolsListView::OnUpdateEditSelectAll(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable( TRUE );
//	pCmdUI->Enable( !GetDocument()->IsEmpty() );
}


/// Handler for the ID_SYM_PROPERTIES command.
///
/// If a single symbol is selected, this handler opens its properties.
/// If there is no selection or a multiple selection, the command is
/// allowed to continue routing. In this case, the document (CResOrgSymbolsDoc)
/// will handle the command to open the properties of the file instead.
///
BOOL CResOrgSymbolsListView::OnCmdSymbolProperties(UINT nID /*= 0*/)
{
	UNREFERENCED_PARAMETER(nID);

	CResourceSymbol* pSymbol = m_ctrlSymbols.GetSelection();
	if (NULL != pSymbol)
	{
		// Create a dialog object and let it do the difficult bit
		CSymbolPropertySheet dlg(IDP_SYM_PROPERTIES_CAPTION, this);

		dlg.Initialise( GetDocument()->GetSymbolBuffer(),
						pSymbol);

		if (IDOK == dlg.DoModal())
		{
			GetDocument()->Set(	pSymbol,
								dlg.GeneralPage().GetName(),
								dlg.GeneralPage().GetValue(),
								(FALSE != dlg.GeneralPage().IsReadOnly() ) );

			GetDocument()->CheckNextSymbolValues( Options.WarnIfNextSymbolValuesInUse() );
		}
		return true;		// Handled
	}
	return false;			// Not handled
}


void CResOrgSymbolsListView::OnCmdAddSymbol(void)
{
	CResourceSymbolManager* pManager = GetDocument()->GetSymbolBuffer();
	if (NULL == pManager)
	{
		ASSERT(FALSE);
		return;
	}

	CString sName = pManager->GetUnusedName(SYM_RESOURCE);
	ASSERT(!sName.IsEmpty());

	CResourceSymbol Symbol(sName, pManager->GetNextResourceValue() );

	// Create a dialog object and let it do the difficult bit
	CSymbolPropertySheet dlg(IDP_SYM_ADD_CAPTION, this);

	dlg.Initialise(pManager, &Symbol);

	dlg.GeneralPage().DisableSymbolChangeWarnings();		// This is a new symbol, so don't warn

	if (IDOK == dlg.DoModal())
	{
		CResourceSymbol* pSymbol = GetDocument()->Add(	dlg.GeneralPage().GetName(),
														dlg.GeneralPage().GetValue(),
														0);

		ASSERT(NULL!= pSymbol);
		if (NULL!= pSymbol)
		{
			pSymbol->SetReadOnly(FALSE != dlg.GeneralPage().IsReadOnly() );

			GetDocument()->UpdateAllViews(NULL, SYM_CHANGED, (CObject*)pSymbol);	// For read only attribute only
		
			// Select the new symbol
			int nItem = m_ctrlSymbols.FindSymbol(pSymbol);
			if (nItem >= 0)
			{
				m_ctrlSymbols.EnsureVisible(nItem, FALSE);

				m_ctrlSymbols.SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
			}
		}
	}
}


void CResOrgSymbolsListView::OnUpdateAddSymbol(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(!GetDocument()->GetSymbolBuffer()->IsKindOf(RUNTIME_CLASS(CResourceSymbolManagerMultiFile) ) );
}


void CResOrgSymbolsListView::OnCmdDeleteSymbol(void) 
{
	CResourceSymbol* pSymbol = NULL;
	switch (m_ctrlSymbols.GetSelectedCount())
	{
		case 1:
			pSymbol = m_ctrlSymbols.GetSelection();
			if (NULL != pSymbol)			// Single selection
			{
				BOOL bOkToDelete = TRUE;
				if (Options.WarnOnSymbolChanges())
				{
					if (!ConfirmDelete(pSymbol->GetName() ) )
					{
						bOkToDelete = FALSE;
					}
				}
				if (bOkToDelete)
				{
					GetDocument()->Remove(pSymbol);
				}
			}
			break;

		default:						// Multiple (or no) selection
			BOOL bOkToDelete = TRUE;
			if (Options.WarnOnSymbolChanges())
			{
				if (!ConfirmDelete() )
				{
					bOkToDelete = FALSE;
				}
			}
			if (bOkToDelete)
			{
				CResourceSymbolList listSymbols;
				m_ctrlSymbols.GetSelection(listSymbols);

				ASSERT(listSymbols.GetCount() > 0);
				POSITION pos = listSymbols.GetHeadPosition();

				while (NULL != pos)
				{
					pSymbol = listSymbols.GetNext(pos);

					GetDocument()->GetSymbolBuffer()->Remove(pSymbol);
					delete pSymbol;
				}
				GetDocument()->SetModifiedFlag();

				GetDocument()->UpdateAllViews(NULL, SYM_REFRESH, NULL);
			}
			break;
	}
}


void CResOrgSymbolsListView::OnUpdateDeleteSymbol(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable( m_ctrlSymbols.GetSelectedCount() >= 1 );
}


LRESULT CResOrgSymbolsListView::OnHelpHitTest(WPARAM, LPARAM)
{
	return IDR_DISPLAY_SYMBOLS + HID_BASE_RESOURCE;
}


void CResOrgSymbolsListView::OnCmdRestoreOriginalValue(void)
{
	POSITION pos = m_ctrlSymbols.GetFirstSelectedItemPosition();
	while (pos != NULL)
	{
		int nItem = m_ctrlSymbols.GetNextSelectedItem(pos);

		CResourceSymbol* pSymbol = (CResourceSymbol*)m_ctrlSymbols.GetItemData(nItem);

		if ( (NULL != pSymbol) && !pSymbol->IsReadOnly() )
		{
			UINT uOriginalValue = pSymbol->GetOriginalValue();
			if (uOriginalValue > 0)
			{
				GetDocument()->Set(	pSymbol,
									pSymbol->GetName(),
									uOriginalValue,
									FALSE);
			}
		}
	}
	GetDocument()->CheckNextSymbolValues( Options.WarnIfNextSymbolValuesInUse() );
}


void CResOrgSymbolsListView::OnUpdateRestoreOriginalValue(CCmdUI* pCmdUI)
{
	BOOL bEnable = FALSE;

	POSITION pos = m_ctrlSymbols.GetFirstSelectedItemPosition();
	while (pos != NULL)
	{
		int nItem = m_ctrlSymbols.GetNextSelectedItem(pos);

		CResourceSymbol* pSymbol = (CResourceSymbol*)m_ctrlSymbols.GetItemData(nItem);

		if (NULL != pSymbol)
		{
			if (!pSymbol->IsReadOnly() && (pSymbol->GetOriginalValue() > 0) )
			{
				bEnable = TRUE;
				break;
			}
		}
	}
	pCmdUI->Enable(bEnable);
}


void CResOrgSymbolsListView::OnCmdFixSymbolValue(void)
{
	BOOL bFailed = FALSE;

	// Create a list of the selected symbols first
	// This ensures the iteration isn't affected by our changes
	CResourceSymbolList listSymbols;

	POSITION pos = m_ctrlSymbols.GetFirstSelectedItemPosition();
	while (pos != NULL)
	{
		int nItem = m_ctrlSymbols.GetNextSelectedItem(pos);

		CResourceSymbol* pSymbol = (CResourceSymbol*)m_ctrlSymbols.GetItemData(nItem);

		listSymbols.AddTail(pSymbol);
	}

	// Now fix them!
	pos = listSymbols.GetHeadPosition();
	while (NULL != pos)
	{
		CResourceSymbol* pSymbol = listSymbols.GetNext(pos);

		if ( (NULL != pSymbol) && !pSymbol->IsReadOnly() )
		{
			CResourceSymbolManager* pManager = GetDocument()->GetSymbolBuffer();

			if (pSymbol->HasConflicts() || pManager->IsOutOfRange(pSymbol) )
			{
				UINT uNewValue = pManager->GetBaseSymbolValue( pSymbol->GetType() );

				while (!IsValueUnique(pSymbol, uNewValue) )
				{
					uNewValue++;
					if (uNewValue >= IDC_STATIC)
					{
						bFailed = TRUE;
						ASSERT(FALSE);
						break;		// Can't fix this one
					}
				}
				if (!bFailed)
				{
					GetDocument()->Set(	pSymbol,
										pSymbol->GetName(),
										uNewValue,
										FALSE);
				}
			}
		}
	}

	// Remove any symbols that should no longer be visible
	if (m_ctrlSymbols.ShowProblemSymbolsOnly() )
	{
		if (GetDocument()->GetSymbolBuffer()->GetProblemSymbolCount() > 0)
		{
			CResourceSymbolList listSymbolsToRemove;

			for (int nItem = 0; nItem < m_ctrlSymbols.GetItemCount(); nItem++)
			{
				CResourceSymbol* pSymbol = m_ctrlSymbols.GetSymbol(nItem);

				if (!m_ctrlSymbols.IsVisible(pSymbol) )
				{
					listSymbolsToRemove.AddTail(pSymbol);
				}
			}
			POSITION pos = listSymbolsToRemove.GetHeadPosition();
			while (NULL != pos)
			{
				CResourceSymbol* pSymbol = listSymbolsToRemove.GetNext(pos);

				m_ctrlSymbols.RemoveSymbol(pSymbol);
			}
		}
		else
		{
			// There aren't any symbols left with conflicts - show the lot!
			m_ctrlSymbols.ShowProblemSymbolsOnly(false);
		}
	}

	GetDocument()->CheckNextSymbolValues( Options.WarnIfNextSymbolValuesInUse() );
}


void CResOrgSymbolsListView::OnUpdateFixSymbolValue(CCmdUI* pCmdUI)
{
	BOOL bEnable = FALSE;

	POSITION pos = m_ctrlSymbols.GetFirstSelectedItemPosition();
	while (pos != NULL)
	{
		int nItem = m_ctrlSymbols.GetNextSelectedItem(pos);

		CResourceSymbol* pSymbol = (CResourceSymbol*)m_ctrlSymbols.GetItemData(nItem);

		if ( (NULL != pSymbol) && !pSymbol->IsReadOnly() )
		{
			if (pSymbol->HasConflicts() ||
				GetDocument()->GetSymbolBuffer()->IsOutOfRange(pSymbol) )
			{
				bEnable = TRUE;
				break;
			}
		}
	}
	pCmdUI->Enable(bEnable);
}


void CResOrgSymbolsListView::OnCmdShowProblemSymbolsOnly(void)
{
	CWaitCursor wait;

	m_ctrlSymbols.ShowProblemSymbolsOnly( !m_ctrlSymbols.ShowProblemSymbolsOnly() );
}


void CResOrgSymbolsListView::OnUpdateShowProblemSymbolsOnly(CCmdUI* pCmdUI)
{
	pCmdUI->SetCheck( m_ctrlSymbols.ShowProblemSymbolsOnly() );
}


void CResOrgSymbolsListView::OnCmdPreviousProblemSymbol(void)
{
	bool bFound = false;

	int nStartItem = m_ctrlSymbols.GetItemCount();

	POSITION pos = m_ctrlSymbols.GetFirstSelectedItemPosition();
	while (NULL != pos)
	{
		nStartItem = m_ctrlSymbols.GetNextSelectedItem(pos);
		m_ctrlSymbols.SetItemState(nStartItem, !LVIS_SELECTED, LVIS_SELECTED);

		if (0 == nStartItem)
		{
			nStartItem = m_ctrlSymbols.GetItemCount();
		}
	}

	for (int nItem = nStartItem - 1; nItem >= 0; nItem--)
	{
		CResourceSymbol* pSymbol = m_ctrlSymbols.GetSymbol(nItem);
		ASSERT(NULL != pSymbol);

		if (NULL != pSymbol)
		{
			if (pSymbol->HasConflicts() || GetDocument()->GetSymbolBuffer()->IsOutOfRange(pSymbol) )
			{
				m_ctrlSymbols.EnsureVisible(nItem, FALSE);
				m_ctrlSymbols.SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
				bFound = true;
				break;
			}
		}
		if (nItem == 0 )
		{
			nItem = m_ctrlSymbols.GetItemCount();
		}
	}
}


void CResOrgSymbolsListView::OnUpdatePreviousProblemSymbol(CCmdUI* pCmdUI)
{
	pCmdUI->Enable(GetDocument()->GetSymbolBuffer()->GetProblemSymbolCount() > 0);
}


void CResOrgSymbolsListView::OnCmdNextProblemSymbol(void)
{
	bool bFound = false;

	int nStartItem = 0;

	POSITION pos = m_ctrlSymbols.GetFirstSelectedItemPosition();
	if (NULL != pos)
	{
		nStartItem = m_ctrlSymbols.GetNextSelectedItem(pos);
		m_ctrlSymbols.SetItemState(nStartItem, !LVIS_SELECTED, LVIS_SELECTED);
	}

	for (int nItem = nStartItem + 1; nItem < m_ctrlSymbols.GetItemCount(); nItem++)
	{
		CResourceSymbol* pSymbol = m_ctrlSymbols.GetSymbol(nItem);
		ASSERT(NULL != pSymbol);

		if (NULL != pSymbol)
		{
			if (pSymbol->HasConflicts() || GetDocument()->GetSymbolBuffer()->IsOutOfRange(pSymbol) )
			{
				m_ctrlSymbols.EnsureVisible(nItem, FALSE);
				m_ctrlSymbols.SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
				bFound = true;
				break;
			}
		}
		if (nItem + 1 == m_ctrlSymbols.GetItemCount() )
		{
			nItem = 0;
		}
	}
}


void CResOrgSymbolsListView::OnUpdateNextProblemSymbol(CCmdUI* pCmdUI)
{
	pCmdUI->Enable(GetDocument()->GetSymbolBuffer()->GetProblemSymbolCount() > 0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -