| 1 |
#include "DapDebuggerSettingsDlg.h" |
| 2 |
|
| 3 |
#include "DapLocator.hpp" |
| 4 |
#include "DapSettingsPage.hpp" |
| 5 |
#include "bitmap_loader.h" |
| 6 |
#include "globals.h" |
| 7 |
#include "imanager.h" |
| 8 |
#include "windowattrmanager.h" |
| 9 |
|
| 10 |
#include <wx/msgdlg.h> |
| 11 |
|
| 12 |
DapDebuggerSettingsDlg::DapDebuggerSettingsDlg(wxWindow* parent, clDapSettingsStore& store) |
| 13 |
: DapDebuggerSettingsDlgBase(parent) |
| 14 |
, m_store(store) |
| 15 |
{ |
| 16 |
auto image_list = new clBitmapList; |
| 17 |
|
| 18 |
m_toolbar->AddTool(wxID_NEW, _("New"), image_list->Add("file_new")); |
| 19 |
m_toolbar->AddTool(wxID_DELETE, _("Delete"), image_list->Add("clean")); |
| 20 |
m_toolbar->AddSeparator(); |
| 21 |
m_toolbar->AddTool(wxID_FIND, _("Scan"), image_list->Add("find")); |
| 22 |
m_toolbar->AddTool(wxID_HELP, _("Help"), image_list->Add("help")); |
| 23 |
m_toolbar->AssignBitmaps(image_list); |
| 24 |
|
| 25 |
m_toolbar->Realize(); |
| 26 |
|
| 27 |
m_toolbar->Bind(wxEVT_TOOL, &DapDebuggerSettingsDlg::OnNew, this, wxID_NEW); |
| 28 |
m_toolbar->Bind(wxEVT_TOOL, &DapDebuggerSettingsDlg::OnScan, this, wxID_FIND); |
| 29 |
m_toolbar->Bind(wxEVT_TOOL, &DapDebuggerSettingsDlg::OnDelete, this, wxID_DELETE); |
| 30 |
m_toolbar->Bind(wxEVT_TOOL, &DapDebuggerSettingsDlg::OnOpenHelpDocs, this, wxID_HELP); |
| 31 |
m_toolbar->Bind(wxEVT_UPDATE_UI, &DapDebuggerSettingsDlg::OnItemsUI, this, wxID_DELETE); |
| 32 |
|
| 33 |
Initialise(); |
| 34 |
|
| 35 |
::clSetDialogSizeAndPosition(this, 0.25); |
| 36 |
WindowAttrManager::Load(this); |
| 37 |
} |
| 38 |
|
| 39 |
DapDebuggerSettingsDlg::~DapDebuggerSettingsDlg() {} |
| 40 |
|
| 41 |
void DapDebuggerSettingsDlg::Initialise() |
| 42 |
{ |
| 43 |
m_notebook->DeleteAllPages(); |
| 44 |
const auto& entries = m_store.GetEntries(); |
| 45 |
for(const auto& vt : entries) { |
| 46 |
m_notebook->AddPage(new DapSettingsPage(m_notebook, m_store, vt.second), vt.first); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
void DapDebuggerSettingsDlg::OnItemsUI(wxUpdateUIEvent& event) { event.Enable(m_notebook->GetPageCount() > 0); } |
| 51 |
|
| 52 |
void DapDebuggerSettingsDlg::OnOpenHelpDocs(wxCommandEvent& event) |
| 53 |
{ |
| 54 |
wxUnusedVar(event); |
| 55 |
::wxLaunchDefaultBrowser("https://docs.codelite.org/plugins/dap"); |
| 56 |
} |
| 57 |
|
| 58 |
void DapDebuggerSettingsDlg::OnDelete(wxCommandEvent& event) |
| 59 |
{ |
| 60 |
wxUnusedVar(event); |
| 61 |
int sel = m_notebook->GetSelection(); |
| 62 |
if(sel == wxNOT_FOUND) { |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
wxString name = m_notebook->GetPageText(sel); |
| 67 |
if(::wxMessageBox(_("Delete '") + name + "'", "CodeLite", wxYES_NO | wxCANCEL | wxCANCEL_DEFAULT | wxICON_WARNING, |
| 68 |
this) != wxYES) { |
| 69 |
return; |
| 70 |
} |
| 71 |
|
| 72 |
m_notebook->DeletePage(sel); |
| 73 |
m_store.Delete(name); |
| 74 |
} |
| 75 |
|
| 76 |
void DapDebuggerSettingsDlg::OnScan(wxCommandEvent& event) |
| 77 |
{ |
| 78 |
if(::wxMessageBox(_("Are you sure you want to scan for dap servers? (this will override your current settings)"), |
| 79 |
"CodeLite", wxYES_NO | wxCANCEL | wxCANCEL_DEFAULT | wxICON_WARNING) != wxYES) { |
| 80 |
return; |
| 81 |
} |
| 82 |
|
| 83 |
wxBusyCursor bc; |
| 84 |
wxUnusedVar(event); |
| 85 |
DapLocator locator; |
| 86 |
std::vector<DapEntry> entries; |
| 87 |
if(locator.Locate(&entries) == 0) { |
| 88 |
return; |
| 89 |
} |
| 90 |
m_store.Clear(); |
| 91 |
for(const auto& entry : entries) { |
| 92 |
m_store.Set(entry); |
| 93 |
} |
| 94 |
Initialise(); |
| 95 |
} |
| 96 |
|
| 97 |
void DapDebuggerSettingsDlg::OnNew(wxCommandEvent& event) |
| 98 |
{ |
| 99 |
wxUnusedVar(event); |
| 100 |
// FIXME |
| 101 |
wxString name = clGetTextFromUser(_("Enter name"), _("New dap server name"), "", wxNOT_FOUND, this); |
| 102 |
if(name.empty()) { |
| 103 |
return; |
| 104 |
} |
| 105 |
|
| 106 |
DapEntry new_entry; |
| 107 |
new_entry.SetName(name); |
| 108 |
m_store.Set(new_entry); |
| 109 |
|
| 110 |
m_notebook->AddPage(new DapSettingsPage(m_notebook, m_store, new_entry), new_entry.GetName(), true); |
| 111 |
} |