summaryrefslogtreecommitdiff
path: root/LiteEditor/compilerlinkeroptionspage.cpp
blob: 3ced9ee015ca35c15ef5477ba69b7ae8f54782c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "compilerlinkeroptionspage.h"
#include "build_settings_config.h"
#include "compiler.h"
#include "globals.h"

CompilerLinkerOptionsPage::CompilerLinkerOptionsPage( wxWindow* parent, const wxString &cmpname )
: CompilerLinkerOptionsBase( parent )
, m_cmpname(cmpname)
, m_selectedLnkOption(wxNOT_FOUND)
{
	m_listLinkerOptions->InsertColumn(0, wxT("Switch"));
	m_listLinkerOptions->InsertColumn(1, wxT("Help"));
	
	CompilerPtr cmp = BuildSettingsConfigST::Get()->GetCompiler(m_cmpname);
	const Compiler::CmpCmdLineOptions& lnkOptions = cmp->GetLinkerOptions();
	Compiler::CmpCmdLineOptions::const_iterator itLnkOption = lnkOptions.begin();
	for ( ; itLnkOption != lnkOptions.end(); ++itLnkOption)
	{
		const Compiler::CmpCmdLineOption& lnkOption = itLnkOption->second;
		long idx = m_listLinkerOptions->InsertItem(m_listLinkerOptions->GetItemCount(), lnkOption.name);
		m_listLinkerOptions->SetItem(idx, 1, lnkOption.help);
	}
	m_listLinkerOptions->SetColumnWidth(0, 100);
	m_listLinkerOptions->SetColumnWidth(1, wxLIST_AUTOSIZE);
}

void CompilerLinkerOptionsPage::Save(CompilerPtr cmp)
{
	Compiler::CmpCmdLineOptions lnkOptions;
	for (int idx = 0; idx < m_listLinkerOptions->GetItemCount(); ++idx)
	{
		Compiler::CmpCmdLineOption lnkOption;
		lnkOption.name = m_listLinkerOptions->GetItemText(idx);
		lnkOption.help = GetColumnText(m_listLinkerOptions, idx, 1);
		
		lnkOptions[lnkOption.name] = lnkOption;
	}
	cmp->SetLinkerOptions(lnkOptions);
}

void CompilerLinkerOptionsPage::OnLinkerOptionActivated( wxListEvent& event )
{
	if (m_selectedLnkOption == wxNOT_FOUND) {
		return;
	}
	
	wxString name = m_listLinkerOptions->GetItemText(m_selectedLnkOption);
	wxString help = GetColumnText(m_listLinkerOptions, m_selectedLnkOption, 1);
	CompilerLinkerOptionDialog dlg(this, name, help);
	if (dlg.ShowModal() == wxID_OK)
	{
		SetColumnText(m_listLinkerOptions, m_selectedLnkOption, 0, dlg.m_sName);
		SetColumnText(m_listLinkerOptions, m_selectedLnkOption, 1, dlg.m_sHelp);
		m_listLinkerOptions->SetColumnWidth(1, wxLIST_AUTOSIZE);
	}
}

void CompilerLinkerOptionsPage::OnNewLinkerOption( wxCommandEvent& event )
{
	CompilerLinkerOptionDialog dlg(this, wxEmptyString, wxEmptyString);
	if (dlg.ShowModal() == wxID_OK)
	{
		long idx = m_listLinkerOptions->InsertItem(m_listLinkerOptions->GetItemCount(), dlg.m_sName);
		m_listLinkerOptions->SetItem(idx, 1, dlg.m_sHelp);
		m_listLinkerOptions->SetColumnWidth(1, wxLIST_AUTOSIZE);
	}
}

void CompilerLinkerOptionsPage::OnDeleteLinkerOption( wxCommandEvent& event )
{
	if (m_selectedLnkOption != wxNOT_FOUND) {
		if (wxMessageBox(_("Are you sure you want to delete this linker option?"), wxT("CodeLite"), wxYES_NO|wxCANCEL) == wxYES) {
			m_listLinkerOptions->DeleteItem(m_selectedLnkOption);
			m_listLinkerOptions->SetColumnWidth(1, wxLIST_AUTOSIZE);
			m_selectedLnkOption = wxNOT_FOUND;
		}
	}
}

void CompilerLinkerOptionsPage::OnLinkerOptionDeSelected(wxListEvent& event)
{
#ifndef __WXMAC__
	m_selectedLnkOption = wxNOT_FOUND;
#endif
	event.Skip();
}

void CompilerLinkerOptionsPage::OnLinkerOptionSelected(wxListEvent& event)
{
	m_selectedLnkOption = event.m_itemIndex;
	event.Skip();
}