]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMSettingsDialog.cpp
Feature #1711 CreaDevManager application implementation
[crea.git] / lib / creaDevManagerLib / wxCDMSettingsDialog.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Sant�)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and 
11 #  abiding by the rules of distribution of free software. You can  use, 
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
13 #  license as circulated by CEA, CNRS and INRIA at the following URL 
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability. 
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ 
26  */
27
28
29 /*
30  * wxCDMMainHelpDialog.cpp
31  *
32  *  Created on: 14/2/2013
33  *      Author: Daniel Felipe Gonzalez Obando
34  */
35
36 #include "wxCDMSettingsDialog.h"
37
38 #include "creaDevManagerIds.h"
39 #include "CDMUtilities.h"
40
41 #include <wx/config.h>
42
43 BEGIN_EVENT_TABLE(wxCDMSettingsDialog, wxDialog)
44 EVT_BUTTON(ID_BUTTON_NEXT, wxCDMSettingsDialog::OnFinish)
45 EVT_BUTTON(ID_BUTTON_PREV, wxCDMSettingsDialog::OnDefaults)
46 EVT_BUTTON(ID_BUTTON_CANCEL, wxCDMSettingsDialog::OnCancel)
47 END_EVENT_TABLE()
48
49 wxCDMSettingsDialog::wxCDMSettingsDialog(
50     wxWindow* parent,
51     wxWindowID id,
52     const wxString& caption,
53     const wxPoint& position,
54     const wxSize& size,
55     long style
56 )
57 {
58   wxCDMSettingsDialog::Create(parent, id, caption, position, size, style);
59 }
60
61 wxCDMSettingsDialog::~wxCDMSettingsDialog()
62 {
63 }
64
65 bool wxCDMSettingsDialog::Create(
66     wxWindow* parent,
67     wxWindowID id,
68     const wxString& caption,
69     const wxPoint& position,
70     const wxSize& size,
71     long int style
72 )
73 {
74   wxDialog::Create(parent, id, caption, position, size, style);
75
76   this->CreateControls();
77
78   return TRUE;
79 }
80
81 bool wxCDMSettingsDialog::IsHelpEnabled()
82 {
83   return this->helpEnabled->GetValue();
84 }
85
86 void wxCDMSettingsDialog::SetHelpEnabled(bool isHelp)
87 {
88   this->helpEnabled->SetValue(isHelp);
89 }
90
91 void wxCDMSettingsDialog::CreateControls()
92 {
93
94   wxBoxSizer* v_sizer1 = new wxBoxSizer(wxVERTICAL);
95
96
97   wxStaticText* title = new wxStaticText(this, wxID_ANY, wxT("Crea Development Manager Settings"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
98   v_sizer1->Add(title, 0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 5);
99
100   wxStaticText* instruction = new wxStaticText(this, wxID_ANY, wxT("Change the values to modify the default behavior of the program."), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
101   v_sizer1->Add(instruction, 0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 5);
102
103   wxFlexGridSizer* formItems = new wxFlexGridSizer(4,2,9,15);
104
105   wxStaticText *stxtTextEditor = new wxStaticText(this, -1, wxT("Text Editor Command"));
106   wxStaticText *stxtFileExplorer = new wxStaticText(this, -1, wxT("File Explorer Command"));
107   wxStaticText *stxtTerminal = new wxStaticText(this, -1, wxT("Terminal Command"));
108   wxStaticText *stxtHelpEnabled = new wxStaticText(this, -1, wxT("Help Enabled"));
109
110   wxConfigBase* pConfig = wxConfigBase::Get();
111
112   this->textEditor = new wxTextCtrl(this, -1, pConfig->Read(wxT("TEXT_EDITOR"), crea::std2wx(CDMUtilities::TEXT_EDITOR)));
113   this->fileExplorer = new wxTextCtrl(this, -1, pConfig->Read(wxT("FILE_EXPLORER"), crea::std2wx(CDMUtilities::FILE_EXPLORER)));
114   this->terminal = new wxTextCtrl(this, -1, pConfig->Read(wxT("TERMINAL"), crea::std2wx(CDMUtilities::TERMINAL)));
115   this->helpEnabled = new wxCheckBox(this, -1, wxT(""));
116   this->helpEnabled->SetValue(pConfig->Read(wxT("HELP"), true));
117
118
119   formItems->Add(stxtTextEditor, 0, wxALIGN_CENTER_VERTICAL);
120   formItems->Add(this->textEditor, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
121   formItems->Add(stxtFileExplorer, 0, wxALIGN_CENTER_VERTICAL);
122   formItems->Add(this->fileExplorer, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
123   formItems->Add(stxtTerminal, 0, wxALIGN_CENTER_VERTICAL);
124   formItems->Add(this->terminal, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
125   formItems->Add(stxtHelpEnabled, 0, wxALIGN_CENTER_VERTICAL);
126   formItems->Add(this->helpEnabled, 1, wxEXPAND);
127
128
129   formItems->AddGrowableCol(1,1);
130
131   v_sizer1->Add(formItems, 1, wxEXPAND | wxALL, 15);
132
133   wxBoxSizer* h_sizer2 = new wxBoxSizer(wxHORIZONTAL);
134   h_sizer2->Add(new wxButton(this, ID_BUTTON_PREV, wxT("Restore Defaults")), 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
135   h_sizer2->Add(new wxButton(this, ID_BUTTON_NEXT, wxT("OK")), 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
136   h_sizer2->Add(new wxButton(this, ID_BUTTON_CANCEL, wxT("Cancel")), 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
137
138
139   v_sizer1->Add(h_sizer2, 0, wxALIGN_CENTER | wxALL | wxEXPAND, 10);
140
141   SetSizer(v_sizer1);
142 }
143
144 void wxCDMSettingsDialog::OnFinish(wxCommandEvent& event)
145 {
146   wxConfigBase* pConfig = wxConfigBase::Get();
147
148   pConfig->Write(wxT("TEXT_EDITOR"), this->textEditor->GetValue());
149   pConfig->Write(wxT("TERMINAL"), this->terminal->GetValue());
150   pConfig->Write(wxT("FILE_EXPLORER"), this->fileExplorer->GetValue());
151   pConfig->Write(wxT("HELP"), this->helpEnabled->GetValue());
152
153   this->EndModal(wxID_OK);
154 }
155
156 void wxCDMSettingsDialog::OnCancel(wxCommandEvent& event)
157 {
158   this->EndModal(wxID_CANCEL);
159 }
160
161 void wxCDMSettingsDialog::OnDefaults(wxCommandEvent& event)
162 {
163   this->textEditor->SetValue(crea::std2wx(CDMUtilities::TEXT_EDITOR));
164   this->terminal->SetValue(crea::std2wx(CDMUtilities::TERMINAL));
165   this->fileExplorer->SetValue(crea::std2wx(CDMUtilities::FILE_EXPLORER));
166   this->helpEnabled->SetValue(true);
167 }