Add a basic dialog for opening Autosave files
This currently consists of just a list of autosave files and the timestamps of the versions available for each file. It'd probably be a good idea to add more information to this later, such as the original file path and perhaps a preview of the file? Closes #781.
This commit is contained in:
parent
6f05d4b466
commit
154f831c7c
8 changed files with 215 additions and 11 deletions
|
@ -23,18 +23,15 @@
|
|||
<ProjectGuid>{9DDDB9E5-E4A1-423D-A224-F6D4E5AAC06A}</ProjectGuid>
|
||||
<RootNamespace>Aegisub</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Aegisub project configuration -->
|
||||
<PropertyGroup Label="AegisubConfiguration">
|
||||
<AegisubProjectType>exe</AegisubProjectType>
|
||||
<AegisubUseWxWidgets>true</AegisubUseWxWidgets>
|
||||
<SrcDir>..\..\src\</SrcDir>
|
||||
</PropertyGroup>
|
||||
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="$(MSBuildThisFileDirectory)..\aegisub.props" />
|
||||
</ImportGroup>
|
||||
|
||||
<!-- Project specific configuration -->
|
||||
<PropertyGroup>
|
||||
<TargetName>aegisub$(AegisubPlatformSuffix)</TargetName>
|
||||
|
@ -47,7 +44,6 @@
|
|||
<AdditionalOptions>/Zm150 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
|
||||
<!-- Project References -->
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\csrihelper\csrihelper.vcxproj">
|
||||
|
@ -81,7 +77,6 @@
|
|||
<Project>{7b56955d-5162-4698-aa5b-47484edc8783}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Source files -->
|
||||
<ItemGroup>
|
||||
<ClInclude Include="$(SrcDir)aegisublocale.h" />
|
||||
|
@ -253,13 +248,15 @@
|
|||
<ClInclude Include="$(SrcDir)scintilla_text_selection_controller.h" />
|
||||
<ClInclude Include="$(SrcDir)text_selection_controller.h" />
|
||||
<ClInclude Include="$(SrcDir)time_range.h" />
|
||||
<ClInclude Include="..\..\src\dialog_autosave.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(SrcDir)aegisublocale.cpp" />
|
||||
<ClCompile Include="$(SrcDir)agi_pre.cpp">
|
||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>agi_pre.h</PrecompiledHeaderFile>
|
||||
<ForcedIncludeFiles></ForcedIncludeFiles>
|
||||
<ForcedIncludeFiles>
|
||||
</ForcedIncludeFiles>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)ass_attachment.cpp" />
|
||||
<ClCompile Include="$(SrcDir)ass_dialogue.cpp" />
|
||||
|
@ -372,11 +369,13 @@
|
|||
<ClCompile Include="$(SrcDir)main.cpp" />
|
||||
<ClCompile Include="$(SrcDir)MatroskaParser.c">
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<ForcedIncludeFiles></ForcedIncludeFiles>
|
||||
<ForcedIncludeFiles>
|
||||
</ForcedIncludeFiles>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)md5.c">
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<ForcedIncludeFiles></ForcedIncludeFiles>
|
||||
<ForcedIncludeFiles>
|
||||
</ForcedIncludeFiles>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SrcDir)menu.cpp" />
|
||||
<ClCompile Include="$(SrcDir)mkv_wrap.cpp" />
|
||||
|
@ -447,12 +446,12 @@
|
|||
<ClCompile Include="$(SrcDir)audio_provider_lock.cpp" />
|
||||
<ClCompile Include="$(SrcDir)scintilla_text_selection_controller.cpp" />
|
||||
<ClCompile Include="$(SrcDir)command\keyframe.cpp" />
|
||||
<ClCompile Include="..\..\src\dialog_autosave.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="$(SrcDir)res.rc" />
|
||||
</ItemGroup>
|
||||
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="$(MSBuildThisFileDirectory)Aegisub.targets" />
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
|
@ -145,6 +145,9 @@
|
|||
<Filter Include="Preferences">
|
||||
<UniqueIdentifier>{39646be7-5dce-471c-ab93-1e3f7f6f9fe1}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Features\Autosave">
|
||||
<UniqueIdentifier>{fde3be82-3653-4519-88f5-8c16ddfb1531}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="$(SrcDir)ass_time.h">
|
||||
|
@ -654,6 +657,9 @@
|
|||
<ClInclude Include="$(SrcDir)placeholder_ctrl.h">
|
||||
<Filter>Controls</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\dialog_autosave.h">
|
||||
<Filter>Features\Autosave</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(SrcDir)ass_dialogue.cpp">
|
||||
|
@ -1202,10 +1208,13 @@
|
|||
<ClCompile Include="$(SrcDir)command\keyframe.cpp">
|
||||
<Filter>Commands</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\dialog_autosave.cpp">
|
||||
<Filter>Features\Autosave</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="$(SrcDir)res.rc">
|
||||
<Filter>Resources</Filter>
|
||||
</ResourceCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
|
@ -164,6 +164,7 @@ SRC += \
|
|||
dialog_about.cpp \
|
||||
dialog_attachments.cpp \
|
||||
dialog_automation.cpp \
|
||||
dialog_autosave.cpp \
|
||||
dialog_colorpicker.cpp \
|
||||
dialog_detached_video.cpp \
|
||||
dialog_dummy_video.cpp \
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "../ass_file.h"
|
||||
#include "../compat.h"
|
||||
#include "../dialog_attachments.h"
|
||||
#include "../dialog_autosave.h"
|
||||
#include "../dialog_manager.h"
|
||||
#include "../dialog_properties.h"
|
||||
#include "../dialog_search_replace.h"
|
||||
|
@ -268,6 +269,19 @@ struct subtitle_open : public Command {
|
|||
}
|
||||
};
|
||||
|
||||
struct subtitle_open_autosave : public Command {
|
||||
CMD_NAME("subtitle/open/autosave")
|
||||
STR_MENU("Open A&utosaved Subtitles...")
|
||||
STR_DISP("Open Autosaved Subtitles")
|
||||
STR_HELP("Open a previous version of a file which was autosaved by Aegisub")
|
||||
|
||||
void operator()(agi::Context *c) {
|
||||
DialogAutosave dialog(c->parent);
|
||||
if (dialog.ShowModal() == wxID_OK)
|
||||
wxGetApp().frame->LoadSubtitles(dialog.ChosenFile());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/// Opens a subtitles file with a specific charset.
|
||||
struct subtitle_open_charset : public Command {
|
||||
|
@ -455,6 +469,7 @@ namespace cmd {
|
|||
reg(new subtitle_insert_before_videotime);
|
||||
reg(new subtitle_new);
|
||||
reg(new subtitle_open);
|
||||
reg(new subtitle_open_autosave);
|
||||
reg(new subtitle_open_charset);
|
||||
reg(new subtitle_open_video);
|
||||
reg(new subtitle_properties);
|
||||
|
|
125
aegisub/src/dialog_autosave.cpp
Normal file
125
aegisub/src/dialog_autosave.cpp
Normal file
|
@ -0,0 +1,125 @@
|
|||
// Copyright (c) 2012, 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 "config.h"
|
||||
|
||||
#include "dialog_autosave.h"
|
||||
|
||||
#include "compat.h"
|
||||
#include "main.h"
|
||||
#include "standard_paths.h"
|
||||
|
||||
#include <boost/range/adaptor/map.hpp>
|
||||
|
||||
#ifndef AGI_PRE
|
||||
#include <map>
|
||||
|
||||
#include <wx/statbox.h>
|
||||
#endif
|
||||
|
||||
DialogAutosave::DialogAutosave(wxWindow *parent)
|
||||
: wxDialog(parent, -1, _("Open autosave file"), wxDefaultPosition, wxSize(800, 350))
|
||||
, directory(StandardPaths::DecodePath(to_wx(OPT_GET("Path/Auto/Save")->GetString())))
|
||||
{
|
||||
wxSizer *files_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Files"));
|
||||
file_list = new wxListBox(this, -1);
|
||||
file_list->Bind(wxEVT_COMMAND_LISTBOX_SELECTED, &DialogAutosave::OnSelectFile, this);
|
||||
files_box->Add(file_list, wxSizerFlags(1).Expand().Border());
|
||||
|
||||
wxSizer *versions_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Versions"));
|
||||
version_list = new wxListBox(this, -1);
|
||||
version_list->Bind(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, [=](wxCommandEvent&) { EndModal(wxID_OK); });
|
||||
versions_box->Add(version_list, wxSizerFlags(1).Expand().Border());
|
||||
|
||||
wxSizer *boxes_sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
boxes_sizer->Add(files_box, wxSizerFlags(1).Expand().Border());
|
||||
boxes_sizer->Add(versions_box, wxSizerFlags(1).Expand().Border());
|
||||
|
||||
wxStdDialogButtonSizer *btn_sizer = CreateStdDialogButtonSizer(wxOK | wxCANCEL);
|
||||
btn_sizer->GetAffirmativeButton()->SetLabelText(_("Open"));
|
||||
|
||||
wxSizer *main_sizer = new wxBoxSizer(wxVERTICAL);
|
||||
main_sizer->Add(boxes_sizer, wxSizerFlags(1).Expand().Border());
|
||||
main_sizer->Add(btn_sizer, wxSizerFlags().Expand().Border(wxALL & ~wxTOP));
|
||||
SetSizer(main_sizer);
|
||||
|
||||
Populate();
|
||||
if (file_list->IsEmpty())
|
||||
btn_sizer->GetAffirmativeButton()->Disable();
|
||||
}
|
||||
|
||||
void DialogAutosave::Populate() {
|
||||
wxDir dir;
|
||||
if (!dir.Open(directory)) return;
|
||||
|
||||
wxString fn;
|
||||
if (!dir.GetFirst(&fn, "*.AUTOSAVE.ass", wxDIR_FILES))
|
||||
return;
|
||||
|
||||
std::map<wxString, AutosaveFile> files_map;
|
||||
do {
|
||||
wxString date_str;
|
||||
wxString name = fn.Left(fn.size() - 13).BeforeLast('.', &date_str);
|
||||
if (!name) continue;
|
||||
|
||||
wxDateTime date;
|
||||
if (!date.ParseFormat(date_str, "%Y-%m-%d-%H-%M-%S"))
|
||||
continue;
|
||||
|
||||
auto it = files_map.find(name);
|
||||
if (it == files_map.end())
|
||||
it = files_map.emplace(name, name).first;
|
||||
it->second.versions.emplace_back(fn, date);
|
||||
} while (dir.GetNext(&fn));
|
||||
|
||||
for (auto& file : files_map | boost::adaptors::map_values)
|
||||
files.emplace_back(std::move(file));
|
||||
|
||||
for (auto& file : files) {
|
||||
sort(begin(file.versions), end(file.versions),
|
||||
[](Version const& a, Version const& b) { return a.date > b.date; });
|
||||
}
|
||||
|
||||
sort(begin(files), end(files),
|
||||
[](AutosaveFile const& a, AutosaveFile const& b) { return a.versions[0].date > b.versions[0].date; });
|
||||
|
||||
for (auto const& file : files)
|
||||
file_list->Append(file.name);
|
||||
file_list->SetSelection(0);
|
||||
|
||||
wxCommandEvent evt;
|
||||
OnSelectFile(evt);
|
||||
}
|
||||
|
||||
void DialogAutosave::OnSelectFile(wxCommandEvent&) {
|
||||
version_list->Clear();
|
||||
int sel_file = file_list->GetSelection();
|
||||
if (sel_file < 0) return;
|
||||
|
||||
for (auto const& version : files[sel_file].versions)
|
||||
version_list->Append(version.date.Format());
|
||||
version_list->SetSelection(0);
|
||||
}
|
||||
|
||||
wxString DialogAutosave::ChosenFile() const {
|
||||
int sel_file = file_list->GetSelection();
|
||||
if (sel_file < 0) return "";
|
||||
|
||||
int sel_version = version_list->GetSelection();
|
||||
if (sel_version < 0) return "";
|
||||
|
||||
return wxFileName(directory, files[sel_file].versions[sel_version].filename).GetFullPath();
|
||||
}
|
53
aegisub/src/dialog_autosave.h
Normal file
53
aegisub/src/dialog_autosave.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
// Copyright (c) 2012, 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/
|
||||
|
||||
#ifndef AGI_PRE
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include <wx/dialog.h>
|
||||
#include <wx/string.h>
|
||||
#endif
|
||||
|
||||
class wxListBox;
|
||||
|
||||
class DialogAutosave : public wxDialog {
|
||||
struct Version {
|
||||
wxString filename;
|
||||
wxDateTime date;
|
||||
Version(wxString const& filename, wxDateTime const& date)
|
||||
: filename(filename), date(date) { }
|
||||
};
|
||||
|
||||
struct AutosaveFile {
|
||||
wxString name;
|
||||
std::vector<Version> versions;
|
||||
AutosaveFile(wxString const& name) : name(name) { }
|
||||
};
|
||||
|
||||
wxString directory;
|
||||
std::vector<AutosaveFile> files;
|
||||
|
||||
wxListBox *file_list;
|
||||
wxListBox *version_list;
|
||||
|
||||
void Populate();
|
||||
void OnSelectFile(wxCommandEvent&);
|
||||
|
||||
public:
|
||||
DialogAutosave(wxWindow *parent);
|
||||
wxString ChosenFile() const;
|
||||
};
|
|
@ -42,6 +42,7 @@
|
|||
{ "command" : "subtitle/open" },
|
||||
{ "command" : "subtitle/open/charset" },
|
||||
{ "command" : "subtitle/open/video" },
|
||||
{ "command" : "subtitle/open/autosave" },
|
||||
{ "command" : "subtitle/save" },
|
||||
{ "command" : "subtitle/save/as" },
|
||||
{ "command" : "tool/export" },
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
{ "command" : "subtitle/open" },
|
||||
{ "command" : "subtitle/open/charset" },
|
||||
{ "command" : "subtitle/open/video" },
|
||||
{ "command" : "subtitle/open/autosave" },
|
||||
{ "recent" : "Subtitle" },
|
||||
{ "command" : "subtitle/save" },
|
||||
{ "command" : "subtitle/save/as" },
|
||||
|
|
Loading…
Reference in a new issue