Skip to content

Commit 80fcb67

Browse files
committed
Refactor: Replace inheritance with composition for Dialogs
1 parent 86a3ce2 commit 80fcb67

File tree

11 files changed

+362
-277
lines changed

11 files changed

+362
-277
lines changed

Explorer.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@
269269
<ClCompile Include="src\Explorer\QuickOpenDialog.cpp" />
270270
<ClCompile Include="src\Explorer\ThemeRenderer.cpp" />
271271
<ClCompile Include="src\Explorer\ToolBar.cpp" />
272-
<ClCompile Include="src\Explorer\TreeHelperClass.cpp" />
272+
<ClCompile Include="src\Explorer\TreeView.cpp" />
273273
<ClCompile Include="src\Explorer\URLCtrl.cpp" />
274274
<ClCompile Include="src\NppPlugin\DockingFeature\StaticDialog.cpp" />
275275
</ItemGroup>
@@ -305,7 +305,7 @@
305305
<ClInclude Include="src\Explorer\StringUtil.h" />
306306
<ClInclude Include="src\Explorer\ThemeRenderer.h" />
307307
<ClInclude Include="src\Explorer\ToolBar.h" />
308-
<ClInclude Include="src\Explorer\TreeHelperClass.h" />
308+
<ClInclude Include="src\Explorer\TreeView.h" />
309309
<ClInclude Include="src\Explorer\URLCtrl.h" />
310310
<ClInclude Include="src\Explorer\version.h" />
311311
<ClInclude Include="src\Explorer\Graphics.h" />

Explorer.vcxproj.filters

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
<ClCompile Include="src\Explorer\ToolBar.cpp">
9494
<Filter>src\Explorer</Filter>
9595
</ClCompile>
96-
<ClCompile Include="src\Explorer\TreeHelperClass.cpp">
96+
<ClCompile Include="src\Explorer\TreeView.cpp">
9797
<Filter>src\Explorer</Filter>
9898
</ClCompile>
9999
<ClCompile Include="src\Explorer\URLCtrl.cpp">
@@ -190,7 +190,7 @@
190190
<ClInclude Include="src\Explorer\ToolBar.h">
191191
<Filter>src\Explorer</Filter>
192192
</ClInclude>
193-
<ClInclude Include="src\Explorer\TreeHelperClass.h">
193+
<ClInclude Include="src\Explorer\TreeView.h">
194194
<Filter>src\Explorer</Filter>
195195
</ClInclude>
196196
<ClInclude Include="src\Explorer\URLCtrl.h">

src/Explorer/ExplorerDialog.cpp

Lines changed: 91 additions & 96 deletions
Large diffs are not rendered by default.

src/Explorer/ExplorerDialog.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2828
#include "Explorer.h"
2929
#include "ExplorerContext.h"
3030
#include "FileList.h"
31-
#include "TreeHelperClass.h"
31+
#include "TreeView.h"
3232
#include "ToolBar.h"
3333
#include "../NppPlugin/DockingFeature/DockingDlgInterface.h"
3434

@@ -52,7 +52,7 @@ struct GetVolumeInfo {
5252
LPBOOL pIsValidDrive;
5353
};
5454

55-
class ExplorerDialog : public DockingDlgInterface, public TreeHelper, public CIDropTarget, public ExplorerContext
55+
class ExplorerDialog : public DockingDlgInterface, public CIDropTarget, public ExplorerContext
5656
{
5757
public:
5858
ExplorerDialog();
@@ -167,4 +167,5 @@ class ExplorerDialog : public DockingDlgInterface, public TreeHelper, public CID
167167
BOOL _isDnDStarted;
168168

169169
INT _iDockedPos;
170+
TreeView _hTreeCtrl;
170171
};

src/Explorer/FavesDialog.cpp

Lines changed: 83 additions & 103 deletions
Large diffs are not rendered by default.

src/Explorer/FavesDialog.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2525

2626
#include "Explorer.h"
2727
#include "FavesModel.h"
28-
#include "TreeHelperClass.h"
28+
#include "TreeView.h"
2929
#include "ToolBar.h"
3030
#include "../NppPlugin/DockingFeature/DockingDlgInterface.h"
3131

@@ -47,7 +47,7 @@ enum MenuID {
4747
};
4848

4949

50-
class FavesDialog : public DockingDlgInterface, public TreeHelper
50+
class FavesDialog : public DockingDlgInterface
5151
{
5252
public:
5353
FavesDialog();
@@ -101,7 +101,6 @@ class FavesDialog : public DockingDlgInterface, public TreeHelper
101101
BOOL DoesLinkExist(LPTSTR link, FavesType type);
102102
void OpenLink(FavesItemPtr pElem);
103103
void UpdateLink(HTREEITEM hParentItem);
104-
void UpdateNode(HTREEITEM hItem, BOOL haveChildren);
105104

106105
void DrawSessionChildren(HTREEITEM hItem);
107106

@@ -141,4 +140,5 @@ class FavesDialog : public DockingDlgInterface, public TreeHelper
141140

142141
/* database */
143142
FavesModel _model;
143+
TreeView _hTreeCtrl;
144144
};

src/Explorer/OptionDialog.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,9 @@ class OptionDlg : public StaticDialog
3232
OptionDlg();
3333
~OptionDlg();
3434

35-
void init(HINSTANCE hInst, HWND hParent)
36-
{
37-
Window::init(hInst, hParent);
38-
};
39-
4035
INT_PTR doDialog(ExProp *prop);
4136

42-
virtual void destroy() {};
43-
37+
void destroy() override {}
4438

4539
protected :
4640
INT_PTR CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) override;

src/Explorer/PropDlg.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ INT_PTR CALLBACK PropDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam
111111
}
112112

113113
SetFocus(::GetDlgItem(_hSelf, IDC_EDIT_NAME));
114-
_hTreeCtrl = ::GetDlgItem(_hSelf, IDC_TREE_SELECT);
114+
_hTreeCtrl.Attach(::GetDlgItem(_hSelf, IDC_TREE_SELECT));
115115

116116
goToCenter();
117117

@@ -155,16 +155,16 @@ INT_PTR CALLBACK PropDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam
155155
return elem->IsGroup();
156156
});
157157

158-
HTREEITEM hItem = InsertItem(_root->m_name, iIconPos, _iUImgPos, 0, 0, TVI_ROOT, TVI_LAST, canExpand, _root);
158+
HTREEITEM hItem = _hTreeCtrl.InsertItem(_root->m_name, iIconPos, _iUImgPos, 0, 0, TVI_ROOT, TVI_LAST, canExpand, _root);
159159

160160
SendMessage(_hTreeCtrl, WM_SETREDRAW, FALSE, 0);
161161
ExpandTreeView(hItem);
162162
SendMessage(_hTreeCtrl, WM_SETREDRAW, TRUE, 0);
163163

164164
if (_selectedGroup) {
165-
hItem = FindTreeItemByParam(_selectedGroup);
165+
hItem = _hTreeCtrl.FindTreeItemByParam(_selectedGroup);
166166
}
167-
TreeView_SelectItem(_hTreeCtrl, hItem);
167+
_hTreeCtrl.SelectItem(hItem);
168168

169169
::SetWindowText(::GetDlgItem(_hSelf, IDC_BUTTON_DETAILS), L"Details <<");
170170
}
@@ -280,16 +280,16 @@ INT_PTR CALLBACK PropDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam
280280
SendDlgItemMessage(_hSelf, IDC_EDIT_LINK, WM_GETTEXT, lengthLink, (LPARAM)_pLink);
281281

282282
if ((wcslen(_pName) != 0) && (wcslen(_pLink) != 0)) {
283-
auto *selectedItem = TreeView_GetSelection(_hTreeCtrl);
284-
_selectedGroup = (FavesItemPtr)GetParam(selectedItem);
283+
auto *selectedItem = _hTreeCtrl.GetSelection();
284+
_selectedGroup = (FavesItemPtr)_hTreeCtrl.GetParam(selectedItem);
285285
::EndDialog(_hSelf, TRUE);
286286
return TRUE;
287287
}
288288
::MessageBox(_hParent, L"Fill out all fields!", L"Error", MB_OK);
289289
}
290290
else {
291-
auto *selectedItem = TreeView_GetSelection(_hTreeCtrl);
292-
_selectedGroup = (FavesItemPtr)GetParam(selectedItem);
291+
auto *selectedItem = _hTreeCtrl.GetSelection();
292+
_selectedGroup = (FavesItemPtr)_hTreeCtrl.GetParam(selectedItem);
293293
::EndDialog(_hSelf, TRUE);
294294
return TRUE;
295295
}
@@ -342,10 +342,10 @@ INT_PTR CALLBACK PropDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam
342342
case TVN_SELCHANGED: {
343343
/* only when link params are also viewed */
344344
if (_bWithLink == TRUE) {
345-
HTREEITEM hItem = TreeView_GetSelection(_hTreeCtrl);
345+
HTREEITEM hItem = _hTreeCtrl.GetSelection();
346346

347347
if (hItem != nullptr) {
348-
FavesItemPtr pElem = (FavesItemPtr)GetParam(hItem);
348+
FavesItemPtr pElem = (FavesItemPtr)_hTreeCtrl.GetParam(hItem);
349349

350350
if (pElem != nullptr) {
351351
if (pElem->IsLink()) {
@@ -400,7 +400,7 @@ void PropDlg::setSelectedGroup(FavesItemPtr group)
400400

401401
void PropDlg::ExpandTreeView(HTREEITEM hParentItem)
402402
{
403-
FavesItemPtr parent = (FavesItemPtr)GetParam(hParentItem);
403+
FavesItemPtr parent = (FavesItemPtr)_hTreeCtrl.GetParam(hParentItem);
404404
if (parent == nullptr) {
405405
return;
406406
}
@@ -414,7 +414,7 @@ void PropDlg::ExpandTreeView(HTREEITEM hParentItem)
414414
}
415415
}
416416
// add new item
417-
HTREEITEM pCurrentItem = InsertItem(child->m_name, ICON_GROUP, ICON_GROUP, 0, 0, hParentItem, TVI_LAST, haveChildren, child.get());
417+
HTREEITEM pCurrentItem = _hTreeCtrl.InsertItem(child->m_name, ICON_GROUP, ICON_GROUP, 0, 0, hParentItem, TVI_LAST, haveChildren, child.get());
418418
ExpandTreeView(pCurrentItem);
419419
}
420420

@@ -424,9 +424,9 @@ void PropDlg::ExpandTreeView(HTREEITEM hParentItem)
424424
INT iIconSelected = 0;
425425
INT iIconOverlayed = 0;
426426
ExtractIcons(child->m_name.c_str(), nullptr, DEVT_FILE, &iIconNormal, &iIconSelected, &iIconOverlayed);
427-
HTREEITEM pCurrentItem = InsertItem(child->m_name, _iUImgPos, _iUImgPos, 0, 0, hParentItem, TVI_LAST, haveChildren, child.get());
427+
HTREEITEM pCurrentItem = _hTreeCtrl.InsertItem(child->m_name, _iUImgPos, _iUImgPos, 0, 0, hParentItem, TVI_LAST, haveChildren, child.get());
428428
ExpandTreeView(pCurrentItem);
429429
}
430430
}
431-
TreeView_Expand(_hTreeCtrl, hParentItem, TVE_EXPAND);
431+
_hTreeCtrl.Expand(hParentItem, TVE_EXPAND);
432432
}

src/Explorer/PropDlg.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2929
#include "Explorer.h"
3030
#include "FileDlg.h"
3131
#include "ExplorerResource.h"
32-
#include "TreeHelperClass.h"
32+
#include "TreeView.h"
3333
#include "FavesModel.h"
3434

3535
enum class LinkDlg {
@@ -38,7 +38,7 @@ enum class LinkDlg {
3838
FILE
3939
};
4040

41-
class PropDlg : public StaticDialog, public TreeHelper
41+
class PropDlg : public StaticDialog
4242
{
4343

4444
public:
@@ -71,4 +71,5 @@ protected :
7171
FavesItemPtr _root;
7272
INT _iUImgPos;
7373
FavesItemPtr _selectedGroup;
74+
TreeView _hTreeCtrl;
7475
};

0 commit comments

Comments
 (0)