OSDN Git Service

Leave the class name as CIniOptionsMgr, but rename the filename to IniOptionsMgr.*
[winmerge-jp/winmerge-jp.git] / Src / FileActionScript.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /**
3  * @file  FileActionScript.h
4  *
5  * @brief Declaration file for FileActionScript and related classes
6  */
7 #pragma once
8
9 #include <vector>
10 #include <memory>
11
12 class ShellFileOperations;
13
14 /** 
15  * @brief Return values for FileActionScript functions.
16  */
17 enum CreateScriptReturn
18 {
19         SCRIPT_FAIL = 0,    /**< The script failed. */
20         SCRIPT_SUCCESS,     /**< The script succeeded. */
21         SCRIPT_USERCANCEL,  /**< The user cancelled the action. */
22         SCRIPT_USERSKIP,    /**< The user wanted to skip one or more items. */
23 };
24
25 /** 
26  * @brief FileAction presents one filesystem action we want to do.
27  *
28  * Action consists of source, destination and action type. This
29  * allows us to combine lots of different kind of actions into
30  * one list.
31  **/
32 struct FileAction
33 {
34         /**
35          * @brief the type of the action.
36          * These action types are low level actions for filesystem, not
37          * higher level actions user is doing (e.g. synchronizing).
38          */
39         enum ACT_TYPE
40         { 
41                 ACT_COPY = 1, /**< Copy the item(s). */
42                 ACT_MOVE,     /**< Move the item(s). */
43                 ACT_DEL,      /**< Delete the item(s). */
44                 ACT_RENAME,   /**< Rename the item(s). */
45         };
46
47         String src; /**< Source for action */
48         String dest; /**< Destination action */
49         bool dirflag; /**< Is it directory? (`true` means directory) */
50         ACT_TYPE atype; /**< Action's type */
51 };
52
53 /** 
54  * @brief FileActionItem presents one filesystem action from GUI perspective.
55  */
56 struct FileActionItem : public FileAction
57 {
58         /**
59          * @brief UI result of the action done.
60          * These values present the change in the UI happening, due to lower
61          * level actions. E.g. delete operation may cause left item to be removed
62          * from the list.
63          */
64         enum UI_RESULT
65         {
66                 UI_SYNC = 1,   /**< Make items identical (synchronized). */
67                 UI_DESYNC,     /**< Make items different. */
68                 UI_DEL,        /**< Remove left item. */
69                 UI_DONT_CARE,  /**< Ignore the GUI change. */
70                 UI_RENAME      /**< Rename item. */
71         };
72
73         /**
74          * Optional context value for the item.
75          * This is an arbitrary value that can be used to associate the item with
76          * other items. This can be e.g. indext of the item in the GUI.
77          */
78         int context;
79         int UIResult; /**< Resulting UI action */
80         int UIOrigin; /**< Original UI-side */
81         int UIDestination; /**< Destination UI-side */
82 };
83
84 /** 
85  * @brief FileActionScript holds list of fileactions and runs those actions.
86  *
87  * This class holds list of actions we want to make with filesystem. After
88  * whole list of actions (script) is composed we can run this sript with
89  * one command.
90  */
91 class FileActionScript
92 {
93 public:
94         FileActionScript();
95         ~FileActionScript();
96
97         void SetParentWindow(HWND hWnd);
98         void UseRecycleBin(bool bUseRecycleBin);
99         bool Run();
100
101         // Manipulate the FileActionList
102         size_t GetActionItemCount() const;
103
104         /**
105          * Add new item to the action list.
106          * @param [in] item Item to add to the list.
107          */
108         void AddActionItem(FileActionItem & item) { m_actions.push_back(item); }
109
110         FileActionItem RemoveTailActionItem();
111
112         /**
113          * Get first action item in the list.
114          * @return First item in the list.
115          */
116         FileActionItem GetHeadActionItem() const { return m_actions[0]; }
117
118         bool IsCanceled() const { return m_bCanceled; }
119
120         String m_destBase; /**< Base destination path for some operations */
121
122 protected:
123         int CreateOperationsScripts();
124         bool RunOp(ShellFileOperations *oplist, bool & userCancelled);
125
126 private:
127         std::vector<FileActionItem> m_actions; /**< List of all actions for this script. */
128         std::unique_ptr<ShellFileOperations> m_pCopyOperations; /**< Copy operations. */
129         bool m_bHasCopyOperations; /**< flag if we've put anything into m_pCopyOperations */
130         std::unique_ptr<ShellFileOperations> m_pMoveOperations; /**< Move operations. */
131         bool m_bHasMoveOperations; /**< flag if we've put anything into m_pMoveOperations */
132         std::unique_ptr<ShellFileOperations> m_pRenameOperations; /**< Rename operations. */
133         bool m_bHasRenameOperations; /**< flag if we've put anything into m_pRenameOperations */
134         std::unique_ptr<ShellFileOperations> m_pDelOperations; /**< Delete operations. */
135         bool m_bHasDelOperations; /**< flag if we've put anything into m_pDelOperations */
136         bool m_bUseRecycleBin; /**< Use recycle bin for script actions? */
137         HWND m_hParentWindow; /**< Parent window for showing messages */
138         bool m_bCanceled;
139 };
140
141 /**
142  * @brief Set parent window used for showing MessageBoxes.
143  * @param [in] hWnd Handle to parent window.
144  */
145 inline void FileActionScript::SetParentWindow(HWND hWnd)
146 {
147         m_hParentWindow = hWnd;
148 }
149
150 /**
151  * @brief Does user want to move deleted files to Recycle Bin?
152  * @param [in] bUseRecycleBin If `true` deleted files are moved to Recycle Bin.
153  */
154 inline void FileActionScript::UseRecycleBin(bool bUseRecycleBin)
155 {
156         m_bUseRecycleBin = bUseRecycleBin;
157 }
158
159 /**
160  * @brief Return amount of actions (copy, move, etc) in script.
161  * @return Amount of actions.
162  */
163 inline size_t FileActionScript::GetActionItemCount() const
164 {
165         return m_actions.size();
166 }
167