A lot of changes, finished Settings dialog.

This commit is contained in:
2015-06-19 12:39:52 +03:00
parent 6a6814fb9f
commit 378655c361
9 changed files with 103 additions and 28 deletions

View File

@@ -571,7 +571,7 @@
<property name="minimum_size"></property>
<property name="name">VSettingsDialog</property>
<property name="pos"></property>
<property name="size">426,224</property>
<property name="size">425,120</property>
<property name="style">wxDEFAULT_DIALOG_STYLE</property>
<property name="subclass"></property>
<property name="title">Settings</property>
@@ -629,7 +629,7 @@
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL</property>
<property name="flag">wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<property name="bg"></property>

View File

@@ -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 );

View File

@@ -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();
};

50
wxCrossGen/fsettings.hpp Normal file
View File

@@ -0,0 +1,50 @@
#ifndef FSETTINGS_HPP
#define FSETTINGS_HPP
#include <wx/wx.h>
#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

View File

@@ -7,11 +7,21 @@
#include <wx/wx.h>
#include <wx/wfstream.h>
#include <wx/textfile.h>
#include <wx/fileconf.h>
#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<wxString> 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();

View File

@@ -0,0 +1,9 @@
#ifndef SETTINGSCONSTS_HPP
#define SETTINGSCONSTS_HPP
#include <wx/wx.h>
const wxString SETTINGS_KEY_DICT_PATH = wxT("/Dict/Path");
const wxString SETTINGS_DEFAULT_DICTPATH = wxT("big_cross_ru.txt");
#endif

View File

@@ -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

View File

@@ -28,6 +28,8 @@
<VirtualDirectory Name="src">
<File Name="main.cpp"/>
<File Name="wxgui.hpp"/>
<File Name="fsettings.hpp"/>
<File Name="settingsconsts.hpp"/>
</VirtualDirectory>
<VirtualDirectory Name="Shared">
<File Name="../src/crossgen.hpp"/>

View File

@@ -8,10 +8,12 @@
#include <wx/intl.h>
#include <wx/aboutdlg.h>
#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,25 +31,20 @@ protected:
public:
void SetGridImage(GridType &grid, size_t w=400);
void procDict(wxString path);
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){
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(_("Aleksey Lobanov"));