diff --git a/aegisub/src/dialog_text_import.cpp b/aegisub/src/dialog_text_import.cpp index cd864fb75..aa72b1385 100644 --- a/aegisub/src/dialog_text_import.cpp +++ b/aegisub/src/dialog_text_import.cpp @@ -36,38 +36,45 @@ #include "dialog_text_import.h" +#include "options.h" +#include "validators.h" + +#include #include #include #include - -#include "compat.h" -#include "options.h" +#include DialogTextImport::DialogTextImport() : 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 - wxFlexGridSizer *fg = new wxFlexGridSizer(2, 5, 5); - 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())); + auto make_text_ctrl = [=](std::string *var) { + return new wxTextCtrl(this, -1, "", wxDefaultPosition, wxDefaultSize, 0, StringBinder(var)); + }; - // Dialog layout + auto fg = new wxFlexGridSizer(2, 5, 5); 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(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(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); SetSizerAndFit(main_sizer); - Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogTextImport::OnOK, this, wxID_OK); -} -void DialogTextImport::OnOK(wxCommandEvent &) { - OPT_SET("Tool/Import/Text/Actor Separator")->SetString(from_wx(edit_separator->GetValue())); - OPT_SET("Tool/Import/Text/Comment Starter")->SetString(from_wx(edit_comment->GetValue())); + Bind(wxEVT_COMMAND_BUTTON_CLICKED, [=](wxCommandEvent&) { + TransferDataFromWindow(); - 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); } diff --git a/aegisub/src/dialog_text_import.h b/aegisub/src/dialog_text_import.h index a69446607..8588d2119 100644 --- a/aegisub/src/dialog_text_import.h +++ b/aegisub/src/dialog_text_import.h @@ -34,18 +34,15 @@ #include -class wxTextCtrl; - /// @class DialogTextImport /// @brief Plain text import separator character selection dialog /// /// A simple dialog to let the user select the format of a plain text file /// being imported into Aegisub class DialogTextImport : public wxDialog { - wxTextCtrl *edit_separator; - wxTextCtrl *edit_comment; - - void OnOK(wxCommandEvent &); + std::string seperator; + std::string comment; + bool include_blank; public: DialogTextImport(); diff --git a/aegisub/src/libresrc/default_config.json b/aegisub/src/libresrc/default_config.json index b87945eec..81e54992e 100644 --- a/aegisub/src/libresrc/default_config.json +++ b/aegisub/src/libresrc/default_config.json @@ -435,7 +435,8 @@ "Import" : { "Text" : { "Actor Separator" : ":", - "Comment Starter" : "#" + "Comment Starter" : "#", + "Include Blank" : false } }, "Kanji Timer" : { diff --git a/aegisub/src/libresrc/osx/default_config.json b/aegisub/src/libresrc/osx/default_config.json index 793d61162..5d79106f8 100644 --- a/aegisub/src/libresrc/osx/default_config.json +++ b/aegisub/src/libresrc/osx/default_config.json @@ -435,7 +435,8 @@ "Import" : { "Text" : { "Actor Separator" : ":", - "Comment Starter" : "#" + "Comment Starter" : "#", + "Include Blank" : false } }, "Kanji Timer" : { diff --git a/aegisub/src/subtitle_format_txt.cpp b/aegisub/src/subtitle_format_txt.cpp index 69bed006d..d246f093b 100644 --- a/aegisub/src/subtitle_format_txt.cpp +++ b/aegisub/src/subtitle_format_txt.cpp @@ -85,7 +85,7 @@ void TXTSubtitleFormat::ReadFile(AssFile *target, agi::fs::path const& filename, // Parse file while (file.HasMoreLines()) { 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 if (boost::starts_with(value, "# timecode")) @@ -99,7 +99,7 @@ void TXTSubtitleFormat::ReadFile(AssFile *target, agi::fs::path const& filename, } // Read actor data - if (!isComment && !separator.empty()) { + if (!isComment && !separator.empty() && !value.empty()) { if (value[0] != ' ' && value[0] != '\t') { size_t pos = value.find(separator); if (pos != std::string::npos) {