OSDN Git Service

refactor
[winmerge-jp/winmerge-jp.git] / Src / PatchTool.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /** 
3  * @file  PatchTool.h
4  *
5  * @brief Declaration file for PatchTool class
6  */
7 #pragma once
8
9 #include "DiffWrapper.h"
10 #include "DiffItem.h"
11
12 class CPatchDlg;
13
14 /** 
15  * @brief Files used for patch creating.
16  * Stores paths of two files used to create a patch. Left side file
17  * is considered as "original" file and right side file as "changed" file.
18  * Times are for printing filetimes to patch file.
19  */
20 struct PATCHFILES
21 {
22         String lfile; /**< Left file */
23         String pathLeft; /**< Left path added to patch file */
24         String rfile; /**< Right file */
25         String pathRight; /**< Right path added to patch file */
26         time_t ltime; /**< Left time */
27         time_t rtime; /**< Right time */
28         PATCHFILES() : ltime(0), rtime(0) {};
29         /**
30          * @brief Swap diff sides.
31          */
32         void swap_sides()
33         {
34                 std::swap(lfile, rfile);
35                 std::swap(pathLeft, pathRight);
36                 std::swap(ltime, rtime);
37         }
38 };
39
40 /** 
41  * @brief A class which creates patch files.
42  * This class is used to create patch files. The files to patch can be added
43  * to list before calling CreatePatch(). Or user can select files in the
44  * the dialog that CreatePatch() shows.
45  */
46 class CPatchTool
47 {
48 public:
49         CPatchTool();
50         ~CPatchTool();
51
52         void AddFiles(const String &file1, const String &file2);
53         void AddFiles(const String &file1, const String &altPath1,
54                 const String &file2, const String &altPath2);
55         int CreatePatch();
56
57 protected:
58         bool ShowDialog(CPatchDlg *pDlgPatch);
59
60 private:
61         void AddFilesToList(const String& sDir1, const String& sDir2, const DirItem* ent1, const DirItem* ent2, std::vector<PATCHFILES>* fileList);
62         int GetItemsForPatchList(const PathContext& paths, const String subdir[], std::vector<PATCHFILES>* fileList);
63
64 private:
65     std::vector<PATCHFILES> m_fileList; /**< List of files to patch. */
66         CDiffWrapper m_diffWrapper; /**< DiffWrapper instance we use to create patch. */
67         String m_sPatchFile; /**< Patch file path and filename. */
68         bool m_bOpenToEditor; /**< Is patch file opened to external editor? */
69         bool m_bCopyToClipbard; /**< Is patch file copied to clipboard? */
70 };