2014-03-25 01:15:14 +01:00
|
|
|
// Copyright (c) 2014, Thomas Goyne <plorkyeran@aegisub.org>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
//
|
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
#include "selection_controller.h"
|
|
|
|
|
|
|
|
#include "ass_dialogue.h"
|
|
|
|
#include "ass_file.h"
|
|
|
|
#include "include/aegisub/context.h"
|
|
|
|
#include "subs_controller.h"
|
|
|
|
|
2014-04-17 23:24:26 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
2014-06-02 19:04:25 +02:00
|
|
|
SelectionController::SelectionController(agi::Context *c) : context(c) { }
|
2014-03-25 01:15:14 +01:00
|
|
|
|
|
|
|
void SelectionController::SetSelectedSet(Selection new_selection) {
|
|
|
|
selection = std::move(new_selection);
|
|
|
|
AnnounceSelectedSetChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionController::SetActiveLine(AssDialogue *new_line) {
|
|
|
|
if (new_line != active_line) {
|
|
|
|
active_line = new_line;
|
2014-05-22 03:32:42 +02:00
|
|
|
if (active_line)
|
|
|
|
context->ass->Properties.active_row = active_line->Row;
|
2014-03-25 01:15:14 +01:00
|
|
|
AnnounceActiveLineChanged(new_line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionController::SetSelectionAndActive(Selection new_selection, AssDialogue *new_line) {
|
2014-04-04 17:57:17 +02:00
|
|
|
bool active_line_changed = new_line != active_line;
|
|
|
|
selection = std::move(new_selection);
|
|
|
|
active_line = new_line;
|
2014-05-22 03:32:42 +02:00
|
|
|
if (active_line)
|
|
|
|
context->ass->Properties.active_row = active_line->Row;
|
2014-04-04 17:57:17 +02:00
|
|
|
|
|
|
|
AnnounceSelectedSetChanged();
|
|
|
|
if (active_line_changed)
|
|
|
|
AnnounceActiveLineChanged(new_line);
|
2014-03-25 01:15:14 +01:00
|
|
|
}
|
|
|
|
|
2014-04-17 23:24:26 +02:00
|
|
|
std::vector<AssDialogue *> SelectionController::GetSortedSelection() const {
|
|
|
|
std::vector<AssDialogue *> ret(selection.begin(), selection.end());
|
|
|
|
sort(begin(ret), end(ret), [](AssDialogue *a, AssDialogue *b) { return a->Row < b->Row; });
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-03-25 01:15:14 +01:00
|
|
|
void SelectionController::PrevLine() {
|
|
|
|
if (!active_line) return;
|
2014-04-04 17:11:09 +02:00
|
|
|
auto it = context->ass->iterator_to(*active_line);
|
2014-03-25 01:15:14 +01:00
|
|
|
if (it != context->ass->Events.begin()) {
|
|
|
|
--it;
|
|
|
|
SetSelectionAndActive({&*it}, &*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionController::NextLine() {
|
|
|
|
if (!active_line) return;
|
2014-04-04 17:11:09 +02:00
|
|
|
auto it = context->ass->iterator_to(*active_line);
|
2014-03-25 01:15:14 +01:00
|
|
|
if (++it != context->ass->Events.end())
|
|
|
|
SetSelectionAndActive({&*it}, &*it);
|
|
|
|
}
|