From 3b4b5cb7b670660e7bac61a2c57fea65007d83e4 Mon Sep 17 00:00:00 2001 From: Nick Gammon Date: Sat, 23 Oct 2010 08:39:00 +1100 Subject: [PATCH] Remembered treeview or not, fixed focus problem --- dialogs/world_prefs/GenPropertyPage.h | 1 + dialogs/world_prefs/configuration.cpp | 11 +++-- dialogs/world_prefs/genpropertypage.cpp | 63 ++++++++++++++++++------- doc.h | 6 +++ doc_construct.cpp | 4 ++ scriptingoptions.cpp | 6 ++- 6 files changed, 70 insertions(+), 21 deletions(-) diff --git a/dialogs/world_prefs/GenPropertyPage.h b/dialogs/world_prefs/GenPropertyPage.h index a45459a9..5a0cf006 100644 --- a/dialogs/world_prefs/GenPropertyPage.h +++ b/dialogs/world_prefs/GenPropertyPage.h @@ -65,6 +65,7 @@ class CGenPropertyPage : public CPropertyPage CListCtrl * m_ctlList; // the list control which displays the items CStatic * m_ctlSummary; // count of items shown bool m_bWantTreeControl; // true if it wants to show a tree control instead of a list control + bool m_bReloadList; // true to reload the list in the idle loop // count of columns is used for arrays below int m_iColumnCount; // how many columns there are diff --git a/dialogs/world_prefs/configuration.cpp b/dialogs/world_prefs/configuration.cpp index 93255d7c..e48f4218 100644 --- a/dialogs/world_prefs/configuration.cpp +++ b/dialogs/world_prefs/configuration.cpp @@ -206,7 +206,7 @@ void CMUSHclientDoc:: LoadPrefsP7 (CPrefsP7 &page7) page7.CompareObjects, &m_AliasesFindInfo, XML_ALIASES, - true); // tree control + m_bTreeviewAliases); // tree control page7.m_iColumnCount = CPrefsP7::eColumnCount; page7.m_iColWidth = new int [CPrefsP7::eColumnCount]; @@ -248,7 +248,7 @@ void CMUSHclientDoc:: LoadPrefsP8 (CPrefsP8 &page8) page8.CompareObjects, &m_TriggersFindInfo, XML_TRIGGERS, - true); // tree control + m_bTreeviewTriggers); // tree control page8.m_iColumnCount = CPrefsP8::eColumnCount; page8.m_iColWidth = new int [CPrefsP8::eColumnCount]; @@ -585,7 +585,7 @@ void CMUSHclientDoc:: LoadPrefsP16 (CPrefsP16 &page16) page16.CompareObjects, &m_TimersFindInfo, XML_TIMERS, - true); // tree control + m_bTreeviewAliases); // tree control page16.m_iColumnCount = CPrefsP16::eColumnCount; @@ -2180,6 +2180,11 @@ Frame.DelayDebugStatus ("World config - loading pages"); m_strLastSelectedTimer = page16.m_strSelectedItem ; m_strLastSelectedVariable = page18.m_strSelectedItem ; + // remember whether they are using tree or list controls + m_bTreeviewAliases = page7.m_bWantTreeControl; + m_bTreeviewTriggers = page8.m_bWantTreeControl; + m_bTreeviewTimers = page16.m_bWantTreeControl; + if (iResult != IDOK) { Frame.SetStatusNormal (); diff --git a/dialogs/world_prefs/genpropertypage.cpp b/dialogs/world_prefs/genpropertypage.cpp index a48f47d4..0c0d305b 100644 --- a/dialogs/world_prefs/genpropertypage.cpp +++ b/dialogs/world_prefs/genpropertypage.cpp @@ -33,6 +33,8 @@ CGenPropertyPage::CGenPropertyPage(const UINT nID) : m_strColumnHeadings = NULL; m_iColumnCount = 0; m_bWantTreeControl = false; + m_bReloadList = false; + } // end of CGenPropertyPage::CGenPropertyPage @@ -267,7 +269,7 @@ void CGenPropertyPage::OnAddItem(CDialog & dlg) // redraw the list if (GetFilterFlag ()) - LoadList (); // full reload because it may have changed filter requirements + m_bReloadList = true; // full reload because it may have changed filter requirements // get dispatch id from the script and put it into the item @@ -571,7 +573,7 @@ void CGenPropertyPage::OnChangeItem(CDialog & dlg) // redraw the list if (GetFilterFlag ()) - LoadList (); // full reload because it may have changed filter requirements + m_bReloadList = true; // full reload because it may have changed filter requirements // resort the list @@ -831,6 +833,11 @@ HTREEITEM CGenPropertyPage::add_tree_item (CObject * pItem, if (strDescription.GetLength () > 100) strDescription = strDescription.Left (100) + " ..."; + + /* + + // looks a bit wanky + CString strLabel = GetLabel (pItem); // add the label if it exists @@ -841,6 +848,8 @@ HTREEITEM CGenPropertyPage::add_tree_item (CObject * pItem, strDescription = strDescription + "]"; } + */ + // insert it HTREEITEM hNewItem = m_cTreeCtrl.InsertItem (strDescription, hParent); @@ -1068,6 +1077,8 @@ void CGenPropertyPage::LoadList (void) SortItems (); + bool bSelected = false; + // put selected item back if (!m_strSelectedItem.IsEmpty ()) { @@ -1087,11 +1098,14 @@ void CGenPropertyPage::LoadList (void) { // select the new item m_cTreeCtrl.SelectItem (hItem); - m_cTreeCtrl.EnsureVisible (hItem); + m_cTreeCtrl.EnsureVisible (hItem); + bSelected = true; break; } } // end for each item + if (bSelected) + break; } // end for each group } // end of tree control @@ -1107,25 +1121,24 @@ void CGenPropertyPage::LoadList (void) { m_ctlList->SetItemState (nItem, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); - m_ctlList->EnsureVisible (nItem, FALSE); + m_ctlList->EnsureVisible (nItem, FALSE); + bSelected = true; break; } } // end of dealing with each item - // set the 1st item to be selected - we do this here because sorting the - // list means our first item is not necessarily the 1st item in the list - if (nItem == -1) - { - if (!m_ObjectMap->IsEmpty ()) // provided we have any - m_ctlList->SetItemState (0, LVIS_FOCUSED | LVIS_SELECTED, - LVIS_FOCUSED | LVIS_SELECTED); - } - } // end of list control } // end of having a previously-selected item + // set the 1st item to be selected - we do this here because sorting the + // list means our first item is not necessarily the 1st item in the list + if (!bSelected && !m_bWantTreeControl) + if (!m_ObjectMap->IsEmpty ()) // provided we have any + m_ctlList->SetItemState (0, LVIS_FOCUSED | LVIS_SELECTED, + LVIS_FOCUSED | LVIS_SELECTED); + CString strSummary = TFormat ("%i item%s.", PLURAL (iCount)); if (iNotShown) @@ -1155,6 +1168,22 @@ void CGenPropertyPage::LoadList (void) LRESULT CGenPropertyPage::OnKickIdle(WPARAM, LPARAM) { + /* + + Note: I was getting access violations at times, in particular when you + double-clicked to edit an entry in tree-view. I think now that this is because + LoadList deleted all items and re-added them, which meant that the tree item + which was being edited got yanked out while the Windows message was still being + processed by the system, and so it got a missing or NULL CWnd item when it didn't + expect it. I now defer reloading the list to the idle loop. + */ + + if (m_bReloadList) + { + m_bReloadList = false; + LoadList (); + } + UpdateDialogControls (AfxGetApp()->m_pMainWnd, false); return 0; } // end of CGenPropertyPage::OnKickIdle @@ -1465,11 +1494,11 @@ BOOL CGenPropertyPage::OnInitDialog() // recover column sequence m_ctlList->SendMessage (LVM_SETCOLUMNORDERARRAY, m_iColumnCount, (DWORD) iColOrder); - - LoadList (); - + delete [] iColOrder; + m_bReloadList = true; // defer so focus gets set correctly + return FALSE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } // end of CGenPropertyPage::OnInitDialog @@ -1742,7 +1771,7 @@ CString strContents; m_doc->SetModifiedFlag (TRUE); // reload the list - we don't know how many were added, and indeed, what they were - LoadList (); + m_bReloadList = true; // full reload because it may have changed filter requirements } // end of CGenPropertyPage::OnPasteItem diff --git a/doc.h b/doc.h index 858044e4..10b47002 100644 --- a/doc.h +++ b/doc.h @@ -874,6 +874,12 @@ class CMUSHclientDoc : public CDocument COLORREF m_OutputLinePreambleNotesTextColour; // text colour - Note preamble COLORREF m_OutputLinePreambleNotesBackColour; // back colour - Note preamble + // version 4.65 + + unsigned short m_bTreeviewTriggers; // show triggers in tree view? + unsigned short m_bTreeviewAliases; // show aliases in tree view? + unsigned short m_bTreeviewTimers; // show timers in tree view? + // end of stuff saved to disk ************************************************************** // stuff from pre version 11, read from disk but not saved diff --git a/doc_construct.cpp b/doc_construct.cpp index 21995978..eeca1c83 100644 --- a/doc_construct.cpp +++ b/doc_construct.cpp @@ -420,6 +420,10 @@ int i; m_iOutputWindowRedrawCount = 0; + m_bTreeviewTriggers = true; + m_bTreeviewAliases = true; + m_bTreeviewTimers = true; + // set up some default triggers for MUSHes /* diff --git a/scriptingoptions.cpp b/scriptingoptions.cpp index 67329a64..1a099c38 100644 --- a/scriptingoptions.cpp +++ b/scriptingoptions.cpp @@ -186,7 +186,11 @@ tConfigurationNumericOption OptionsTable [] = { {"timestamp_notes_back_colour", RGB (0, 0, 0), O(m_OutputLinePreambleNotesBackColour), 0, 0xFFFFFF, OPT_RGB_COLOUR | OPT_UPDATE_VIEWS}, {"timestamp_output_back_colour", RGB (0, 0, 0), O(m_OutputLinePreambleOutputBackColour),0, 0xFFFFFF, OPT_RGB_COLOUR | OPT_UPDATE_VIEWS}, {"translate_backslash_sequences", false, O(m_bTranslateBackslashSequences)}, -{"translate_german", false, O(m_bTranslateGerman)}, +{"translate_german", false, O(m_bTranslateGerman)}, +{"treeview_triggers", true, O(m_bTreeviewTriggers)}, +{"treeview_aliases", true, O(m_bTreeviewAliases)}, +{"treeview_timers", true, O(m_bTreeviewTimers)}, + {"underline_hyperlinks", true, O(m_bUnderlineHyperlinks), 0, 0, OPT_SERVER_CAN_WRITE}, {"unpause_on_send", true, O(m_bUnpauseOnSend)}, {"use_custom_link_colour", true, O(m_bUseCustomLinkColour), 0, 0, OPT_SERVER_CAN_WRITE},