File: addoptioncheckdlg.cpp

package info (click to toggle)
codelite 6.1.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 48,992 kB
  • ctags: 43,502
  • sloc: cpp: 334,263; ansic: 18,441; xml: 4,713; yacc: 2,653; lex: 2,449; python: 1,188; sh: 385; makefile: 40
file content (163 lines) | stat: -rw-r--r-- 4,908 bytes parent folder | download
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2014 The CodeLite Team
// file name            : addoptioncheckdlg.cpp
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

#include "addoptioncheckdlg.h"
#include "windowattrmanager.h"
#include <wx/tokenzr.h>
#include <wx/txtstrm.h>
#include <wx/sstream.h>
#include <list>
#include <algorithm> // std::find

AddOptionCheckDlg::AddOptionCheckDlg(wxWindow* parent, const wxString& title, const Compiler::CmpCmdLineOptions& cmpOptions, const wxString& value)
: AddOptionCheckDialogBase(parent, wxID_ANY, title)
, m_cmpOptions(cmpOptions)
{
	WindowAttrManager::Load(this, wxT("AddOptionCheckDlg"), NULL);

	// Fill the list of available options
	Compiler::CmpCmdLineOptions::const_iterator itOption = m_cmpOptions.begin();
	for ( ; itOption != m_cmpOptions.end(); ++itOption)
	{
		const Compiler::CmpCmdLineOption& cmpOption = itOption->second;
		m_checkListOptions->Append(cmpOption.help + wxT(" [") + cmpOption.name + wxT("]"));
	}
	
	// Update controls
	SetValue(value);
}

AddOptionCheckDlg::~AddOptionCheckDlg()
{
	WindowAttrManager::Save(this, wxT("AddOptionCheckDlg"), NULL);
}

void AddOptionCheckDlg::SetValue(const wxString& value)
{
	m_textCmdLn->SetValue(value);
	
	UpdateOptions();
	UpdateCmdLine();
}

wxString AddOptionCheckDlg::GetValue() const
{
	return m_textCmdLn->GetValue();
}

void AddOptionCheckDlg::OnOptionToggled( wxCommandEvent& event )
{
	UpdateCmdLine();
	UpdateOptions();
}

void AddOptionCheckDlg::OnOptionsText( wxCommandEvent& event )
{
	UpdateCmdLine();
}

void AddOptionCheckDlg::UpdateOptions()
{
	// Remove all check boxes
	m_checkListOptions->Freeze();
	
	for (unsigned int idx = 0; idx < m_checkListOptions->GetCount(); ++idx)
	{
		m_checkListOptions->Check(idx, false);
	}
	
	// Check all options entered 
	wxString customOptions;
	wxStringTokenizer tkz(m_textCmdLn->GetValue(), wxT(";"));
	while(tkz.HasMoreTokens())
	{
		wxString token = tkz.GetNextToken();
		token = token.Trim().Trim(false);
		if (!token.empty())
		{
			Compiler::CmpCmdLineOptions::const_iterator itOption = m_cmpOptions.find(token);
			if(itOption != m_cmpOptions.end())
			{
				const Compiler::CmpCmdLineOption& cmpOption = itOption->second;
				m_checkListOptions->Check(m_checkListOptions->FindString(cmpOption.help + wxT(" [") + cmpOption.name + wxT("]")));			
			}
			else
			{
				if(!customOptions.empty()) customOptions << wxT(";");
				customOptions << token;
			}
		}
	}
	m_textOptions->ChangeValue(customOptions);
	
	m_checkListOptions->Thaw();
}

void AddOptionCheckDlg::UpdateCmdLine()
{
	// Store all actual options
	std::list<wxString> options;
	wxStringInputStream input(m_textOptions->GetValue());
	wxTextInputStream text(input);
	while( !input.Eof() ) {
		wxString option = text.ReadLine().Trim().Trim(false);
		if (!option.empty())
		{
			options.push_back(option);
		}
	}
	
	// Read check box options
	for (unsigned int idx = 0; idx < m_checkListOptions->GetCount(); ++idx)
	{
		wxString value = m_checkListOptions->GetString(idx).AfterLast(wxT('[')).BeforeLast(wxT(']'));
		if (m_checkListOptions->IsChecked(idx))
		{
			// If the option doesn't exist actually, add it
			if (std::find(options.begin(), options.end(), value) == options.end())
			{
				//options.push_back(value.AfterLast(wxT('[')).BeforeLast(wxT(']')));
				options.insert(options.begin(), value);
			}
			else
				// uncheck the option if already defined manualy
				m_checkListOptions->Check(idx, false);
		}
	}
	
	// Update the options textctrl
	wxString value;
	std::list<wxString>::const_iterator itOption = options.begin();
	for ( ; itOption != options.end(); ++itOption)
	{
		if(!value.Contains(*itOption + wxT(";")))
		{
			if(!value.empty()) value << wxT(";");
			value << *itOption;
		}
	}
	m_textCmdLn->SetValue(value);
}