From c88a59ca340860fbb15ea7c4da7e7e222f1aac16 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Fri, 29 Aug 2003 11:52:30 +0000 Subject: [PATCH] PATCH: [ 796756 ] Diff API --- Src/DiffWrapper.cpp | 190 +++++++++++++++++++++++++++++++++++++++------------- Src/DiffWrapper.h | 83 ++++++++++++++++------- Src/DirDoc.cpp | 23 +++++++ Src/DirDoc.h | 5 ++ Src/DirView.cpp | 17 ++++- Src/MainFrm.cpp | 77 ++++++++++----------- Src/MainFrm.h | 7 +- Src/MergeDoc.cpp | 48 +++++++------ Src/MergeDoc.h | 2 +- Src/readme.txt | 5 ++ 10 files changed, 316 insertions(+), 141 deletions(-) diff --git a/Src/DiffWrapper.cpp b/Src/DiffWrapper.cpp index 96bd3234d..b837a94c0 100644 --- a/Src/DiffWrapper.cpp +++ b/Src/DiffWrapper.cpp @@ -33,12 +33,27 @@ extern int recursive; CDiffWrapper::CDiffWrapper() { + DIFFOPTIONS options = {0}; + ZeroMemory(&m_settings, sizeof(DIFFSETTINGS)); + ZeroMemory(&m_globalSettings, sizeof(DIFFSETTINGS)); ZeroMemory(&m_status, sizeof(DIFFSTATUS)); m_bCreatePatchFile = FALSE; m_bUseDiffList = FALSE; m_bAddCmdLine = TRUE; m_bAppendFiles = FALSE; m_nDiffs = 0; + + // Read options from registry and convert + // to internal format + ReadDiffOptions(&options); + InternalSetOptions(&options); + m_settings.heuristic = 1; + m_settings.outputStyle = OUTPUT_NORMAL; + m_settings.context = -1; + + // What is this? + line_end_char = '\n'; + //ignore_blank_lines_flag = 1; } /** @@ -73,19 +88,19 @@ void CDiffWrapper::SetDiffList(CArray *diffs) /** * @brief Returns current set of options used by diff-engine */ -void CDiffWrapper::GetOptions(DIFFSETTINGS *options) +void CDiffWrapper::GetOptions(DIFFOPTIONS *options) { ASSERT(options); - CopyMemory(options, &m_options, sizeof(DIFFSETTINGS)); + InternalGetOptions(options); } /** * @brief Set options used by diff-engine */ -void CDiffWrapper::SetOptions(DIFFSETTINGS *options) +void CDiffWrapper::SetOptions(DIFFOPTIONS *options) { ASSERT(options); - CopyMemory(&m_options, options, sizeof(DIFFSETTINGS)); + InternalSetOptions(options); } /** @@ -130,7 +145,7 @@ BOOL CDiffWrapper::SetCreatePatchFile(BOOL bCreatePatchFile) BOOL CDiffWrapper::RunFileDiff() { BOOL bRetStatus = FALSE; - SwapToInternalOptions(); + SwapToInternalSettings(); if (m_bUseDiffList) m_nDiffs = m_diffs->GetSize(); @@ -347,7 +362,7 @@ BOOL CDiffWrapper::RunFileDiff() if (free1) free (free1); - SwapToGlobalOptions(); + SwapToGlobalSettings(); bRetStatus = !failed; if (failed) @@ -362,58 +377,105 @@ BOOL CDiffWrapper::RunFileDiff() } /** + * @brief Return current diffutils options + */ +void CDiffWrapper::InternalGetOptions(DIFFOPTIONS *options) +{ + int nIgnoreWhitespace = 0; + + if (m_settings.ignoreAllSpace) + nIgnoreWhitespace = 2; + else if (m_settings.ignoreSpaceChange) + nIgnoreWhitespace = 1; + + options->nIgnoreWhitespace = nIgnoreWhitespace; + options->bIgnoreBlankLines = m_settings.ignoreBlankLines; + options->bIgnoreCase = m_settings.ignoreCase; + options->bEolSensitive = !m_settings.ignoreEOLDiff; + +} + +/** + * @brief Set diffutils options + */ +void CDiffWrapper::InternalSetOptions(DIFFOPTIONS *options) +{ + m_settings.ignoreAllSpace = (options->nIgnoreWhitespace == 2); + m_settings.ignoreSpaceChange = (options->nIgnoreWhitespace == 1); + m_settings.ignoreBlankLines = options->bIgnoreBlankLines; + m_settings.ignoreEOLDiff = !options->bEolSensitive; + m_settings.ignoreCase = options->bIgnoreCase; + m_settings.ignoreSomeChanges = (options->nIgnoreWhitespace != 0) || + options->bIgnoreCase || options->bIgnoreBlankLines || + !options->bEolSensitive; + m_settings.lengthVaries = (options->nIgnoreWhitespace!=0); +} + +/** * @brief Replaces global options used by diff-engine with options in diff-wrapper */ -void CDiffWrapper::SwapToInternalOptions() +void CDiffWrapper::SwapToInternalSettings() { // Save current settings to temp variables - m_globalOptions.outputStyle = output_style; - output_style = m_options.outputStyle; + m_globalSettings.outputStyle = output_style; + output_style = m_settings.outputStyle; - m_globalOptions.context = context; - context = m_options.context; + m_globalSettings.context = context; + context = m_settings.context; - m_globalOptions.alwaysText = always_text_flag; - always_text_flag = m_options.alwaysText; + m_globalSettings.alwaysText = always_text_flag; + always_text_flag = m_settings.alwaysText; + + m_globalSettings.horizLines = horizon_lines; + horizon_lines = m_settings.horizLines; - m_globalOptions.horizLines = horizon_lines; - horizon_lines = m_options.horizLines; + m_globalSettings.ignoreSpaceChange = ignore_space_change_flag; + ignore_space_change_flag = m_settings.ignoreSpaceChange; - m_globalOptions.ignoreSpaceChange = ignore_space_change_flag; - ignore_space_change_flag = m_options.ignoreSpaceChange; + m_globalSettings.ignoreAllSpace = ignore_all_space_flag; + ignore_all_space_flag = m_settings.ignoreAllSpace; - m_globalOptions.ignoreAllSpace = ignore_all_space_flag; - ignore_all_space_flag = m_options.ignoreAllSpace; + m_globalSettings.ignoreBlankLines = ignore_blank_lines_flag; + ignore_blank_lines_flag = m_settings.ignoreBlankLines; - m_globalOptions.ignoreBlankLines = ignore_blank_lines_flag; - ignore_blank_lines_flag = m_options.ignoreBlankLines; + m_globalSettings.ignoreCase = ignore_case_flag; + ignore_case_flag = m_settings.ignoreCase; - m_globalOptions.ignoreCase = ignore_case_flag; - ignore_case_flag = m_options.ignoreCase; + m_globalSettings.ignoreEOLDiff = ignore_eol_diff; + ignore_eol_diff = m_settings.ignoreEOLDiff; - m_globalOptions.heuristic = heuristic; - heuristic = m_options.heuristic; + m_globalSettings.ignoreSomeChanges = ignore_some_changes; + ignore_some_changes = m_settings.ignoreSomeChanges; - m_globalOptions.recursive = recursive; - recursive = m_options.recursive; + m_globalSettings.lengthVaries = length_varies; + length_varies = m_settings.lengthVaries; + + m_globalSettings.heuristic = heuristic; + heuristic = m_settings.heuristic; + + m_globalSettings.recursive = recursive; + recursive = m_settings.recursive; } /** * @brief Resumes global options as they were before calling SwapToInternalOptions() */ -void CDiffWrapper::SwapToGlobalOptions() +void CDiffWrapper::SwapToGlobalSettings() { // Resume values - output_style = m_globalOptions.outputStyle; - context = m_globalOptions.context; - always_text_flag = m_globalOptions.alwaysText; - horizon_lines = m_globalOptions.horizLines; - ignore_space_change_flag = m_globalOptions.ignoreSpaceChange; - ignore_all_space_flag = m_globalOptions.ignoreAllSpace; - ignore_blank_lines_flag = m_globalOptions.ignoreBlankLines; - ignore_case_flag = m_globalOptions.ignoreCase; - heuristic = m_globalOptions.heuristic; - recursive = m_globalOptions.recursive; + output_style = m_globalSettings.outputStyle; + context = m_globalSettings.context; + always_text_flag = m_globalSettings.alwaysText; + horizon_lines = m_globalSettings.horizLines; + ignore_space_change_flag = m_globalSettings.ignoreSpaceChange; + ignore_all_space_flag = m_globalSettings.ignoreAllSpace; + ignore_blank_lines_flag = m_globalSettings.ignoreBlankLines; + ignore_case_flag = m_globalSettings.ignoreCase; + ignore_eol_diff = m_globalSettings.ignoreEOLDiff; + ignore_some_changes = m_globalSettings.ignoreSomeChanges; + length_varies = m_globalSettings.lengthVaries; + heuristic = m_globalSettings.heuristic; + recursive = m_globalSettings.recursive; } /** @@ -506,7 +568,7 @@ CString CDiffWrapper::FormatSwitchString() CString switches; TCHAR tmpNum[5] = {0}; - switch (m_options.outputStyle) + switch (m_settings.outputStyle) { case OUTPUT_CONTEXT: switches = _T(" C"); @@ -534,22 +596,22 @@ CString CDiffWrapper::FormatSwitchString() break; } - if (m_options.context > 0) + if (m_settings.context > 0) { - _itot(m_options.context, tmpNum, 10); + _itot(m_settings.context, tmpNum, 10); switches += tmpNum; } - if (m_options.ignoreAllSpace > 0) + if (m_settings.ignoreAllSpace > 0) switches += _T("w"); - if (m_options.ignoreBlankLines > 0) + if (m_settings.ignoreBlankLines > 0) switches += _T("B"); - if (m_options.ignoreCase > 0) + if (m_settings.ignoreCase > 0) switches += _T("i"); - if (m_options.ignoreSpaceChange > 0) + if (m_settings.ignoreSpaceChange > 0) switches += _T("b"); return switches; @@ -572,3 +634,41 @@ BOOL CDiffWrapper::SetAppendFiles(BOOL bAppendFiles) m_bAppendFiles = bAppendFiles; return temp; } + +/** + * @brief Sets options for directory compare + */ +void CDiffWrapper::StartDirectoryDiff() +{ + SwapToInternalSettings(); +} + +/** + * @brief resumes options after directory compare + */ +void CDiffWrapper::EndDirectoryDiff() +{ + SwapToGlobalSettings(); +} + +/** + * @brief Static function for reading diffoptions from registry + */ +void CDiffWrapper::ReadDiffOptions(DIFFOPTIONS *options) +{ + options->nIgnoreWhitespace = ::AfxGetApp()->GetProfileInt(_T("Settings"), _T("IgnoreSpace"), 1); + options->bIgnoreBlankLines = ::AfxGetApp()->GetProfileInt(_T("Settings"), _T("IgnoreBlankLines"), FALSE)!=0; + options->bEolSensitive = ::AfxGetApp()->GetProfileInt(_T("Settings"), _T("EolSensitive"), FALSE)!=0; + options->bIgnoreCase = ::AfxGetApp()->GetProfileInt(_T("Settings"), _T("IgnoreCase"), FALSE)!=0; +} + +/** + * @brief Static function for writing diffoptions to registry + */ +void CDiffWrapper::WriteDiffOptions(DIFFOPTIONS *options) +{ + ::AfxGetApp()->WriteProfileInt(_T("Settings"), _T("IgnoreSpace"), options->nIgnoreWhitespace); + ::AfxGetApp()->WriteProfileInt(_T("Settings"), _T("EolSensitive"), options->bEolSensitive); + ::AfxGetApp()->WriteProfileInt(_T("Settings"), _T("IgnoreBlankLines"), options->bIgnoreBlankLines); + ::AfxGetApp()->WriteProfileInt(_T("Settings"), _T("IgnoreCase"), options->bIgnoreCase); +} diff --git a/Src/DiffWrapper.h b/Src/DiffWrapper.h index d3f06e5f4..dc080bfe2 100644 --- a/Src/DiffWrapper.h +++ b/Src/DiffWrapper.h @@ -40,20 +40,55 @@ enum }; /** - * @brief One difference defined by linenumbers - * @note xxxx1 values are calculated in CMergeDoc::PrimeTextBuffers() + * @brief One difference defined by linenumbers. + * + * This struct defines one set of different lines "diff". + * @p begin0, @p end0, @p begin1 & @p end1 are linenumbers + * in original files. Other struct members point to linenumbers + * calculated by WinMerge after adding empty lines to make diffs + * be in line in screen. + * + * @note @p blank0 & @p blank1 are -1 if there are no blank lines */ typedef struct tagDIFFRANGE { - UINT begin0,end0,begin1,end1; - UINT dbegin0,dend0,dbegin1,dend1; - int blank0,blank1; - BYTE op; + UINT begin0; /**< First diff line in original file1 */ + UINT end0; /**< Last diff line in original file1 */ + UINT begin1; /**< First diff line in original file2 */ + UINT end1; /**< Last diff line in original file2 */ + UINT dbegin0; /**< First deleted line in file1 */ + UINT dend0; /**< Last deleted line in file1 */ + UINT dbegin1; /**< First deleted line in file2 */ + UINT dend1; /**< Last deleted line in file2 */ + int blank0; /**< Number of blank lines in file1 */ + int blank1; /**< Number of blank lines in file2 */ + BYTE op; /**< Operation done with this diff */ } DIFFRANGE; /** - * @brief Diffutils options - * @note DO NOT add diff-unrelated data here! + * @brief Diffutils options users of this class must use + */ +typedef struct tagDIFFOPTIONS +{ + int nIgnoreWhitespace; + BOOL bIgnoreCase; + BOOL bIgnoreBlankLines; + BOOL bEolSensitive; +} DIFFOPTIONS; + +/** + * @brief Diffutils returns this statusdata about files compared + */ +typedef struct tagDIFFSTATUS +{ + BOOL bLeftMissingNL; + BOOL bRightMissingNL; + BOOL bBinaries; + BOOL bPatchFileFailed; +} DIFFSTATUS; + +/** + * @brief Internally used diffutils options */ typedef struct tagDIFFSETTINGS { @@ -65,22 +100,14 @@ typedef struct tagDIFFSETTINGS int ignoreAllSpace; int ignoreBlankLines; int ignoreCase; + int ignoreEOLDiff; + int ignoreSomeChanges; + int lengthVaries; int heuristic; int recursive; } DIFFSETTINGS; /** - * @brief Diffutils returns this statusdata about files compared - */ -typedef struct tagDIFFSTATUS -{ - BOOL bLeftMissingNL; - BOOL bRightMissingNL; - BOOL bBinaries; - BOOL bPatchFileFailed; -} DIFFSTATUS; - -/** * @brief Wrapper class for GNU/diffutils */ class CDiffWrapper @@ -90,8 +117,8 @@ public: void SetCompareFiles(CString file1, CString file2); void SetPatchFile(CString file); void SetDiffList(CArray *diffs); - void GetOptions(DIFFSETTINGS *options); - void SetOptions(DIFFSETTINGS *options); + void GetOptions(DIFFOPTIONS *options); + void SetOptions(DIFFOPTIONS *options); BOOL GetUseDiffList() const; BOOL SetUseDiffList(BOOL bUseDiffList); BOOL GetAppendFiles() const; @@ -102,15 +129,21 @@ public: void GetDiffStatus(DIFFSTATUS *status); void AddDiffRange(UINT begin0, UINT end0, UINT begin1, UINT end1, BYTE op); void FixLastDiffRange(int leftBufferLines, int rightBufferLines, BOOL left); + void StartDirectoryDiff(); + void EndDirectoryDiff(); + static void ReadDiffOptions(DIFFOPTIONS *options); + static void WriteDiffOptions(DIFFOPTIONS *options); protected: - void SwapToInternalOptions(); - void SwapToGlobalOptions(); + void InternalGetOptions(DIFFOPTIONS *options); + void InternalSetOptions(DIFFOPTIONS *options); + void SwapToInternalSettings(); + void SwapToGlobalSettings(); CString FormatSwitchString(); private: - DIFFSETTINGS m_options; - DIFFSETTINGS m_globalOptions; // Temp for storing globals + DIFFSETTINGS m_settings; + DIFFSETTINGS m_globalSettings; // Temp for storing globals DIFFSTATUS m_status; CString m_sFile1; CString m_sFile2; diff --git a/Src/DirDoc.cpp b/Src/DirDoc.cpp index 3ada9cb2d..56097b9ed 100644 --- a/Src/DirDoc.cpp +++ b/Src/DirDoc.cpp @@ -235,6 +235,8 @@ void CDirDoc::Rescan() m_pCtxt->m_piFilter = m_pFilter; + m_diffWrapper.StartDirectoryDiff(); + m_diffThread.SetContext(m_pCtxt); m_diffThread.SetHwnd(m_pDirView->GetSafeHwnd()); m_diffThread.SetMessageIDs(MSG_UI_UPDATE, MSG_STAT_UPDATE); @@ -585,6 +587,27 @@ void CDirDoc::UpdateChangedItem(LPCTSTR pathLeft, LPCTSTR pathRight, bool unifie } /** + * @brief Cleans up after directory compare + */ +void CDirDoc::CompareReady() +{ + m_diffWrapper.EndDirectoryDiff(); +} + +/** + * @brief Read doc settings from registry + * + * @note Currently loads only diffutils settings, but later others too + */ +void CDirDoc::ReadSettings() +{ + DIFFOPTIONS options; + + CDiffWrapper::ReadDiffOptions(&options); + m_diffWrapper.SetOptions(&options); +} + +/** * @brief Set left/right side readonly-status * @param bLeft Select side to set (TRUE = left) * @param bReadOnly New status of selected side diff --git a/Src/DirDoc.h b/Src/DirDoc.h index 28dc3cf6e..2adc22451 100644 --- a/Src/DirDoc.h +++ b/Src/DirDoc.h @@ -35,6 +35,7 @@ #include "DirView.h" #include "DiffContext.h" #include "diffThread.h" +#include "DiffWrapper.h" class CMergeDoc; typedef CTypedPtrList MergeDocPtrList; @@ -80,6 +81,8 @@ public: public: BOOL GetReadOnly(BOOL bLeft) const; void SetReadOnly(BOOL bLeft, BOOL bReadOnly); + void ReadSettings(); + void CompareReady(); void UpdateChangedItem(LPCTSTR pathLeft, LPCTSTR pathRight, bool unified); POSITION FindItemFromPaths(LPCTSTR pathLeft, LPCTSTR pathRight); void SetDiffContext(CDiffContext *pCtxt); @@ -103,6 +106,8 @@ public: protected: void UpdateScreenItemStatus(UINT nIdx, DIFFITEM di); + CDiffWrapper m_diffWrapper; + // Generated message map functions //{{AFX_MSG(CDirDoc) // NOTE - the ClassWizard will add and remove member functions here. diff --git a/Src/DirView.cpp b/Src/DirView.cpp index 34c47cd20..fdee6bc2c 100644 --- a/Src/DirView.cpp +++ b/Src/DirView.cpp @@ -335,7 +335,7 @@ void CDirView::ListContextMenu(CPoint point, int /*i*/) */ void CDirView::HeaderContextMenu(CPoint point, int /*i*/) { -ToDoDeleteThisValidateColumnOrdering(); + ToDoDeleteThisValidateColumnOrdering(); CMenu menu; VERIFY(menu.LoadMenu(IDR_POPUP_DIRVIEW)); @@ -716,7 +716,7 @@ int CDirView::GetItemIndex(DWORD key) findInfo.flags = LVFI_PARAM; // Search for itemdata findInfo.lParam = key; - return m_pList->FindItem( &findInfo ); + return m_pList->FindItem(&findInfo); } // User chose (context menu) open left @@ -735,6 +735,7 @@ void CDirView::OnCtxtDirOpenLeftWith() { DoOpenWith(SIDE_LEFT); } + // User chose (context menu) open right with void CDirView::OnCtxtDirOpenRightWith() { @@ -1171,9 +1172,19 @@ void CDirView::OnUpdateRefresh(CCmdUI* pCmdUI) pCmdUI->Enable(TRUE); } +/** + * @brief Called when compare thread asks UI update + * @note Currently thread asks update after compare is ready + */ void CDirView::OnUpdateUIMessage(WPARAM wParam, LPARAM lParam) { - GetDocument()->Redisplay(); + CDirDoc * pDoc = GetDocument(); + ASSERT(pDoc); + + // Currently UI (update) message is sent after compare is ready + pDoc->CompareReady(); + pDoc->Redisplay(); + if (mf->m_bScrollToFirst) OnFirstdiff(); } diff --git a/Src/MainFrm.cpp b/Src/MainFrm.cpp index b6bb81065..70ebd5502 100644 --- a/Src/MainFrm.cpp +++ b/Src/MainFrm.cpp @@ -105,6 +105,9 @@ BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) //}}AFX_MSG_MAP END_MESSAGE_MAP() +/** + * @brief MainFrame statusbar panels/indicators + */ static UINT indicators[] = { ID_SEPARATOR, // status line indicator @@ -126,9 +129,6 @@ CMainFrame::CMainFrame() m_bFirstTime = TRUE; m_bAutomaticRescan = theApp.GetProfileInt(_T("Settings"), _T("AutomaticRescan"), TRUE)!=0; - m_bIgnoreBlankLines = theApp.GetProfileInt(_T("Settings"), _T("IgnoreBlankLines"), FALSE)!=0; - m_bEolSensitive = theApp.GetProfileInt(_T("Settings"), _T("EolSensitive"), FALSE)!=0; - m_bIgnoreCase = theApp.GetProfileInt(_T("Settings"), _T("IgnoreCase"), FALSE)!=0; m_bShowUniqueLeft = theApp.GetProfileInt(_T("Settings"), _T("ShowUniqueLeft"), TRUE)!=0; m_bShowUniqueRight = theApp.GetProfileInt(_T("Settings"), _T("ShowUniqueRight"), TRUE)!=0; m_bShowDiff = theApp.GetProfileInt(_T("Settings"), _T("ShowDifferent"), TRUE)!=0; @@ -137,7 +137,6 @@ CMainFrame::CMainFrame() m_bBackup = theApp.GetProfileInt(_T("Settings"), _T("BackupFile"), TRUE)!=0; m_bViewWhitespace = theApp.GetProfileInt(_T("Settings"), _T("ViewWhitespace"), FALSE)!=0; m_bScrollToFirst = theApp.GetProfileInt(_T("Settings"), _T("ScrollToFirst"), FALSE)!=0; - m_nIgnoreWhitespace = theApp.GetProfileInt(_T("Settings"), _T("IgnoreSpace"), 1); m_bHideBak = theApp.GetProfileInt(_T("Settings"), _T("HideBak"), TRUE)!=0; m_nVerSys = theApp.GetProfileInt(_T("Settings"), _T("VersionSystem"), 0); m_strVssProject = theApp.GetProfileString(_T("Settings"), _T("VssProject"), _T("")); @@ -195,21 +194,9 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) return -1; mf = this; - ignore_space_change_flag = (m_nIgnoreWhitespace==1); - ignore_all_space_flag = (m_nIgnoreWhitespace==2); - length_varies = (m_nIgnoreWhitespace!=0); - ignore_case_flag = m_bIgnoreCase; - ignore_blank_lines_flag = m_bIgnoreBlankLines; - ignore_eol_diff = !m_bEolSensitive; - ignore_some_changes = (m_nIgnoreWhitespace!=0) || m_bIgnoreCase || m_bIgnoreBlankLines || !m_bEolSensitive; + // build the initial reg expression list RebuildRegExpList(); - - heuristic = 1; - output_style = OUTPUT_NORMAL; - context = -1; - line_end_char = '\n'; - //ignore_blank_lines_flag = 1; GetFontProperties(); if (!m_wndToolBar.CreateEx(this,TBSTYLE_FLAT,WS_CHILD|WS_VISIBLE|CBRS_GRIPPER|CBRS_TOP|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC) || @@ -409,6 +396,7 @@ void CMainFrame::OnUpdateHideBackupFiles(CCmdUI* pCmdUI) pCmdUI->SetCheck(m_bHideBak); } +/// Show GNU licence information in notepad (local file) or in Web Browser void CMainFrame::OnHelpGnulicense() { CString spath = GetModulePath() + _T("\\Copying"); @@ -669,6 +657,7 @@ BOOL CMainFrame::SaveToVersionControl(CString& strSavePath) void CMainFrame::OnOptions() { + DIFFOPTIONS diffOptions = {0}; CStringList filefilters; CString selectedFilter; theApp.GetFileFilterNameList(filefilters, selectedFilter); @@ -691,10 +680,10 @@ void CMainFrame::OnOptions() vss.m_strPath = m_strVssPath; gen.m_bBackup = m_bBackup; - gen.m_nIgnoreWhite = m_nIgnoreWhitespace; - gen.m_bIgnoreCase = m_bIgnoreCase; - gen.m_bIgnoreBlankLines = m_bIgnoreBlankLines; - gen.m_bEolSensitive = m_bEolSensitive; + gen.m_nIgnoreWhite = diffOptions.nIgnoreWhitespace; + gen.m_bIgnoreCase = diffOptions.bIgnoreCase; + gen.m_bIgnoreBlankLines = diffOptions.bIgnoreBlankLines; + gen.m_bEolSensitive = diffOptions.bEolSensitive; gen.m_bScroll = m_bScrollToFirst; gen.m_nTabSize = m_nTabSize; gen.m_nTabType = m_nTabType; @@ -717,15 +706,10 @@ void CMainFrame::OnOptions() theApp.m_bDisableSplash = gen.m_bDisableSplash; m_bAutomaticRescan = gen.m_bAutomaticRescan; - m_nIgnoreWhitespace = gen.m_nIgnoreWhite; - ignore_all_space_flag = (m_nIgnoreWhitespace==2); - ignore_space_change_flag = (m_nIgnoreWhitespace==1); - ignore_blank_lines_flag = m_bIgnoreBlankLines = gen.m_bIgnoreBlankLines; - m_bEolSensitive = gen.m_bEolSensitive; - ignore_eol_diff = !m_bEolSensitive; - ignore_case_flag = m_bIgnoreCase = gen.m_bIgnoreCase; - ignore_some_changes = (m_nIgnoreWhitespace!=0) || m_bIgnoreCase || m_bIgnoreBlankLines || !m_bEolSensitive; - length_varies = (m_nIgnoreWhitespace!=0); + diffOptions.nIgnoreWhitespace = gen.m_nIgnoreWhite; + diffOptions.bIgnoreBlankLines = gen.m_bIgnoreBlankLines; + diffOptions.bEolSensitive = gen.m_bEolSensitive; + diffOptions.bIgnoreCase = gen.m_bIgnoreCase; m_bIgnoreRegExp = filter.m_bIgnoreRegExp; m_sPattern = filter.m_sPattern; @@ -739,16 +723,12 @@ void CMainFrame::OnOptions() theApp.SetSelDiffTextColor(colors.m_clrSelDiffText); theApp.WriteProfileInt(_T("Settings"), _T("VersionSystem"), m_nVerSys); - theApp.WriteProfileInt(_T("Settings"), _T("IgnoreSpace"), m_nIgnoreWhitespace); theApp.WriteProfileInt(_T("Settings"), _T("ScrollToFirst"), m_bScrollToFirst); theApp.WriteProfileInt(_T("Settings"), _T("BackupFile"), m_bBackup); theApp.WriteProfileString(_T("Settings"), _T("VssPath"), m_strVssPath); theApp.WriteProfileInt(_T("Settings"), _T("TabSize"), m_nTabSize); theApp.WriteProfileInt(_T("Settings"), _T("TabType"), m_nTabType); - theApp.WriteProfileInt(_T("Settings"), _T("EolSensitive"), m_bEolSensitive); theApp.WriteProfileInt(_T("Settings"), _T("AutomaticRescan"), m_bAutomaticRescan); - theApp.WriteProfileInt(_T("Settings"), _T("IgnoreBlankLines"), m_bIgnoreBlankLines); - theApp.WriteProfileInt(_T("Settings"), _T("IgnoreCase"), m_bIgnoreCase); theApp.WriteProfileInt(_T("Settings"), _T("IgnoreRegExp"), m_bIgnoreRegExp); theApp.WriteProfileString(_T("Settings"), _T("RegExps"), m_sPattern); theApp.WriteProfileInt(_T("Settings"), _T("DisableSplash"), theApp.m_bDisableSplash); @@ -769,6 +749,9 @@ void CMainFrame::OnOptions() CMergeEditView * pLeft = pMergeDoc->GetLeftView(); CMergeEditView * pRight = pMergeDoc->GetRightView(); + // Re-read MergeDoc settings + pMergeDoc->ReadSettings(); + // Enable/disable automatic rescan (rescan after editing) pLeft->EnableRescan(m_bAutomaticRescan); pRight->EnableRescan(m_bAutomaticRescan); @@ -800,6 +783,16 @@ void CMainFrame::OnOptions() } if (!savedAll) AfxMessageBox(IDS_DIFF_OPEN_NO_SET_PROPS,MB_ICONEXCLAMATION); + + // Update all dirdoc settings + DirDocList dirDocs; + GetAllDirDocs(&dirDocs); + + while (!dirDocs.IsEmpty()) + { + CDirDoc *pDirDoc = dirDocs.RemoveHead(); + pDirDoc->ReadSettings(); + } } } @@ -927,7 +920,6 @@ BOOL CMainFrame::DoFileOpen(LPCTSTR pszLeft /*=NULL*/, LPCTSTR pszRight /*=NULL* m_nVerSys, m_strVssPath, m_bBackup, - m_nIgnoreWhitespace, m_bScrollToFirst); } @@ -962,6 +954,7 @@ BOOL CMainFrame::DoFileOpen(LPCTSTR pszLeft /*=NULL*/, LPCTSTR pszRight /*=NULL* return TRUE; } +/// Creates backup before file is saved over BOOL CMainFrame::CreateBackup(LPCTSTR pszPath) { // first, make a backup copy of the original @@ -1125,7 +1118,6 @@ void CMainFrame::UpdateCurrentFileStatus(CDirDoc * pDirDoc, UINT nStatus, int id pDirDoc->m_pCtxt->UpdateStatusCode(diffpos, (BYTE)nStatus); // update DIFFITEM time, and also tell views pDirDoc->ReloadItemStatus(idx); - //m_pDirDoc->Redisplay(); } void CMainFrame::OnViewSelectfont() @@ -1398,7 +1390,7 @@ add_regexp(struct regexp_list **reglist, *reglist = r; } -// utility function to update CSuperComboBox format MRU +/// Utility function to update CSuperComboBox format MRU void CMainFrame::addToMru(LPCSTR szItem, LPCSTR szRegSubKey, UINT nMaxItems) { CString s,s2; @@ -1447,12 +1439,13 @@ void CMainFrame::OnViewWhitespace() } } +/// Enables View/View Whitespace menuitem when merge view is active void CMainFrame::OnUpdateViewWhitespace(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_bViewWhitespace); } -// get list of MergeDocs (documents underlying edit sessions) +/// Get list of MergeDocs (documents underlying edit sessions) void CMainFrame::GetAllMergeDocs(MergeDocList * pMergeDocs) { CMultiDocTemplate * pTemplate = theApp.m_pDiffTemplate; @@ -1464,7 +1457,7 @@ void CMainFrame::GetAllMergeDocs(MergeDocList * pMergeDocs) } } -// get list of DirDocs (documents underlying a scan) +/// Get list of DirDocs (documents underlying a scan) void CMainFrame::GetAllDirDocs(DirDocList * pDirDocs) { CMultiDocTemplate * pTemplate = theApp.m_pDirTemplate; @@ -1476,7 +1469,7 @@ void CMainFrame::GetAllDirDocs(DirDocList * pDirDocs) } } -// get pointers to all views into typed lists (both arguments are optional) +/// Get pointers to all views into typed lists (both arguments are optional) void CMainFrame::GetAllViews(MergeEditViewList * pEditViews, DirViewList * pDirViews) { for (POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition(); pos; ) @@ -1520,14 +1513,14 @@ void CMainFrame::GetAllViews(MergeEditViewList * pEditViews, DirViewList * pDirV } } -// Obtain a merge doc to display a difference in files +/// Obtain a merge doc to display a difference in files CMergeDoc * CMainFrame::GetMergeDocToShow(CDirDoc * pDirDoc, BOOL * pNew) { CMergeDoc * pMergeDoc = pDirDoc->GetMergeDocForDiff(pNew); return pMergeDoc; } -// get pointer to a dir doc for displaying a scan +/// Get pointer to a dir doc for displaying a scan CDirDoc * CMainFrame::GetDirDocToShow(BOOL * pNew) { CDirDoc * pDirDoc = 0; diff --git a/Src/MainFrm.h b/Src/MainFrm.h index 50443ae4c..2fbe0599c 100644 --- a/Src/MainFrm.h +++ b/Src/MainFrm.h @@ -37,6 +37,9 @@ #define BACKUP_FILE_EXT _T(".bak") +/** + * @brief Flags used when opening files + */ enum { FFILEOPEN_NONE = 0x0000, @@ -74,7 +77,6 @@ public: BOOL m_bBackup; LOGFONT m_lfDiff; BOOL m_bFontSpecified; - BOOL m_bEolSensitive; BOOL m_bReuseDirDoc; // policy to reuse existing dir doc BOOL m_bAutomaticRescan; @@ -113,8 +115,6 @@ protected: public: BOOL m_bFirstTime; CString m_strSaveAsPath; - BOOL m_bIgnoreBlankLines; - BOOL m_bIgnoreCase; BOOL m_bIgnoreRegExp; CString m_sPattern; UINT m_nTabSize; @@ -124,7 +124,6 @@ public: CString m_strVssPassword; // BSP - Visual Source Safe Password int m_nVerSys; BOOL m_bHideBak; - int m_nIgnoreWhitespace; BOOL m_bScrollToFirst; UINT m_nTabType; BOOL m_bViewWhitespace; diff --git a/Src/MergeDoc.cpp b/Src/MergeDoc.cpp index dcd592477..b8ac0fa1c 100644 --- a/Src/MergeDoc.cpp +++ b/Src/MergeDoc.cpp @@ -238,8 +238,8 @@ void CMergeDoc::Dump(CDumpContext& dc) const */ int CMergeDoc::Rescan(BOOL bForced /* =FALSE */) { - DIFFSETTINGS diffSettings; - DIFFSTATUS status; + DIFFOPTIONS diffOptions = {0}; + DIFFSTATUS status = {0}; BOOL diffSuccess; int nResult = RESCAN_OK; @@ -278,20 +278,8 @@ int CMergeDoc::Rescan(BOOL bForced /* =FALSE */) m_diffWrapper.SetCompareFiles(m_strTempLeftFile, m_strTempRightFile); m_diffWrapper.SetDiffList(&m_diffs); m_diffWrapper.SetUseDiffList(TRUE); // Add diffs to list + m_diffWrapper.GetOptions(&diffOptions); - // Global diff-options - diffSettings.outputStyle = output_style; - diffSettings.context = context; - diffSettings.alwaysText = always_text_flag; - diffSettings.horizLines = horizon_lines; - diffSettings.ignoreSpaceChange = ignore_space_change_flag; - diffSettings.ignoreAllSpace = ignore_all_space_flag; - diffSettings.ignoreBlankLines = ignore_blank_lines_flag; - diffSettings.ignoreCase = ignore_case_flag; - diffSettings.heuristic = heuristic; - diffSettings.recursive = 0; // File scan is always non-recursive! - m_diffWrapper.SetOptions(&diffSettings); - // Clear diff list m_diffs.RemoveAll(); m_nDiffs = 0; @@ -307,7 +295,7 @@ int CMergeDoc::Rescan(BOOL bForced /* =FALSE */) // If comparing whitespaces and // other file has EOL before EOF and other not... if (status.bLeftMissingNL != status.bRightMissingNL && - !mf->m_nIgnoreWhitespace) + !diffOptions.nIgnoreWhitespace) { // ..lasf DIFFRANGE of file which has EOL must be // fixed to contain last line too @@ -1710,9 +1698,11 @@ static int lastdiff(BOOL case_sensitive, int whitespace, const CString & str1, c } } -// Highlight difference in current line +/// Highlight difference in current line void CMergeDoc::Showlinediff(CMergeEditView * pView) { + DIFFOPTIONS diffOptions = {0}; + m_diffWrapper.GetOptions(&diffOptions); CMergeEditView * pOther = (pView == m_pLeftView ? m_pRightView : m_pLeftView); int line = pView->GetCursorPos().y; @@ -1721,7 +1711,7 @@ void CMergeDoc::Showlinediff(CMergeEditView * pView) CString str1 = pView->GetLineChars(line); CString str2 = pOther->GetLineChars(line); - int begin = firstdiff(!mf->m_bIgnoreCase, mf->m_nIgnoreWhitespace, str1, str2); + int begin = firstdiff(!diffOptions.bIgnoreCase, diffOptions.nIgnoreWhitespace, str1, str2); if (begin<0) { @@ -1731,7 +1721,7 @@ void CMergeDoc::Showlinediff(CMergeEditView * pView) if (begin>=width) begin = width; - int end = lastdiff(!mf->m_bIgnoreCase, mf->m_nIgnoreWhitespace, str1, str2)+1; + int end = lastdiff(!diffOptions.bIgnoreCase, diffOptions.nIgnoreWhitespace, str1, str2)+1; if (end>=width) end = width; @@ -1812,12 +1802,14 @@ int CMergeDoc::LoadFile(CString sFileName, BOOL bLeft) BOOL CMergeDoc::OpenDocs(CString sLeftFile, CString sRightFile, BOOL bROLeft, BOOL bRORight) { + DIFFOPTIONS diffOptions = {0}; int nRescanResult = RESCAN_OK; + m_diffWrapper.GetOptions(&diffOptions); CChildFrame *pf = GetParentFrame(); ASSERT(pf); - m_ltBuf.SetEolSensitivity(mf->m_bEolSensitive); - m_rtBuf.SetEolSensitivity(mf->m_bEolSensitive); + m_ltBuf.SetEolSensitivity(diffOptions.bEolSensitive); + m_rtBuf.SetEolSensitivity(diffOptions.bEolSensitive); undoTgt.clear(); curUndo = undoTgt.begin(); @@ -1902,3 +1894,17 @@ BOOL CMergeDoc::OpenDocs(CString sLeftFile, CString sRightFile, } return TRUE; } + +/** + * @brief Read doc settings from registry + * + * @note Currently loads only diffutils settings, but later others too + */ +void CMergeDoc::ReadSettings() +{ + DIFFOPTIONS diffOptions = {0}; + + // We have to first get current options + CDiffWrapper::ReadDiffOptions(&diffOptions); + m_diffWrapper.SetOptions(&diffOptions); +} diff --git a/Src/MergeDoc.h b/Src/MergeDoc.h index 6b4e3c9b9..642dd6f0d 100644 --- a/Src/MergeDoc.h +++ b/Src/MergeDoc.h @@ -48,7 +48,6 @@ /** * @brief Return statuses of file rescan */ - enum { RESCAN_OK = 0, @@ -182,6 +181,7 @@ public: UINT m_nDiffs; CString m_strLeftFile, m_strRightFile; + void ReadSettings(); BOOL OpenDocs(CString sLeftFile, CString sRightFile, BOOL bROLeft = FALSE, BOOL bRORight = FALSE); int LoadFile(CString sFileName, BOOL bLeft); diff --git a/Src/readme.txt b/Src/readme.txt index 3a328802e..3d7126e95 100644 --- a/Src/readme.txt +++ b/Src/readme.txt @@ -1,3 +1,8 @@ +2003-08-29 Kimmo + PATCH: [ 796756 ] Diff API + WinMerge: DiffWrapper.h DiffWrapper.cpp DirDoc.h DirDoc.cpp DirView.cpp + MainFrm.h MainFrm.cpp MergeDoc.h MergeDoc.cpp + 2003-08-28 Laoran PATCH: [ 794345 ] make visible the changed text when undo/redo WinMerge: MergeEditView.cpp -- 2.11.0