From 157fdd70097efc81cb9bcd3a3b19392b8a144655 Mon Sep 17 00:00:00 2001 From: Daniel Gonzalez Date: Thu, 14 Feb 2013 17:52:15 +0100 Subject: [PATCH] Feature #1711 CreaDevManager application implementation - Settings implemented. Help enabled, text editor, terminal, file explorer names are saved. --- appli/creaDevManager/creaDevManager.cpp | 7 + lib/creaDevManagerLib/CDMUtilities.cpp | 12 +- lib/creaDevManagerLib/CDMUtilities.h | 37 ++-- lib/creaDevManagerLib/creaDevManagerIds.h | 2 +- lib/creaDevManagerLib/wxCDMMainFrame.cpp | 28 ++- lib/creaDevManagerLib/wxCDMMainFrame.h | 5 + .../wxCDMNewBlackBoxDialog.cpp | 6 +- lib/creaDevManagerLib/wxCDMSettingsDialog.cpp | 167 ++++++++++++++++++ lib/creaDevManagerLib/wxCDMSettingsDialog.h | 149 ++++++++++++++++ 9 files changed, 386 insertions(+), 27 deletions(-) create mode 100644 lib/creaDevManagerLib/wxCDMSettingsDialog.cpp create mode 100644 lib/creaDevManagerLib/wxCDMSettingsDialog.h diff --git a/appli/creaDevManager/creaDevManager.cpp b/appli/creaDevManager/creaDevManager.cpp index 0ff5bf2..fd922da 100644 --- a/appli/creaDevManager/creaDevManager.cpp +++ b/appli/creaDevManager/creaDevManager.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include // for std::cout #include "creaDevManager.h" @@ -41,6 +42,11 @@ wxCreaDevManagerApp::wxCreaDevManagerApp():wxApp() bool wxCreaDevManagerApp::OnInit() { wxApp::OnInit(); + this->SetVendorName(wxT("Creatis")); + this->SetAppName(wxT("creaDevManager")); + + wxConfigBase *pConfig = wxConfigBase::Get(); + mainWindow = new wxCDMMainFrame(NULL); SetTopWindow(mainWindow); mainWindow->SetSize(750, 700); @@ -53,6 +59,7 @@ bool wxCreaDevManagerApp::OnInit() int wxCreaDevManagerApp::OnExit() { + delete wxConfigBase::Set((wxConfigBase *) NULL); wxApp::OnExit(); std::cout << "Crea DevManager closed." << std::endl; return 0; diff --git a/lib/creaDevManagerLib/CDMUtilities.cpp b/lib/creaDevManagerLib/CDMUtilities.cpp index ac1b532..64a6987 100644 --- a/lib/creaDevManagerLib/CDMUtilities.cpp +++ b/lib/creaDevManagerLib/CDMUtilities.cpp @@ -41,6 +41,9 @@ #include #include +#include +#include + namespace CDMUtilities { template @@ -109,7 +112,8 @@ namespace CDMUtilities int openTextEditor(const std::string& file) { - std::string command = TEXT_EDITOR; + wxConfigBase* pConfig = wxConfigBase::Get(); + std::string command = crea::wx2std(pConfig->Read(wxT("TEXT_EDITOR"), crea::std2wx(CDMUtilities::TEXT_EDITOR))); if(file != "") command += " \"" + file + "\""; @@ -120,7 +124,8 @@ namespace CDMUtilities int openFileExplorer(const std::string& file) { - std::string command = FILE_EXPLORER; + wxConfigBase* pConfig = wxConfigBase::Get(); + std::string command = crea::wx2std(pConfig->Read(wxT("FILE_EXPLORER"), crea::std2wx(CDMUtilities::FILE_EXPLORER))); if(file != "") command += " \"" + file + "\""; @@ -158,7 +163,8 @@ namespace CDMUtilities int openTerminal(const std::string& command) { - std::string comm = TERMINAL; + wxConfigBase* pConfig = wxConfigBase::Get(); + std::string comm = crea::wx2std(pConfig->Read(wxT("TERMINAl"), crea::std2wx(CDMUtilities::TERMINAL))); if (command != "") comm += + " " + command; comm += " &"; diff --git a/lib/creaDevManagerLib/CDMUtilities.h b/lib/creaDevManagerLib/CDMUtilities.h index 99dd04c..5430aea 100644 --- a/lib/creaDevManagerLib/CDMUtilities.h +++ b/lib/creaDevManagerLib/CDMUtilities.h @@ -43,15 +43,15 @@ namespace CDMUtilities /** * Path slash */ - #ifdef _WIN32 - // ------ Windows - static std::string SLASH = "\\"; - #elif __APPLE__ - // ------ Apple - static std::string SLASH = "/"; - #else - static std::string SLASH = "/"; - #endif +#ifdef _WIN32 + // ------ Windows + static std::string SLASH = "\\"; +#elif __APPLE__ + // ------ Apple + static std::string SLASH = "/"; +#else + static std::string SLASH = "/"; +#endif /** * Text editor program @@ -82,16 +82,15 @@ namespace CDMUtilities /** * Terminal program */ - #ifdef _WIN32 - // ------ Windows - static std::string TERMINAL = "start cmd.exe"; - #elif __APPLE__ - // ------ Apple - //TODO: implementation for apple - #else - static std::string TERMINAL = "gnome-terminal"; - #endif - +#ifdef _WIN32 + // ------ Windows + static std::string TERMINAL = "start cmd.exe"; +#elif __APPLE__ + // ------ Apple + //TODO: implementation for apple +#else + static std::string TERMINAL = "gnome-terminal"; +#endif /** * Structure that handles the split method for c++ diff --git a/lib/creaDevManagerLib/creaDevManagerIds.h b/lib/creaDevManagerLib/creaDevManagerIds.h index 4376d3e..a73f569 100644 --- a/lib/creaDevManagerLib/creaDevManagerIds.h +++ b/lib/creaDevManagerLib/creaDevManagerIds.h @@ -47,7 +47,7 @@ #define ID_MENU_EXIT 10207 #define ID_MENU_REFRESH_PROJECT 10208 -#define ID_MENU_CUT 10209 +#define ID_MENU_SETTINGS 10209 #define ID_MENU_COPY 10210 #define ID_MENU_PASTE 10211 #define ID_MENU_DELETE 10212 diff --git a/lib/creaDevManagerLib/wxCDMMainFrame.cpp b/lib/creaDevManagerLib/wxCDMMainFrame.cpp index 441d99e..98dfb28 100755 --- a/lib/creaDevManagerLib/wxCDMMainFrame.cpp +++ b/lib/creaDevManagerLib/wxCDMMainFrame.cpp @@ -38,6 +38,7 @@ #include "wx/tooltip.h" #include "wx/wxhtml.h" #include "wx/statline.h" +#include "wx/config.h" #include "CDMUtilities.h" #include "creaDevManagerIds.h" @@ -54,6 +55,8 @@ #include "wxCDMFileDescriptionPanel.h" #include "wxCDMPackageManagerPanel.h" +#include "wxCDMSettingsDialog.h" + #include "wxCDMProjectActionsPanel.h" #include "wxCDMNewProjectDialog.h" @@ -66,6 +69,7 @@ EVT_MENU(ID_MENU_CLOSE_PROJECT, wxCDMMainFrame::OnMenuCloseProject) EVT_MENU(ID_MENU_EXPORT_HIERARCHY, wxCDMMainFrame::OnMenuExportHierarchy) EVT_MENU(ID_MENU_EXIT, wxCDMMainFrame::OnMenuExit) EVT_MENU(ID_MENU_REFRESH_PROJECT, wxCDMMainFrame::OnMenuRefreshProject) +EVT_MENU(ID_MENU_SETTINGS, wxCDMMainFrame::OnMenuSettings) EVT_MENU(ID_MENU_BBTK_GRAPHICAL_EDITOR, wxCDMMainFrame::OnMenuBBTKGraphicalEditor) EVT_MENU(ID_MENU_MINITOOLS, wxCDMMainFrame::OnMenuMiniTools) EVT_MENU(ID_MENU_CODE_EDITOR, wxCDMMainFrame::OnMenuCodeEditor) @@ -123,8 +127,13 @@ bool wxCDMMainFrame::Create( ) { wxFrame::Create(parent, id, caption, pos, size, style); - this->model = new modelCDMMain(); this->help = true; + + wxConfigBase* pConfig = wxConfigBase::Get(); + this->help = pConfig->Read(wxT("HELP"), this->help); + + this->model = new modelCDMMain(); + CreateMenus(); CreateControls(); return TRUE; @@ -176,6 +185,7 @@ void wxCDMMainFrame::CreateMenus() //EditMenu menu_Edit = new wxMenu(); menu_Edit->Append(ID_MENU_REFRESH_PROJECT, wxT("&Refresh Project")); + menu_Edit->Append(ID_MENU_SETTINGS, wxT("&Settings")); menuBar->Append(menu_Edit, wxT("&Edit")); @@ -496,6 +506,19 @@ void wxCDMMainFrame::OnMenuRefreshProject(wxCommandEvent& event) event.Skip(); } +void wxCDMMainFrame::OnMenuSettings(wxCommandEvent& event) +{ + wxCDMSettingsDialog* settingsDialog = new wxCDMSettingsDialog(this, -1); + settingsDialog->SetHelpEnabled(this->help); + + int res = settingsDialog->ShowModal(); + if(res == wxID_OK) + { + this->help = settingsDialog->IsHelpEnabled(); + this->menu_Help->Check(ID_MENU_TOGGLE_HELP, this->help); + } +} + void wxCDMMainFrame::OnMenuBBTKGraphicalEditor(wxCommandEvent& event) { std::cerr << "Event OnMenuBBTKGraphicalEditor not implemented" << std::endl; @@ -920,7 +943,8 @@ void wxCDMMainFrame::OnChangeView(wxCommandEvent& event) auiManager.Update(); break; default: - event.Skip(); + event.Skip(); + break; } } diff --git a/lib/creaDevManagerLib/wxCDMMainFrame.h b/lib/creaDevManagerLib/wxCDMMainFrame.h index 9df0879..b5180f1 100755 --- a/lib/creaDevManagerLib/wxCDMMainFrame.h +++ b/lib/creaDevManagerLib/wxCDMMainFrame.h @@ -210,6 +210,11 @@ protected: * @param event The event object that triggers the handler. */ void OnMenuRefreshProject(wxCommandEvent& event); + /** + * Open the settings dialog. + * @param event The event object that triggers the handler. + */ + void OnMenuSettings(wxCommandEvent& event); //Tools /** diff --git a/lib/creaDevManagerLib/wxCDMNewBlackBoxDialog.cpp b/lib/creaDevManagerLib/wxCDMNewBlackBoxDialog.cpp index 7e0c69f..c154288 100644 --- a/lib/creaDevManagerLib/wxCDMNewBlackBoxDialog.cpp +++ b/lib/creaDevManagerLib/wxCDMNewBlackBoxDialog.cpp @@ -125,7 +125,8 @@ const wxString wxCDMNewBlackBoxDialog::GetBlackBoxType() const #endif break; default: - res = wxT("std"); + res = wxT("std"); + break; } return res; } @@ -142,7 +143,8 @@ const wxString wxCDMNewBlackBoxDialog::GetBlackBoxFormat() const res = wxT("XML"); break; default: - res = wxT("C++"); + res = wxT("C++"); + break; } return res; } diff --git a/lib/creaDevManagerLib/wxCDMSettingsDialog.cpp b/lib/creaDevManagerLib/wxCDMSettingsDialog.cpp new file mode 100644 index 0000000..306c5a8 --- /dev/null +++ b/lib/creaDevManagerLib/wxCDMSettingsDialog.cpp @@ -0,0 +1,167 @@ +/* +# --------------------------------------------------------------------- +# +# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image +# pour la Sant�) +# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton +# Previous Authors : Laurent Guigues, Jean-Pierre Roux +# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil +# +# This software is governed by the CeCILL-B license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL-B +# license as circulated by CEA, CNRS and INRIA at the following URL +# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +# or in the file LICENSE.txt. +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL-B license and that you accept its terms. +# ------------------------------------------------------------------------ + */ + + +/* + * wxCDMMainHelpDialog.cpp + * + * Created on: 14/2/2013 + * Author: Daniel Felipe Gonzalez Obando + */ + +#include "wxCDMSettingsDialog.h" + +#include "creaDevManagerIds.h" +#include "CDMUtilities.h" + +#include + +BEGIN_EVENT_TABLE(wxCDMSettingsDialog, wxDialog) +EVT_BUTTON(ID_BUTTON_NEXT, wxCDMSettingsDialog::OnFinish) +EVT_BUTTON(ID_BUTTON_PREV, wxCDMSettingsDialog::OnDefaults) +EVT_BUTTON(ID_BUTTON_CANCEL, wxCDMSettingsDialog::OnCancel) +END_EVENT_TABLE() + +wxCDMSettingsDialog::wxCDMSettingsDialog( + wxWindow* parent, + wxWindowID id, + const wxString& caption, + const wxPoint& position, + const wxSize& size, + long style +) +{ + wxCDMSettingsDialog::Create(parent, id, caption, position, size, style); +} + +wxCDMSettingsDialog::~wxCDMSettingsDialog() +{ +} + +bool wxCDMSettingsDialog::Create( + wxWindow* parent, + wxWindowID id, + const wxString& caption, + const wxPoint& position, + const wxSize& size, + long int style +) +{ + wxDialog::Create(parent, id, caption, position, size, style); + + this->CreateControls(); + + return TRUE; +} + +bool wxCDMSettingsDialog::IsHelpEnabled() +{ + return this->helpEnabled->GetValue(); +} + +void wxCDMSettingsDialog::SetHelpEnabled(bool isHelp) +{ + this->helpEnabled->SetValue(isHelp); +} + +void wxCDMSettingsDialog::CreateControls() +{ + + wxBoxSizer* v_sizer1 = new wxBoxSizer(wxVERTICAL); + + + wxStaticText* title = new wxStaticText(this, wxID_ANY, wxT("Crea Development Manager Settings"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); + v_sizer1->Add(title, 0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 5); + + wxStaticText* instruction = new wxStaticText(this, wxID_ANY, wxT("Change the values to modify the default behavior of the program."), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); + v_sizer1->Add(instruction, 0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, 5); + + wxFlexGridSizer* formItems = new wxFlexGridSizer(4,2,9,15); + + wxStaticText *stxtTextEditor = new wxStaticText(this, -1, wxT("Text Editor Command")); + wxStaticText *stxtFileExplorer = new wxStaticText(this, -1, wxT("File Explorer Command")); + wxStaticText *stxtTerminal = new wxStaticText(this, -1, wxT("Terminal Command")); + wxStaticText *stxtHelpEnabled = new wxStaticText(this, -1, wxT("Help Enabled")); + + wxConfigBase* pConfig = wxConfigBase::Get(); + + this->textEditor = new wxTextCtrl(this, -1, pConfig->Read(wxT("TEXT_EDITOR"), crea::std2wx(CDMUtilities::TEXT_EDITOR))); + this->fileExplorer = new wxTextCtrl(this, -1, pConfig->Read(wxT("FILE_EXPLORER"), crea::std2wx(CDMUtilities::FILE_EXPLORER))); + this->terminal = new wxTextCtrl(this, -1, pConfig->Read(wxT("TERMINAL"), crea::std2wx(CDMUtilities::TERMINAL))); + this->helpEnabled = new wxCheckBox(this, -1, wxT("")); + this->helpEnabled->SetValue(pConfig->Read(wxT("HELP"), true)); + + + formItems->Add(stxtTextEditor, 0, wxALIGN_CENTER_VERTICAL); + formItems->Add(this->textEditor, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL); + formItems->Add(stxtFileExplorer, 0, wxALIGN_CENTER_VERTICAL); + formItems->Add(this->fileExplorer, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL); + formItems->Add(stxtTerminal, 0, wxALIGN_CENTER_VERTICAL); + formItems->Add(this->terminal, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL); + formItems->Add(stxtHelpEnabled, 0, wxALIGN_CENTER_VERTICAL); + formItems->Add(this->helpEnabled, 1, wxEXPAND); + + + formItems->AddGrowableCol(1,1); + + v_sizer1->Add(formItems, 1, wxEXPAND | wxALL, 15); + + wxBoxSizer* h_sizer2 = new wxBoxSizer(wxHORIZONTAL); + h_sizer2->Add(new wxButton(this, ID_BUTTON_PREV, wxT("Restore Defaults")), 0, wxALL | wxALIGN_CENTER_VERTICAL, 5); + h_sizer2->Add(new wxButton(this, ID_BUTTON_NEXT, wxT("OK")), 0, wxALL | wxALIGN_CENTER_VERTICAL, 5); + h_sizer2->Add(new wxButton(this, ID_BUTTON_CANCEL, wxT("Cancel")), 0, wxALL | wxALIGN_CENTER_VERTICAL, 5); + + + v_sizer1->Add(h_sizer2, 0, wxALIGN_CENTER | wxALL | wxEXPAND, 10); + + SetSizer(v_sizer1); +} + +void wxCDMSettingsDialog::OnFinish(wxCommandEvent& event) +{ + wxConfigBase* pConfig = wxConfigBase::Get(); + + pConfig->Write(wxT("TEXT_EDITOR"), this->textEditor->GetValue()); + pConfig->Write(wxT("TERMINAL"), this->terminal->GetValue()); + pConfig->Write(wxT("FILE_EXPLORER"), this->fileExplorer->GetValue()); + pConfig->Write(wxT("HELP"), this->helpEnabled->GetValue()); + + this->EndModal(wxID_OK); +} + +void wxCDMSettingsDialog::OnCancel(wxCommandEvent& event) +{ + this->EndModal(wxID_CANCEL); +} + +void wxCDMSettingsDialog::OnDefaults(wxCommandEvent& event) +{ + this->textEditor->SetValue(crea::std2wx(CDMUtilities::TEXT_EDITOR)); + this->terminal->SetValue(crea::std2wx(CDMUtilities::TERMINAL)); + this->fileExplorer->SetValue(crea::std2wx(CDMUtilities::FILE_EXPLORER)); + this->helpEnabled->SetValue(true); +} diff --git a/lib/creaDevManagerLib/wxCDMSettingsDialog.h b/lib/creaDevManagerLib/wxCDMSettingsDialog.h new file mode 100644 index 0000000..5f70b60 --- /dev/null +++ b/lib/creaDevManagerLib/wxCDMSettingsDialog.h @@ -0,0 +1,149 @@ +/* +# --------------------------------------------------------------------- +# +# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image +# pour la Sant�) +# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton +# Previous Authors : Laurent Guigues, Jean-Pierre Roux +# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil +# +# This software is governed by the CeCILL-B license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL-B +# license as circulated by CEA, CNRS and INRIA at the following URL +# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +# or in the file LICENSE.txt. +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL-B license and that you accept its terms. +# ------------------------------------------------------------------------ + */ + + +/* + * wxCDMSettingsDialog.h + * + * Created on: 14/2/2013 + * Author: Daniel Felipe Gonzalez Obando + */ + +#ifndef WXCDMSETTINGSDIALOG_H_ +#define WXCDMSETTINGSDIALOG_H_ + +#include +#include +#include + +/** + * Settings Dialog + */ +class wxCDMSettingsDialog : public wxDialog +{ + DECLARE_EVENT_TABLE() +public: + /** + * Settings Dialog Constructor. + * @param parent Parent window. + * @param id Dialog ID. By default wxID_ANY. + * @param caption Dialog label. By default "Settings - CreaDevManager CREATIS". + * @param position Dialog position. By default wxDefaultPosition. + * @param size Dialog size. By default 350, 370. + * @param style Dialog style. By default wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER. + */ + wxCDMSettingsDialog( + wxWindow* parent, + wxWindowID id = wxID_ANY, + const wxString& caption = wxT("Settings - CreaDevManager CREATIS"), + const wxPoint& position = wxDefaultPosition, + const wxSize& size = wxSize(350,320), + long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER + ); + /** + * Destructor. + */ + ~wxCDMSettingsDialog(); + /** + * Settings Dialog Creator. + * @param parent Parent window. + * @param id Dialog ID. By default wxID_ANY. + * @param caption Dialog label. By default "Settings - CreaDevManager CREATIS". + * @param position Dialog position. By default wxDefaultPosition. + * @param size Dialog size. By default 350, 370. + * @param style Dialog style. By default wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER. + * @return if the creation was successful. + */ + bool Create( + wxWindow* parent, + wxWindowID id = wxID_ANY, + const wxString& caption = wxT("Settings - CreaDevManager CREATIS"), + const wxPoint& position = wxDefaultPosition, + const wxSize& size = wxSize(350,320), + long style = wxDEFAULT_DIALOG_STYLE + ); + + /** + * Retrieves if the user has help enabled. + * @return True if the user has the help enabled. + */ + bool IsHelpEnabled(); + + /** + * Sets the help enabled checkbox value. + * @param isHelp value of the help enabled checkbox. + */ + void SetHelpEnabled(bool isHelp); + +protected: + /** + * Creates the help controls (text and buttons). + */ + void CreateControls(); + + //attributes +private: + /** + * Text Editor Command. + */ + wxTextCtrl* textEditor; + /** + * Terminal Command. + */ + wxTextCtrl* terminal; + /** + * File Explorer Command. + */ + wxTextCtrl* fileExplorer; + /** + * Help Enabled. + */ + wxCheckBox* helpEnabled; + + + //handlers +protected: + /** + * Handler to close help dialog saving changes. + * @param event Unused. + */ + void OnFinish(wxCommandEvent& event); + + /** + * Handler to close help dialog discarding changes. + * @param event Unused. + */ + void OnCancel(wxCommandEvent& event); + + /** + * Handler to return to default settings. + * @param event Unused. + */ + void OnDefaults(wxCommandEvent& event); +}; + +#endif /* WXCDMSETTINGSDIALOG_H_ */ -- 2.45.0