1
// Copyright (c) 2005, Rodrigo Braz Monteiro
2
// All rights reserved.
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are met:
7
// * Redistributions of source code must retain the above copyright notice,
8
// this list of conditions and the following disclaimer.
9
// * Redistributions in binary form must reproduce the above copyright notice,
10
// this list of conditions and the following disclaimer in the documentation
11
// and/or other materials provided with the distribution.
12
// * Neither the name of the Aegisub Group nor the names of its contributors
13
// may be used to endorse or promote products derived from this software
14
// without specific prior written permission.
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
// POSSIBILITY OF SUCH DAMAGE.
28
// -----------------------------------------------------------------------------
32
// Website: http://aegisub.cellosoft.com
33
// Contact: mailto:zeratul@cellosoft.com
42
#include <wx/wxprec.h>
54
class AssDialogueBlock;
55
class AssDialogueBlockOverride;
56
class AssDialogueBlockPlain;
60
//////////////////////////////////////
61
// Class to store the actual ass file
67
static std::list<AssFile*> UndoStack;
68
static std::list<AssFile*> RedoStack;
69
static bool StackModified;
70
static void StackClear();
73
std::list<AssEntry*> Line;
76
wxString undodescription;
80
AssFile(AssFile &from);
83
bool IsModified(); // Returns if file has unmodified changes
84
void FlagAsModified(wxString desc); // Flag file as being modified, will automatically put a copy on stack
85
void Clear(); // Wipes file
86
void CompressForStack(bool compress); // Compress/decompress for storage on stack
87
void LoadDefault(bool defline=true); // Loads default file. Pass false to prevent it from adding a default line too
88
void InsertStyle(AssStyle *style); // Inserts a style to file
89
void InsertAttachment(AssAttachment *attach); // Inserts an attachment
90
void InsertAttachment(wxString filename); // Inserts a file as an attachment
91
wxArrayString GetStyles(); // Gets a list of all styles available
92
AssStyle *GetStyle(wxString name); // Gets style by its name
94
//wxString GetString(); // Returns the whole file as a single string
95
void Load(wxString file,wxString charset=_T(""),bool addToRecent=true); // Load from a file
96
void Save(wxString file,bool setfilename=false,bool addToRecent=true,const wxString encoding=_T("")); // Save to a file. Pass true to second argument if this isn't a copy
97
void SaveMemory(std::vector<char> &dst,const wxString encoding=_T("")); // Save to a memory string
98
void Export(wxString file); // Saves exported copy, with effects applied
99
void AddToRecent(wxString file); // Adds file name to list of recently opened files
100
bool CanSave(); // Returns true if the file can be saved in its current format
101
static wxString GetWildcardList(int mode); // Returns the list of wildcards supported (0 = open, 1 = save, 2 = export)
103
void GetResolution(int &w,int &h); // Get resolution
104
int GetScriptInfoAsInt(const wxString key); // Returns the value in a [Script Info] key as int.
105
wxString GetScriptInfo(const wxString key); // Returns the value in a [Script Info] key as string.
106
void SetScriptInfo(const wxString key,const wxString value); // Sets the value of a [Script Info] key. Adds it if it doesn't exist.
107
void AddComment(const wxString comment); // Adds a ";" comment under [Script Info].
108
int AddLine(wxString data,wxString group,int lasttime,int &version,wxString *outGroup=NULL);
110
static void StackPop(); // Pop subs from stack and sets 'top' to it
111
static void StackRedo(); // Redoes action on stack
112
static void StackPush(wxString desc); // Puts a copy of 'top' on the stack
113
static void StackReset(); // Resets stack. Do this before loading new subtitles.
114
static bool IsUndoStackEmpty(); // Checks if undo stack is empty
115
static bool IsRedoStackEmpty(); // Checks if undo stack is empty
116
static wxString GetUndoDescription(); // Gets field undodescription from back of UndoStack
117
static wxString GetRedoDescription(); // Gets field undodescription from back of RedoStack
118
static bool Popping; // Flags the stack as popping. You must unset this after popping
119
static AssFile *top; // Current script file. It is "above" the stack.
125
typedef std::list<AssEntry*>::iterator entryIter;
128
//////////////////////////////////////////////////////
129
// Hack to get STL sort to work on a list of pointers
130
template <typename T>
131
class LessByPointedToValue : std::binary_function<T const *, T const *, bool> {
133
bool operator()(T const * x, T const * y) const {
134
return std::less<T>()(*x, *y);