2006-02-18 22:55:58 +01:00
|
|
|
// Copyright (c) 2006, Rodrigo Braz Monteiro
|
2006-01-16 22:02:54 +01:00
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file subs_grid.cpp
|
|
|
|
/// @brief Subtitles grid control in main window
|
|
|
|
/// @ingroup main_ui
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2006-03-01 04:17:31 +01:00
|
|
|
#include <algorithm>
|
2010-06-26 09:26:27 +02:00
|
|
|
#include <utility>
|
2009-09-10 15:06:40 +02:00
|
|
|
|
2006-03-01 04:17:31 +01:00
|
|
|
#include <wx/clipbrd.h>
|
|
|
|
#include <wx/filename.h>
|
2010-08-03 00:14:11 +02:00
|
|
|
#include <wx/regex.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <wx/tokenzr.h>
|
|
|
|
|
2011-11-08 01:24:41 +01:00
|
|
|
#include "subs_grid.h"
|
|
|
|
|
2011-01-16 08:16:54 +01:00
|
|
|
#include "include/aegisub/context.h"
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
|
2011-09-28 21:44:07 +02:00
|
|
|
#include "ass_dialogue.h"
|
2006-01-16 22:02:54 +01:00
|
|
|
#include "ass_file.h"
|
2013-01-07 02:50:09 +01:00
|
|
|
#include "options.h"
|
2006-03-01 04:17:31 +01:00
|
|
|
#include "utils.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "video_context.h"
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-10-15 03:57:57 +02:00
|
|
|
SubtitlesGrid::SubtitlesGrid(wxWindow *parent, agi::Context *context)
|
|
|
|
: BaseGrid(parent, context, wxDefaultSize, wxWANTS_CHARS | wxSUNKEN_BORDER)
|
2006-01-16 22:02:54 +01:00
|
|
|
{
|
2006-06-27 07:13:41 +02:00
|
|
|
}
|
|
|
|
|
2012-12-04 23:35:59 +01:00
|
|
|
static void trim_text(wxString *text) {
|
2012-01-25 20:07:27 +01:00
|
|
|
static wxRegEx start("^( |\t|\\\\[nNh])+");
|
|
|
|
static wxRegEx end("( |\t|\\\\[nNh])+$");
|
2012-12-04 23:35:59 +01:00
|
|
|
start.ReplaceFirst(text, "");
|
|
|
|
end.ReplaceFirst(text, "");
|
2010-07-12 09:10:40 +02:00
|
|
|
}
|
2011-11-08 01:24:41 +01:00
|
|
|
|
2010-07-12 09:10:40 +02:00
|
|
|
static void expand_times(AssDialogue *src, AssDialogue *dst) {
|
2011-12-22 22:28:51 +01:00
|
|
|
dst->Start = std::min(dst->Start, src->Start);
|
|
|
|
dst->End = std::max(dst->End, src->End);
|
2010-07-12 09:10:40 +02:00
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2012-12-04 23:35:59 +01:00
|
|
|
static bool check_lines(AssDialogue *d1, AssDialogue *d2, bool (wxString::*pred)(wxString const&, wxString *) const) {
|
|
|
|
wxString rest;
|
|
|
|
if ((d1->Text.get().*pred)(d2->Text.get(), &rest)) {
|
|
|
|
trim_text(&rest);
|
|
|
|
d1->Text = rest;
|
|
|
|
expand_times(d1, d2);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool check_start(AssDialogue *d1, AssDialogue *d2) {
|
|
|
|
return check_lines(d1, d2, &wxString::StartsWith);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool check_end(AssDialogue *d1, AssDialogue *d2) {
|
|
|
|
return check_lines(d1, d2, &wxString::EndsWith);
|
|
|
|
}
|
|
|
|
|
2012-03-25 06:05:06 +02:00
|
|
|
/// @brief Recombine
|
2011-01-16 08:17:46 +01:00
|
|
|
void SubtitlesGrid::RecombineLines() {
|
2010-07-12 09:10:40 +02:00
|
|
|
Selection selectedSet = GetSelectedSet();
|
|
|
|
if (selectedSet.size() < 2) return;
|
|
|
|
|
|
|
|
AssDialogue *activeLine = GetActiveLine();
|
|
|
|
|
2012-10-15 06:37:14 +02:00
|
|
|
std::vector<AssDialogue*> sel(selectedSet.begin(), selectedSet.end());
|
2010-07-12 09:10:40 +02:00
|
|
|
sort(sel.begin(), sel.end(), &AssFile::CompStart);
|
2012-12-04 23:35:59 +01:00
|
|
|
for (auto &diag : sel) {
|
|
|
|
wxString text = diag->Text;
|
|
|
|
trim_text(&text);
|
|
|
|
diag->Text = text;
|
|
|
|
}
|
2010-07-12 09:10:40 +02:00
|
|
|
|
2012-12-04 23:35:59 +01:00
|
|
|
auto end = sel.end() - 1;
|
|
|
|
for (auto cur = sel.begin(); cur != end; ++cur) {
|
2010-07-12 09:10:40 +02:00
|
|
|
AssDialogue *d1 = *cur;
|
2012-12-04 23:35:59 +01:00
|
|
|
auto d2 = cur + 1;
|
2010-07-12 09:10:40 +02:00
|
|
|
|
|
|
|
// 1, 1+2 (or 2+1), 2 gets turned into 1, 2, 2 so kill the duplicate
|
|
|
|
if (d1->Text == (*d2)->Text) {
|
|
|
|
expand_times(d1, *d2);
|
2012-10-15 06:37:14 +02:00
|
|
|
delete d1;
|
2010-07-12 09:10:40 +02:00
|
|
|
continue;
|
|
|
|
}
|
2006-11-23 20:08:46 +01:00
|
|
|
|
2010-07-12 09:10:40 +02:00
|
|
|
// 1, 1+2, 1 turns into 1, 2, [empty]
|
2012-12-04 23:35:59 +01:00
|
|
|
if (d1->Text.get().empty()) {
|
2012-10-15 06:37:14 +02:00
|
|
|
delete d1;
|
2010-07-12 09:10:40 +02:00
|
|
|
continue;
|
2006-12-30 23:38:05 +01:00
|
|
|
}
|
2012-12-04 23:35:59 +01:00
|
|
|
|
2012-04-06 17:50:54 +02:00
|
|
|
// If d2 is the last line in the selection it'll never hit the above test
|
2012-12-04 23:35:59 +01:00
|
|
|
if (d2 == end && (*d2)->Text.get().empty()) {
|
2012-10-15 06:37:14 +02:00
|
|
|
delete *d2;
|
2012-04-06 17:50:54 +02:00
|
|
|
continue;
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2010-07-12 09:10:40 +02:00
|
|
|
// 1, 1+2
|
2012-12-04 23:35:59 +01:00
|
|
|
while (d2 <= end && check_start(*d2, d1))
|
2010-07-12 09:10:40 +02:00
|
|
|
++d2;
|
2007-01-26 05:11:32 +01:00
|
|
|
|
2010-07-12 09:10:40 +02:00
|
|
|
// 1, 2+1
|
2012-12-04 23:35:59 +01:00
|
|
|
while (d2 <= end && check_end(*d2, d1))
|
2010-07-12 09:10:40 +02:00
|
|
|
++d2;
|
2006-11-23 20:08:46 +01:00
|
|
|
|
2010-07-12 09:10:40 +02:00
|
|
|
// 1+2, 2
|
2012-12-04 23:35:59 +01:00
|
|
|
while (d2 <= end && check_end(d1, *d2))
|
2010-07-12 09:10:40 +02:00
|
|
|
++d2;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2010-07-12 09:10:40 +02:00
|
|
|
// 2+1, 2
|
2012-12-04 23:35:59 +01:00
|
|
|
while (d2 <= end && check_start(d1, *d2))
|
2010-07-12 09:10:40 +02:00
|
|
|
++d2;
|
2006-02-01 03:16:57 +01:00
|
|
|
}
|
2006-11-23 20:08:46 +01:00
|
|
|
|
2010-07-12 09:10:40 +02:00
|
|
|
// Remove now non-existent lines from the selection
|
|
|
|
Selection lines;
|
2011-01-16 08:17:36 +01:00
|
|
|
transform(context->ass->Line.begin(), context->ass->Line.end(), inserter(lines, lines.begin()), cast<AssDialogue*>());
|
2010-07-12 09:10:40 +02:00
|
|
|
Selection newSel;
|
|
|
|
set_intersection(lines.begin(), lines.end(), selectedSet.begin(), selectedSet.end(), inserter(newSel, newSel.begin()));
|
|
|
|
|
2011-09-15 07:16:32 +02:00
|
|
|
if (newSel.empty())
|
|
|
|
newSel.insert(*lines.begin());
|
2010-07-12 09:10:40 +02:00
|
|
|
|
|
|
|
// Restore selection
|
2012-05-05 04:11:09 +02:00
|
|
|
if (!newSel.count(activeLine))
|
2010-07-12 09:10:40 +02:00
|
|
|
activeLine = *newSel.begin();
|
2012-05-05 04:11:09 +02:00
|
|
|
SetSelectionAndActive(newSel, activeLine);
|
2011-09-15 07:16:32 +02:00
|
|
|
|
|
|
|
context->ass->Commit(_("combining"), AssFile::COMMIT_DIAG_ADDREM | AssFile::COMMIT_DIAG_FULL);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SubtitlesGrid::AdjoinLines(int n1,int n2,bool setStart) {
|
2010-07-23 08:40:22 +02:00
|
|
|
if (n1 == n2) {
|
|
|
|
if (setStart) {
|
|
|
|
--n1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
++n2;
|
|
|
|
}
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
// Set start
|
|
|
|
if (setStart) {
|
|
|
|
AssDialogue *prev = GetDialogue(n1);
|
|
|
|
AssDialogue *cur;
|
|
|
|
for (int i=n1+1;i<=n2;i++) {
|
|
|
|
cur = GetDialogue(i);
|
|
|
|
if (!cur) return;
|
|
|
|
cur->Start = prev->End;
|
|
|
|
prev = cur;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set end
|
|
|
|
else {
|
|
|
|
AssDialogue *next;
|
|
|
|
AssDialogue *cur = GetDialogue(n1);
|
|
|
|
for (int i=n1;i<n2;i++) {
|
|
|
|
next = GetDialogue(i+1);
|
|
|
|
if (!next) return;
|
|
|
|
cur->End = next->Start;
|
|
|
|
cur = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-15 07:16:32 +02:00
|
|
|
context->ass->Commit(_("adjoin"), AssFile::COMMIT_DIAG_TIME);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|