void CTemplateSelectDialog::OnOK() { // Get the template, if possible. CTreeCursor cursor = m_tree.GetSelectedItem(); if (cursor != NULL) { m_code = (WWhizTemplate*)cursor.GetData(); } // Save the tree state. g_wwhizTemplateManager->SaveTreeState(m_tree); // Close the dialog. TEMPLATE_SELECT_DIALOG::OnOK(); // If there wasn't a template, exit. if (!m_code) return; m_code->ResetDictionaryDefaults(); // If there are dialog wizard pages, then pop up the wizard dialog. if (m_code->GetPageCount() > 0) { CTemplateWizardDialog dlg(*m_code); if (dlg.DoModal() == IDCANCEL) return; } }
void CTemplateSelectDialog::OnRclickTsTree(NMHDR* pNMHDR, LRESULT* pResult) { CTreeCursor cursor = m_tree.GetDropHilightItem(); if (!cursor) cursor = m_tree.GetSelectedItem(); if (!cursor) return; WWhizTemplate* code = (WWhizTemplate*)cursor.GetData(); if (code) { // Open the document. ObjModelHelper objModel; if (objModel.OpenDocument(code->GetParent().GetFilename(), "Auto")) { objModel.PutLanguage("cpp"); objModel.MoveTo(code->GetLineNumber(), 1, false); objModel.ScrollToCenter(); OnCancel(); } } *pResult = 0; }
void CPageSelectSig::OnSelchangedTreeLinesig(NMHDR* pNMHDR, LRESULT* pResult) { NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; CTreeCursor bmk = m_treeSig.GetSelectedItem(); if( 0L != bmk.GetData() ) { m_strSigname = bmk.GetText(); UpdatePreview( ); } *pResult = 0; }
void CTemplateSelectDialog::OnDblclkCtTree(NMHDR* pNMHDR, LRESULT* pResult) { CTreeCursor cursor = m_tree.GetSelectedItem(); WWhizTemplate* code = (WWhizTemplate*)cursor.GetData(); if (code) OnOK(); *pResult = 0; }
static CTreeCursor AddTreeBranch(CTreeCursor cursor, const CString& branchName) { CTreeCursor foundCursor = FindTreeBranch(cursor, branchName); if (foundCursor) return foundCursor; foundCursor = cursor.AddTail(branchName); foundCursor.SetData(NULL); return foundCursor; }
static CTreeCursor FindTreeBranch(CTreeCursor cursor, LPCTSTR branchName) { cursor = cursor.GetChild(); while (cursor != NULL) { if (cursor.GetText() == branchName) { return cursor; } cursor = cursor.GetNextSibling(); } return cursor; }
void CTemplateSelectDialog::OnSelchangedCtTree(NMHDR* pNMHDR, LRESULT* pResult) { NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; // TODO: Add your control notification handler code here // int treeIndex = pNMTreeView->itemNew.lParam; // Get new index CTreeCursor cursor; cursor = m_tree.GetSelectedItem(); WWhizTemplate* code = (WWhizTemplate*)cursor.GetData(); if (code) { m_memo.SetWindowText(code->GetMemo()); } else { m_memo.SetWindowText(""); } *pResult = 0; }
/** Saves a tree control's state. **/ void TemplateManager::SaveTreeState(CTreeCtrlEx& tree) { // Save the tree state. m_treeStateFile.SetLength(0); // Grab all the template file stuff and save it, so we can later save this // information to the registry. WORD wCount = GetCount(); m_treeStateFile.Write(&wCount, sizeof(WORD)); for (int i = 0; i < (int)wCount; i++) { // Get the template file pointer. WWhizTemplateGroup* file = GetTemplateGroup(i); // Write out the template file name. WORD len = file->GetFilename().GetLength(); m_treeStateFile.Write(&len, sizeof(WORD)); m_treeStateFile.Write((LPCTSTR)file->GetFilename(), len); // Write out the time stamp. unsigned __int64 time = file->GetTimeStamp().GetTime(); m_treeStateFile.Write(&time, sizeof(unsigned __int64)); } // Write the tree item count. DWORD dwCount = tree.GetCount(); m_treeStateFile.Write(&dwCount, sizeof(DWORD)); // Now save all the tree branch stuff. CTreeCursor cursor = tree.GetRootItem(); while (cursor) { UINT state = cursor.GetState(0xFF); m_treeStateFile.Write(&state, sizeof(UINT)); cursor = cursor.GetNext(); } }
static void AddTreeItem(CTreeCursor cursor, UINT id, CString name) { int curPos = 0; int nextPos; // Autoexpand. bool autoExpand = false; if (name[0] == '+') { curPos++; autoExpand = true; } while (true) { // See if there is a sub-tree. nextPos = name.Find('|', curPos); if (nextPos == -1) break; CString branchName = name.Mid(curPos, nextPos - curPos); curPos = nextPos + 1; cursor = AddTreeBranch(cursor, branchName); if (autoExpand) cursor.GetParent().Expand(); cursor.SortChildren(); } CTreeCursor lastBranchCursor; lastBranchCursor = cursor.AddTail(name.Mid(curPos)); lastBranchCursor.SetData(id); if (autoExpand) { lastBranchCursor.Expand(); lastBranchCursor.GetParent().Expand(); } cursor.SortChildren(); }
void CTemplateSelectDialog::Refresh() { // Try refreshing the template files. bool changed = g_wwhizTemplateManager->Refresh(); // Delete all the items in the tree. m_tree.DeleteAllItems(); // Get the root tree item. CTreeCursor rootCursor = m_tree.GetRootItem(); // Walk each template file. int count = g_wwhizTemplateManager->GetCount(); for (int i = 0; i < count; i++) { // Add each template file to the root of the tree. WWhizTemplateGroup* file = g_wwhizTemplateManager->GetTemplateGroup(i); if (!file->IsActive()) continue; CTreeCursor topCursor = rootCursor.AddTail(file->GetName()); topCursor.SetData(NULL); // Add each template stored in the template file as children. for (int index = 0; index < file->GetCount(); index++) { WWhizTemplate* code = file->Get(index); if (code->GetName().GetAt(0) != '-') // - is private. AddTreeItem(topCursor, (UINT)code, code->GetName()); topCursor.SortChildren(); } } // Sort the root. rootCursor.SortChildren(); // Set the input focus to the tree. m_tree.SetFocus(); m_tree.GetRootItem().Select(); // If there wasn't a refresh, then check the tree state. if (!changed) changed |= g_wwhizTemplateManager->RestoreTreeState(m_tree); }
/** Restores a tree control's state. **/ bool TemplateManager::RestoreTreeState(CTreeCtrlEx& tree) { // Check the file length. if (m_treeStateFile.GetLength() == 0) return false; // Unchanged. // Restore the tree state. m_treeStateFile.Seek(0, CFile::begin); // Read the template file count. WORD wCount; m_treeStateFile.Read(&wCount, sizeof(WORD)); if ((int)wCount != GetCount()) return true; // Changed. // Run each template file. for (int i = 0; i < (int)wCount; i++) { CString filename; // Read in the template file name. WORD len; m_treeStateFile.Read(&len, sizeof(WORD)); LPTSTR buf = filename.GetBufferSetLength(len); m_treeStateFile.Read(buf, len); filename.ReleaseBuffer(len); // Write out the time stamp. unsigned __int64 timeIn; m_treeStateFile.Read(&timeIn, sizeof(unsigned __int64)); time_t time = timeIn; // Now, find it. int j; for (j = 0; j < GetCount(); j++) { WWhizTemplateGroup* file = GetTemplateGroup(j); // If we found a match, continue in the outer loop. if (file->GetFilename() == filename && file->GetTimeStamp() == time) break; } // If we reached the end, then the entry wasn't found. if (j == GetCount()) return true; // Changed. } // Read the tree item count. DWORD dwCount; m_treeStateFile.Read(&dwCount, sizeof(DWORD)); // One more sanity check. if (dwCount != tree.GetCount()) return true; // Changed. // Read the tree info. CTreeCursor selectedCursor; CTreeCursor cursor = tree.GetRootItem(); while (cursor) { UINT state; state = cursor.GetState(0xFF); m_treeStateFile.Read(&state, sizeof(UINT)); if (state & TVIS_EXPANDED) cursor.Expand(); else cursor.Expand(TVE_COLLAPSE); if (state & TVIS_SELECTED) { cursor.Select(TVGN_CARET | TVGN_FIRSTVISIBLE); cursor.Select(); selectedCursor = cursor; } cursor = cursor.GetNext(); } selectedCursor.EnsureVisible(); return false; }