| 1 |
////////////////////////////////////////////////////////////////////////////// |
| 2 |
////////////////////////////////////////////////////////////////////////////// |
| 3 |
// |
| 4 |
// copyright : (C) 2008 by Eran Ifrah |
| 5 |
// file name : codeformatterdlg.cpp |
| 6 |
// |
| 7 |
// ------------------------------------------------------------------------- |
| 8 |
// A |
| 9 |
// _____ _ _ _ _ |
| 10 |
// / __ \ | | | | (_) | |
| 11 |
// | / \/ ___ __| | ___| | _| |_ ___ |
| 12 |
// | | / _ \ / _ |/ _ \ | | | __/ _ ) |
| 13 |
// | \__/\ (_) | (_| | __/ |___| | || __/ |
| 14 |
// \____/\___/ \__,_|\___\_____/_|\__\___| |
| 15 |
// |
| 16 |
// F i l e |
| 17 |
// |
| 18 |
// This program is free software; you can redistribute it and/or modify |
| 19 |
// it under the terms of the GNU General Public License as published by |
| 20 |
// the Free Software Foundation; either version 2 of the License, or |
| 21 |
// (at your option) any later version. |
| 22 |
// |
| 23 |
////////////////////////////////////////////////////////////////////////////// |
| 24 |
////////////////////////////////////////////////////////////////////////////// |
| 25 |
#include "codeformatterdlg.h" |
| 26 |
|
| 27 |
#include "ColoursAndFontsManager.h" |
| 28 |
#include "StringUtils.h" |
| 29 |
#include "clSTCLineKeeper.h" |
| 30 |
#include "codeformatter.h" |
| 31 |
#include "editor_config.h" |
| 32 |
#include "fileextmanager.h" |
| 33 |
#include "globals.h" |
| 34 |
#include "lexer_configuration.h" |
| 35 |
#include "windowattrmanager.h" |
| 36 |
|
| 37 |
#include <wx/menu.h> |
| 38 |
#include <wx/msgdlg.h> |
| 39 |
#include <wx/tokenzr.h> |
| 40 |
|
| 41 |
CodeFormatterDlg::CodeFormatterDlg(wxWindow* parent, CodeFormatterManager& mgr) |
| 42 |
: CodeFormatterBaseDlg(parent) |
| 43 |
, m_formatter_manager(mgr) |
| 44 |
{ |
| 45 |
m_dvListCtrl->Bind(wxEVT_DATAVIEW_SELECTION_CHANGING, &CodeFormatterDlg::OnSelectionChanging, this); |
| 46 |
m_page = new FormatterPage(m_mainPanel); |
| 47 |
boxSizerFormatter->Add(m_page, wxSizerFlags(1).Expand().Border(wxALL, 5)); |
| 48 |
|
| 49 |
InitDialog(); |
| 50 |
::clSetDialogBestSizeAndPosition(this); |
| 51 |
} |
| 52 |
|
| 53 |
CodeFormatterDlg::~CodeFormatterDlg() |
| 54 |
{ |
| 55 |
m_dvListCtrl->Unbind(wxEVT_DATAVIEW_SELECTION_CHANGING, &CodeFormatterDlg::OnSelectionChanging, this); |
| 56 |
} |
| 57 |
|
| 58 |
void CodeFormatterDlg::InitDialog() |
| 59 |
{ |
| 60 |
wxArrayString all_formatters; |
| 61 |
m_formatter_manager.GetAllNames(&all_formatters); |
| 62 |
m_dvListCtrl->DeleteAllItems(); |
| 63 |
m_dvListCtrl->Begin(); |
| 64 |
for(const auto& name : all_formatters) { |
| 65 |
wxVector<wxVariant> cols; |
| 66 |
cols.push_back(name); |
| 67 |
m_dvListCtrl->AppendItem(cols); |
| 68 |
} |
| 69 |
|
| 70 |
if(!m_dvListCtrl->IsEmpty()) { |
| 71 |
m_dvListCtrl->SelectRow(0); |
| 72 |
} |
| 73 |
m_dvListCtrl->Commit(); |
| 74 |
} |
| 75 |
|
| 76 |
void CodeFormatterDlg::OnOK(wxCommandEvent& e) |
| 77 |
{ |
| 78 |
wxUnusedVar(e); |
| 79 |
EndModal(wxID_OK); |
| 80 |
} |
| 81 |
|
| 82 |
void CodeFormatterDlg::OnSelectionChanged(wxDataViewEvent& event) |
| 83 |
{ |
| 84 |
auto item = event.GetItem(); |
| 85 |
auto formatter = m_formatter_manager.GetFormatterByName(m_dvListCtrl->GetItemText(item)); |
| 86 |
m_page->Load(formatter); |
| 87 |
} |
| 88 |
|
| 89 |
void CodeFormatterDlg::OnSelectionChanging(wxDataViewEvent& event) { event.Skip(); } |
| 90 |
|
| 91 |
void CodeFormatterDlg::OnRevert(wxCommandEvent& event) |
| 92 |
{ |
| 93 |
wxUnusedVar(event); |
| 94 |
if(::wxMessageBox(_("Lose all your modifications and restore default settings?"), "CodeLite", |
| 95 |
wxICON_WARNING | wxYES_NO | wxCANCEL | wxCANCEL_DEFAULT) != wxYES) { |
| 96 |
return; |
| 97 |
} |
| 98 |
m_formatter_manager.RestoreDefaults(); |
| 99 |
InitDialog(); |
| 100 |
} |
| 101 |
|
| 102 |
void CodeFormatterDlg::OnSelectFileTypes(wxCommandEvent& event) |
| 103 |
{ |
| 104 |
// wxArrayString selected; |
| 105 |
// |
| 106 |
// wxString cur = m_textCtrlFileTypes->GetValue(); |
| 107 |
// wxArrayString initial = wxStringTokenize(cur, ";", wxTOKEN_STRTOK); |
| 108 |
// if(!::clShowFileTypeSelectionDialog(this, initial, &selected)) { |
| 109 |
// return; |
| 110 |
// } |
| 111 |
// |
| 112 |
// wxString value = wxJoin(selected, ';'); |
| 113 |
// m_textCtrlFileTypes->ChangeValue(value); |
| 114 |
} |