2025-06-28 17:40:42 +02:00
|
|
|
// /*
|
|
|
|
|
// * File: XS7.cpp
|
|
|
|
|
// * Author: Saleem Edah-Tally - nmset@yandex.com
|
|
|
|
|
// * License : CeCILL
|
|
|
|
|
// * Copyright Saleem Edah-Tally - © 2023
|
|
|
|
|
// *
|
|
|
|
|
// * Created on 18 06 2025, 22:42
|
|
|
|
|
// */
|
|
|
|
|
|
|
|
|
|
#include "XS7.h"
|
|
|
|
|
#include "globals.h"
|
|
|
|
|
#include "TimeredStatusBar.h"
|
|
|
|
|
#include "MiscTools.h"
|
|
|
|
|
#include "page.xpm"
|
|
|
|
|
#include <wx/stdpaths.h>
|
|
|
|
|
#include <wx/cmdline.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
2025-07-01 22:38:07 +02:00
|
|
|
IMPLEMENT_CLASS( XS7, S7 )
|
|
|
|
|
|
2025-06-28 17:40:42 +02:00
|
|
|
XS7::XS7(wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style)
|
|
|
|
|
: S7(parent, id, caption, pos, size, style)
|
|
|
|
|
{}
|
|
|
|
|
|
2025-07-13 12:46:36 +02:00
|
|
|
void XS7::Setup(wxConfig * config)
|
2025-06-28 17:40:42 +02:00
|
|
|
{
|
2025-07-13 12:46:36 +02:00
|
|
|
m_config = config;
|
2025-06-28 17:40:42 +02:00
|
|
|
TimeredStatusBar * sb = new TimeredStatusBar(this);
|
|
|
|
|
SetStatusBar(sb);
|
|
|
|
|
|
2025-07-13 12:46:36 +02:00
|
|
|
m_insaneWidget = new XInsaneWidget(panMain, sb, m_config);
|
2025-07-01 22:38:07 +02:00
|
|
|
m_insaneWidget->Setup();
|
|
|
|
|
szMain->Insert(2, m_insaneWidget, 1, wxGROW | wxALL);
|
2025-06-28 17:40:42 +02:00
|
|
|
|
|
|
|
|
dpkDestination->Bind ( wxEVT_DIRPICKER_CHANGED, &XS7::OnDpkRepositoryChange, this );
|
|
|
|
|
dpkDestination->GetTextCtrl()->Bind ( wxEVT_LEFT_DCLICK, &XS7::OnDpkDoubleClick, this );
|
|
|
|
|
Bind(wxEVT_CHAR_HOOK, &XS7::OnAppKeyPressed, this);
|
|
|
|
|
m_insaneWidget->lblNewDoc->Bind ( wxEVT_LEFT_UP, &XS7::OnNewDocLeftClick, this );
|
|
|
|
|
dpkDestination->SetPath(m_config->Read("/Docroot"));
|
|
|
|
|
|
|
|
|
|
txtBasename->SetValidator(*MiscTools::MakeFileNameValidator(false));
|
|
|
|
|
txtBasename->Bind(wxEVT_LEFT_UP, &XS7::OnAbout, this);
|
2025-07-13 12:46:36 +02:00
|
|
|
MiscTools::RestoreSizePos(m_config, this, wxString("/" + wxString(_APPNAME_)));
|
2025-06-28 17:40:42 +02:00
|
|
|
|
|
|
|
|
S7::SetTitle(wxString(_APPNAME_) + " - version " + to_string(_APPVERSION_));
|
|
|
|
|
|
|
|
|
|
SetIcon(wxICON(page));
|
|
|
|
|
wxString fixedTip = _("'Shift + left' click to generate a new destination file name.");
|
|
|
|
|
fixedTip += _T("\n") + m_insaneWidget->lblNewDoc->GetToolTipText();
|
|
|
|
|
m_insaneWidget->lblNewDoc->SetToolTip(fixedTip);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XS7::~XS7()
|
|
|
|
|
{
|
|
|
|
|
if (m_config)
|
2025-07-13 12:46:36 +02:00
|
|
|
MiscTools::SaveSizePos(m_config, this, wxString("/") + _APPNAME_);
|
2025-06-28 17:40:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void XS7::OnDpkRepositoryChange ( wxFileDirPickerEvent& evt )
|
|
|
|
|
{
|
|
|
|
|
m_config->Write ( _T ( "/DocRoot" ), dpkDestination->GetPath() );
|
|
|
|
|
m_config->Flush();
|
|
|
|
|
evt.Skip();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void XS7::OnDpkDoubleClick ( wxMouseEvent& evt )
|
|
|
|
|
{
|
|
|
|
|
const wxString command = _T ( "xdg-open " ) + dpkDestination->GetPath();
|
|
|
|
|
if ( wxExecute ( command ) == 0 )
|
|
|
|
|
{
|
|
|
|
|
const wxString msg = _( "Could not launch default file manager" );
|
|
|
|
|
MiscTools::MessageBox( msg, true );
|
|
|
|
|
cerr << msg << endl;
|
|
|
|
|
}
|
|
|
|
|
evt.Skip();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void XS7::OnAppKeyPressed(wxKeyEvent& evt)
|
|
|
|
|
{
|
2025-07-09 17:16:30 +02:00
|
|
|
if (evt.ControlDown())
|
|
|
|
|
{
|
|
|
|
|
if (evt.GetKeyCode() == 'Q')
|
|
|
|
|
Close();
|
|
|
|
|
}
|
2025-06-28 17:40:42 +02:00
|
|
|
if (evt.GetKeyCode() == WXK_ESCAPE)
|
|
|
|
|
if (m_insaneWidget)
|
|
|
|
|
m_insaneWidget->CancelScanning();
|
|
|
|
|
evt.Skip();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void XS7::OnNewDocLeftClick ( wxMouseEvent& evt )
|
|
|
|
|
{
|
2025-07-11 21:10:59 +02:00
|
|
|
if ( !evt.ShiftDown() || !m_insaneWidget->lblNewDoc->IsEnabled() )
|
2025-06-28 17:40:42 +02:00
|
|
|
{
|
|
|
|
|
evt.Skip();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( !dpkDestination->GetDirName().Exists() )
|
|
|
|
|
{
|
|
|
|
|
const wxString msg = _( "Invalid folder name." );
|
|
|
|
|
MiscTools::MessageBox ( msg, true );
|
|
|
|
|
cerr << msg << endl;
|
|
|
|
|
evt.Skip();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( txtBasename->GetValue().IsEmpty() )
|
|
|
|
|
{
|
|
|
|
|
const wxString msg = _( "Invalid file basename." );
|
|
|
|
|
MiscTools::MessageBox ( msg, true );
|
|
|
|
|
cerr << msg << endl;
|
|
|
|
|
evt.Skip();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const wxString filepath = dpkDestination->GetPath() + wxFileName::GetPathSeparator() + txtBasename->GetValue();
|
|
|
|
|
|
|
|
|
|
m_insaneWidget->txtNewDoc->SetValue ( filepath );
|
|
|
|
|
m_insaneWidget->ResetScanProject();
|
|
|
|
|
evt.Skip();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void XS7::OnAbout(wxMouseEvent& evt)
|
|
|
|
|
{
|
|
|
|
|
if (!evt.ControlDown())
|
|
|
|
|
{
|
|
|
|
|
evt.Skip();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const wxString msg = wxString(_APPNAME_) + _(" - version ") + to_string((_APPVERSION_))
|
|
|
|
|
+ _ (", using InsaneWidget.\n\n")
|
|
|
|
|
+ _ ( "Copyright: Saleem Edah-Tally [Surgeon] [Hobbyist developer]\n" )
|
|
|
|
|
+ _ ( "License: CeCILL/CeCILL-C per file header." );
|
|
|
|
|
|
|
|
|
|
MiscTools::MessageBox(msg);
|
|
|
|
|
evt.Skip();
|
|
|
|
|
}
|