예제 #1
0
SubsController::SubsController(agi::Context *context)
: context(context)
, undo_connection(context->ass->AddUndoManager(&SubsController::OnCommit, this))
, commit_id(0)
, saved_commit_id(0)
, autosaved_commit_id(0)
{
	autosave_timer_changed(&autosave_timer);
	OPT_SUB("App/Auto/Save", autosave_timer_changed, &autosave_timer);
	OPT_SUB("App/Auto/Save Every Seconds", autosave_timer_changed, &autosave_timer);

	autosave_timer.Bind(wxEVT_TIMER, [=](wxTimerEvent&) {
		try {
			auto fn = AutoSave();
			if (!fn.empty())
				StatusTimeout(wxString::Format(_("File backup saved as \"%s\"."), fn.wstring()));
		}
		catch (const agi::Exception& err) {
			StatusTimeout(to_wx("Exception when attempting to autosave file: " + err.GetMessage()));
		}
		catch (...) {
			StatusTimeout("Unhandled exception when attempting to autosave file.");
		}
	});
}
예제 #2
0
void FrameMain::OnAutoSave(wxTimerEvent &) try {
	wxString fn = context->ass->AutoSave();
	if (!fn.empty())
		StatusTimeout(wxString::Format(_("File backup saved as \"%s\"."), fn));
}
catch (const agi::Exception& err) {
	StatusTimeout(lagi_wxString("Exception when attempting to autosave file: " + err.GetMessage()));
}
catch (wxString err) {
	StatusTimeout("Exception when attempting to autosave file: " + err);
}
catch (const char *err) {
	StatusTimeout("Exception when attempting to autosave file: " + wxString(err));
}
catch (...) {
	StatusTimeout("Unhandled exception when attempting to autosave file.");
}
예제 #3
0
void DialogSelection::Process(wxCommandEvent&) {
	std::set<AssDialogue*> matches;

	try {
		matches = process(
			from_wx(match_text->GetValue()), case_sensitive->IsChecked(),
			match_mode->GetSelection(), select_unmatching_lines->GetValue(),
			apply_to_comments->IsChecked(), apply_to_dialogue->IsChecked(),
			dialogue_field->GetSelection(), con->ass);
	}
	catch (agi::Exception const&) {
		Close();
		return;
	}

	int action = selection_change_type->GetSelection();

	SubtitleSelection old_sel, new_sel;
	if (action != ACTION_SET)
		con->selectionController->GetSelectedSet(old_sel);

	wxString message;
	size_t count = 0;
	switch (action) {
		case ACTION_SET:
			new_sel = matches;
			switch (count = new_sel.size()) {
				case 0:  message = _("Selection was set to no lines"); break;
				case 1:  message = _("Selection was set to one line"); break;
				default: message = wxString::Format(_("Selection was set to %u lines"), (unsigned)count);
			}
			break;

		case ACTION_ADD:
			set_union(old_sel.begin(), old_sel.end(), matches.begin(), matches.end(), inserter(new_sel, new_sel.begin()));
			switch (count = new_sel.size() - old_sel.size()) {
				case 0:  message = _("No lines were added to selection"); break;
				case 1:  message = _("One line was added to selection"); break;
				default: message = wxString::Format(_("%u lines were added to selection"), (unsigned)count);
			}
			break;

		case ACTION_SUB:
			set_difference(old_sel.begin(), old_sel.end(), matches.begin(), matches.end(), inserter(new_sel, new_sel.begin()));
			switch (count = old_sel.size() - new_sel.size()) {
				case 0:  message = _("No lines were removed from selection"); break;
				case 1:  message = _("One line was removed from selection"); break;
				default: message = wxString::Format(_("%u lines were removed from selection"), (unsigned)count);
			}
			break;

		case ACTION_INTERSECT:
			set_intersection(old_sel.begin(), old_sel.end(), matches.begin(), matches.end(), inserter(new_sel, new_sel.begin()));
			switch (count = old_sel.size() - new_sel.size()) {
				case 0:  message = _("No lines were removed from selection"); break;
				case 1:  message = _("One line was removed from selection"); break;
				default: message = wxString::Format(_("%u lines were removed from selection"), (unsigned)count);
			}
			break;
	}

	if (count == 0)
		wxMessageBox(message, _("Selection"), wxOK | wxCENTER, this);
	else
		StatusTimeout(message);

	if (new_sel.size() && !new_sel.count(con->selectionController->GetActiveLine()))
		con->selectionController->SetActiveLine(*new_sel.begin());
	con->selectionController->SetSelectedSet(new_sel);

	AssDialogue *new_active = con->selectionController->GetActiveLine();
	if (new_sel.size() && !new_sel.count(new_active))
		new_active = *new_sel.begin();
	con->selectionController->SetSelectionAndActive(new_sel, new_active);

	Close();
}