OSDN Git Service

3b23daa6448f8c1835a01349b46dc45134273f98
[winmerge-jp/winmerge-jp.git] / Src / FileActionScript.h
1 /////////////////////////////////////////////////////////////////////////////
2 //    License (GPLv2+):
3 //    This program is free software; you can redistribute it and/or modify
4 //    it under the terms of the GNU General Public License as published by
5 //    the Free Software Foundation; either version 2 of the License, or
6 //    (at your option) any later version.
7 //
8 //    This program is distributed in the hope that it will be useful, but
9 //    WITHOUT ANY WARRANTY; without even the implied warranty of
10 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //    General Public License for more details.
12 //
13 //    You should have received a copy of the GNU General Public License
14 //    along with this program; if not, write to the Free Software
15 //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 /////////////////////////////////////////////////////////////////////////////
17 /**
18  * @file  FileActionScript.h
19  *
20  * @brief Declaration file for FileActionScript and related classes
21  */
22 #pragma once
23
24 #include <vector>
25 #include <memory>
26
27 class ShellFileOperations;
28
29 /** 
30  * @brief Return values for FileActionScript functions.
31  */
32 enum CreateScriptReturn
33 {
34         SCRIPT_FAIL = 0,    /**< The script failed. */
35         SCRIPT_SUCCESS,     /**< The script succeeded. */
36         SCRIPT_USERCANCEL,  /**< The user cancelled the action. */
37         SCRIPT_USERSKIP,    /**< The user wanted to skip one or more items. */
38 };
39
40 /** 
41  * @brief FileAction presents one filesystem action we want to do.
42  *
43  * Action consists of source, destination and action type. This
44  * allows us to combine lots of different kind of actions into
45  * one list.
46  **/
47 struct FileAction
48 {
49         /**
50          * @brief the type of the action.
51          * These action types are low level actions for filesystem, not
52          * higher level actions user is doing (e.g. synchronizing).
53          */
54         enum ACT_TYPE
55         { 
56                 ACT_COPY = 1, /**< Copy the item(s). */
57                 ACT_MOVE,     /**< Move the item(s). */
58                 ACT_DEL,      /**< Delete the item(s). */
59                 ACT_RENAME,   /**< Rename the item(s). */
60         };
61
62         String src; /**< Source for action */
63         String dest; /**< Destination action */
64         bool dirflag; /**< Is it directory? (TRUE means directory) */
65         ACT_TYPE atype; /**< Action's type */
66 };
67
68 /** 
69  * @brief FileActionItem presents one filesystem action from GUI perspective.
70  */
71 struct FileActionItem : public FileAction
72 {
73         /**
74          * @brief UI result of the action done.
75          * These values present the change in the UI happening, due to lower
76          * level actions. E.g. delete operation may cause left item to be removed
77          * from the list.
78          */
79         enum UI_RESULT
80         {
81                 UI_SYNC = 1,   /**< Make items identical (synchronized). */
82                 UI_DESYNC,     /**< Make items different. */
83                 UI_DEL,        /**< Remove left item. */
84                 UI_DONT_CARE,  /**< Ignore the GUI change. */
85                 UI_RENAME      /**< Rename item. */
86         };
87
88         /**
89          * Optional context value for the item.
90          * This is an arbitrary value that can be used to associate the item with
91          * other items. This can be e.g. indext of the item in the GUI.
92          */
93         int context;
94         int UIResult; /**< Resulting UI action */
95         int UIOrigin; /**< Original UI-side */
96         int UIDestination; /**< Destination UI-side */
97 };
98
99 /** 
100  * @brief FileActionScript holds list of fileactions and runs those actions.
101  *
102  * This class holds list of actions we want to make with filesystem. After
103  * whole list of actions (script) is composed we can run this sript with
104  * one command.
105  */
106 class FileActionScript
107 {
108 public:
109         typedef 
110         FileActionScript();
111         ~FileActionScript();
112
113         void SetParentWindow(HWND hWnd);
114         void UseRecycleBin(BOOL bUseRecycleBin);
115         BOOL Run();
116
117         // Manipulate the FileActionList
118         size_t GetActionItemCount() const;
119
120         /**
121          * Add new item to the action list.
122          * @param [in] item Item to add to the list.
123          */
124         void AddActionItem(FileActionItem & item) { m_actions.push_back(item); }
125
126         FileActionItem RemoveTailActionItem();
127
128         /**
129          * Get first action item in the list.
130          * @return First item in the list.
131          */
132         FileActionItem GetHeadActionItem() const { return m_actions[0]; }
133
134         String m_destBase; /**< Base destination path for some operations */
135
136 protected:
137         int VCSCheckOut(const String &path, BOOL &bApplyToAll);
138         int CreateOperationsScripts();
139         bool RunOp(ShellFileOperations *oplist, bool & userCancelled);
140
141 private:
142         std::vector<FileActionItem> m_actions; /**< List of all actions for this script. */
143         std::unique_ptr<ShellFileOperations> m_pCopyOperations; /**< Copy operations. */
144         BOOL m_bHasCopyOperations; /**< flag if we've put anything into m_pCopyOperations */
145         std::unique_ptr<ShellFileOperations> m_pMoveOperations; /**< Move operations. */
146         BOOL m_bHasMoveOperations; /**< flag if we've put anything into m_pMoveOperations */
147         std::unique_ptr<ShellFileOperations> m_pRenameOperations; /**< Rename operations. */
148         BOOL m_bHasRenameOperations; /**< flag if we've put anything into m_pRenameOperations */
149         std::unique_ptr<ShellFileOperations> m_pDelOperations; /**< Delete operations. */
150         BOOL m_bHasDelOperations; /**< flag if we've put anything into m_pDelOperations */
151         BOOL m_bUseRecycleBin; /**< Use recycle bin for script actions? */
152         HWND m_hParentWindow; /**< Parent window for showing messages */
153 };