Skip to content

Commit 6972c5f

Browse files
author
fishjam
committed
1.add DialogSameFilesList to handle same name files when try to locate in VS ide.
2.fix some bugs.
1 parent 4f0197a commit 6972c5f

13 files changed

+273
-192
lines changed

LogViewer/DialogSameFilesList.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// DialogSameFilesList.cpp : implementation file
2+
//
3+
4+
#include "stdafx.h"
5+
#include "LogViewer.h"
6+
#include "DialogSameFilesList.h"
7+
#include "afxdialogex.h"
8+
9+
10+
// CDialogSameFilesList dialog
11+
12+
IMPLEMENT_DYNAMIC(CDialogSameFilesList, CDialog)
13+
14+
BEGIN_MESSAGE_MAP(CDialogSameFilesList, CDialog)
15+
ON_LBN_SELCHANGE(IDC_LIST_SAME_FILES, &CDialogSameFilesList::OnLbnSelchangeListSameFiles)
16+
END_MESSAGE_MAP()
17+
18+
19+
CDialogSameFilesList::CDialogSameFilesList(SameNameFilePathListPtr spSameNameFilePathList, CWnd* pParent /*=NULL*/)
20+
: CDialog(IDD_DIALOG_SAME_FILE_LISTS, pParent)
21+
, m_spSameNameFilePathList(spSameNameFilePathList)
22+
{
23+
24+
}
25+
26+
CDialogSameFilesList::~CDialogSameFilesList()
27+
{
28+
}
29+
30+
void CDialogSameFilesList::DoDataExchange(CDataExchange* pDX)
31+
{
32+
CDialog::DoDataExchange(pDX);
33+
DDX_Control(pDX, IDC_LIST_SAME_FILES, m_SameFilesList);
34+
}
35+
36+
BOOL CDialogSameFilesList::OnInitDialog()
37+
{
38+
CDialog::OnInitDialog();
39+
if (m_spSameNameFilePathList)
40+
{
41+
for (SameNameFilePathList::iterator iter = m_spSameNameFilePathList->begin();
42+
iter != m_spSameNameFilePathList->end();
43+
iter++)
44+
{
45+
CString strFullPath = *iter;
46+
int itemIndex = m_SameFilesList.AddString(strFullPath);
47+
}
48+
}
49+
return TRUE; // return TRUE unless you set the focus to a control
50+
}
51+
52+
53+
54+
afx_msg void CDialogSameFilesList::OnLbnSelchangeListSameFiles()
55+
{
56+
int curSel = m_SameFilesList.GetCurSel();
57+
if (curSel != LB_ERR)
58+
{
59+
m_SameFilesList.GetText(curSel, m_strSelectFilePath);
60+
}
61+
else {
62+
m_strSelectFilePath = TEXT("");
63+
}
64+
}
65+
// CDialogSameFilesList message handlers

LogViewer/DialogSameFilesList.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#pragma once
2+
3+
4+
// CDialogSameFilesList dialog
5+
6+
class CDialogSameFilesList : public CDialog
7+
{
8+
DECLARE_DYNAMIC(CDialogSameFilesList)
9+
10+
public:
11+
CDialogSameFilesList(SameNameFilePathListPtr spSameNameFilePathList, CWnd* pParent = NULL); // standard constructor
12+
13+
virtual ~CDialogSameFilesList();
14+
15+
const CString& GetSelectFilePath() const {
16+
return m_strSelectFilePath;
17+
}
18+
19+
// Dialog Data
20+
#ifdef AFX_DESIGN_TIME
21+
enum { IDD = IDD_DIALOG_SAME_FILE_LISTS };
22+
#endif
23+
24+
protected:
25+
SameNameFilePathListPtr m_spSameNameFilePathList;
26+
CListBox m_SameFilesList;
27+
CString m_strSelectFilePath;
28+
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
29+
virtual BOOL OnInitDialog();
30+
31+
DECLARE_MESSAGE_MAP()
32+
afx_msg void OnLbnSelchangeListSameFiles();
33+
34+
};

LogViewer/LogItemView.cpp

Lines changed: 66 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "LogManager.h"
88
#include "MachinePidTidTreeView.h"
99
#include "DialogGoTo.h"
10+
#include "DialogSameFilesList.h"
11+
1012
#include <ftlShell.h>
1113
#include <regex>
1214

@@ -59,8 +61,9 @@ CLogItemView::~CLogItemView()
5961
}
6062

6163
BEGIN_MESSAGE_MAP(CLogItemView, CListView)
62-
ON_COMMAND_EX(ID_EDIT_GOTO, &CLogItemView::OnEditGoTo)
63-
ON_NOTIFY(HDN_ITEMCLICK, 0, &CLogItemView::OnHdnItemclickListAllLogitems)
64+
ON_COMMAND_EX(ID_EDIT_GOTO, &CLogItemView::OnEditGoTo)
65+
ON_COMMAND_EX(ID_EDIT_CLEAR_CACHE, &CLogItemView::OnEditClearCache)
66+
ON_NOTIFY(HDN_ITEMCLICK, 0, &CLogItemView::OnHdnItemclickListAllLogitems)
6467
//ON_NOTIFY_RANGE(LVN_COLUMNCLICK,0,0xffff,OnColumnClick)
6568
//ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnGetdispinfo)
6669
ON_NOTIFY_REFLECT(NM_CLICK, &CLogItemView::OnNMClick)
@@ -485,39 +488,62 @@ void CLogItemView::OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult)
485488
}
486489
if (!strFileName.IsEmpty() && line != 0)
487490
{
488-
TCHAR szPathFull[MAX_PATH] = {0};
489-
if (PathIsRelative(strFileName))
490-
{
491-
if (rLogManager.NeedScanSourceFiles())
492-
{
493-
CString strExistSourceDir = AfxGetApp()->GetProfileString(SECTION_CONFIG, ENTRY_SOURCE_DIR);
491+
TCHAR szPathFull[MAX_PATH] = { 0 };
492+
493+
//优先在缓存里面查找(主要是减少 重复文件时的选择问题), 如果有, 则直接使用, 否则再走后面的逻辑
494+
CString strFileLineCache;
495+
strFileLineCache.Format(TEXT("%s:%d"), strFileName, line);
496+
CString strFullPathFromUserCache = rLogManager.GetFullPathFromUserCache(strFileLineCache);
497+
if (!strFullPathFromUserCache.IsEmpty())
498+
{
499+
StringCchCopy(szPathFull, _countof(szPathFull), strFullPathFromUserCache);
500+
}
501+
else {
502+
if (PathIsRelative(strFileName))
503+
{
504+
if (rLogManager.NeedScanSourceFiles())
505+
{
506+
CString strExistSourceDir = AfxGetApp()->GetProfileString(SECTION_CONFIG, ENTRY_SOURCE_DIR);
507+
508+
CFDirBrowser dirBrowser(TEXT("Choose Project Source Root Path"), m_hWnd, strExistSourceDir);
509+
if (dirBrowser.DoModal())
510+
{
511+
CString strFolderPath = dirBrowser.GetSelectPath();
512+
AfxGetApp()->WriteProfileString(SECTION_CONFIG, ENTRY_SOURCE_DIR, strFolderPath);
513+
rLogManager.ScanSourceFiles(strFolderPath);
514+
}
515+
}
516+
517+
SameNameFilePathListPtr spFilePathList = rLogManager.FindFileFullPath(ATLPath::FindFileName(strFileName));
518+
if (spFilePathList != nullptr)
519+
{
520+
int nSameFileNameCount = spFilePathList->size();
521+
if (nSameFileNameCount > 1)
522+
{
523+
FTLTRACEEX(FTL::tlWarn, TEXT("find %d source files with %s"), nSameFileNameCount, strFileName);
524+
CDialogSameFilesList dlgSameFilesList(spFilePathList);
525+
if (IDOK == dlgSameFilesList.DoModal())
526+
{
527+
StringCchCopy(szPathFull, _countof(szPathFull), dlgSameFilesList.GetSelectFilePath());
528+
rLogManager.SetFullPathForUserCache(strFileLineCache, szPathFull);
529+
}
530+
}
531+
if (szPathFull[0] == TEXT('\0'))
532+
{
533+
StringCchCopy(szPathFull, _countof(szPathFull), spFilePathList->front());
534+
}
535+
//TODO: if there are more than one file with same name, then prompt user choose
536+
537+
}
538+
}
539+
else
540+
{
541+
StringCchCopy(szPathFull, _countof(szPathFull), strFileName);
542+
}
543+
}
494544

495-
CFDirBrowser dirBrowser(TEXT("Choose Project Source Root Path"), m_hWnd, strExistSourceDir);
496-
if (dirBrowser.DoModal())
497-
{
498-
CString strFolderPath = dirBrowser.GetSelectPath();
499-
AfxGetApp()->WriteProfileString(SECTION_CONFIG, ENTRY_SOURCE_DIR, strFolderPath);
500-
rLogManager.ScanSourceFiles(strFolderPath);
501-
}
502-
}
503-
504-
SameNameFilePathListPtr spFilePathList = rLogManager.FindFileFullPath(ATLPath::FindFileName(strFileName));
505-
if (spFilePathList != nullptr)
506-
{
507-
int nSameFileNameCount = spFilePathList->size();
508-
if (nSameFileNameCount > 1)
509-
{
510-
FTLTRACEEX(FTL::tlWarn, TEXT("find %d source files with %s"), nSameFileNameCount, strFileName);
511-
}
512-
//TODO: if there are more than one file with same name, then prompt user choose
513-
StringCchCopy(szPathFull, _countof(szPathFull), spFilePathList->front());
514-
}
515-
}
516-
else
517-
{
518-
StringCchCopy(szPathFull, _countof(szPathFull), strFileName);
519-
}
520545
CString path(szPathFull);
546+
FTLASSERT(!path.IsEmpty());
521547
if (!path.IsEmpty())
522548
{
523549
path.Replace(_T('/'), _T('\\'));
@@ -910,3 +936,10 @@ BOOL CLogItemView::OnEditGoTo(UINT nID)
910936
}
911937
return bRet;
912938
}
939+
940+
BOOL CLogItemView::OnEditClearCache(UINT nID)
941+
{
942+
CLogManager& logManager = GetDocument()->m_FTLogManager;
943+
logManager.ClearUserFullPathCache();
944+
return TRUE;
945+
}

LogViewer/LogItemView.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ class CLogItemView : public CListView
6060
afx_msg void OnDetailSelectCurrentPid();
6161
afx_msg void OnDetailSelectCurrentTid();
6262
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
63-
afx_msg BOOL OnEditGoTo(UINT nID);
63+
afx_msg BOOL OnEditGoTo(UINT nID);
64+
afx_msg BOOL OnEditClearCache(UINT nID);
6465

6566
afx_msg void OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult);
6667
afx_msg void OnUpdateIndicatorSelectedLogItem(CCmdUI *pCmdUI);

0 commit comments

Comments
 (0)