From 8a9d55e37404c121d7ba0f29440e280a7cd1c3ec Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 14 Oct 2005 17:01:15 +0000 Subject: Added commands to edit/add/remove categories from the pieces tree context menu. git-svn-id: http://svn.leocad.org/trunk@427 c7d43263-9d01-0410-8a33-9dba5d9f93d6 --- common/library.cpp | 5 ++++ common/library.h | 4 +++ win/LeoCAD.rc | 4 +-- win/Mainfrm.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++- win/Piecebar.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++++++++----- win/Piecebar.h | 3 +- win/System.cpp | 2 ++ 7 files changed, 162 insertions(+), 11 deletions(-) diff --git a/common/library.cpp b/common/library.cpp index 370b6df..20c9ab5 100755 --- a/common/library.cpp +++ b/common/library.cpp @@ -502,6 +502,11 @@ void PiecesLibrary::AddCategory(const String& Name, const String& Keywords) SystemUpdateCategories(true); } +void PiecesLibrary::RemoveCategory(int Index) +{ + m_Categories.RemoveIndex(Index); +} + unsigned long PiecesLibrary::GetDefaultPieceGroup (const char* name) { char tmp[9]; diff --git a/common/library.h b/common/library.h index 3ecdde9..0300e04 100755 --- a/common/library.h +++ b/common/library.h @@ -41,10 +41,14 @@ public: void GetPatternedPieces(PieceInfo* Parent, PtrArray& Pieces); void SetCategory(int Index, const String& Name, const String& Keywords); void AddCategory(const String& Name, const String& Keywords); + void RemoveCategory(int Index); const char* GetCategoryName(int Index) const { return m_Categories[Index].Name; } + const char* GetCategoryKeywords(int Index) const + { return m_Categories[Index].Keywords; } + int GetNumCategories() const { return m_Categories.GetSize(); } diff --git a/win/LeoCAD.rc b/win/LeoCAD.rc index 1be254e..fb412f6 100644 --- a/win/LeoCAD.rc +++ b/win/LeoCAD.rc @@ -363,7 +363,7 @@ BEGIN POPUP "0" BEGIN MENUITEM "New Category...", ID_PIECEBAR_NEWCATEGORY - MENUITEM "Remove Category", ID_PIECEBAR_REMOVECATEGORY + MENUITEM "Remove Category...", ID_PIECEBAR_REMOVECATEGORY MENUITEM "Edit Category...", ID_PIECEBAR_EDITCATEGORY MENUITEM SEPARATOR MENUITEM "Group Pieces", ID_PIECEBAR_GROUP @@ -2051,7 +2051,7 @@ END STRINGTABLE DISCARDABLE BEGIN - ID_ACTION_SELECT "Select objects with the mouse\nSelect" + ID_ACTION_SELECT "Select objects (hold control down to select multiple objects)\nSelect" ID_ACTION_INSERT "Add pieces to the project\nInsert" ID_ACTION_LIGHT "Add a positional light source\nPositional Light" ID_ACTION_SPOTLIGHT "Add a spotlight\nSpotlight" diff --git a/win/Mainfrm.cpp b/win/Mainfrm.cpp index 4cf8901..a1cb1fc 100644 --- a/win/Mainfrm.cpp +++ b/win/Mainfrm.cpp @@ -14,6 +14,8 @@ #include "cadview.h" #include "console.h" #include "keyboard.h" +#include "system.h" +#include "library.h" #include "Print.h" @@ -984,7 +986,76 @@ BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam) project->HandleCommand(LC_HELP_ABOUT, 0); } break; - default: return CFrameWnd::OnCommand(wParam, lParam); + case ID_PIECEBAR_EDITCATEGORY: + { + HTREEITEM Item = m_wndPiecesBar.m_PiecesTree.GetSelectedItem(); + + if (Item == NULL) + break; + + PiecesLibrary* Lib = project->GetPiecesLibrary(); + CString CategoryName = m_wndPiecesBar.m_PiecesTree.GetItemText(Item); + int Index = Lib->FindCategoryIndex((const char*)CategoryName); + + if (Index == -1) + break; + + LC_CATEGORYDLG_OPTS Opts; + Opts.Name = Lib->GetCategoryName(Index); + Opts.Keywords = Lib->GetCategoryKeywords(Index); + + if (SystemDoDialog(LC_DLG_EDITCATEGORY, &Opts)) + { + String OldName = Lib->GetCategoryName(Index); + Lib->SetCategory(Index, Opts.Name, Opts.Keywords); + m_wndPiecesBar.UpdatePiecesTree(OldName, Opts.Name); + } + + } break; + + case ID_PIECEBAR_NEWCATEGORY: + { + LC_CATEGORYDLG_OPTS Opts; + Opts.Name = "New Category"; + Opts.Keywords = ""; + + if (SystemDoDialog(LC_DLG_EDITCATEGORY, &Opts)) + { + PiecesLibrary* Lib = project->GetPiecesLibrary(); + Lib->AddCategory(Opts.Name, Opts.Keywords); + m_wndPiecesBar.UpdatePiecesTree(NULL, Opts.Name); + } + + } break; + + case ID_PIECEBAR_REMOVECATEGORY: + { + HTREEITEM Item = m_wndPiecesBar.m_PiecesTree.GetSelectedItem(); + + if (Item == NULL) + break; + + PiecesLibrary* Lib = project->GetPiecesLibrary(); + CString CategoryName = m_wndPiecesBar.m_PiecesTree.GetItemText(Item); + int Index = Lib->FindCategoryIndex((const char*)CategoryName); + + if (Index == -1) + break; + + char Msg[1024]; + String Name = Lib->GetCategoryName(Index); + sprintf(Msg, "Are you sure you want to remove the %s category?", Name); + + if (SystemDoMessageBox(Msg, LC_MB_YESNO | LC_MB_ICONQUESTION) == LC_YES) + { + Lib->RemoveCategory(Index); + m_wndPiecesBar.UpdatePiecesTree(Name, NULL); + } + + } break; + + default: + return CFrameWnd::OnCommand(wParam, lParam); } return TRUE; 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(); diff --git a/win/Piecebar.h b/win/Piecebar.h index 8682133..ac87fa1 100644 --- a/win/Piecebar.h +++ b/win/Piecebar.h @@ -39,7 +39,7 @@ public: public: // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CPiecesBar) -public: + public: virtual BOOL Create(LPCTSTR lpszWindowName, CWnd* pParentWnd, CSize sizeDefault, BOOL bHasGripper, UINT nID, DWORD dwStyle = WS_CHILD | WS_VISIBLE | CBRS_TOP); virtual CSize CalcFixedLayout(BOOL bStretch, BOOL bHorz); virtual CSize CalcDynamicLayout(int nLength, DWORD dwMode); @@ -95,6 +95,7 @@ public: int m_nCurGroup; void UpdatePiecesTree(bool SearchOnly); + void UpdatePiecesTree(const char* OldCategory, const char* NewCategory); // Generated message map functions protected: diff --git a/win/System.cpp b/win/System.cpp index 2c29db4..e60bad4 100644 --- a/win/System.cpp +++ b/win/System.cpp @@ -1541,6 +1541,8 @@ bool SystemDoDialog(int nMode, void* param) { Opts->Keywords = Dlg.m_Keywords; Opts->Name = Dlg.m_Name; + + return true; } } break; -- cgit v1.2.3