2011-09-15 07:17:14 +02:00
|
|
|
// Copyright (c) 2011, Thomas Goyne <plorkyeran@aegisub.org>
|
2006-01-16 22:02:54 +01:00
|
|
|
//
|
2011-09-15 07:17:14 +02:00
|
|
|
// 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.
|
2006-01-16 22:02:54 +01:00
|
|
|
//
|
2011-09-15 07:17:14 +02:00
|
|
|
// 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.
|
2006-01-16 22:02:54 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file dialog_shift_times.cpp
|
|
|
|
/// @brief Shift Times dialogue box and logic
|
|
|
|
/// @ingroup secondary_ui
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
#include "dialog_shift_times.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_dialogue.h"
|
|
|
|
#include "ass_file.h"
|
|
|
|
#include "ass_time.h"
|
2011-09-15 07:17:14 +02:00
|
|
|
#include "compat.h"
|
2011-01-16 08:17:36 +01:00
|
|
|
#include "include/aegisub/context.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "help_button.h"
|
|
|
|
#include "libresrc/libresrc.h"
|
2013-01-07 02:50:09 +01:00
|
|
|
#include "options.h"
|
2013-01-26 02:57:46 +01:00
|
|
|
#include "subs_controller.h"
|
2011-01-16 08:17:36 +01:00
|
|
|
#include "timeedit_ctrl.h"
|
2010-07-08 06:29:04 +02:00
|
|
|
#include "video_context.h"
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <libaegisub/fs.h>
|
|
|
|
#include <libaegisub/io.h>
|
|
|
|
#include <libaegisub/log.h>
|
|
|
|
#include <libaegisub/of_type_adaptor.h>
|
2013-01-30 04:35:37 +01:00
|
|
|
#include <libaegisub/path.h>
|
2013-10-23 23:43:05 +02:00
|
|
|
#include <libaegisub/util.h>
|
2013-01-04 16:01:50 +01:00
|
|
|
|
|
|
|
#include <libaegisub/cajun/elements.h>
|
|
|
|
#include <libaegisub/cajun/reader.h>
|
|
|
|
#include <libaegisub/cajun/writer.h>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <wx/listbox.h>
|
|
|
|
#include <wx/radiobox.h>
|
|
|
|
#include <wx/radiobut.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/textctrl.h>
|
|
|
|
|
2012-01-26 00:09:45 +01:00
|
|
|
static wxString get_history_string(json::Object &obj) {
|
2012-12-23 00:18:38 +01:00
|
|
|
wxString filename = to_wx(obj["filename"]);
|
2012-01-26 00:09:45 +01:00
|
|
|
if (filename.empty())
|
|
|
|
filename = _("unsaved");
|
|
|
|
|
2012-12-23 00:18:38 +01:00
|
|
|
wxString shift_amount(to_wx(obj["amount"]));
|
2012-01-26 00:09:45 +01:00
|
|
|
if (!obj["is by time"])
|
|
|
|
shift_amount = wxString::Format(_("%s frames"), shift_amount);
|
|
|
|
|
|
|
|
wxString shift_direction = obj["is backward"] ? _("backward") : _("forward");
|
|
|
|
|
|
|
|
int64_t time_field = obj["fields"];
|
|
|
|
wxString fields =
|
|
|
|
time_field == 0 ? _("s+e") :
|
|
|
|
time_field == 1 ? _("s") :
|
|
|
|
_("e") ;
|
|
|
|
|
|
|
|
json::Array const& sel = obj["selection"];
|
|
|
|
wxString lines;
|
|
|
|
|
|
|
|
int64_t sel_mode = obj["mode"];
|
|
|
|
if (sel_mode == 0)
|
|
|
|
lines = _("all");
|
|
|
|
else if (sel_mode == 2)
|
|
|
|
lines = wxString::Format(_("from %d onward"), (int)(int64_t)sel.front()["start"]);
|
|
|
|
else {
|
|
|
|
lines += _("sel ");
|
2013-09-16 21:10:00 +02:00
|
|
|
for (auto it = sel.begin(); it != sel.end(); ++it) {
|
2012-01-26 00:09:45 +01:00
|
|
|
int beg = (int64_t)(*it)["start"];
|
|
|
|
int end = (int64_t)(*it)["end"];
|
|
|
|
if (beg == end)
|
2013-09-18 17:31:26 +02:00
|
|
|
lines += std::to_wstring(beg);
|
2012-01-26 00:09:45 +01:00
|
|
|
else
|
|
|
|
lines += wxString::Format("%d-%d", beg, end);
|
|
|
|
if (it + 1 != sel.end())
|
|
|
|
lines += ";";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return wxString::Format("%s, %s %s, %s, %s", filename, shift_amount, shift_direction, fields, lines);
|
|
|
|
}
|
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
DialogShiftTimes::DialogShiftTimes(agi::Context *context)
|
|
|
|
: wxDialog(context->parent, -1, _("Shift Times"))
|
2011-01-16 08:17:36 +01:00
|
|
|
, context(context)
|
2013-01-30 04:35:37 +01:00
|
|
|
, history_filename(config::path->Decode("?user/shift_history.json"))
|
2013-10-23 23:43:05 +02:00
|
|
|
, history(agi::util::make_unique<json::Array>())
|
2011-09-15 07:17:14 +02:00
|
|
|
, timecodes_loaded_slot(context->videoController->AddTimecodesListener(&DialogShiftTimes::OnTimecodesLoaded, this))
|
2012-10-05 05:22:54 +02:00
|
|
|
, selected_set_changed_slot(context->selectionController->AddSelectionListener(&DialogShiftTimes::OnSelectedSetChanged, this))
|
2006-01-16 22:02:54 +01:00
|
|
|
{
|
2012-04-03 22:40:24 +02:00
|
|
|
SetIcon(GETICON(shift_times_toolbutton_16));
|
2007-07-05 01:09:40 +02:00
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
// Create controls
|
2011-11-18 19:49:09 +01:00
|
|
|
shift_by_time = new wxRadioButton(this, -1, _("&Time: "), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
|
2011-09-15 07:17:14 +02:00
|
|
|
shift_by_time->SetToolTip(_("Shift by time"));
|
|
|
|
shift_by_time->Bind(wxEVT_COMMAND_RADIOBUTTON_SELECTED, &DialogShiftTimes::OnByTime, this);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-11-18 19:49:09 +01:00
|
|
|
shift_by_frames = new wxRadioButton(this, -1 , _("&Frames: "));
|
2011-09-15 07:17:14 +02:00
|
|
|
shift_by_frames->SetToolTip(_("Shift by frames"));
|
|
|
|
shift_by_frames->Bind(wxEVT_COMMAND_RADIOBUTTON_SELECTED, &DialogShiftTimes::OnByFrames, this);
|
2006-12-30 19:53:19 +01:00
|
|
|
|
2011-12-22 22:18:16 +01:00
|
|
|
shift_time = new TimeEdit(this, -1, context);
|
2011-09-15 07:17:14 +02:00
|
|
|
shift_time->SetToolTip(_("Enter time in h:mm:ss.cs notation"));
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
shift_frames = new wxTextCtrl(this, -1);
|
|
|
|
shift_frames->SetToolTip(_("Enter number of frames to shift by"));
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-11-18 19:49:09 +01:00
|
|
|
shift_forward = new wxRadioButton(this, -1, _("For&ward"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
|
2011-09-15 07:17:14 +02:00
|
|
|
shift_forward->SetToolTip(_("Shifts subs forward, making them appear later. Use if they are appearing too soon."));
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-11-18 19:49:09 +01:00
|
|
|
shift_backward = new wxRadioButton(this, -1, _("&Backward"));
|
2011-09-15 07:17:14 +02:00
|
|
|
shift_backward->SetToolTip(_("Shifts subs backward, making them appear earlier. Use if they are appearing too late."));
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-10-11 18:34:22 +02:00
|
|
|
wxString selection_mode_vals[] = { _("&All rows"), _("Selected &rows"), _("Selection &onward") };
|
2011-09-15 07:17:14 +02:00
|
|
|
selection_mode = new wxRadioBox(this, -1, _("Affect"), wxDefaultPosition, wxDefaultSize, 3, selection_mode_vals, 1);
|
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
|
|
|
|
2011-11-18 19:49:09 +01:00
|
|
|
wxString time_field_vals[] = { _("Start a&nd End times"), _("&Start times only"), _("&End times only") };
|
2011-09-15 07:17:14 +02:00
|
|
|
time_fields = new wxRadioBox(this, -1, _("Times"), wxDefaultPosition, wxDefaultSize, 3, time_field_vals, 1);
|
2007-01-17 07:18:12 +01:00
|
|
|
|
2012-11-13 17:51:01 +01:00
|
|
|
history_box = new wxListBox(this, -1, wxDefaultPosition, wxSize(350, 100), 0, nullptr, wxLB_HSCROLL);
|
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
|
|
|
|
2011-11-18 19:49:09 +01:00
|
|
|
wxButton *clear_button = new wxButton(this, -1, _("&Clear"));
|
2011-09-15 07:17:14 +02:00
|
|
|
clear_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogShiftTimes::OnClear, this);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
// Set initial control states
|
|
|
|
OnTimecodesLoaded(context->videoController->FPS());
|
2012-10-05 05:22:54 +02:00
|
|
|
OnSelectedSetChanged();
|
2011-09-15 07:17:14 +02:00
|
|
|
LoadHistory();
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
shift_time->SetTime(OPT_GET("Tool/Shift Times/Time")->GetInt());
|
|
|
|
*shift_frames << (int)OPT_GET("Tool/Shift Times/Frames")->GetInt();
|
|
|
|
shift_by_frames->SetValue(!OPT_GET("Tool/Shift Times/ByTime")->GetBool() && shift_by_frames->IsEnabled());
|
|
|
|
time_fields->SetSelection(OPT_GET("Tool/Shift Times/Type")->GetInt());
|
|
|
|
selection_mode->SetSelection(OPT_GET("Tool/Shift Times/Affect")->GetInt());
|
|
|
|
shift_backward->SetValue(OPT_GET("Tool/Shift Times/Direction")->GetBool());
|
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
|
|
|
|
2011-10-13 01:08:02 +02:00
|
|
|
if (shift_by_frames->GetValue())
|
|
|
|
shift_time->Disable();
|
|
|
|
else
|
|
|
|
shift_frames->Disable();
|
|
|
|
|
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
// Position controls
|
|
|
|
wxSizer *shift_amount_sizer = new wxFlexGridSizer(2, 2, 5, 5);
|
|
|
|
shift_amount_sizer->Add(shift_by_time, wxSizerFlags(0).Align(wxALIGN_CENTER_VERTICAL));
|
|
|
|
shift_amount_sizer->Add(shift_time, wxSizerFlags(1));
|
|
|
|
shift_amount_sizer->Add(shift_by_frames, wxSizerFlags(0).Align(wxALIGN_CENTER_VERTICAL));
|
|
|
|
shift_amount_sizer->Add(shift_frames, wxSizerFlags(1));
|
2009-06-05 02:02:26 +02:00
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
wxSizer *shift_direction_sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
shift_direction_sizer->Add(shift_forward, wxSizerFlags(1).Expand());
|
|
|
|
shift_direction_sizer->Add(shift_backward, wxSizerFlags(1).Expand().Border(wxLEFT));
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
wxSizer *shift_by_sizer = new wxStaticBoxSizer(wxVERTICAL, this, _("Shift by"));
|
|
|
|
shift_by_sizer->Add(shift_amount_sizer, wxSizerFlags().Expand());
|
|
|
|
shift_by_sizer->Add(shift_direction_sizer, wxSizerFlags().Expand().Border(wxTOP));
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
wxSizer *left_sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
left_sizer->Add(shift_by_sizer, wxSizerFlags().Expand().Border(wxBOTTOM));
|
|
|
|
left_sizer->Add(selection_mode, wxSizerFlags().Expand().Border(wxBOTTOM));
|
|
|
|
left_sizer->Add(time_fields, wxSizerFlags().Expand());
|
2006-12-30 19:53:19 +01:00
|
|
|
|
2012-01-27 21:04:14 +01:00
|
|
|
wxSizer *history_sizer = new wxStaticBoxSizer(wxVERTICAL, this, _("Load from history"));
|
2012-01-26 00:09:45 +01:00
|
|
|
history_sizer->Add(history_box, wxSizerFlags(1).Expand());
|
2011-09-15 07:17:14 +02:00
|
|
|
history_sizer->Add(clear_button, wxSizerFlags().Expand().Border(wxTOP));
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
wxSizer *top_sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
top_sizer->Add(left_sizer, wxSizerFlags().Border(wxALL & ~wxRIGHT).Expand());
|
|
|
|
top_sizer->Add(history_sizer, wxSizerFlags().Border().Expand());
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
wxSizer *main_sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
main_sizer->Add(top_sizer, wxSizerFlags().Border(wxALL & ~wxBOTTOM));
|
|
|
|
main_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL | wxHELP), wxSizerFlags().Right().Border());
|
|
|
|
SetSizerAndFit(main_sizer);
|
|
|
|
CenterOnParent();
|
|
|
|
|
|
|
|
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogShiftTimes::Process, this, wxID_OK);
|
2012-09-25 01:35:27 +02:00
|
|
|
Bind(wxEVT_COMMAND_BUTTON_CLICKED, std::bind(&HelpButton::OpenPage, "Shift Times"), wxID_HELP);
|
2012-07-24 04:39:40 +02:00
|
|
|
shift_time->Bind(wxEVT_COMMAND_TEXT_ENTER, &DialogShiftTimes::Process, this);
|
2012-01-26 00:09:45 +01:00
|
|
|
history_box->Bind(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, &DialogShiftTimes::OnHistoryClick, this);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
DialogShiftTimes::~DialogShiftTimes() {
|
2012-05-10 16:18:54 +02:00
|
|
|
long shift;
|
|
|
|
shift_frames->GetValue().ToLong(&shift);
|
|
|
|
|
|
|
|
OPT_SET("Tool/Shift Times/Time")->SetInt(shift_time->GetTime());
|
|
|
|
OPT_SET("Tool/Shift Times/Frames")->SetInt(shift);
|
|
|
|
OPT_SET("Tool/Shift Times/ByTime")->SetBool(shift_by_time->GetValue());
|
|
|
|
OPT_SET("Tool/Shift Times/Type")->SetInt(time_fields->GetSelection());
|
|
|
|
OPT_SET("Tool/Shift Times/Affect")->SetInt(selection_mode->GetSelection());
|
|
|
|
OPT_SET("Tool/Shift Times/Direction")->SetBool(shift_backward->GetValue());
|
2011-09-15 07:17:14 +02:00
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
void DialogShiftTimes::OnTimecodesLoaded(agi::vfr::Framerate const& new_fps) {
|
|
|
|
fps = new_fps;
|
|
|
|
if (fps.IsLoaded()) {
|
|
|
|
shift_by_frames->Enable();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
shift_by_time->SetValue(true);
|
|
|
|
shift_by_frames->Disable();
|
|
|
|
shift_time->Enable();
|
|
|
|
shift_frames->Disable();
|
|
|
|
}
|
|
|
|
}
|
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-10-05 05:22:54 +02:00
|
|
|
void DialogShiftTimes::OnSelectedSetChanged() {
|
2011-09-15 07:17:14 +02:00
|
|
|
if (context->selectionController->GetSelectedSet().empty()) {
|
|
|
|
selection_mode->Enable(1, false);
|
|
|
|
selection_mode->Enable(2, false);
|
|
|
|
selection_mode->SetSelection(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
selection_mode->Enable(1, true);
|
|
|
|
selection_mode->Enable(2, true);
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
void DialogShiftTimes::OnClear(wxCommandEvent &) {
|
2013-01-04 16:01:50 +01:00
|
|
|
agi::fs::Remove(history_filename);
|
2012-01-26 00:09:45 +01:00
|
|
|
history_box->Clear();
|
|
|
|
history->clear();
|
2011-09-15 07:17:14 +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
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
void DialogShiftTimes::OnByTime(wxCommandEvent &) {
|
|
|
|
shift_time->Enable(true);
|
|
|
|
shift_frames->Enable(false);
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
void DialogShiftTimes::OnByFrames(wxCommandEvent &) {
|
|
|
|
shift_time->Enable(false);
|
|
|
|
shift_frames->Enable(true);
|
|
|
|
}
|
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-01-26 00:09:45 +01:00
|
|
|
void DialogShiftTimes::OnHistoryClick(wxCommandEvent &evt) {
|
|
|
|
size_t entry = evt.GetInt();
|
|
|
|
if (entry >= history->size()) return;
|
2011-09-15 07:17:14 +02:00
|
|
|
|
2012-01-26 00:09:45 +01:00
|
|
|
json::Object& obj = (*history)[entry];
|
|
|
|
if (obj["is by time"]) {
|
2013-01-04 16:01:50 +01:00
|
|
|
shift_time->SetTime(AssTime((std::string)obj["amount"]));
|
2012-01-26 00:09:45 +01:00
|
|
|
shift_by_time->SetValue(true);
|
|
|
|
OnByTime(evt);
|
|
|
|
}
|
2011-09-15 07:17:14 +02:00
|
|
|
else {
|
2012-12-23 00:18:38 +01:00
|
|
|
shift_frames->SetValue(to_wx(obj["amount"]));
|
2012-01-26 00:09:45 +01:00
|
|
|
if (shift_by_frames->IsEnabled()) {
|
|
|
|
shift_by_frames->SetValue(true);
|
|
|
|
OnByFrames(evt);
|
2011-09-15 07:17:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-26 00:09:45 +01:00
|
|
|
if (obj["is backward"])
|
|
|
|
shift_backward->SetValue(true);
|
|
|
|
else
|
|
|
|
shift_forward->SetValue(true);
|
2011-09-15 07:17:14 +02:00
|
|
|
|
2012-01-26 00:09:45 +01:00
|
|
|
selection_mode->SetSelection((int64_t)obj["mode"]);
|
|
|
|
time_fields->SetSelection((int64_t)obj["fields"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogShiftTimes::SaveHistory(json::Array const& shifted_blocks) {
|
|
|
|
json::Object new_entry;
|
2013-01-26 02:57:46 +01:00
|
|
|
new_entry["filename"] = context->subsController->Filename().filename().string();
|
2012-01-26 00:09:45 +01:00
|
|
|
new_entry["is by time"] = shift_by_time->GetValue();
|
|
|
|
new_entry["is backward"] = shift_backward->GetValue();
|
2012-12-23 00:18:38 +01:00
|
|
|
new_entry["amount"] = from_wx(shift_by_time->GetValue() ? shift_time->GetValue() : shift_frames->GetValue());
|
2012-01-26 00:09:45 +01:00
|
|
|
new_entry["fields"] = time_fields->GetSelection();
|
|
|
|
new_entry["mode"] = selection_mode->GetSelection();
|
|
|
|
new_entry["selection"] = shifted_blocks;
|
|
|
|
|
|
|
|
history->push_front(new_entry);
|
2013-10-27 21:08:58 +01:00
|
|
|
if (history->size() > 50)
|
|
|
|
history->resize(50);
|
2012-01-26 00:09:45 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
json::Writer::Write(*history, agi::io::Save(history_filename).Get());
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2013-01-04 16:01:50 +01:00
|
|
|
catch (agi::fs::FileSystemError const& e) {
|
2011-09-15 07:17:14 +02:00
|
|
|
LOG_E("dialog_shift_times/save_history") << "Cannot save shift times history: " << e.GetChainedMessage();
|
|
|
|
}
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
void DialogShiftTimes::LoadHistory() {
|
2012-01-26 00:09:45 +01:00
|
|
|
history_box->Clear();
|
|
|
|
history_box->Freeze();
|
2011-09-15 07:17:14 +02:00
|
|
|
|
|
|
|
try {
|
2013-02-17 04:47:31 +01:00
|
|
|
std::unique_ptr<std::istream> file(agi::io::Open(history_filename));
|
2012-01-26 00:09:45 +01:00
|
|
|
json::UnknownElement root;
|
2013-02-17 04:47:31 +01:00
|
|
|
json::Reader::Read(root, *file);
|
2012-01-26 00:09:45 +01:00
|
|
|
*history = root;
|
|
|
|
|
2012-11-04 04:53:03 +01:00
|
|
|
for (auto& history_entry : *history)
|
|
|
|
history_box->Append(get_history_string(history_entry));
|
2011-09-15 07:17:14 +02:00
|
|
|
}
|
2013-01-04 16:01:50 +01:00
|
|
|
catch (agi::fs::FileSystemError const& e) {
|
2012-01-26 00:09:45 +01:00
|
|
|
LOG_D("dialog_shift_times/load_history") << "Cannot load shift times history: " << e.GetChainedMessage();
|
2011-09-15 07:17:14 +02:00
|
|
|
}
|
|
|
|
catch (...) {
|
2012-01-26 00:09:45 +01:00
|
|
|
history_box->Thaw();
|
2011-09-15 07:17:14 +02:00
|
|
|
throw;
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-01-26 00:09:45 +01:00
|
|
|
history_box->Thaw();
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
void DialogShiftTimes::Process(wxCommandEvent &) {
|
|
|
|
int mode = selection_mode->GetSelection();
|
|
|
|
int type = time_fields->GetSelection();
|
|
|
|
bool reverse = shift_backward->GetValue();
|
|
|
|
bool by_time = shift_by_time->GetValue();
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
bool start = type != 2;
|
|
|
|
bool end = type != 1;
|
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-10-05 05:22:54 +02:00
|
|
|
SubtitleSelection sel = context->selectionController->GetSelectedSet();
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
long shift;
|
|
|
|
if (by_time) {
|
2011-12-22 22:28:51 +01:00
|
|
|
shift = shift_time->GetTime();
|
2011-09-15 07:17:14 +02:00
|
|
|
if (shift == 0) {
|
|
|
|
Close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
shift_frames->GetValue().ToLong(&shift);
|
|
|
|
|
|
|
|
if (reverse)
|
|
|
|
shift = -shift;
|
|
|
|
|
|
|
|
// Track which rows were shifted for the log
|
|
|
|
int row_number = 0;
|
|
|
|
int block_start = 0;
|
2012-01-26 00:09:45 +01:00
|
|
|
json::Array shifted_blocks;
|
2011-09-15 07:17:14 +02:00
|
|
|
|
2012-11-05 17:20:58 +01:00
|
|
|
for (auto line : context->ass->Line | agi::of_type<AssDialogue>()) {
|
2011-09-15 07:17:14 +02:00
|
|
|
++row_number;
|
|
|
|
|
|
|
|
if (!sel.count(line)) {
|
|
|
|
if (block_start) {
|
2012-01-26 00:09:45 +01:00
|
|
|
json::Object block;
|
|
|
|
block["start"] = block_start;
|
|
|
|
block["end"] = row_number - 1;
|
|
|
|
shifted_blocks.push_back(block);
|
2011-09-15 07:17:14 +02:00
|
|
|
block_start = 0;
|
|
|
|
}
|
|
|
|
if (mode == 1) continue;
|
|
|
|
if (mode == 2 && shifted_blocks.empty()) continue;
|
|
|
|
}
|
|
|
|
else if (!block_start)
|
|
|
|
block_start = row_number;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
if (start)
|
2011-12-22 22:28:51 +01:00
|
|
|
line->Start = Shift(line->Start, shift, by_time, agi::vfr::START);
|
2011-09-15 07:17:14 +02:00
|
|
|
if (end)
|
2011-12-22 22:28:51 +01:00
|
|
|
line->End = Shift(line->End, shift, by_time, agi::vfr::END);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
context->ass->Commit(_("shifting"), AssFile::COMMIT_DIAG_TIME);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-01-26 00:09:45 +01:00
|
|
|
if (block_start) {
|
|
|
|
json::Object block;
|
|
|
|
block["start"] = block_start;
|
|
|
|
block["end"] = row_number - 1;
|
|
|
|
shifted_blocks.push_back(block);
|
|
|
|
}
|
2009-07-29 07:43:02 +02:00
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
SaveHistory(shifted_blocks);
|
|
|
|
Close();
|
|
|
|
}
|
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
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
int DialogShiftTimes::Shift(int initial_time, int shift, bool by_time, agi::vfr::Time type) {
|
|
|
|
if (by_time)
|
|
|
|
return initial_time + shift;
|
|
|
|
else
|
|
|
|
return fps.TimeAtFrame(shift + fps.FrameAtTime(initial_time, type), type);
|
|
|
|
}
|