OSDN Git Service

Fix untranslated strings
[winmerge-jp/winmerge-jp.git] / Src / FileTransform.h
1 /////////////////////////////////////////////////////////////////////////////
2 //    WinMerge:  an interactive diff/merge utility
3 //    Copyright (C) 1997-2000  Thingamahoochie Software
4 //    Author: Dean Grimm
5 //
6 //    This program is free software; you can redistribute it and/or modify
7 //    it under the terms of the GNU General Public License as published by
8 //    the Free Software Foundation; either version 2 of the License, or
9 //    (at your option) any later version.
10 //
11 //    This program is distributed in the hope that it will be useful,
12 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //    GNU General Public License for more details.
15 //
16 //    You should have received a copy of the GNU General Public License
17 //    along with this program; if not, write to the Free Software
18 //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 //
20 /////////////////////////////////////////////////////////////////////////////
21 /**
22  *  @file FileTransform.h
23  *
24  *  @brief Declaration of file transformations
25  */ 
26 #pragma once
27
28 #include <vector>
29 #include "UnicodeString.h"
30 #include "MergeApp.h"
31
32 namespace FileTransform
33 {
34 extern int g_bUnpackerMode;
35 extern int g_bPredifferMode;
36 }
37
38 class UniFile;
39
40 /**
41  * @brief Modes for plugin (Modes for prediffing included)
42  */
43 enum PLUGIN_MODE
44 {
45         // Modes for unpacking
46         PLUGIN_MANUAL,
47         PLUGIN_AUTO,
48         PLUGIN_BUILTIN_XML,
49         // Modes for prediffing
50         PREDIFF_MANUAL = PLUGIN_MANUAL,
51         PREDIFF_AUTO = PLUGIN_AUTO,
52 };
53
54 /**
55  * @brief Plugin information for a given file
56  *
57  * @note Can be be passed/copied between threads
58  */
59 class PluginForFile
60 {
61 public:
62         void Initialize(int bMode)
63         {
64                 // TODO: Convert bMode to PLUGIN_MODE and fix compile errors
65                 // init functions as a valid "do nothing" unpacker
66                 bWithFile = false;
67                 // and init bAutomatic flag and name according to global variable
68                 if (bMode != PLUGIN_AUTO)
69                 {
70                         pluginName.erase();
71                 }
72                 else
73                 {
74                         pluginName = _("<Automatic>");
75                 }
76                 bToBeScanned = bMode;
77         };
78         explicit PluginForFile(PLUGIN_MODE bMode) 
79         {
80                 Initialize(bMode);
81         };
82 public:
83         /// TRUE if the plugin will be defined during the first use (through scan of all available plugins)
84         int bToBeScanned; // TODO: Convert to PLUGIN_MODE and fix compile errors
85         /// plugin name when it is defined
86         String pluginName;
87         /// TRUE is the plugins exchange data through a file, false is the data is passed as parameter (BSTR/ARRAY)
88         bool    bWithFile;
89 };
90
91 /**
92  * @brief Unpacking/packing information for a given file
93  *
94  * @note Can be be copied between threads
95  * Each thread really needs its own instance so that subcode is really defined
96  * during the unpacking (open file) of the thread
97  */
98 class PackingInfo : public PluginForFile
99 {
100 public:
101         explicit PackingInfo(PLUGIN_MODE bMode = (PLUGIN_MODE)FileTransform::g_bUnpackerMode)
102         : PluginForFile(bMode)
103         , subcode(0)
104         , pufile(0)
105         , disallowMixedEOL(false)
106         {
107         }
108 public:
109         /// keep some info from unpacking for packing
110         int subcode;
111         /// text type to override syntax highlighting
112         String textType;
113         /// custom UniFile
114         UniFile *pufile;
115         bool disallowMixedEOL;
116 };
117
118 /**
119  * @brief Prediffing information for a given file
120  *
121  * @note Can be be passed/copied between threads
122  */
123 class PrediffingInfo : public PluginForFile
124 {
125 public:
126         explicit PrediffingInfo(PLUGIN_MODE bMode = (PLUGIN_MODE)FileTransform::g_bPredifferMode)
127         : PluginForFile(bMode)
128         {
129         }
130 };
131
132 namespace FileTransform
133 {
134
135 // Events handler
136 // WinMerge uses one of these entry points to call a plugin
137
138 // bMayOverwrite : tells if we can overwrite the source file
139 // if we don't, don't forget do delete the temp file after use
140
141 /**
142  * @brief Prepare one file for loading, scan all available plugins (events+filename filtering) 
143  *
144  * @param filepath : [in, out] Most plugins change this filename
145  * @param handler : unpacking handler, to keep to pack again
146  *
147  * @return Tells if WinMerge handles this file
148  *
149  * @note Event FILE_UNPACK
150  * Apply only the first correct handler
151  */
152 bool Unpacking(String & filepath, const String& filteredText, PackingInfo * handler, int * handlerSubcode);
153 /**
154  * @brief Prepare one file for loading, known handler
155  *
156  * @param filepath : [in, out] Most plugins change this filename
157  */
158 bool Unpacking(String & filepath, const PackingInfo * handler, int * handlerSubcode);
159
160 bool Unpacking(PackingInfo * handler, String & filepath, const String& filteredText);
161
162 /**
163  * @brief Prepare one file for saving, known handler
164  *
165  * @return Tells if we can save the file (really hope we can)
166  *
167  * @param filepath : [in, out] Most plugins change this filename
168  *
169  * @note Event FILE_PACK
170  * Never do Unicode conversion, it was done in SaveFromFile
171  */
172 bool Packing(String & filepath, PackingInfo handler);
173
174 /**
175  * @brief Prepare one file for diffing, scan all available plugins (events+filename filtering) 
176  *
177  * @param filepath : [in, out] Most plugins change this filename
178  * @param handler : unpacking handler, to keep to pack again
179  *
180  * @return Tells if WinMerge handles this file
181  *
182  * @note Event FILE_PREDIFF BUFFER_PREDIFF
183  * Apply only the first correct handler
184  */
185 bool Prediffing(String & filepath, const String& filteredText, PrediffingInfo * handler, bool bMayOverwrite);
186 /**
187  * @brief Prepare one file for diffing, known handler
188  *
189  * @param filepath : [in, out] Most plugins change this filename
190  */
191 bool Prediffing(String & filepath, PrediffingInfo handler, bool bMayOverwrite);
192
193 bool Prediffing(PrediffingInfo * handler, String & filepath, const String& filteredText, bool bMayOverwrite);
194
195 /**
196  * @brief Transform all files to UTF8 aslong possible
197  *
198  * @param codepage : [in] codepage of source file
199  * @param filepath : [in,out] path of file to be prepared. This filename is updated if bMayOverwrite is false
200  * @param bMayOverwrite : [in] True only if the filepath points out a temp file
201  *
202  * @return Tells if we can go on with diffutils
203  * convert all Ansi or unicode-files to UTF8 
204  * if other file is unicode or uses a different codepage
205  */
206 bool AnyCodepageToUTF8(int codepage, String & filepath, bool bMayOverwrite);
207
208
209 /**
210  * @brief Get the list of all the free functions in all the scripts for this event :
211  * 
212  * @note the order is :
213  * 1st script file, 1st function name
214  * 1st script file, 2nd function name
215  * 1st script file, ...
216  * 1st script file, last function name
217  * 2nd script file, 1st function name
218  * 2nd script file, 2nd function name
219  * 2nd script file, ...
220  * 2nd script file, last function name
221  * ... script file
222  * last script file, 1st function name
223  * last script file, 2nd function name
224  * last script file, ...
225  * last script file, last function name
226  */
227 void GetFreeFunctionsInScripts(std::vector<String> & sNamesArray, const wchar_t *TransformationEvent);
228
229 /** 
230  * @brief : Execute one free function from one script
231  *
232  * @param iFncChosen : index of the function in the list returned by GetFreeFunctionsInScripts
233  *
234  * @return Tells if the text has been changed 
235  *
236  * @note Event EDITOR_SCRIPT, ?
237  */
238 bool Interactive(String & text, const wchar_t *TransformationEvent, int iFncChosen);
239
240 }