OSDN Git Service

Shell Extension for Windows 11 or later (5)
[winmerge-jp/winmerge-jp.git] / Src / DiffTextBuffer.h
1 /** 
2  * @file  DiffTextBuffer.h
3  *
4  * @brief Declaration of CDiffTextBuffer class
5  */
6 #pragma once
7
8 #include "GhostTextBuffer.h"
9 #include "FileTextEncoding.h"
10
11 class CMergeDoc;
12 class PackingInfo;
13
14 /**
15  * @brief Specialized buffer to save file data
16  */
17 class CDiffTextBuffer : public CGhostTextBuffer
18 {
19         friend class CMergeDoc;
20
21 private :
22         CMergeDoc * m_pOwnerDoc; /**< Merge document owning this buffer. */
23         int m_nThisPane; /**< Left/Right side */
24         String m_strTempPath; /**< Temporary files folder. */
25         String m_strTempFileName; /**< Temporary file name. */
26         std::vector<int> m_unpackerSubcodes; /**< Plugin information. */
27         bool m_bMixedEOL; /**< EOL style of this buffer is mixed? */
28
29         /** 
30          * @brief Unicode encoding from ucr::UNICODESET.
31          *
32          * @note m_unicoding and m_codepage are indications of how the buffer is
33          * supposed to be saved on disk. In memory, it is invariant, depending on
34          * build:
35          * - ANSI: in memory it is CP_ACP/CP_THREAD_ACP 8-bit characters
36          * - Unicode: in memory it is wchars
37          */
38         FileTextEncoding m_encoding;
39
40         bool FlagIsSet(UINT line, DWORD flag) const;
41
42 public :
43         CDiffTextBuffer(CMergeDoc * pDoc, int pane);
44
45         void SetTempPath(const String &path);
46         String GetTempFileName() const { return m_strTempFileName; }
47         virtual void AddUndoRecord (bool bInsert, const CPoint & ptStartPos,
48                 const CPoint & ptEndPos, LPCTSTR pszText, size_t cchText,
49                 int nActionType = CE_ACTION_UNKNOWN,
50                 CDWordArray *paSavedRevisionNumbers = nullptr) override;
51         bool curUndoGroup();
52         void ReplaceFullLines(CDiffTextBuffer& dbuf, CDiffTextBuffer& sbuf, CCrystalTextView * pSource, int nLineBegin, int nLineEnd, int nAction =CE_ACTION_UNKNOWN);
53
54         int LoadFromFile(LPCTSTR pszFileName, PackingInfo& infoUnpacker,
55                 LPCTSTR filteredFilenames, bool & readOnly, CRLFSTYLE nCrlfStyle,
56                 const FileTextEncoding & encoding, CString &sError);
57         int SaveToFile (const String& pszFileName, bool bTempFile, String & sError,
58                 PackingInfo& infoUnpacker, CRLFSTYLE nCrlfStyle = CRLFSTYLE::AUTOMATIC,
59                 bool bClearModifiedFlag = true, int nStartLine = 0, int nLines = -1);
60         ucr::UNICODESET getUnicoding() const { return m_encoding.m_unicoding; }
61         void setUnicoding(ucr::UNICODESET value) { m_encoding.m_unicoding = value; }
62         int getCodepage() const { return m_encoding.m_codepage; }
63         void setCodepage(int value) { m_encoding.SetCodepage(value); }
64         bool getHasBom() const { return m_encoding.m_bom; }
65         void setHasBom(bool value) { m_encoding.m_bom = value; }
66         const FileTextEncoding & getEncoding() const { return m_encoding; }
67         void setEncoding(const FileTextEncoding &encoding) { m_encoding = encoding; }
68         bool IsMixedEOL() const { return m_bMixedEOL; }
69         void SetMixedEOL(bool bMixed) { m_bMixedEOL = bMixed; }
70
71         // If line has text (excluding eol), set strLine to text (excluding eol)
72         bool GetLine(int nLineIndex, CString &strLine) const;
73
74         // if line has any text (including eol), set strLine to text (including eol)
75         bool GetFullLine(int nLineIndex, CString &strLine) const;
76
77         virtual void SetModified (bool bModified = true) override;
78         void prepareForRescan();
79         virtual void OnNotifyLineHasBeenEdited(int nLine) override;
80         bool IsInitialized() const;
81         virtual bool DeleteText2 (CCrystalTextView * pSource, int nStartLine,
82                 int nStartPos, int nEndLine, int nEndPos,
83                 int nAction = CE_ACTION_UNKNOWN, bool bHistory = true) override;
84 };
85
86 /**
87  * @brief Set the folder for temp files.
88  * @param [in] path Temp files folder.
89  */
90 inline void CDiffTextBuffer::SetTempPath(const String &path)
91 {
92         m_strTempPath = path;
93 }
94
95 /**
96  * @brief Is the buffer initialized?
97  * @return true if the buffer is initialized, false otherwise.
98  */
99 inline bool CDiffTextBuffer::IsInitialized() const
100 {
101         return !!m_bInit;
102 }
103