1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * @file FileActionScript.h
5 * @brief Declaration file for FileActionScript and related classes
12 class ShellFileOperations;
15 * @brief Return values for FileActionScript functions.
17 enum CreateScriptReturn
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. */
26 * @brief FileAction presents one filesystem action we want to do.
28 * Action consists of source, destination and action type. This
29 * allows us to combine lots of different kind of actions into
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).
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). */
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 */
54 * @brief FileActionItem presents one filesystem action from GUI perspective.
56 struct FileActionItem : public FileAction
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
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. */
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.
79 int UIResult; /**< Resulting UI action */
80 int UIOrigin; /**< Original UI-side */
81 int UIDestination; /**< Destination UI-side */
85 * @brief FileActionScript holds list of fileactions and runs those actions.
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
91 class FileActionScript
97 void SetParentWindow(HWND hWnd);
98 void UseRecycleBin(bool bUseRecycleBin);
101 // Manipulate the FileActionList
102 size_t GetActionItemCount() const;
105 * Add new item to the action list.
106 * @param [in] item Item to add to the list.
108 void AddActionItem(FileActionItem & item) { m_actions.push_back(item); }
110 FileActionItem RemoveTailActionItem();
113 * Get first action item in the list.
114 * @return First item in the list.
116 FileActionItem GetHeadActionItem() const { return m_actions[0]; }
118 bool IsCanceled() const { return m_bCanceled; }
120 String m_destBase; /**< Base destination path for some operations */
123 int CreateOperationsScripts();
124 bool RunOp(ShellFileOperations *oplist, bool & userCancelled);
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 */
142 * @brief Set parent window used for showing MessageBoxes.
143 * @param [in] hWnd Handle to parent window.
145 inline void FileActionScript::SetParentWindow(HWND hWnd)
147 m_hParentWindow = hWnd;
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.
154 inline void FileActionScript::UseRecycleBin(bool bUseRecycleBin)
156 m_bUseRecycleBin = bUseRecycleBin;
160 * @brief Return amount of actions (copy, move, etc) in script.
161 * @return Amount of actions.
163 inline size_t FileActionScript::GetActionItemCount() const
165 return m_actions.size();