summaryrefslogtreecommitdiff
path: root/win/Piecebar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'win/Piecebar.cpp')
-rw-r--r--win/Piecebar.cpp82
1 files changed, 75 insertions, 7 deletions
diff --git a/win/Piecebar.cpp b/win/Piecebar.cpp
index 3ef8a56..49f1249 100644
--- a/win/Piecebar.cpp
+++ b/win/Piecebar.cpp
@@ -906,17 +906,30 @@ void CPiecesBar::OnContextMenu(CWnd* pWnd, CPoint point)
if (pMenu)
{
- HTREEITEM Item = m_PiecesTree.GetSelectedItem();
bool CategorySelected = false;
- if (Item != NULL)
+ CRect r;
+ m_PiecesTree.GetWindowRect(&r);
+
+ if (r.PtInRect(point))
{
- PiecesLibrary *Lib = project->GetPiecesLibrary();
- CString CategoryName = m_PiecesTree.GetItemText(Item);
- int CategoryIndex = Lib->FindCategoryIndex((const char*)CategoryName);
+ HTREEITEM Item = m_PiecesTree.GetSelectedItem();
- if (CategoryIndex != -1)
- CategorySelected = true;
+ if (Item != NULL)
+ {
+ PiecesLibrary *Lib = project->GetPiecesLibrary();
+ CString CategoryName = m_PiecesTree.GetItemText(Item);
+ int CategoryIndex = Lib->FindCategoryIndex((const char*)CategoryName);
+
+ if (CategoryIndex != -1)
+ CategorySelected = true;
+ }
+
+ pMenu->EnableMenuItem(ID_PIECEBAR_NEWCATEGORY, MF_BYCOMMAND | MF_ENABLED);
+ }
+ else
+ {
+ pMenu->EnableMenuItem(ID_PIECEBAR_NEWCATEGORY, MF_BYCOMMAND | MF_GRAYED);
}
pMenu->EnableMenuItem(ID_PIECEBAR_REMOVECATEGORY, MF_BYCOMMAND | (CategorySelected ? MF_ENABLED : MF_GRAYED));
@@ -927,6 +940,61 @@ void CPiecesBar::OnContextMenu(CWnd* pWnd, CPoint point)
}
}
+void CPiecesBar::UpdatePiecesTree(const char* OldCategory, const char* NewCategory)
+{
+ if (OldCategory && NewCategory)
+ {
+ HTREEITEM Item = m_PiecesTree.GetChildItem(TVI_ROOT);
+
+ while (Item != NULL)
+ {
+ CString Name = m_PiecesTree.GetItemText(Item);
+
+ if (Name == OldCategory)
+ break;
+
+ Item = m_PiecesTree.GetNextSiblingItem(Item);
+ }
+
+ if (Item == NULL)
+ return;
+
+ m_PiecesTree.SetItemText(Item, NewCategory);
+
+ m_PiecesTree.EnsureVisible(Item);
+ if (m_PiecesTree.GetItemState(Item, TVIS_EXPANDED) & TVIS_EXPANDED)
+ {
+ m_PiecesTree.Expand(Item, TVE_COLLAPSE | TVE_COLLAPSERESET);
+ m_PiecesTree.Expand(Item, TVE_EXPAND);
+ }
+ }
+ else if (NewCategory)
+ {
+ HTREEITEM Item;
+ Item = m_PiecesTree.InsertItem(TVIF_CHILDREN|TVIF_PARAM|TVIF_TEXT, NewCategory, 0, 0, 0, 0, 0, TVI_ROOT, TVI_SORT);
+ m_PiecesTree.EnsureVisible(Item);
+ }
+ else if (OldCategory)
+ {
+ HTREEITEM Item = m_PiecesTree.GetChildItem(TVI_ROOT);
+
+ while (Item != NULL)
+ {
+ CString Name = m_PiecesTree.GetItemText(Item);
+
+ if (Name == OldCategory)
+ break;
+
+ Item = m_PiecesTree.GetNextSiblingItem(Item);
+ }
+
+ if (Item == NULL)
+ return;
+
+ m_PiecesTree.DeleteItem(Item);
+ }
+}
+
void CPiecesBar::UpdatePiecesTree(bool SearchOnly)
{
PiecesLibrary *Lib = project->GetPiecesLibrary();