diff --git a/src/mmg/mmg.cpp b/src/mmg/mmg.cpp index 44a8f87cf..e4f99901e 100644 --- a/src/mmg/mmg.cpp +++ b/src/mmg/mmg.cpp @@ -42,6 +42,7 @@ mmg_dialog *mdlg; wxString last_open_dir; wxString mkvmerge_path; vector last_settings; +vector last_chapters; vector files; wxString &break_line(wxString &line, int break_after) { @@ -153,7 +154,7 @@ mmg_dialog::mmg_dialog(): wxFrame(NULL, -1, "mkvmerge GUI v" VERSION, _T("Sa&ve command line\tCtrl-V"), _T("Save the command line to a file")); - wxMenu *chapter_menu = new wxMenu(); + chapter_menu = new wxMenu(); chapter_menu->Append(ID_M_CHAPTERS_NEW, _T("&New"), _T("Create a new chapter file")); chapter_menu->Append(ID_M_CHAPTERS_LOAD, _T("&Load"), @@ -168,6 +169,8 @@ mmg_dialog::mmg_dialog(): wxFrame(NULL, -1, "mkvmerge GUI v" VERSION, chapter_menu->Append(ID_M_CHAPTERS_VERIFY, _T("&Verify"), _T("Verify the current chapter entries to see if there " "are any errors")); + chapter_menu_sep = false; + update_chapter_menu(); wxMenu *help_menu = new wxMenu(); help_menu->Append(ID_M_HELP_ABOUT, _T("&About\tF1"), @@ -388,6 +391,36 @@ void mmg_dialog::set_last_settings_in_menu(wxString name) { update_file_menu(); } +void mmg_dialog::set_last_chapters_in_menu(wxString name) { + uint32_t i; + vector::iterator eit; + wxConfigBase *cfg; + wxString s; + + i = 0; + while (i < last_chapters.size()) { + if (last_chapters[i] == name) { + eit = last_chapters.begin(); + eit += i; + last_chapters.erase(eit); + } else + i++; + } + last_chapters.insert(last_chapters.begin(), name); + while (last_chapters.size() > 4) + last_chapters.pop_back(); + + cfg = wxConfigBase::Get(); + cfg->SetPath("/GUI"); + for (i = 0; i < last_chapters.size(); i++) { + s.Printf("last_chapters %d", i); + cfg->Write(s, last_chapters[i]); + } + cfg->Flush(); + + update_chapter_menu(); +} + void mmg_dialog::on_run(wxCommandEvent &evt) { mux_dialog *mdlg; @@ -758,6 +791,16 @@ void mmg_dialog::on_file_load_last(wxCommandEvent &evt) { load(last_settings[evt.GetId() - ID_M_FILE_LOADLAST1]); } +void mmg_dialog::on_chapters_load_last(wxCommandEvent &evt) { + if ((evt.GetId() < ID_M_CHAPTERS_LOADLAST1) || + ((evt.GetId() - ID_M_CHAPTERS_LOADLAST1) >= last_chapters.size())) + return; + + notebook->SetSelection(4); + chapter_editor_page->load(last_chapters[evt.GetId() - + ID_M_CHAPTERS_LOADLAST1]); +} + void mmg_dialog::update_file_menu() { uint32_t i; wxMenuItem *mi; @@ -779,6 +822,27 @@ void mmg_dialog::update_file_menu() { } } +void mmg_dialog::update_chapter_menu() { + uint32_t i; + wxMenuItem *mi; + wxString s; + + for (i = ID_M_CHAPTERS_LOADLAST1; i <= ID_M_CHAPTERS_LOADLAST4; i++) { + mi = chapter_menu->Remove(i); + if (mi != NULL) + delete mi; + } + + if ((last_chapters.size() > 0) && !chapter_menu_sep) { + chapter_menu->AppendSeparator(); + chapter_menu_sep = true; + } + for (i = 0; i < last_chapters.size(); i++) { + s.Printf("&%u. %s", i + 1, last_chapters[i].c_str()); + chapter_menu->Append(ID_M_CHAPTERS_LOADLAST1 + i, s); + } +} + void mmg_dialog::on_new_chapters(wxCommandEvent &evt) { notebook->SetSelection(4); chapter_editor_page->on_new_chapters(evt); @@ -825,6 +889,10 @@ BEGIN_EVENT_TABLE(mmg_dialog, wxFrame) EVT_MENU(ID_M_CHAPTERS_SAVE, mmg_dialog::on_save_chapters) EVT_MENU(ID_M_CHAPTERS_SAVEAS, mmg_dialog::on_save_chapters_as) EVT_MENU(ID_M_CHAPTERS_VERIFY, mmg_dialog::on_verify_chapters) + EVT_MENU(ID_M_CHAPTERS_LOADLAST1, mmg_dialog::on_chapters_load_last) + EVT_MENU(ID_M_CHAPTERS_LOADLAST2, mmg_dialog::on_chapters_load_last) + EVT_MENU(ID_M_CHAPTERS_LOADLAST3, mmg_dialog::on_chapters_load_last) + EVT_MENU(ID_M_CHAPTERS_LOADLAST4, mmg_dialog::on_chapters_load_last) END_EVENT_TABLE(); bool mmg_app::OnInit() { @@ -841,6 +909,9 @@ bool mmg_app::OnInit() { k.Printf("last_settings %u", i); if (cfg->Read(k, &v)) last_settings.push_back(v); + k.Printf("last_chapters %u", i); + if (cfg->Read(k, &v)) + last_chapters.push_back(v); } app = this; diff --git a/src/mmg/mmg.h b/src/mmg/mmg.h index a92d6c881..6f6de887e 100644 --- a/src/mmg/mmg.h +++ b/src/mmg/mmg.h @@ -132,6 +132,11 @@ using namespace libmatroska; #define ID_M_CHAPTERS_SAVE 20202 #define ID_M_CHAPTERS_SAVEAS 20203 #define ID_M_CHAPTERS_VERIFY 20204 +#define ID_M_CHAPTERS_LOADSEPARATOR 20290 +#define ID_M_CHAPTERS_LOADLAST1 20291 +#define ID_M_CHAPTERS_LOADLAST2 20292 +#define ID_M_CHAPTERS_LOADLAST3 20293 +#define ID_M_CHAPTERS_LOADLAST4 20294 #define ID_M_HELP_ABOUT 29900 @@ -160,6 +165,7 @@ typedef struct { extern wxString last_open_dir; extern wxString mkvmerge_path; extern vector last_settings; +extern vector last_chapters; extern vector files; extern vector attachments; extern wxArrayString sorted_charsets; @@ -336,6 +342,7 @@ public: wxString create_chapter_label(KaxChapterAtom &chapter); void enable_inputs(bool enable); bool select_file_name(); + bool load(wxString name); void save(); }; @@ -387,8 +394,8 @@ protected: wxStatusBar *status_bar; wxNotebook *notebook; - wxMenu *file_menu; - bool file_menu_sep; + wxMenu *file_menu, *chapter_menu; + bool file_menu_sep, chapter_menu_sep; tab_input *input_page; tab_attachments *attachments_page; @@ -424,6 +431,10 @@ public: void on_file_load_last(wxCommandEvent &evt); void update_file_menu(); + void set_last_chapters_in_menu(wxString name); + void on_chapters_load_last(wxCommandEvent &evt); + void update_chapter_menu(); + void on_new_chapters(wxCommandEvent &evt); void on_load_chapters(wxCommandEvent &evt); void on_save_chapters(wxCommandEvent &evt); diff --git a/src/mmg/tab_chapters.cpp b/src/mmg/tab_chapters.cpp index 811dad681..1051501ae 100644 --- a/src/mmg/tab_chapters.cpp +++ b/src/mmg/tab_chapters.cpp @@ -270,46 +270,52 @@ void tab_chapters::add_recursively(wxTreeItemId &parent, EbmlMaster &master) { } void tab_chapters::on_load_chapters(wxCommandEvent &evt) { - KaxChapters *new_chapters; - wxString s; wxFileDialog dlg(NULL, "Choose a chapter file", last_open_dir, "", _T("Chapter files (*.xml;*.txt)|*.xml;*.txt|" ALLFILES), wxOPEN); - if(dlg.ShowModal() == wxID_OK) { - last_open_dir = dlg.GetDirectory(); - try { - new_chapters = parse_chapters(dlg.GetPath().c_str(), 0, -1, 0, NULL, - NULL, true); - } catch (error_c e) { - s = (const char *)e; - break_line(s); - while (s[s.Length() - 1] == '\n') - s.Remove(s.Length() - 1); - wxMessageBox(s, _T("Error parsing the chapter file"), - wxOK | wxCENTER | wxICON_ERROR); - return; - } + if (dlg.ShowModal() == wxID_OK) + if (load(dlg.GetPath())) + last_open_dir = dlg.GetDirectory(); +} - if (chapters != NULL) - delete chapters; - tc_chapters->DeleteAllItems(); - chapters = new_chapters; - m_chapters->Enable(ID_M_CHAPTERS_SAVE, true); - m_chapters->Enable(ID_M_CHAPTERS_SAVEAS, true); - m_chapters->Enable(ID_M_CHAPTERS_VERIFY, true); - b_add_chapter->Enable(true); - b_remove_chapter->Enable(true); +bool tab_chapters::load(wxString name) { + KaxChapters *new_chapters; + wxString s; - file_name = dlg.GetPath(); - tid_root = tc_chapters->AddRoot(file_name); - add_recursively(tid_root, *chapters); - expand_subtree(*tc_chapters, tid_root); - - enable_inputs(false); - - mdlg->set_status_bar("Chapters loaded."); + try { + new_chapters = parse_chapters(name.c_str(), 0, -1, 0, NULL, NULL, true); + } catch (error_c e) { + s = (const char *)e; + break_line(s); + while (s[s.Length() - 1] == '\n') + s.Remove(s.Length() - 1); + wxMessageBox(s, _T("Error parsing the chapter file"), + wxOK | wxCENTER | wxICON_ERROR); + return false; } + + if (chapters != NULL) + delete chapters; + tc_chapters->DeleteAllItems(); + chapters = new_chapters; + m_chapters->Enable(ID_M_CHAPTERS_SAVE, true); + m_chapters->Enable(ID_M_CHAPTERS_SAVEAS, true); + m_chapters->Enable(ID_M_CHAPTERS_VERIFY, true); + b_add_chapter->Enable(true); + b_remove_chapter->Enable(true); + + file_name = name; + tid_root = tc_chapters->AddRoot(file_name); + add_recursively(tid_root, *chapters); + expand_subtree(*tc_chapters, tid_root); + + enable_inputs(false); + + mdlg->set_last_chapters_in_menu(name); + mdlg->set_status_bar("Chapters loaded."); + + return true; } void tab_chapters::on_save_chapters(wxCommandEvent &evt) { @@ -362,6 +368,7 @@ void tab_chapters::save() { fprintf(fout, "\n"); fclose(fout); + mdlg->set_last_chapters_in_menu(file_name); mdlg->set_status_bar(_("Chapters written.")); }