| 206 | } |
| 207 | |
| 208 | wxString MacroCommands::WriteMacro(const wxString & macro, wxWindow *parent) |
| 209 | { |
| 210 | // Build the default filename |
| 211 | wxFileName name(FileNames::MacroDir(), macro, wxT("txt")); |
| 212 | |
| 213 | // But, ask the user for the real name if we're exporting |
| 214 | if (parent) { |
| 215 | FilePath fn = SelectFile(FileNames::Operation::_None, |
| 216 | XO("Export Macro"), |
| 217 | wxEmptyString, |
| 218 | name.GetName(), |
| 219 | wxT("txt"), |
| 220 | { FileNames::TextFiles }, |
| 221 | wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER, |
| 222 | parent); |
| 223 | |
| 224 | // User canceled... |
| 225 | if (fn.empty()) { |
| 226 | return wxEmptyString; |
| 227 | } |
| 228 | |
| 229 | name.Assign(fn); |
| 230 | } |
| 231 | |
| 232 | // Set the file name |
| 233 | wxTextFile tf(name.GetFullPath()); |
| 234 | |
| 235 | // Create the file (Create() doesn't leave the file open) |
| 236 | if (!tf.Exists()) { |
| 237 | tf.Create(); |
| 238 | } |
| 239 | |
| 240 | // Open it |
| 241 | tf.Open(); |
| 242 | |
| 243 | if (!tf.IsOpened()) { |
| 244 | // wxTextFile will display any errors |
| 245 | return wxEmptyString; |
| 246 | } |
| 247 | |
| 248 | // Start with a clean slate |
| 249 | tf.Clear(); |
| 250 | |
| 251 | // Copy over the commands |
| 252 | int lines = mCommandMacro.size(); |
| 253 | for (int i = 0; i < lines; i++) { |
| 254 | // using GET to serialize macro definition to a text file |
| 255 | tf.AddLine(mCommandMacro[i].GET() + wxT(":") + mParamsMacro[ i ]); |
| 256 | } |
| 257 | |
| 258 | // Write the macro |
| 259 | tf.Write(); |
| 260 | |
| 261 | // Done with the file |
| 262 | tf.Close(); |
| 263 | |
| 264 | return name.GetName(); |
| 265 | } |