diff --git a/wxCrossGen/FormBuilderGUI.fbp b/wxCrossGen/FormBuilderGUI.fbp index 8ebaf3c..4024f65 100644 --- a/wxCrossGen/FormBuilderGUI.fbp +++ b/wxCrossGen/FormBuilderGUI.fbp @@ -571,7 +571,7 @@ VSettingsDialog - 426,224 + 425,120 wxDEFAULT_DIALOG_STYLE Settings @@ -629,7 +629,7 @@ none 5 - wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL + wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxLEFT 0 diff --git a/wxCrossGen/fbgui/fbgui.cpp b/wxCrossGen/fbgui/fbgui.cpp index a00028b..9f00af5 100644 --- a/wxCrossGen/fbgui/fbgui.cpp +++ b/wxCrossGen/fbgui/fbgui.cpp @@ -123,7 +123,7 @@ VSettingsDialog::VSettingsDialog( wxWindow* parent, wxWindowID id, const wxStrin m_staticText1 = new wxStaticText( this, wxID_ANY, _("Dict path:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticText1->Wrap( -1 ); - bSizer6->Add( m_staticText1, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5 ); + bSizer6->Add( m_staticText1, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); bSizer6->Add( 0, 0, 1, wxEXPAND, 5 ); diff --git a/wxCrossGen/fbgui/fbgui.h b/wxCrossGen/fbgui/fbgui.h index 71e0857..0616bf8 100644 --- a/wxCrossGen/fbgui/fbgui.h +++ b/wxCrossGen/fbgui/fbgui.h @@ -92,7 +92,7 @@ class VSettingsDialog : public wxDialog public: - VSettingsDialog( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Settings"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 426,224 ), long style = wxDEFAULT_DIALOG_STYLE ); + VSettingsDialog( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Settings"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 425,120 ), long style = wxDEFAULT_DIALOG_STYLE ); ~VSettingsDialog(); }; diff --git a/wxCrossGen/fsettings.hpp b/wxCrossGen/fsettings.hpp new file mode 100644 index 0000000..9d6e48f --- /dev/null +++ b/wxCrossGen/fsettings.hpp @@ -0,0 +1,50 @@ +#ifndef FSETTINGS_HPP +#define FSETTINGS_HPP + +#include + +#include "fbgui/fbgui.h" + +class SettingsDialog: public VSettingsDialog { + public: + void onDictPathClick(wxCommandEvent& event); + void onCancelClick(wxCommandEvent& event) { + EndModal(wxID_CANCEL); + } + void onOkClick(wxCommandEvent& event); + + SettingsDialog( wxWindow* parent ) : VSettingsDialog(parent) {}; + + wxString getDictPath() { + return tDictPath->GetValue(); + } + void setDictPath(wxString path) { + tDictPath->SetValue(path); + } +}; + +void SettingsDialog::onDictPathClick(wxCommandEvent& event) { + wxFileDialog dlgOpen(this, _("Open dictionary file"), wxEmptyString, wxEmptyString, + _("Files of dictionaris (*.txt)|*.txt"), wxFD_OPEN|wxFD_FILE_MUST_EXIST); + + if ( dlgOpen.ShowModal() == wxID_CANCEL ) + return; + + wxFileInputStream input_stream(dlgOpen.GetPath()); + if ( !input_stream.IsOk() ) { + wxMessageBox(_("Cannot open dictionary file ") + dlgOpen.GetPath(), _("Error"), wxICON_ERROR); + return; + } + tDictPath->SetValue(dlgOpen.GetPath()); +} + +void SettingsDialog::onOkClick(wxCommandEvent& event) { + wxFileInputStream input_stream(tDictPath->GetValue()); + if ( !input_stream.IsOk() ) { + wxMessageBox(_("Cannot open dictionary file ") + tDictPath->GetValue(), _("Error"), wxICON_ERROR); + return; + } + EndModal(wxID_OK); +} + +#endif diff --git a/wxCrossGen/main.cpp b/wxCrossGen/main.cpp index 6345cd8..d532376 100644 --- a/wxCrossGen/main.cpp +++ b/wxCrossGen/main.cpp @@ -7,11 +7,21 @@ #include #include #include +#include #include "wxgui.hpp" #include "crossgen.hpp" #include "crossexport.hpp" +#include "settingsconsts.hpp" +void MainFrame::procDict(wxString path){ + _dict.clear(); + _allWords.clear(); + _transType.clear(); + readDict(path, _dict); + generateAllWords(_dict, _allWords, _transType); + _isDictLoaded = true; +} void MainFrame::onOpenGridClick(wxCommandEvent &event) { wxFileDialog dlgOpen(this, _("Open crossword file"), wxEmptyString, wxEmptyString, @@ -19,11 +29,9 @@ void MainFrame::onOpenGridClick(wxCommandEvent &event) { if ( dlgOpen.ShowModal() == wxID_CANCEL ) return; - // proceed loading the file chosen by the user; - // this can be done with e.g. wxWidgets input streams: wxFileInputStream input_stream(dlgOpen.GetPath()); if ( !input_stream.IsOk() ) { - wxLogError(_("Cannot open file ") + dlgOpen.GetPath()); + wxMessageBox(_("Cannot open file ") + dlgOpen.GetPath(), _("Error"), wxICON_ERROR ); return; } tPath->SetValue(dlgOpen.GetPath()); @@ -112,10 +120,9 @@ void MainFrame::SetGridImage(GridType &grid, size_t w) { } void MainFrame::onGenerateClick(wxCommandEvent &event) { + auto config = wxConfigBase::Get(); if ( !_isDictLoaded ) { - readDict(wxT("big_cross_ru.txt"), _dict); - generateAllWords(_dict, _allWords, _transType); - _isDictLoaded = true; + procDict(config->Read(SETTINGS_KEY_DICT_PATH, SETTINGS_DEFAULT_DICTPATH)); } std::vector words_out; @@ -123,7 +130,7 @@ void MainFrame::onGenerateClick(wxCommandEvent &event) { wxMessageBox( _("Crossword grid isn't loaded!"), _("Info"), wxICON_INFORMATION); return; } - try{ + try { generateCross(_grid, _allWords, _transType, words_out); _ans = words_out; @@ -178,7 +185,15 @@ void MainFrame::onExportClick(wxCommandEvent& event) { } void MainFrame::onSettingsClick( wxCommandEvent& event ){ - + SettingsDialog fSettings(this); + auto *config = wxConfigBase::Get(); + fSettings.setDictPath(config->Read(SETTINGS_KEY_DICT_PATH, SETTINGS_DEFAULT_DICTPATH)); + if ( fSettings.ShowModal() == wxID_OK ){ + if ( config->Read(SETTINGS_KEY_DICT_PATH, SETTINGS_DEFAULT_DICTPATH) != fSettings.getDictPath() ) { + config->Write(SETTINGS_KEY_DICT_PATH, fSettings.getDictPath()); + procDict(fSettings.getDictPath()); + } + } } class MyApp: public wxApp { @@ -201,6 +216,8 @@ bool MyApp::OnInit() SetAppName(wxT("CrossGen")); wxInitAllImageHandlers(); + wxConfigBase *config = new wxFileConfig; + wxConfigBase::Set(config); MainFrame* fMain = new MainFrame(NULL); SetTopWindow(fMain); fMain->Show(); diff --git a/wxCrossGen/settingsconsts.hpp b/wxCrossGen/settingsconsts.hpp new file mode 100644 index 0000000..66673a9 --- /dev/null +++ b/wxCrossGen/settingsconsts.hpp @@ -0,0 +1,9 @@ +#ifndef SETTINGSCONSTS_HPP +#define SETTINGSCONSTS_HPP + +#include + +const wxString SETTINGS_KEY_DICT_PATH = wxT("/Dict/Path"); +const wxString SETTINGS_DEFAULT_DICTPATH = wxT("big_cross_ru.txt"); + +#endif diff --git a/wxCrossGen/wxCrossGen.mk b/wxCrossGen/wxCrossGen.mk index e9fa56b..c0afb24 100644 --- a/wxCrossGen/wxCrossGen.mk +++ b/wxCrossGen/wxCrossGen.mk @@ -13,7 +13,7 @@ CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=Aleksey Lobanov -Date :=18/06/15 +Date :=19/06/15 CodeLitePath :="/home/alex/.codelite" LinkerName :=/usr/bin/g++-4.8 SharedObjectLinkerName :=/usr/bin/g++-4.8 -shared -fPIC diff --git a/wxCrossGen/wxCrossGen.project b/wxCrossGen/wxCrossGen.project index 924e985..e2b8596 100644 --- a/wxCrossGen/wxCrossGen.project +++ b/wxCrossGen/wxCrossGen.project @@ -28,6 +28,8 @@ + + diff --git a/wxCrossGen/wxgui.hpp b/wxCrossGen/wxgui.hpp index 503299d..cd85639 100644 --- a/wxCrossGen/wxgui.hpp +++ b/wxCrossGen/wxgui.hpp @@ -8,10 +8,12 @@ #include #include -#include "crossgen.hpp" - #include "fbgui/fbgui.h" +#include "crossgen.hpp" +#include "fsettings.hpp" + + #ifndef APP_CATALOG #define APP_CATALOG "app" // replace with the appropriate catalog name #endif @@ -29,28 +31,23 @@ protected: public: void SetGridImage(GridType &grid, size_t w=400); - - MainFrame( - wxWindow* parent, - wxWindowID id = wxID_ANY, - const wxString& title = _("CrossGen"), - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxSize( 700,500 ), - long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL ) - : VMainFrame(parent){ - + void procDict(wxString path); + + MainFrame( wxWindow* parent): VMainFrame(parent) { _isDictLoaded = false; srand(time(NULL)); } void onExitClick( wxCloseEvent& event ) { event.Skip(); } void onOpenGridClick( wxCommandEvent& event ); void onGenerateClick( wxCommandEvent& event ); - void onPreferencesClick( wxCommandEvent& event ); + void onSettingsClick( wxCommandEvent& event ); void onExportClick( wxCommandEvent& event ); - void onExitClick( wxCommandEvent& event ) { event.Skip(); } + void onExitClick( wxCommandEvent& event ) { + Close(); + } void onAboutClick( wxCommandEvent& event ) { wxAboutDialogInfo info; - info.AddDeveloper(_("AlekseyLobanov")); + info.AddDeveloper(_("Aleksey Lobanov")); info.SetDescription(_("Simple GUI cross-generation application. Yet another bike")); info.SetName(wxTheApp->GetAppName()); info.SetWebSite(wxT("http://likemath.ru"));