Add a button to the split editbox to remove the line text only, leaving override tags

This commit is contained in:
Thomas Goyne 2012-11-02 21:24:11 -07:00
parent 31d2054ab3
commit 879c2c19ae
3 changed files with 24 additions and 1 deletions

View File

@ -86,6 +86,7 @@ public:
class AssDialogueBlockPlain : public AssDialogueBlock {
public:
using AssDialogueBlock::text;
AssBlockType GetType() const override { return BLOCK_PLAIN; }
AssDialogueBlockPlain(std::string const& text = std::string()) : AssDialogueBlock(text) { }
};

View File

@ -65,8 +65,10 @@
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/format.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/adaptor/sliced.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <libaegisub/of_type_adaptor.h>
@ -945,6 +947,24 @@ struct edit_clear : public Command {
}
};
wxString get_text(AssDialogueBlock &d) { return d.GetText(); }
struct edit_clear_text : public Command {
CMD_NAME("edit/clear/text")
STR_DISP("Clear Text")
STR_MENU("Clear Text")
STR_HELP("Clear the current line's text, leaving override tags")
void operator()(agi::Context *c) {
AssDialogue *line = c->selectionController->GetActiveLine();
boost::ptr_vector<AssDialogueBlock> blocks(line->ParseTags());
line->Text = join(blocks
| filtered([](AssDialogueBlock const& b) { return b.GetType() != BLOCK_PLAIN; })
| transformed(get_text),
wxS(""));
c->ass->Commit(_("clear line"), AssFile::COMMIT_DIAG_TEXT, -1, line);
}
};
struct edit_insert_original : public Command {
CMD_NAME("edit/insert_original")
STR_DISP("Insert Original")
@ -956,7 +976,7 @@ struct edit_insert_original : public Command {
int sel_start = c->textSelectionController->GetSelectionStart();
int sel_end = c->textSelectionController->GetSelectionEnd();
line->Text = line->Text.Left(sel_start) + c->initialLineState->GetInitialText() + line->Text.Mid(sel_end);
line->Text = line->Text.get().Left(sel_start) + c->initialLineState->GetInitialText() + line->Text.get().Mid(sel_end);
c->ass->Commit(_("insert original"), AssFile::COMMIT_DIAG_TEXT, -1, line);
}
};
@ -995,5 +1015,6 @@ namespace cmd {
reg(new edit_revert);
reg(new edit_insert_original);
reg(new edit_clear);
reg(new edit_clear_text);
}
}

View File

@ -191,6 +191,7 @@ SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context)
bottom_sizer = new wxBoxSizer(wxHORIZONTAL);
bottom_sizer->Add(MakeBottomButton("edit/revert"));
bottom_sizer->Add(MakeBottomButton("edit/clear"));
bottom_sizer->Add(MakeBottomButton("edit/clear/text"));
bottom_sizer->Add(MakeBottomButton("edit/insert_original"));
main_sizer->Add(bottom_sizer);
main_sizer->Hide(bottom_sizer);