diff --git a/src/gui/editor.cpp b/src/gui/editor.cpp index 160af435..d778002d 100644 --- a/src/gui/editor.cpp +++ b/src/gui/editor.cpp @@ -106,7 +106,6 @@ void CommonEditor::ApplyEdits(const wxString& plugin, wxListView * wxList) { } } - boss::File CommonEditor::RowToFile(wxListView * list, long row) const { return boss::File( string(list->GetItemText(row, 0).ToUTF8()), @@ -150,18 +149,21 @@ boss::PluginDirtyInfo CommonEditor::RowToPluginDirtyInfo(wxListView * list, long MiniEditor::MiniEditor(wxWindow *parent, const wxString& title, const std::list& plugins, const boss::Game& game) : wxDialog(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER), CommonEditor(plugins, game) { + //Initialise editing panel. + editingPanel = new wxPanel(this, wxID_ANY); + //Initialise controls. - pluginText = new wxStaticText(this, wxID_ANY, ""); - prioritySpin = new wxSpinCtrl(this, wxID_ANY, "0"); + pluginText = new wxStaticText(editingPanel, wxID_ANY, ""); + prioritySpin = new wxSpinCtrl(editingPanel, wxID_ANY, "0"); prioritySpin->SetRange(std::numeric_limits::min(), std::numeric_limits::max()); - filterCheckbox = new wxCheckBox(this, wxID_ANY, translate("Show only conflicting plugins.")); + filterCheckbox = new wxCheckBox(editingPanel, wxID_ANY, translate("Show only conflicting plugins.")); pluginList = new wxListView(this, LIST_Plugins, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL); - loadAfterList = new wxListView(this, LIST_LoadAfter, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL); + loadAfterList = new wxListView(editingPanel, LIST_LoadAfter, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL); loadAfterList->SetDropTarget(new TextDropTarget(loadAfterList)); - addBtn = new wxToggleButton(this, BUTTON_AddRow, translate("Add Plugin(s)...")); - removeBtn = new wxButton(this, BUTTON_RemoveRow, translate("Remove Plugin")); + addBtn = new wxToggleButton(editingPanel, BUTTON_AddRow, translate("Add Plugin(s)...")); + removeBtn = new wxButton(editingPanel, BUTTON_RemoveRow, translate("Remove Plugin")); //Set up list columns. pluginList->AppendColumn(translate("Plugin")); @@ -191,24 +193,17 @@ MiniEditor::MiniEditor(wxWindow *parent, const wxString& title, const std::list< Bind(wxEVT_CHECKBOX, &MiniEditor::OnFilterToggle, this); Bind(wxEVT_BUTTON, &MiniEditor::OnApply, this, wxID_APPLY); - //Set up layout. - wxBoxSizer * bigBox = new wxBoxSizer(wxVERTICAL); - - wxBoxSizer * hBox = new wxBoxSizer(wxHORIZONTAL); - - hBox->Add(pluginList, 0, wxEXPAND | wxALL, 10); - + //Set up editing panel layout. wxBoxSizer * mainBox = new wxBoxSizer(wxVERTICAL); - mainBox->Add(pluginText, 0, wxTOP | wxBOTTOM, 10); mainBox->Add(filterCheckbox, 0, wxTOP | wxBOTTOM, 10); wxBoxSizer * hbox2 = new wxBoxSizer(wxHORIZONTAL); - hbox2->Add(new wxStaticText(this, wxID_ANY, translate("Priority: ")), 0, wxALIGN_RIGHT | wxLEFT | wxRIGHT, 5); + hbox2->Add(new wxStaticText(editingPanel, wxID_ANY, translate("Priority: ")), 0, wxALIGN_RIGHT | wxLEFT | wxRIGHT, 5); hbox2->Add(prioritySpin, 0, wxALIGN_RIGHT); mainBox->Add(hbox2, 0, wxEXPAND | wxALIGN_RIGHT | wxBOTTOM, 10); - wxStaticBoxSizer * staticBox = new wxStaticBoxSizer(wxVERTICAL, this, translate("Load After")); + wxStaticBoxSizer * staticBox = new wxStaticBoxSizer(wxVERTICAL, editingPanel, translate("Load After")); staticBox->Add(loadAfterList, 1, wxEXPAND); wxBoxSizer * hbox3 = new wxBoxSizer(wxHORIZONTAL); hbox3->Add(addBtn, 0, wxRIGHT, 10); @@ -216,9 +211,19 @@ MiniEditor::MiniEditor(wxWindow *parent, const wxString& title, const std::list< staticBox->Add(hbox3, 0, wxEXPAND | wxALIGN_RIGHT | wxTOP, 10); mainBox->Add(staticBox, 1, wxEXPAND); - hBox->Add(mainBox, 1, wxEXPAND | wxTOP | wxBOTTOM | wxRIGHT, 10); + editingPanel->SetSizerAndFit(mainBox); + editingPanel->Layout(); + + //Set up rest of layout. + wxBoxSizer * bigBox = new wxBoxSizer(wxVERTICAL); + + wxBoxSizer * hBox = new wxBoxSizer(wxHORIZONTAL); + hBox->Add(pluginList, 0, wxEXPAND | wxALL, 10); + hBox->Add(editingPanel, 1, wxEXPAND | wxTOP | wxBOTTOM | wxRIGHT, 10); bigBox->Add(hBox, 1, wxEXPAND | wxALL, 5); + bigBox->Add(new wxStaticText(this, wxID_ANY, translate("Do you want to set the load order given above?"))); + //Need to add 'Yes' and 'No' buttons. wxSizer * sizer = CreateSeparatedButtonSizer(wxAPPLY | wxCANCEL); @@ -240,19 +245,30 @@ MiniEditor::MiniEditor(wxWindow *parent, const wxString& title, const std::list< ++i; } pluginList->SetColumnWidth(0, wxLIST_AUTOSIZE); + pluginList->SetColumnWidth(1, 0); SetBackgroundColour(wxColour(255, 255, 255)); SetIcon(wxIconLocation("BOSS.exe")); + editingPanel->Hide(); SetSizerAndFit(bigBox); Layout(); } void MiniEditor::OnPluginSelect(wxListEvent& event) { + //Change layout. + pluginList->SetColumnWidth(1, wxLIST_AUTOSIZE_USEHEADER); + pluginList->InvalidateBestSize(); + if (!editingPanel->IsShown()) + editingPanel->Show(); + Refresh(); + //Create Plugin object for selected plugin. wxString selectedPlugin = pluginList->GetItemText(event.GetIndex()); wxString currentPlugin = pluginText->GetLabelText(); + //lastSelected = pluginText->GetLabelText(); + //Check if the selected plugin is the same as the current plugin. if (selectedPlugin != currentPlugin) { BOOST_LOG_TRIVIAL(debug) << "User selected plugin: " << selectedPlugin.ToUTF8(); @@ -292,6 +308,9 @@ void MiniEditor::OnPluginSelect(wxListEvent& event) { addBtn->Enable(true); removeBtn->Enable(false); } + editingPanel->InvalidateBestSize(); + editingPanel->Fit(); + editingPanel->SetMinSize(editingPanel->GetSize()); Fit(); } @@ -395,6 +414,9 @@ void MiniEditor::OnRemoveRow(wxCommandEvent& event) { } void MiniEditor::OnDragStart(wxListEvent& event) { + // if (!lastSelected.empty()) + // pluginList->Select(pluginList->FindItem(-1, lastSelected)); + wxTextDataObject data(pluginList->GetItemText(event.GetItem())); wxDropSource dropSource(pluginList); dropSource.SetData(data); diff --git a/src/gui/editor.h b/src/gui/editor.h index f3af5f01..a05bcc7c 100644 --- a/src/gui/editor.h +++ b/src/gui/editor.h @@ -94,6 +94,7 @@ public: const std::list& GetEditedPlugins() const; private: wxListView * pluginList; + wxPanel * editingPanel; wxToggleButton * addBtn; wxButton * removeBtn; wxListView * loadAfterList; @@ -101,6 +102,8 @@ private: wxSpinCtrl * prioritySpin; wxStaticText * pluginText; + wxString lastSelected; + boss::Plugin GetNewData(const wxString& plugin) const; }; diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 4dc2b066..58091932 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -801,77 +801,67 @@ void Launcher::OnSortPlugins(wxCommandEvent& event) { progDia = NULL; BOOST_LOG_TRIVIAL(debug) << "Displaying load order preview."; - LoadOrderPreview preview(this, translate("BOSS: Calculated Load Order"), plugins, _game); + MiniEditor editor(this, translate("BOSS: Calculated Load Order"), plugins, _game); - long ret = preview.ShowModal(); + long ret = editor.ShowModal(); + const std::list edits = editor.GetEditedPlugins(); - applyLoadOrder = ret == wxID_NO; - if (ret != wxID_YES) + if (ret != wxID_APPLY) { + applyLoadOrder = false; break; + } + else if (edits.empty()) { + applyLoadOrder = true; + break; + } else { - //User wants to make changes. Need to display editor and loop around again. + //Recreate progress dialog. + progDia = new wxProgressDialog(translate("BOSS: Working..."), translate("BOSS working..."), 1000, this, wxPD_APP_MODAL | wxPD_AUTO_HIDE | wxPD_ELAPSED_TIME); - MiniEditor editor(this, translate("BOSS: Mini Editor"), plugins, _game); + //User accepted edits, now apply them, then loop. + //Apply edits to the graph vertices. + boss::vertex_it vit, vitend; + for (boost::tie(vit, vitend) = boost::vertices(graph); vit != vitend; ++vit) { + std::list::const_iterator pos = std::find(edits.begin(), edits.end(), graph[*vit]); - ret = editor.ShowModal(); - const std::list edits = editor.GetEditedPlugins(); - - if (ret != wxID_APPLY) - break; - else if (edits.empty()) { - //No edits were actually made, so just go straight to applying the load order. - applyLoadOrder = true; - break; + if (pos != edits.end()) { + BOOST_LOG_TRIVIAL(trace) << "Merging edits down to plugin list data."; + graph[*vit].MergeMetadata(*pos); + } } - else { - //Recreate progress dialog. - progDia = new wxProgressDialog(translate("BOSS: Working..."), translate("BOSS working..."), 1000, this, wxPD_APP_MODAL | wxPD_AUTO_HIDE | wxPD_ELAPSED_TIME); - //User accepted edits, now apply them, then loop. - //Apply edits to the graph vertices. - boss::vertex_it vit, vitend; - for (boost::tie(vit, vitend) = boost::vertices(graph); vit != vitend; ++vit) { - std::list::const_iterator pos = std::find(edits.begin(), edits.end(), graph[*vit]); - - if (pos != edits.end()) { - BOOST_LOG_TRIVIAL(trace) << "Merging edits down to plugin list data."; - graph[*vit].MergeMetadata(*pos); - } - } - - //Clear all existing edges from the graph. - std::pair edge_range = boost::edges(graph); - for (edge_it it = edge_range.first; it != edge_range.second; ++it) { - boost::remove_edge(*it, graph); - } - - //Merge edits down to the userlist entries. - BOOST_LOG_TRIVIAL(trace) << "Merging down edits to the userlist."; - for (list::const_iterator it = edits.begin(), endit = edits.end(); it != endit; ++it) { - list::iterator jt = find(ulist_plugins.begin(), ulist_plugins.end(), *it); - - if (jt != ulist_plugins.end()) { - jt->MergeMetadata(*it); - } - else { - ulist_plugins.push_back(*it); - } - } - - //Save edits to userlist. - BOOST_LOG_TRIVIAL(debug) << "Saving edited userlist."; - YAML::Emitter yout; - yout.SetIndent(2); - yout << YAML::BeginMap - << YAML::Key << "plugins" << YAML::Value << ulist_plugins - << YAML::EndMap; - - boss::ofstream uout(_game.UserlistPath()); - uout << yout.c_str(); - uout.close(); - - //Now loop. + //Clear all existing edges from the graph. + std::pair edge_range = boost::edges(graph); + for (edge_it it = edge_range.first; it != edge_range.second; ++it) { + boost::remove_edge(*it, graph); } + + //Merge edits down to the userlist entries. + BOOST_LOG_TRIVIAL(trace) << "Merging down edits to the userlist."; + for (list::const_iterator it = edits.begin(), endit = edits.end(); it != endit; ++it) { + list::iterator jt = find(ulist_plugins.begin(), ulist_plugins.end(), *it); + + if (jt != ulist_plugins.end()) { + jt->MergeMetadata(*it); + } + else { + ulist_plugins.push_back(*it); + } + } + + //Save edits to userlist. + BOOST_LOG_TRIVIAL(debug) << "Saving edited userlist."; + YAML::Emitter yout; + yout.SetIndent(2); + yout << YAML::BeginMap + << YAML::Key << "plugins" << YAML::Value << ulist_plugins + << YAML::EndMap; + + boss::ofstream uout(_game.UserlistPath()); + uout << yout.c_str(); + uout.close(); + + //Now loop. } } while (true); diff --git a/src/gui/misc.cpp b/src/gui/misc.cpp index ee8af661..850a0725 100644 --- a/src/gui/misc.cpp +++ b/src/gui/misc.cpp @@ -477,51 +477,4 @@ unsigned int DirtInfoEditDialog::GetDeletedNavmeshes() const { wxString DirtInfoEditDialog::GetUtility() const { return _utility->GetValue(); -} - -LoadOrderPreview::LoadOrderPreview(wxWindow *parent, const wxString title, const std::list& plugins, const boss::Game& game) : wxDialog(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) { - - //Init controls. - _loadOrder = new wxListView(this, LIST_LoadOrder, wxDefaultPosition, wxDefaultSize, wxLC_REPORT); - - //Populate list. - _loadOrder->AppendColumn(translate("Load Order")); - size_t i = 0; - for (list::const_iterator it = plugins.begin(), endit = plugins.end(); it != endit; ++it, ++i) { - _loadOrder->InsertItem(i, FromUTF8(it->Name())); - if (it->FormIDs().empty()) { - _loadOrder->SetItemTextColour(i, wxColour(122, 122, 122)); - } - else if (it->LoadsBSA(game)) { - _loadOrder->SetItemTextColour(i, wxColour(0, 142, 219)); - } - } - _loadOrder->SetColumnWidth(0, wxLIST_AUTOSIZE); - - //Set up event handling. - Bind(wxEVT_BUTTON, &LoadOrderPreview::OnYesNo, this, wxID_YES); - Bind(wxEVT_BUTTON, &LoadOrderPreview::OnYesNo, this, wxID_NO); - - //Set up layout. - wxBoxSizer * bigBox = new wxBoxSizer(wxVERTICAL); - - bigBox->Add(_loadOrder, 1, wxEXPAND | wxALL, 15); - - bigBox->Add(new wxStaticText(this, wxID_ANY, translate("Do you wish to make any changes to the load order above?")), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 15); - - //Need to add 'Yes' and 'No' buttons. - wxSizer * sizer = CreateSeparatedButtonSizer(wxYES | wxNO | wxCANCEL); - - //Now add buttons to window sizer. - if (sizer != NULL) - bigBox->Add(sizer, 0, wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT, 15); - - //Now set the layout and sizes. - SetBackgroundColour(wxColour(255, 255, 255)); - SetIcon(wxIconLocation("BOSS.exe")); - SetSizerAndFit(bigBox); -} - -void LoadOrderPreview::OnYesNo(wxCommandEvent& event) { - EndModal(event.GetId()); } \ No newline at end of file diff --git a/src/gui/misc.h b/src/gui/misc.h index 2b5ff4e8..ad537d24 100644 --- a/src/gui/misc.h +++ b/src/gui/misc.h @@ -129,13 +129,4 @@ private: wxSpinCtrl * _nav; wxTextCtrl * _utility; }; - -class LoadOrderPreview : public wxDialog { -public: - LoadOrderPreview(wxWindow *parent, const wxString title, const std::list& plugins, const boss::Game& game); - - void OnYesNo(wxCommandEvent& event); -private: - wxListView * _loadOrder; -}; #endif \ No newline at end of file