mirror of https://github.com/odrling/Aegisub
Add an option to not skip blank lines when importing plain text files
This commit is contained in:
parent
d55949d9c1
commit
2a5134a5ca
|
@ -36,38 +36,45 @@
|
||||||
|
|
||||||
#include "dialog_text_import.h"
|
#include "dialog_text_import.h"
|
||||||
|
|
||||||
|
#include "options.h"
|
||||||
|
#include "validators.h"
|
||||||
|
|
||||||
|
#include <wx/checkbox.h>
|
||||||
#include <wx/sizer.h>
|
#include <wx/sizer.h>
|
||||||
#include <wx/stattext.h>
|
#include <wx/stattext.h>
|
||||||
#include <wx/textctrl.h>
|
#include <wx/textctrl.h>
|
||||||
|
#include <wx/valgen.h>
|
||||||
#include "compat.h"
|
|
||||||
#include "options.h"
|
|
||||||
|
|
||||||
DialogTextImport::DialogTextImport()
|
DialogTextImport::DialogTextImport()
|
||||||
: wxDialog(nullptr , -1, _("Text import options"))
|
: wxDialog(nullptr , -1, _("Text import options"))
|
||||||
|
, seperator(OPT_GET("Tool/Import/Text/Actor Separator")->GetString())
|
||||||
|
, comment(OPT_GET("Tool/Import/Text/Comment Starter")->GetString())
|
||||||
|
, include_blank(OPT_GET("Tool/Import/Text/Include Blank")->GetBool())
|
||||||
{
|
{
|
||||||
// Main controls
|
auto make_text_ctrl = [=](std::string *var) {
|
||||||
wxFlexGridSizer *fg = new wxFlexGridSizer(2, 5, 5);
|
return new wxTextCtrl(this, -1, "", wxDefaultPosition, wxDefaultSize, 0, StringBinder(var));
|
||||||
wxBoxSizer *main_sizer = new wxBoxSizer(wxVERTICAL);
|
};
|
||||||
edit_separator = new wxTextCtrl(this, -1, to_wx(OPT_GET("Tool/Import/Text/Actor Separator")->GetString()));
|
|
||||||
edit_comment = new wxTextCtrl(this, -1, to_wx(OPT_GET("Tool/Import/Text/Comment Starter")->GetString()));
|
|
||||||
|
|
||||||
// Dialog layout
|
auto fg = new wxFlexGridSizer(2, 5, 5);
|
||||||
fg->Add(new wxStaticText(this, -1, _("Actor separator:")), 0, wxALIGN_CENTRE_VERTICAL);
|
fg->Add(new wxStaticText(this, -1, _("Actor separator:")), 0, wxALIGN_CENTRE_VERTICAL);
|
||||||
fg->Add(edit_separator, 0, wxEXPAND);
|
fg->Add(make_text_ctrl(&seperator), 0, wxEXPAND);
|
||||||
fg->Add(new wxStaticText(this, -1, _("Comment starter:")), 0, wxALIGN_CENTRE_VERTICAL);
|
fg->Add(new wxStaticText(this, -1, _("Comment starter:")), 0, wxALIGN_CENTRE_VERTICAL);
|
||||||
fg->Add(edit_comment, 0, wxEXPAND);
|
fg->Add(make_text_ctrl(&comment), 0, wxEXPAND);
|
||||||
|
|
||||||
|
auto main_sizer = new wxBoxSizer(wxVERTICAL);
|
||||||
main_sizer->Add(fg, 1, wxALL|wxEXPAND, 5);
|
main_sizer->Add(fg, 1, wxALL|wxEXPAND, 5);
|
||||||
|
main_sizer->Add(new wxCheckBox(this, -1, _("Include blank lines"), wxDefaultPosition, wxDefaultSize, 0, wxGenericValidator(&include_blank)), 0, wxLEFT|wxRIGHT|wxALIGN_RIGHT, 5);
|
||||||
main_sizer->Add(CreateSeparatedButtonSizer(wxOK|wxCANCEL), 0, wxALL|wxEXPAND, 5);
|
main_sizer->Add(CreateSeparatedButtonSizer(wxOK|wxCANCEL), 0, wxALL|wxEXPAND, 5);
|
||||||
SetSizerAndFit(main_sizer);
|
SetSizerAndFit(main_sizer);
|
||||||
|
|
||||||
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogTextImport::OnOK, this, wxID_OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DialogTextImport::OnOK(wxCommandEvent &) {
|
Bind(wxEVT_COMMAND_BUTTON_CLICKED, [=](wxCommandEvent&) {
|
||||||
OPT_SET("Tool/Import/Text/Actor Separator")->SetString(from_wx(edit_separator->GetValue()));
|
TransferDataFromWindow();
|
||||||
OPT_SET("Tool/Import/Text/Comment Starter")->SetString(from_wx(edit_comment->GetValue()));
|
|
||||||
|
|
||||||
EndModal(wxID_OK);
|
OPT_SET("Tool/Import/Text/Actor Separator")->SetString(seperator);
|
||||||
|
OPT_SET("Tool/Import/Text/Comment Starter")->SetString(comment);
|
||||||
|
OPT_SET("Tool/Import/Text/Include Blank")->SetBool(include_blank);
|
||||||
|
|
||||||
|
EndModal(wxID_OK);
|
||||||
|
}, wxID_OK);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,18 +34,15 @@
|
||||||
|
|
||||||
#include <wx/dialog.h>
|
#include <wx/dialog.h>
|
||||||
|
|
||||||
class wxTextCtrl;
|
|
||||||
|
|
||||||
/// @class DialogTextImport
|
/// @class DialogTextImport
|
||||||
/// @brief Plain text import separator character selection dialog
|
/// @brief Plain text import separator character selection dialog
|
||||||
///
|
///
|
||||||
/// A simple dialog to let the user select the format of a plain text file
|
/// A simple dialog to let the user select the format of a plain text file
|
||||||
/// being imported into Aegisub
|
/// being imported into Aegisub
|
||||||
class DialogTextImport : public wxDialog {
|
class DialogTextImport : public wxDialog {
|
||||||
wxTextCtrl *edit_separator;
|
std::string seperator;
|
||||||
wxTextCtrl *edit_comment;
|
std::string comment;
|
||||||
|
bool include_blank;
|
||||||
void OnOK(wxCommandEvent &);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DialogTextImport();
|
DialogTextImport();
|
||||||
|
|
|
@ -435,7 +435,8 @@
|
||||||
"Import" : {
|
"Import" : {
|
||||||
"Text" : {
|
"Text" : {
|
||||||
"Actor Separator" : ":",
|
"Actor Separator" : ":",
|
||||||
"Comment Starter" : "#"
|
"Comment Starter" : "#",
|
||||||
|
"Include Blank" : false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Kanji Timer" : {
|
"Kanji Timer" : {
|
||||||
|
|
|
@ -435,7 +435,8 @@
|
||||||
"Import" : {
|
"Import" : {
|
||||||
"Text" : {
|
"Text" : {
|
||||||
"Actor Separator" : ":",
|
"Actor Separator" : ":",
|
||||||
"Comment Starter" : "#"
|
"Comment Starter" : "#",
|
||||||
|
"Include Blank" : false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Kanji Timer" : {
|
"Kanji Timer" : {
|
||||||
|
|
|
@ -85,7 +85,7 @@ void TXTSubtitleFormat::ReadFile(AssFile *target, agi::fs::path const& filename,
|
||||||
// Parse file
|
// Parse file
|
||||||
while (file.HasMoreLines()) {
|
while (file.HasMoreLines()) {
|
||||||
std::string value = file.ReadLineFromFile();
|
std::string value = file.ReadLineFromFile();
|
||||||
if(value.empty()) continue;
|
if (value.empty() && !OPT_GET("Tool/Import/Text/Include Blank")->GetBool()) continue;
|
||||||
|
|
||||||
// Check if this isn't a timecodes file
|
// Check if this isn't a timecodes file
|
||||||
if (boost::starts_with(value, "# timecode"))
|
if (boost::starts_with(value, "# timecode"))
|
||||||
|
@ -99,7 +99,7 @@ void TXTSubtitleFormat::ReadFile(AssFile *target, agi::fs::path const& filename,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read actor data
|
// Read actor data
|
||||||
if (!isComment && !separator.empty()) {
|
if (!isComment && !separator.empty() && !value.empty()) {
|
||||||
if (value[0] != ' ' && value[0] != '\t') {
|
if (value[0] != ' ' && value[0] != '\t') {
|
||||||
size_t pos = value.find(separator);
|
size_t pos = value.find(separator);
|
||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
|
|
Loading…
Reference in New Issue