From 0f046772390f2ebcfbfeb396b93f529982b23193 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Mon, 13 Apr 2009 11:47:23 +0000 Subject: [PATCH] PATCH: [ 2726531 ] Show XML config files like XML files Submitted by bulklodd --- Docs/Users/ChangeLog.txt | 1 + Src/MergeDoc.cpp | 11 +++++++++++ Src/editlib/ccrystaltextview.cpp | 13 +++++++++++++ Src/editlib/ccrystaltextview.h | 1 + 4 files changed, 26 insertions(+) diff --git a/Docs/Users/ChangeLog.txt b/Docs/Users/ChangeLog.txt index 2eab2b965..71151ca25 100644 --- a/Docs/Users/ChangeLog.txt +++ b/Docs/Users/ChangeLog.txt @@ -8,6 +8,7 @@ WinMerge 2.13.6 color (#2669526) Disable folder compare tree-view by default (#2714968) Allow setting codepage from command line (#2725549) + Improve detecting XML files in file compare (#2726531) Bugfix: Says files are identical after making files different in another application and re-loading them (#2672737) Bugfix: Difference pane didn't show added lines (#2710146) diff --git a/Src/MergeDoc.cpp b/Src/MergeDoc.cpp index e284d903e..80ba445ce 100644 --- a/Src/MergeDoc.cpp +++ b/Src/MergeDoc.cpp @@ -2315,6 +2315,17 @@ OPENRESULTS_TYPE CMergeDoc::OpenDocs(FileLocation filelocLeft, FileLocation file pRightDetail->SetTextType(sextR.c_str()); } + // If textypes of the files aren't recogzined by their extentions, + // try to recognize them using their first lines + if (!bLeftTyped && !bRightTyped) + { + CString sFirstLine; + m_ptBuf[0]->GetLine(0, sFirstLine); + bLeftTyped = pLeft->SetTextTypeByContent(sFirstLine); + m_ptBuf[1]->GetLine(0, sFirstLine); + bRightTyped = pRight->SetTextTypeByContent(sFirstLine); + } + // If other side didn't have recognized texttype, apply recognized // type to unrecognized one. (comparing file.cpp and file.bak applies // cpp file type to .bak file. diff --git a/Src/editlib/ccrystaltextview.cpp b/Src/editlib/ccrystaltextview.cpp index cbd0aebee..069a37223 100644 --- a/Src/editlib/ccrystaltextview.cpp +++ b/Src/editlib/ccrystaltextview.cpp @@ -6183,6 +6183,19 @@ void CCrystalTextView::EnsureVisible (CPoint ptStart, CPoint ptEnd) } } +// Analyze the first line of file to detect its type +// Mainly it works for xml files +bool CCrystalTextView:: +SetTextTypeByContent (LPCTSTR pszContent) +{ + int nLen; + if (::FindStringHelper(pszContent, _T("^\\s*\\<\\?xml\\s+.+?\\?\\>\\s*$"), + FIND_REGEXP, nLen) == 0) + { + return SetTextType(CCrystalTextView::SRC_XML); + } + return false; +} //////////////////////////////////////////////////////////////////////////// #pragma warning ( default : 4100 ) diff --git a/Src/editlib/ccrystaltextview.h b/Src/editlib/ccrystaltextview.h index 5d192f683..662dcab2e 100644 --- a/Src/editlib/ccrystaltextview.h +++ b/Src/editlib/ccrystaltextview.h @@ -790,6 +790,7 @@ public : virtual bool SetTextType (LPCTSTR pszExt); virtual bool SetTextType (CCrystalTextView::TextType enuType); virtual bool SetTextType (CCrystalTextView::TextDefinition *def); + virtual bool SetTextTypeByContent (LPCTSTR pszContent); static void LoadSettings (); static void SaveSettings (); -- 2.11.0