forked from mia/Aegisub
Added a "modify line" action.
Originally committed to SVN as r2067.
This commit is contained in:
parent
0a0f383b4a
commit
fb1de2da07
9 changed files with 85 additions and 6 deletions
|
@ -84,4 +84,19 @@ namespace Gorgonsub {
|
|||
ActionPtr GetAntiAction(const Model &model) const;
|
||||
void Execute(Model &model);
|
||||
};
|
||||
|
||||
// Modify line
|
||||
class ActionModify : public Action {
|
||||
private:
|
||||
shared_ptr<SectionEntry> entry;
|
||||
const String section;
|
||||
int lineNumber;
|
||||
|
||||
public:
|
||||
ActionModify(shared_ptr<SectionEntry> entry,int line,const String §ion);
|
||||
virtual ~ActionModify() {}
|
||||
|
||||
ActionPtr GetAntiAction(const Model &model) const;
|
||||
void Execute(Model &model);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -68,6 +68,7 @@ namespace Gorgonsub {
|
|||
void Finish();
|
||||
void InsertLine(SectionEntryPtr line,int position=-1,const String section=L"");
|
||||
void RemoveLine(int position,const String section);
|
||||
SectionEntryPtr ModifyLine(int position,const String section);
|
||||
};
|
||||
typedef shared_ptr<ActionList> ActionListPtr;
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@ namespace Gorgonsub {
|
|||
void RemoveEntryByIndex(size_t index);
|
||||
void RemoveEntry(SectionEntryPtr entry);
|
||||
SectionEntryPtr GetEntry(size_t index) const;
|
||||
SectionEntryPtr& GetEntryRef(size_t index);
|
||||
size_t GetEntryCount() const;
|
||||
};
|
||||
typedef shared_ptr<Section> SectionPtr;
|
||||
|
|
|
@ -77,6 +77,7 @@ namespace Gorgonsub {
|
|||
public:
|
||||
virtual SectionEntryType GetType() const =0;
|
||||
virtual String GetDefaultGroup() const =0;
|
||||
virtual SectionEntryPtr Clone() const =0;
|
||||
|
||||
static const SectionEntryPlainPtr GetAsPlain(const SectionEntryPtr &ptr);
|
||||
static const SectionEntryDialoguePtr GetAsDialogue(const SectionEntryPtr &ptr);
|
||||
|
|
|
@ -45,7 +45,7 @@ SectionPtr Action::GetSection(const Model &model,const String &name) const
|
|||
}
|
||||
|
||||
|
||||
/////////////////// Insert line /////////////////////////////
|
||||
///////////////////////////// Insert line /////////////////////////////
|
||||
|
||||
///////////////
|
||||
// Constructor
|
||||
|
@ -79,7 +79,7 @@ void ActionInsert::Execute(Model &model)
|
|||
|
||||
|
||||
|
||||
/////////////////// Remove line /////////////////////////////
|
||||
///////////////////////////// Remove line /////////////////////////////
|
||||
|
||||
|
||||
///////////////
|
||||
|
@ -110,3 +110,35 @@ void ActionRemove::Execute(Model &model)
|
|||
// Remove the line
|
||||
section->RemoveEntryByIndex(lineNumber);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////// Modify line /////////////////////////////
|
||||
|
||||
///////////////
|
||||
// Constructor
|
||||
ActionModify::ActionModify(shared_ptr<SectionEntry> data,int line,const String &sName)
|
||||
: entry(data), lineNumber(line), section(sName) {}
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Create anti-action for insert
|
||||
ActionPtr ActionModify::GetAntiAction(const Model &model) const
|
||||
{
|
||||
SectionPtr sect = GetSection(model,section);
|
||||
SectionEntryPtr entry = sect->GetEntry(lineNumber);
|
||||
return ActionPtr(new ActionModify(entry,lineNumber,section));
|
||||
}
|
||||
|
||||
|
||||
/////////////////////
|
||||
// Execute insertion
|
||||
void ActionModify::Execute(Model &model)
|
||||
{
|
||||
// Find the section to insert it on
|
||||
String sectionName = section;
|
||||
if (sectionName.IsEmpty()) sectionName = entry->GetDefaultGroup();
|
||||
SectionPtr sect = GetSection(model,sectionName);
|
||||
|
||||
// Insert the line
|
||||
sect->GetEntryRef(lineNumber) = entry;
|
||||
}
|
||||
|
|
|
@ -118,3 +118,15 @@ void ActionList::RemoveLine(int position,const String section)
|
|||
ActionPtr action = ActionPtr (new ActionRemove(position,section));
|
||||
AddAction(action);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Insert a "modify line" action
|
||||
SectionEntryPtr ActionList::ModifyLine(int position,const String section)
|
||||
{
|
||||
SectionPtr sect = model.GetSection(section);
|
||||
SectionEntryPtr entry = sect->GetEntry(position)->Clone();
|
||||
ActionPtr action = ActionPtr (new ActionModify(entry,position,section));
|
||||
AddAction(action);
|
||||
return entry;
|
||||
}
|
||||
|
|
|
@ -91,12 +91,15 @@ namespace Gorgonsub {
|
|||
DialogueASS();
|
||||
DialogueASS(const String &data,int version);
|
||||
|
||||
// Basic features
|
||||
String GetDefaultGroup() const { return L"Events"; }
|
||||
SectionEntryPtr Clone() const { return SectionEntryPtr(new DialogueASS(*this)); }
|
||||
|
||||
// Capabilities
|
||||
bool HasText() const { return true; }
|
||||
bool HasTime() const { return true; }
|
||||
bool HasStyle() const { return true; }
|
||||
bool HasMargins() const { return true; }
|
||||
String GetDefaultGroup() const { return L"Events"; }
|
||||
|
||||
// Read accessors
|
||||
const String& GetText() const { return text; }
|
||||
|
@ -158,14 +161,16 @@ namespace Gorgonsub {
|
|||
StyleASS();
|
||||
StyleASS(String data,int version);
|
||||
|
||||
// Basic features
|
||||
String GetDefaultGroup() const;
|
||||
SectionEntryPtr Clone() const { return SectionEntryPtr(new StyleASS(*this)); }
|
||||
|
||||
// Read accessors
|
||||
String GetName() const { return name; }
|
||||
String GetFontName() const { return font; }
|
||||
float GetFontSize() const { return fontSize; }
|
||||
Colour GetColour(int n) const { return colour.at(n); }
|
||||
int GetMargin(int n) const { return margin.at(n); }
|
||||
|
||||
String GetDefaultGroup() const;
|
||||
};
|
||||
|
||||
// Raw line
|
||||
|
@ -178,9 +183,12 @@ namespace Gorgonsub {
|
|||
PlainASS();
|
||||
PlainASS(String _data) : data(_data) {}
|
||||
|
||||
// Basic features
|
||||
String GetDefaultGroup() const { return L"Events"; }
|
||||
SectionEntryPtr Clone() const { return SectionEntryPtr(new PlainASS(*this)); }
|
||||
|
||||
String GetText() const { return data; }
|
||||
void SetText(const String &_data) { data = _data; }
|
||||
String GetDefaultGroup() const { return L"Events"; }
|
||||
};
|
||||
|
||||
// Advanced Substation Alpha format base class
|
||||
|
|
|
@ -75,6 +75,11 @@ SectionEntryPtr Section::GetEntry(size_t index) const
|
|||
return entries[index];
|
||||
}
|
||||
|
||||
SectionEntryPtr& Section::GetEntryRef(size_t index)
|
||||
{
|
||||
return entries[index];
|
||||
}
|
||||
|
||||
size_t Section::GetEntryCount() const
|
||||
{
|
||||
return entries.size();
|
||||
|
|
|
@ -84,6 +84,8 @@ int main()
|
|||
ActionListPtr actions = control.CreateActionList(L"Insert line");
|
||||
actions->InsertLine(line,2);
|
||||
actions->RemoveLine(3,L"Events");
|
||||
SectionEntryDialoguePtr diag = dynamic_pointer_cast<SectionEntryDialogue> (actions->ModifyLine(10,L"Events"));
|
||||
diag->SetText(L"Hay guise sup");
|
||||
actions->Finish();
|
||||
timer.Pause();
|
||||
cout << "Done in " << timer.Time() << " ms.\n";
|
||||
|
@ -98,6 +100,8 @@ int main()
|
|||
timer.Pause();
|
||||
cout << "Done in " << timer.Time() << " ms.\n";
|
||||
control.SaveFile(L"subs_out2.ass",L"UTF-8");
|
||||
control.Undo();
|
||||
control.SaveFile(L"subs_out3.ass",L"UTF-8");
|
||||
}
|
||||
|
||||
catch (std::exception &e) {
|
||||
|
|
Loading…
Reference in a new issue