21#include "../../kernel/core/ui/language.hpp"
22#include "../../kernel/core/utils/stringtools.hpp"
23#include "../editor/editor.h"
24#include <wx/clipbrd.h>
27#define ID_DUPLICATECODE_START 12000
28#define ID_DUPLICATECODE_COPY 12001
29#define ID_DUPLICATECODE_REPORT 12002
30#define SEMANTICS_VAR 1
31#define SEMANTICS_STRING 2
32#define SEMANTICS_NUM 4
33#define SEMANTICS_FUNCTION 8
64 m_mainPanel =
new wxPanel(
this, wxID_ANY, wxDefaultPosition);
66 wxBoxSizer* vSizer =
new wxBoxSizer(wxVERTICAL);
67 wxBoxSizer* hSizer =
new wxBoxSizer(wxHORIZONTAL);
68 wxBoxSizer* paramSizer =
new wxBoxSizer(wxHORIZONTAL);
70 wxStaticBoxSizer* checkBox =
new wxStaticBoxSizer(wxVERTICAL, m_mainPanel,
_guilang.
get(
"GUI_DUPCODE_SETTINGS"));
72 m_varSemantics =
new wxCheckBox(checkBox->GetStaticBox(), wxID_ANY,
_guilang.
get(
"GUI_DUPCODE_VARSEMANTICS"));
73 m_StringSemantics =
new wxCheckBox(checkBox->GetStaticBox(), wxID_ANY,
_guilang.
get(
"GUI_DUPCODE_STRINGSEMANTICS"));
74 m_NumSemantics =
new wxCheckBox(checkBox->GetStaticBox(), wxID_ANY,
_guilang.
get(
"GUI_DUPCODE_NUMSEMANTICS"));
75 m_FunctionSemantics =
new wxCheckBox(checkBox->GetStaticBox(), wxID_ANY,
_guilang.
get(
"GUI_DUPCODE_FUNCTIONSEMANTICS"));
76 wxStaticText* spinctrlLabel =
new wxStaticText(m_mainPanel, wxID_ANY,
_guilang.
get(
"GUI_DUPCODE_NUMLINES"));
77 m_NumLines =
new wxSpinCtrl(m_mainPanel, wxID_ANY,
"6", wxDefaultPosition, wxDefaultSize, 0x4000 | wxALIGN_RIGHT, 3, 100, 6);
79 checkBox->Add(m_varSemantics, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5);
80 checkBox->Add(m_StringSemantics, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5);
81 checkBox->Add(m_NumSemantics, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5);
82 checkBox->Add(m_FunctionSemantics, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5);
84 paramSizer->Add(checkBox, 0, wxEXPAND | wxALL, 5);
85 paramSizer->Add(m_NumLines, 1, wxALIGN_LEFT | wxALL, 5);
86 paramSizer->Add(spinctrlLabel, 0, wxEXPAND | wxALL, 5);
91 wxButton* buttonOK =
new wxButton(m_mainPanel, wxID_OK);
93 hSizer->Add(buttonStart, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
94 hSizer->Add(buttonCopy, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
95 hSizer->Add(buttonReport, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
96 hSizer->Add(buttonOK, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
98 m_resultList =
new wxListCtrl(m_mainPanel, wxID_ANY, wxDefaultPosition, wxSize(400*
g_pixelScale, 400*
g_pixelScale), wxLC_REPORT);
99 m_resultList->AppendColumn(
_guilang.
get(
"GUI_DUPCODE_MATCH"));
100 m_resultList->AppendColumn(
_guilang.
get(
"GUI_DUPCODE_PERCENTAGE"));
101 m_resultList->AppendColumn(
_guilang.
get(
"GUI_DUPCODE_LINES"));
103 m_progressGauge =
new wxGauge(m_mainPanel, wxID_ANY, 100, wxDefaultPosition, wxSize(-1, 24*
g_pixelScale), wxHORIZONTAL);
105 vSizer->Add(m_resultList, 2, wxEXPAND | wxALL, 5);
106 vSizer->Add(m_progressGauge, 0, wxEXPAND | wxALL, 5);
107 vSizer->Add(paramSizer, 0, wxEXPAND | wxALL, 5);
108 vSizer->Add(hSizer, 0, wxALIGN_CENTER_HORIZONTAL, 5);
110 m_mainPanel->SetSizer(vSizer);
112 m_progressGauge->SetValue(0);
113 m_varSemantics->SetValue(
true);
127 return this->GetTitle() +
"\n" +
_guilang.
get(
"GUI_DUPCODE_MATCH") +
"\t" +
_guilang.
get(
"GUI_DUPCODE_PERCENTAGE") +
"\t" +
_guilang.
get(
"GUI_DUPCODE_LINES") +
"\n" + sText;
139 for (
size_t i = 0; i < vResult.size(); i++)
141 m_resultList->InsertItem(i, vResult[i].substr(0, vResult[i].find(
'[')));
142 std::string itemtext =
m_resultList->GetItemText(i).ToStdString();
143 int line1 = atoi(itemtext.substr(0, itemtext.find(
'-')).c_str());
144 int line2 = atoi(itemtext.substr(itemtext.find(
'-') + 1, itemtext.find(
'=') - itemtext.find(
'-') - 1).c_str());
145 m_resultList->SetItem(i, 1, vResult[i].substr(vResult[i].find(
'[')));
175 if (!sSelection.length())
177 if (wxTheClipboard->Open())
179 wxTheClipboard->SetData(
new wxTextDataObject(sSelection));
180 wxTheClipboard->Close();
187 if (!sSelection.length())
190 wxFileDialog filedialog(
this,
_guilang.
get(
"GUI_DUPCODE_SAVEREPORT"), wxEmptyString,
"duplicatecodereport.txt",
_guilang.
get(
"COMMON_FILETYPE_TXT") +
" (*.txt)|*.txt", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
191 if (filedialog.ShowModal() == wxID_CANCEL)
193 wxString filename = filedialog.GetPath();
194 wxFile file(filename, wxFile::write);
196 file.Write(sSelection);
212 std::string sItemText = sSelection.ToStdString();
213 int nStart1, nEnd1, nStart2, nEnd2, nSelection;
215 nStart1 =
StrToInt(sItemText.substr(0, sItemText.find(
'-')));
216 nEnd1 =
StrToInt(sItemText.substr(sItemText.find(
'-') + 1, sItemText.find(
' ') - sItemText.find(
'-') - 1));
217 sItemText.erase(0, sItemText.find(
"== ") + 3);
218 nStart2 =
StrToInt(sItemText.substr(0, sItemText.find(
'-')));
219 nEnd2 =
StrToInt(sItemText.substr(sItemText.find(
'-') + 1));
222 nSelection = nStart1 - 1;
224 nSelection = nStart2 - 1;
248 int nCol =
event.GetColumn();
253 std::vector<double> vData;
254 std::vector<int> vIndex;
255 std::vector<wxString> vStringData;
257 std::string sCurrentItem;
261 sCurrentItem =
m_resultList->GetItemText(i, nCol).ToStdString();
262 vIndex.push_back(vData.size());
266 while (sCurrentItem.find_first_of(
"-= ") != std::string::npos)
267 sCurrentItem.erase(sCurrentItem.find_first_of(
"-= "), 1);
268 vData.push_back(
StrToDb(sCurrentItem));
271 vData.push_back(
StrToDb(sCurrentItem.substr(sCurrentItem.find(
'[') + 1, sCurrentItem.find(
']') - sCurrentItem.find(
'[') - 1)));
274 vData.push_back(
StrToDb(sCurrentItem));
279 std::stable_sort(vIndex.begin(), vIndex.end(),
compare_index(vData));
281 for (
int j = 0; j <
m_resultList->GetColumnCount(); j++)
wxCheckBox * m_FunctionSemantics
void SetResult(const std::vector< std::string > &vResult)
void OnButtonCopy(wxCommandEvent &event)
void OnColumnHeaderClick(wxListEvent &event)
void OnItemClick(wxListEvent &event)
void OnItemRightClick(wxListEvent &event)
void OnClose(wxCloseEvent &event)
void OnButtonReport(wxCommandEvent &event)
void highlightSelection(const wxString &sSelection, bool firstMatch)
wxString createTextFromList()
void OnButtonStart(wxCommandEvent &event)
wxListCtrl * m_resultList
wxGauge * m_progressGauge
void OnButtonOK(wxCommandEvent &event)
wxCheckBox * m_varSemantics
void SetProgress(double dPercentage)
wxCheckBox * m_StringSemantics
wxCheckBox * m_NumSemantics
This class handles the internal language system and returns the language strings of the selected lang...
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
The class of the editor window.
void notifyDialogClose()
Notifies the editor that the duplicated code dialog had been closed.
void OnFindDuplicateCode(int nDuplicateFlag=1, int nNumDuplicatedLines=6)
Wrapper for detectCodeDuplicates.
void IndicateDuplicatedLine(int nStart1, int nEnd1, int nStart2, int nEnd2, int nSelectionLine)
Highlights differences between two blocks of code.
This class generalizes a set of basic floating window functionalities like being closable by pressing...
#define ID_DUPLICATECODE_COPY
#define ID_DUPLICATECODE_START
#define SEMANTICS_FUNCTION
#define ID_DUPLICATECODE_REPORT
int StrToInt(const std::string &)
Converts a string into an integer.
compare_index(const std::vector< double > &arr)
const std::vector< double > base_arr
bool operator()(int a, int b) const
std::string toString(int)
Converts an integer to a string without the Settings bloat.