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/
|
2006-01-16 22:02:54 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @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"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#ifndef AGI_PRE
|
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>
|
|
|
|
#endif
|
|
|
|
|
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"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "dialog_paste_over.h"
|
2012-01-27 00:21:19 +01:00
|
|
|
#include "main.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
|
|
|
|
2011-01-16 08:17:36 +01:00
|
|
|
SubtitlesGrid::SubtitlesGrid(wxWindow *parent, agi::Context *context, const wxSize& size, long style, const wxString& name)
|
|
|
|
: BaseGrid(parent,context,size,style,name)
|
2006-01-16 22:02:54 +01:00
|
|
|
{
|
2006-06-27 07:13:41 +02:00
|
|
|
}
|
|
|
|
|
2010-07-12 09:10:40 +02:00
|
|
|
static void trim_text(AssDialogue *diag) {
|
2012-01-25 20:07:27 +01:00
|
|
|
static wxRegEx start("^( |\t|\\\\[nNh])+");
|
|
|
|
static wxRegEx end("( |\t|\\\\[nNh])+$");
|
2010-07-12 09:10:40 +02:00
|
|
|
start.ReplaceFirst(&diag->Text, "");
|
|
|
|
end.ReplaceFirst(&diag->Text, "");
|
|
|
|
}
|
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-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
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
Selection selectedSet = GetSelectedSet();
|
|
|
|
if (selectedSet.size() < 2) return;
|
|
|
|
|
|
|
|
AssDialogue *activeLine = GetActiveLine();
|
|
|
|
|
|
|
|
vector<AssDialogue*> sel;
|
|
|
|
sel.reserve(selectedSet.size());
|
|
|
|
copy(selectedSet.begin(), selectedSet.end(), back_inserter(sel));
|
|
|
|
for_each(sel.begin(), sel.end(), trim_text);
|
|
|
|
sort(sel.begin(), sel.end(), &AssFile::CompStart);
|
|
|
|
|
|
|
|
typedef vector<AssDialogue*>::iterator diag_iter;
|
|
|
|
diag_iter end = sel.end() - 1;
|
|
|
|
for (diag_iter cur = sel.begin(); cur != end; ++cur) {
|
|
|
|
AssDialogue *d1 = *cur;
|
|
|
|
diag_iter d2 = cur + 1;
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
delete d1;
|
2011-01-16 08:17:36 +01:00
|
|
|
context->ass->Line.remove(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]
|
|
|
|
if (d1->Text.empty()) {
|
|
|
|
delete d1;
|
2011-01-16 08:17:36 +01:00
|
|
|
context->ass->Line.remove(d1);
|
2010-07-12 09:10:40 +02:00
|
|
|
continue;
|
2006-12-30 23:38:05 +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
|
|
|
|
if (d2 == end && (*d2)->Text.empty()) {
|
|
|
|
delete *d2;
|
|
|
|
context->ass->Line.remove(*d2);
|
|
|
|
continue;
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2010-07-12 09:10:40 +02:00
|
|
|
// 1, 1+2
|
|
|
|
while (d2 <= end && (*d2)->Text.StartsWith(d1->Text, &(*d2)->Text)) {
|
|
|
|
expand_times(*d2, d1);
|
|
|
|
trim_text(*d2);
|
|
|
|
++d2;
|
2007-01-26 05:11:32 +01:00
|
|
|
}
|
|
|
|
|
2010-07-12 09:10:40 +02:00
|
|
|
// 1, 2+1
|
|
|
|
while (d2 <= end && (*d2)->Text.EndsWith(d1->Text, &(*d2)->Text)) {
|
|
|
|
expand_times(*d2, d1);
|
|
|
|
trim_text(*d2);
|
|
|
|
++d2;
|
2006-12-30 23:38:05 +01:00
|
|
|
}
|
2006-11-23 20:08:46 +01:00
|
|
|
|
2010-07-12 09:10:40 +02:00
|
|
|
// 1+2, 2
|
|
|
|
while (d2 <= end && d1->Text.EndsWith((*d2)->Text, &d1->Text)) {
|
|
|
|
expand_times(d1, *d2);
|
|
|
|
trim_text(d1);
|
|
|
|
++d2;
|
2006-12-30 23:38:05 +01:00
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2010-07-12 09:10:40 +02:00
|
|
|
// 2+1, 2
|
|
|
|
while (d2 <= end && d1->Text.StartsWith((*d2)->Text, &d1->Text)) {
|
|
|
|
expand_times(d1, *d2);
|
|
|
|
trim_text(d1);
|
|
|
|
++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
|
|
|
}
|
|
|
|
|
2012-03-25 06:05:06 +02:00
|
|
|
/// @brief Insert a line
|
|
|
|
/// @param line
|
|
|
|
/// @param n
|
|
|
|
/// @param after
|
|
|
|
/// @param update
|
2006-01-16 22:02:54 +01:00
|
|
|
void SubtitlesGrid::InsertLine(AssDialogue *line,int n,bool after,bool update) {
|
2010-10-11 22:06:31 +02:00
|
|
|
AssDialogue *rel_line = GetDialogue(n);
|
2011-01-16 08:17:36 +01:00
|
|
|
entryIter pos = std::find(context->ass->Line.begin(), context->ass->Line.end(), rel_line);
|
2010-10-11 22:06:31 +02:00
|
|
|
if (after) ++pos;
|
2010-07-13 07:29:08 +02:00
|
|
|
|
2011-11-19 05:46:45 +01:00
|
|
|
context->ass->Line.insert(pos,line);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// Update
|
|
|
|
if (update) {
|
2011-09-15 07:16:32 +02:00
|
|
|
context->ass->Commit(_("line insertion"), AssFile::COMMIT_DIAG_ADDREM);
|
2010-12-07 20:09:28 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
UpdateMaps();
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-22 07:49:20 +01:00
|
|
|
void SubtitlesGrid::CopyLines(wxArrayInt target) {
|
2006-01-16 22:02:54 +01:00
|
|
|
// Prepare text
|
2012-01-31 01:44:43 +01:00
|
|
|
wxString data;
|
2006-01-16 22:02:54 +01:00
|
|
|
AssDialogue *cur;
|
2006-02-22 07:49:20 +01:00
|
|
|
int nrows = target.Count();
|
2006-01-16 22:02:54 +01:00
|
|
|
bool first = true;
|
|
|
|
for (int i=0;i<nrows;i++) {
|
2011-09-28 21:43:11 +02:00
|
|
|
if (!first) data += "\r\n";
|
2006-02-22 07:49:20 +01:00
|
|
|
first = false;
|
|
|
|
cur = GetDialogue(target[i]);
|
2006-02-27 03:23:50 +01:00
|
|
|
data += cur->GetEntryData();
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Send to clipboard
|
|
|
|
if (wxTheClipboard->Open()) {
|
|
|
|
wxTheClipboard->SetData(new wxTextDataObject(data));
|
|
|
|
wxTheClipboard->Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-22 07:49:20 +01:00
|
|
|
void SubtitlesGrid::CutLines(wxArrayInt target) {
|
2006-11-23 20:08:46 +01:00
|
|
|
BeginBatch();
|
2006-02-22 07:49:20 +01:00
|
|
|
CopyLines(target);
|
|
|
|
DeleteLines(target);
|
2006-11-23 20:08:46 +01:00
|
|
|
EndBatch();
|
2006-02-22 05:59:39 +01:00
|
|
|
}
|
|
|
|
|
2010-07-20 05:11:11 +02:00
|
|
|
/// @brief Paste lines from clipboard
|
2012-03-25 06:05:06 +02:00
|
|
|
/// @param n
|
|
|
|
/// @param pasteOver
|
2006-12-17 19:30:19 +01:00
|
|
|
void SubtitlesGrid::PasteLines(int n,bool pasteOver) {
|
2006-11-23 20:08:46 +01:00
|
|
|
BeginBatch();
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
// Prepare text
|
2010-07-20 05:11:11 +02:00
|
|
|
wxString data;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// Read from clipboard
|
|
|
|
if (wxTheClipboard->Open()) {
|
|
|
|
if (wxTheClipboard->IsSupported(wxDF_TEXT)) {
|
|
|
|
wxTextDataObject rawdata;
|
|
|
|
wxTheClipboard->GetData(rawdata);
|
|
|
|
data = rawdata.GetText();
|
|
|
|
}
|
|
|
|
wxTheClipboard->Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if it actually got anything
|
|
|
|
if (!data.empty()) {
|
2006-12-17 19:30:19 +01:00
|
|
|
// Insert data
|
2006-01-16 22:02:54 +01:00
|
|
|
int inserted = 0;
|
2010-06-22 02:03:16 +02:00
|
|
|
std::vector<bool> pasteOverOptions;
|
2011-09-28 21:43:11 +02:00
|
|
|
wxStringTokenizer token (data,"\r\n",wxTOKEN_STRTOK);
|
2006-01-16 22:02:54 +01:00
|
|
|
while (token.HasMoreTokens()) {
|
2006-12-17 19:30:19 +01:00
|
|
|
// Convert data into an AssDialogue
|
2006-01-16 22:02:54 +01:00
|
|
|
wxString curdata = token.GetNextToken();
|
|
|
|
curdata.Trim(true);
|
|
|
|
curdata.Trim(false);
|
2006-12-17 19:30:19 +01:00
|
|
|
AssDialogue *curdiag;
|
2012-03-25 06:05:06 +02:00
|
|
|
try {
|
2008-06-15 15:18:28 +02:00
|
|
|
// Try to interpret the line as an ASS line
|
2006-12-17 19:30:19 +01:00
|
|
|
curdiag = new AssDialogue(curdata);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
catch (...) {
|
2010-07-20 05:11:11 +02:00
|
|
|
// Line didn't parse correctly, assume it's plain text that
|
2008-06-15 15:18:28 +02:00
|
|
|
// should be pasted in the Text field only
|
2006-12-17 19:30:19 +01:00
|
|
|
curdiag = new AssDialogue();
|
|
|
|
curdiag->Text = curdata;
|
2008-06-15 15:18:28 +02:00
|
|
|
// Make sure pasted plain-text lines always are blank-timed
|
2011-12-22 22:28:51 +01:00
|
|
|
curdiag->Start = 0;
|
|
|
|
curdiag->End = 0;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2006-12-17 19:30:19 +01:00
|
|
|
|
|
|
|
// Paste over
|
|
|
|
if (pasteOver) {
|
|
|
|
if (n+inserted < GetRows()) {
|
|
|
|
// Get list of options to paste over, if not asked yet
|
2010-06-22 02:03:16 +02:00
|
|
|
if (pasteOverOptions.empty()) {
|
2012-01-27 00:21:19 +01:00
|
|
|
DialogPasteOver diag(context->parent);
|
|
|
|
if (diag.ShowModal()) {
|
2006-12-17 20:41:52 +01:00
|
|
|
delete curdiag;
|
2012-03-25 06:04:42 +02:00
|
|
|
EndBatch();
|
2006-12-17 20:41:52 +01:00
|
|
|
return;
|
|
|
|
}
|
2012-01-27 00:21:19 +01:00
|
|
|
pasteOverOptions = OPT_GET("Tool/Paste Lines Over/Fields")->GetListBool();
|
2006-12-17 19:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Paste over
|
|
|
|
AssDialogue *target = GetDialogue(n+inserted);
|
|
|
|
if (pasteOverOptions[0]) target->Layer = curdiag->Layer;
|
|
|
|
if (pasteOverOptions[1]) target->Start = curdiag->Start;
|
|
|
|
if (pasteOverOptions[2]) target->End = curdiag->End;
|
|
|
|
if (pasteOverOptions[3]) target->Style = curdiag->Style;
|
|
|
|
if (pasteOverOptions[4]) target->Actor = curdiag->Actor;
|
2007-01-05 19:27:15 +01:00
|
|
|
if (pasteOverOptions[5]) target->Margin[0] = curdiag->Margin[0];
|
|
|
|
if (pasteOverOptions[6]) target->Margin[1] = curdiag->Margin[1];
|
|
|
|
if (pasteOverOptions[7]) target->Margin[2] = curdiag->Margin[2];
|
2007-03-28 03:37:13 +02:00
|
|
|
if (pasteOverOptions[8]) target->Effect = curdiag->Effect;
|
|
|
|
if (pasteOverOptions[9]) target->Text = curdiag->Text;
|
2006-12-17 19:30:19 +01:00
|
|
|
}
|
|
|
|
delete curdiag;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Paste normally
|
|
|
|
else InsertLine(curdiag,n+inserted,false,false);
|
|
|
|
|
|
|
|
// Increment insertion
|
|
|
|
inserted++;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2006-12-17 19:30:19 +01:00
|
|
|
// Update data post-insertion
|
2006-01-16 22:02:54 +01:00
|
|
|
if (inserted > 0) {
|
2011-09-15 07:16:32 +02:00
|
|
|
context->ass->Commit(_("paste"), pasteOver ? AssFile::COMMIT_DIAG_FULL : AssFile::COMMIT_DIAG_ADDREM);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// Set selection
|
2006-12-17 19:30:19 +01:00
|
|
|
if (!pasteOver) {
|
2010-06-26 13:32:16 +02:00
|
|
|
Selection newsel;
|
|
|
|
for (int i=n;i<n+inserted;i++) {
|
|
|
|
newsel.insert(GetDialogue(i));
|
2006-12-17 19:30:19 +01:00
|
|
|
}
|
2010-06-26 13:32:16 +02:00
|
|
|
SetSelectedSet(newsel);
|
|
|
|
SetActiveLine(GetDialogue(GetFirstSelRow()));
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-11-23 20:08:46 +01:00
|
|
|
EndBatch();
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2009-07-23 00:30:57 +02:00
|
|
|
void SubtitlesGrid::DeleteLines(wxArrayInt target, bool flagModified) {
|
2011-01-16 08:17:36 +01:00
|
|
|
entryIter before_first = std::find_if(context->ass->Line.begin(), context->ass->Line.end(), cast<AssDialogue*>()); --before_first;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2010-07-13 07:29:08 +02:00
|
|
|
int row = -1;
|
2011-12-22 22:09:31 +01:00
|
|
|
size_t deleted = 0;
|
2011-01-16 08:17:36 +01:00
|
|
|
for (entryIter cur = context->ass->Line.begin(); cur != context->ass->Line.end();) {
|
2010-07-13 07:29:08 +02:00
|
|
|
if (dynamic_cast<AssDialogue*>(*cur) && ++row == target[deleted]) {
|
2011-12-22 22:16:34 +01:00
|
|
|
delete *cur;
|
2011-01-16 08:17:36 +01:00
|
|
|
cur = context->ass->Line.erase(cur);
|
2010-07-13 07:29:08 +02:00
|
|
|
++deleted;
|
|
|
|
if (deleted == target.size()) break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
++cur;
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add default line if file was wiped
|
2011-12-28 22:27:22 +01:00
|
|
|
if ((size_t)GetRows() == deleted) {
|
2006-01-16 22:02:54 +01:00
|
|
|
AssDialogue *def = new AssDialogue;
|
2010-06-26 09:26:27 +02:00
|
|
|
++before_first;
|
2011-01-16 08:17:36 +01:00
|
|
|
context->ass->Line.insert(before_first, def);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2009-07-23 00:30:57 +02:00
|
|
|
if (flagModified) {
|
2011-09-15 07:16:32 +02:00
|
|
|
context->ass->Commit(_("delete"), AssFile::COMMIT_DIAG_ADDREM);
|
2010-12-07 20:09:28 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
UpdateMaps();
|
2009-07-23 00:30:57 +02:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2010-06-26 09:26:27 +02:00
|
|
|
/// @brief Retrieve a list of selected lines in the actual ASS file (ie. not as displayed in the grid but as represented in the file)
|
2012-03-25 06:05:06 +02:00
|
|
|
/// @return
|
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-03-20 01:39:10 +01:00
|
|
|
std::vector<int> SubtitlesGrid::GetAbsoluteSelection() const {
|
2011-07-15 06:05:43 +02:00
|
|
|
Selection sel = GetSelectedSet();
|
2006-12-28 23:31:33 +01:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
std::vector<int> result;
|
|
|
|
result.reserve(sel.size());
|
2010-06-26 09:26:27 +02:00
|
|
|
|
|
|
|
int line_index = 0;
|
2011-01-16 08:17:36 +01:00
|
|
|
for (entryIter it = context->ass->Line.begin(); it != context->ass->Line.end(); ++it, ++line_index) {
|
2010-06-26 09:26:27 +02:00
|
|
|
if (sel.find(dynamic_cast<AssDialogue*>(*it)) != sel.end())
|
|
|
|
result.push_back(line_index);
|
2006-12-28 23:31:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2007-02-06 23:58:05 +01:00
|
|
|
|
2010-06-26 09:26:27 +02:00
|
|
|
/// @brief Update list of selected lines from absolute selection
|
2012-03-25 06:05:06 +02:00
|
|
|
/// @param selection
|
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
|
|
|
///
|
2007-02-06 23:58:05 +01:00
|
|
|
void SubtitlesGrid::SetSelectionFromAbsolute(std::vector<int> &selection) {
|
2010-06-26 09:26:27 +02:00
|
|
|
Selection newsel;
|
2007-02-06 23:58:05 +01:00
|
|
|
|
2010-06-26 09:26:27 +02:00
|
|
|
std::sort(selection.begin(), selection.end());
|
|
|
|
|
|
|
|
int i = 0;
|
2011-01-16 08:17:36 +01:00
|
|
|
std::list<AssEntry*>::iterator j = context->ass->Line.begin();
|
2012-03-25 06:05:06 +02:00
|
|
|
|
2010-06-26 09:26:27 +02:00
|
|
|
for (size_t selveci = 0; selveci < selection.size(); ++selveci) {
|
2011-01-16 08:17:36 +01:00
|
|
|
while (i != selection[selveci] && j != context->ass->Line.end()) ++i, ++j;
|
|
|
|
if (j == context->ass->Line.end()) break; /// @todo Report error somehow
|
2010-06-26 09:26:27 +02:00
|
|
|
AssDialogue *dlg = dynamic_cast<AssDialogue*>(*j);
|
|
|
|
if (dlg) newsel.insert(dlg);
|
2007-02-06 23:58:05 +01:00
|
|
|
}
|
2010-06-26 09:26:27 +02:00
|
|
|
|
|
|
|
SetSelectedSet(newsel);
|
2007-02-06 23:58:05 +01:00
|
|
|
}
|