File: libselectdlg.cpp

package info (click to toggle)
codeblocks 10.05-2.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 41,516 kB
  • sloc: cpp: 334,954; ansic: 26,117; sh: 10,395; xml: 5,273; asm: 3,827; makefile: 3,821; python: 163
file content (184 lines) | stat: -rw-r--r-- 6,886 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
* This file is part of lib_finder plugin for Code::Blocks Studio
* Copyright (C) 2007  Bartlomiej Swiecki
*
* wxSmith 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.
*
* wxSmith is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with wxSmith; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
* $Revision: 4504 $
* $Id: wxsmithpluginregistrants.cpp 4504 2007-10-02 21:52:30Z byo $
* $HeadURL: svn+ssh://byo@svn.berlios.de/svnroot/repos/codeblocks/trunk/src/plugins/contrib/wxSmith/plugin/wxsmithpluginregistrants.cpp $
*/

#include "libselectdlg.h"

//(*InternalHeaders(LibSelectDlg)
#include <wx/checklst.h>
#include <wx/checkbox.h>
#include <wx/sizer.h>
#include <wx/button.h>
#include <wx/radiobut.h>
#include <wx/string.h>
#include <wx/intl.h>
#include <wx/stattext.h>
//*)

#include <manager.h>
#include <configmanager.h>

//(*IdInit(LibSelectDlg)
const long LibSelectDlg::ID_STATICTEXT1 = wxNewId();
const long LibSelectDlg::ID_CHECKLISTBOX1 = wxNewId();
const long LibSelectDlg::ID_RADIOBUTTON1 = wxNewId();
const long LibSelectDlg::ID_RADIOBUTTON2 = wxNewId();
const long LibSelectDlg::ID_RADIOBUTTON3 = wxNewId();
const long LibSelectDlg::ID_CHECKBOX1 = wxNewId();
//*)

BEGIN_EVENT_TABLE(LibSelectDlg,wxScrollingDialog)
	//(*EventTable(LibSelectDlg)
	//*)
	EVT_BUTTON(wxID_OK,LibSelectDlg::OnOk)
END_EVENT_TABLE()

LibSelectDlg::LibSelectDlg(wxWindow* parent,const wxArrayString& Names,bool addOnly)
{
	//(*Initialize(LibSelectDlg)
	wxBoxSizer* BoxSizer1;
	wxStdDialogButtonSizer* StdDialogButtonSizer1;
	wxStaticBoxSizer* StaticBoxSizer1;
	
	Create(parent, wxID_ANY, _("Setting up libraries"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("wxID_ANY"));
	BoxSizer1 = new wxBoxSizer(wxVERTICAL);
	StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("Select libraries You want to set up:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
	BoxSizer1->Add(StaticText1, 0, wxTOP|wxLEFT|wxRIGHT|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 10);
	m_Libraries = new wxCheckListBox(this, ID_CHECKLISTBOX1, wxDefaultPosition, wxSize(361,251), 0, 0, 0, wxDefaultValidator, _T("ID_CHECKLISTBOX1"));
	BoxSizer1->Add(m_Libraries, 1, wxTOP|wxLEFT|wxRIGHT|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 10);
	StaticBoxSizer1 = new wxStaticBoxSizer(wxVERTICAL, this, _("Previous settings"));
	m_DontClear = new wxRadioButton(this, ID_RADIOBUTTON1, _("Do not clear previous results (but remove duplicates)"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP, wxDefaultValidator, _T("ID_RADIOBUTTON1"));
	StaticBoxSizer1->Add(m_DontClear, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 10);
	m_ClearSelected = new wxRadioButton(this, ID_RADIOBUTTON2, _("Clear previous results for selected libraries"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_RADIOBUTTON2"));
	m_ClearSelected->SetValue(true);
	StaticBoxSizer1->Add(m_ClearSelected, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 10);
	m_ClearAll = new wxRadioButton(this, ID_RADIOBUTTON3, _("Clear all previous libraries settings"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_RADIOBUTTON3"));
	StaticBoxSizer1->Add(m_ClearAll, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 10);
	BoxSizer1->Add(StaticBoxSizer1, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 10);
	m_SetupGlobalVars = new wxCheckBox(this, ID_CHECKBOX1, _("Set up Global Variables"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX1"));
	m_SetupGlobalVars->SetValue(true);
	BoxSizer1->Add(m_SetupGlobalVars, 0, wxLEFT|wxRIGHT|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 10);
	StdDialogButtonSizer1 = new wxStdDialogButtonSizer();
	StdDialogButtonSizer1->AddButton(new wxButton(this, wxID_OK, wxEmptyString));
	StdDialogButtonSizer1->AddButton(new wxButton(this, wxID_CANCEL, wxEmptyString));
	StdDialogButtonSizer1->Realize();
	BoxSizer1->Add(StdDialogButtonSizer1, 0, wxLEFT|wxRIGHT|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 10);
	SetSizer(BoxSizer1);
	BoxSizer1->Fit(this);
	BoxSizer1->SetSizeHints(this);
	Center();
	//*)

	if ( (m_AddOnly = addOnly) )
	{
	    m_DontClear->SetValue( true );
	    m_ClearSelected->SetValue( false );
	    m_ClearAll->SetValue( false );
	    m_DontClear->Disable();
	    m_ClearSelected->Disable();
	    m_ClearAll->Disable();
	}

	m_Libraries->Append(Names);

	ConfigManager* Cfg = Manager::Get()->GetConfigManager(_T("lib_finder"));
	switch ( Cfg->ReadInt(_T("libselect/previous"),1) )
	{
	    case 0: m_DontClear->SetValue(true); break;
	    case 2: m_ClearAll->SetValue(true); break;
	    case 1:
	    default: m_ClearSelected->SetValue(true); break;
	}
	m_SetupGlobalVars->SetValue(Cfg->ReadBool(_T("libselect/setup_global_vars"),true));
}

LibSelectDlg::~LibSelectDlg()
{
	//(*Destroy(LibSelectDlg)
	//*)
}

void LibSelectDlg::SetSelections(const wxArrayInt& Selections)
{
    m_Libraries->Freeze();

    // First clear all
    for ( size_t i=0; i<m_Libraries->GetCount(); i++ )
    {
        m_Libraries->Check(i,false);
    }

    // Next select only those which are on the list
    for ( size_t i=0; i<Selections.Count(); i++ )
    {
        m_Libraries->Check(Selections[i],true);
    }

    m_Libraries->Thaw();
}

wxArrayInt LibSelectDlg::GetSelections()
{
    wxArrayInt Ret;
    for ( size_t i=0; i<m_Libraries->GetCount(); i++ )
    {
        if ( m_Libraries->IsChecked(i) )
        {
            Ret.Add((int)i);
        }
    }
    return Ret;
}

bool LibSelectDlg::GetSetupGlobalVars()
{
    return m_SetupGlobalVars->GetValue();
}

bool LibSelectDlg::GetDontClearPrevious()
{
    return m_DontClear->GetValue();
}

bool LibSelectDlg::GetClearSelectedPrevious()
{
    return m_ClearSelected->GetValue();
}

bool LibSelectDlg::GetClearAllPrevious()
{
    return m_ClearAll->GetValue();
}

void LibSelectDlg::OnOk(wxCommandEvent& event)
{
	ConfigManager* Cfg = Manager::Get()->GetConfigManager(_T("lib_finder"));

	if ( !m_DontClear )
	{
        if ( m_DontClear->GetValue()     ) Cfg->Write(_T("libselect/previous"),0);
        if ( m_ClearSelected->GetValue() ) Cfg->Write(_T("libselect/previous"),1);
        if ( m_ClearAll->GetValue()      ) Cfg->Write(_T("libselect/previous"),2);
	}
	Cfg->Write(_T("libselect/setup_global_vars"),m_SetupGlobalVars->GetValue());
    event.Skip();
}