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/
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_dialogue.h"
|
|
|
|
#include "ass_file.h"
|
2011-09-15 07:17:14 +02:00
|
|
|
#include "compat.h"
|
2014-05-22 21:07:15 +02:00
|
|
|
#include "dialog_manager.h"
|
2014-05-29 17:28:37 +02:00
|
|
|
#include "format.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"
|
2014-05-22 01:23:28 +02:00
|
|
|
#include "project.h"
|
2014-03-25 01:15:14 +01:00
|
|
|
#include "selection_controller.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"
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2014-07-06 16:28:58 +02:00
|
|
|
#include <libaegisub/ass/time.h>
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <libaegisub/fs.h>
|
|
|
|
#include <libaegisub/io.h>
|
|
|
|
#include <libaegisub/log.h>
|
2013-01-30 04:35:37 +01:00
|
|
|
#include <libaegisub/path.h>
|
2014-05-22 21:07:15 +02:00
|
|
|
#include <libaegisub/signal.h>
|
|
|
|
#include <libaegisub/vfr.h>
|
2013-01-04 16:01:50 +01:00
|
|
|
|
|
|
|
#include <libaegisub/cajun/elements.h>
|
|
|
|
#include <libaegisub/cajun/reader.h>
|
|
|
|
#include <libaegisub/cajun/writer.h>
|
|
|
|
|
2014-05-22 21:07:15 +02:00
|
|
|
#include <boost/filesystem/path.hpp>
|
|
|
|
#include <wx/dialog.h>
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <wx/listbox.h>
|
|
|
|
#include <wx/radiobox.h>
|
|
|
|
#include <wx/radiobut.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/textctrl.h>
|
|
|
|
|
2014-05-22 21:07:15 +02:00
|
|
|
namespace {
|
|
|
|
class DialogShiftTimes final : public wxDialog {
|
|
|
|
agi::Context *context;
|
|
|
|
|
|
|
|
agi::fs::path history_filename;
|
|
|
|
json::Array history;
|
|
|
|
agi::vfr::Framerate fps;
|
|
|
|
agi::signal::Connection timecodes_loaded_slot;
|
|
|
|
agi::signal::Connection selected_set_changed_slot;
|
|
|
|
|
|
|
|
TimeEdit *shift_time;
|
|
|
|
wxTextCtrl *shift_frames;
|
|
|
|
wxRadioButton *shift_by_time;
|
|
|
|
wxRadioButton *shift_by_frames;
|
|
|
|
wxRadioButton *shift_forward;
|
|
|
|
wxRadioButton *shift_backward;
|
|
|
|
wxRadioBox *selection_mode;
|
|
|
|
wxRadioBox *time_fields;
|
|
|
|
wxListBox *history_box;
|
|
|
|
|
2014-06-28 05:44:47 +02:00
|
|
|
void SaveHistory(json::Array shifted_blocks);
|
2014-05-22 21:07:15 +02:00
|
|
|
void LoadHistory();
|
|
|
|
void Process(wxCommandEvent&);
|
|
|
|
int Shift(int initial_time, int shift, bool by_time, agi::vfr::Time type);
|
|
|
|
|
|
|
|
void OnClear(wxCommandEvent&);
|
|
|
|
void OnByTime(wxCommandEvent&);
|
|
|
|
void OnByFrames(wxCommandEvent&);
|
|
|
|
void OnHistoryClick(wxCommandEvent&);
|
|
|
|
|
|
|
|
void OnSelectedSetChanged();
|
|
|
|
void OnTimecodesLoaded(agi::vfr::Framerate const& new_fps);
|
|
|
|
|
|
|
|
public:
|
|
|
|
DialogShiftTimes(agi::Context *context);
|
|
|
|
~DialogShiftTimes();
|
|
|
|
};
|
|
|
|
|
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"])
|
2014-05-29 17:28:37 +02:00
|
|
|
shift_amount = fmt_tl("%s frames", shift_amount);
|
2012-01-26 00:09:45 +01:00
|
|
|
|
|
|
|
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") ;
|
|
|
|
|
2014-06-28 05:44:47 +02:00
|
|
|
json::Array& sel = obj["selection"];
|
2012-01-26 00:09:45 +01:00
|
|
|
wxString lines;
|
|
|
|
|
|
|
|
int64_t sel_mode = obj["mode"];
|
|
|
|
if (sel_mode == 0)
|
|
|
|
lines = _("all");
|
2014-11-22 22:21:58 +01:00
|
|
|
else if (sel_mode == 2) {
|
|
|
|
if (!sel.empty())
|
|
|
|
lines = fmt_tl("from %d onward", (int64_t)static_cast<json::Object&>(sel.front())["start"]);
|
|
|
|
}
|
2012-01-26 00:09:45 +01:00
|
|
|
else {
|
|
|
|
lines += _("sel ");
|
2013-09-16 21:10:00 +02:00
|
|
|
for (auto it = sel.begin(); it != sel.end(); ++it) {
|
2014-06-28 05:44:47 +02:00
|
|
|
json::Object& range = *it;
|
|
|
|
int beg = (int64_t)range["start"];
|
|
|
|
int end = (int64_t)range["end"];
|
2012-01-26 00:09:45 +01:00
|
|
|
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
|
2014-05-29 17:28:37 +02:00
|
|
|
lines += fmt_wx("%d-%d", beg, end);
|
2012-01-26 00:09:45 +01:00
|
|
|
if (it + 1 != sel.end())
|
|
|
|
lines += ";";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-29 17:28:37 +02:00
|
|
|
return fmt_wx("%s, %s %s, %s, %s", filename, shift_amount, shift_direction, fields, lines);
|
2012-01-26 00:09:45 +01:00
|
|
|
}
|
|
|
|
|
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"))
|
2014-05-22 01:23:28 +02:00
|
|
|
, timecodes_loaded_slot(context->project->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"));
|
2013-12-12 03:25:13 +01:00
|
|
|
shift_by_time->Bind(wxEVT_RADIOBUTTON, &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"));
|
2013-12-12 03:25:13 +01:00
|
|
|
shift_by_frames->Bind(wxEVT_RADIOBUTTON, &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"));
|
2013-12-12 03:25:13 +01:00
|
|
|
clear_button->Bind(wxEVT_BUTTON, &DialogShiftTimes::OnClear, this);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
// Set initial control states
|
2014-05-22 01:23:28 +02:00
|
|
|
OnTimecodesLoaded(context->project->Timecodes());
|
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();
|
|
|
|
|
2013-12-12 03:25:13 +01:00
|
|
|
Bind(wxEVT_BUTTON, &DialogShiftTimes::Process, this, wxID_OK);
|
|
|
|
Bind(wxEVT_BUTTON, std::bind(&HelpButton::OpenPage, "Shift Times"), wxID_HELP);
|
|
|
|
shift_time->Bind(wxEVT_TEXT_ENTER, &DialogShiftTimes::Process, this);
|
|
|
|
history_box->Bind(wxEVT_LISTBOX_DCLICK, &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();
|
2014-05-22 21:07:15 +02:00
|
|
|
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();
|
2014-05-22 21:07:15 +02:00
|
|
|
if (entry >= history.size()) return;
|
2011-09-15 07:17:14 +02:00
|
|
|
|
2014-05-22 21:07:15 +02:00
|
|
|
json::Object& obj = history[entry];
|
2012-01-26 00:09:45 +01:00
|
|
|
if (obj["is by time"]) {
|
2014-07-06 16:28:58 +02:00
|
|
|
shift_time->SetTime(agi::Time((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"]);
|
|
|
|
}
|
|
|
|
|
2014-06-28 05:44:47 +02:00
|
|
|
void DialogShiftTimes::SaveHistory(json::Array shifted_blocks) {
|
2012-01-26 00:09:45 +01:00
|
|
|
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();
|
2014-06-28 05:44:47 +02:00
|
|
|
new_entry["selection"] = std::move(shifted_blocks);
|
2012-01-26 00:09:45 +01:00
|
|
|
|
2014-06-28 05:44:47 +02:00
|
|
|
history.insert(history.begin(), std::move(new_entry));
|
2014-05-22 21:07:15 +02:00
|
|
|
if (history.size() > 50)
|
|
|
|
history.resize(50);
|
2012-01-26 00:09:45 +01:00
|
|
|
|
|
|
|
try {
|
2014-06-28 04:38:53 +02:00
|
|
|
agi::JsonWriter::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) {
|
2014-05-29 14:57:27 +02:00
|
|
|
LOG_E("dialog_shift_times/save_history") << "Cannot save shift times history: " << e.GetMessage();
|
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::LoadHistory() {
|
2012-01-26 00:09:45 +01:00
|
|
|
history_box->Clear();
|
|
|
|
history_box->Freeze();
|
2011-09-15 07:17:14 +02:00
|
|
|
|
|
|
|
try {
|
2012-01-26 00:09:45 +01:00
|
|
|
json::UnknownElement root;
|
2014-06-28 04:38:53 +02:00
|
|
|
json::Reader::Read(root, *agi::io::Open(history_filename));
|
2014-06-28 05:44:47 +02:00
|
|
|
history = std::move(static_cast<json::Array&>(root));
|
2012-01-26 00:09:45 +01:00
|
|
|
|
2014-05-22 21:07:15 +02:00
|
|
|
for (auto& history_entry : history)
|
2012-11-04 04:53:03 +01:00
|
|
|
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) {
|
2014-05-29 14:57:27 +02:00
|
|
|
LOG_D("dialog_shift_times/load_history") << "Cannot load shift times history: " << e.GetMessage();
|
2011-09-15 07:17:14 +02:00
|
|
|
}
|
2014-08-24 16:42:56 +02:00
|
|
|
catch (json::Exception const& e) {
|
|
|
|
LOG_D("dialog_shift_times/load_history") << "Cannot load shift times history: " << e.what();
|
|
|
|
}
|
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
|
|
|
|
2014-03-25 01:15:14 +01:00
|
|
|
auto const& 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 block_start = 0;
|
2012-01-26 00:09:45 +01:00
|
|
|
json::Array shifted_blocks;
|
2011-09-15 07:17:14 +02:00
|
|
|
|
2014-03-07 19:58:51 +01:00
|
|
|
for (auto& line : context->ass->Events) {
|
|
|
|
if (!sel.count(&line)) {
|
2011-09-15 07:17:14 +02:00
|
|
|
if (block_start) {
|
2012-01-26 00:09:45 +01:00
|
|
|
json::Object block;
|
|
|
|
block["start"] = block_start;
|
2014-04-17 23:24:26 +02:00
|
|
|
block["end"] = line.Row;
|
2014-06-28 05:44:47 +02:00
|
|
|
shifted_blocks.push_back(std::move(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)
|
2014-04-17 23:24:26 +02:00
|
|
|
block_start = line.Row + 1;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-15 07:17:14 +02:00
|
|
|
if (start)
|
2014-03-07 19:58:51 +01:00
|
|
|
line.Start = Shift(line.Start, shift, by_time, agi::vfr::START);
|
2011-09-15 07:17:14 +02:00
|
|
|
if (end)
|
2014-03-07 19:58: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;
|
2014-04-17 23:24:26 +02:00
|
|
|
block["end"] = context->ass->Events.back().Row + 1;
|
2014-06-28 05:44:47 +02:00
|
|
|
shifted_blocks.push_back(std::move(block));
|
2012-01-26 00:09:45 +01:00
|
|
|
}
|
2009-07-29 07:43:02 +02:00
|
|
|
|
2014-06-28 05:44:47 +02:00
|
|
|
SaveHistory(std::move(shifted_blocks));
|
2011-09-15 07:17:14 +02:00
|
|
|
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);
|
|
|
|
}
|
2014-05-22 21:07:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShowShiftTimesDialog(agi::Context *c) {
|
|
|
|
c->dialog->Show<DialogShiftTimes>(c);
|
|
|
|
}
|