2002-04-07 10:50:00 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wxedit.cpp
|
|
|
|
// Author: Robert Roebling
|
|
|
|
// Created: 04/07/02
|
2004-10-06 16:54:57 -04:00
|
|
|
// Copyright:
|
2002-04-07 10:50:00 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// For compilers that support precompilation
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
2002-04-07 16:46:55 -04:00
|
|
|
#include "wx/filename.h"
|
2002-04-10 12:01:39 -04:00
|
|
|
#include "wx/config.h"
|
2002-04-07 16:46:55 -04:00
|
|
|
|
2002-04-07 10:50:00 -04:00
|
|
|
// Include private headers
|
|
|
|
#include "wxedit.h"
|
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define HISTORY_ENTRIES 3
|
|
|
|
|
2002-04-07 10:50:00 -04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// MyFrame
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyFrame,wxFrame)
|
|
|
|
EVT_MENU(ID_ABOUT, MyFrame::OnAbout)
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-07 10:50:00 -04:00
|
|
|
EVT_MENU(ID_NEW, MyFrame::OnNew)
|
|
|
|
EVT_MENU(ID_OPEN, MyFrame::OnOpen)
|
|
|
|
EVT_MENU(ID_SAVE, MyFrame::OnSave)
|
|
|
|
EVT_MENU(ID_SAVEAS, MyFrame::OnSaveAs)
|
|
|
|
EVT_MENU(ID_QUIT, MyFrame::OnQuit)
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-08 17:48:29 -04:00
|
|
|
EVT_MENU(ID_COPY, MyFrame::OnCopy)
|
|
|
|
EVT_MENU(ID_CUT, MyFrame::OnCut)
|
|
|
|
EVT_MENU(ID_PASTE, MyFrame::OnPaste)
|
|
|
|
EVT_MENU(ID_DELETE, MyFrame::OnDelete)
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
EVT_MENU_RANGE(ID_LAST_1, ID_LAST_3, MyFrame::OnLastFiles)
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-07 10:50:00 -04:00
|
|
|
EVT_CLOSE(MyFrame::OnCloseWindow)
|
2004-05-25 15:25:01 -04:00
|
|
|
EVT_UPDATE_UI(wxID_ANY,MyFrame::OnUpdateUI)
|
2002-04-07 10:50:00 -04:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
MyFrame::MyFrame( wxWindow *parent, wxWindowID id, const wxString &title,
|
|
|
|
const wxPoint &position, const wxSize& size, long style ) :
|
|
|
|
wxFrame( parent, id, title, position, size, style )
|
|
|
|
{
|
2002-04-10 12:01:39 -04:00
|
|
|
// Create menu and status bar.
|
2002-04-07 10:50:00 -04:00
|
|
|
CreateMyMenuBar();
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2002-04-07 10:50:00 -04:00
|
|
|
CreateStatusBar(1);
|
2003-08-14 13:35:49 -04:00
|
|
|
SetStatusText( _T("Welcome to wxEdit!") );
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
// Create edit control. Since it is the only
|
|
|
|
// control in the frame, it will be resized
|
|
|
|
// to file it out.
|
2005-08-24 13:47:11 -04:00
|
|
|
m_text = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
// Read .ini file for file history etc.
|
|
|
|
wxConfig *conf = (wxConfig*) wxConfig::Get();
|
|
|
|
|
2004-10-06 16:54:57 -04:00
|
|
|
int entries = 0;
|
2003-08-14 13:35:49 -04:00
|
|
|
conf->Read( _T("/History/Count"), &entries );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
for (int i = 0; i < entries; i++)
|
|
|
|
{
|
|
|
|
wxString tmp;
|
2003-08-14 13:35:49 -04:00
|
|
|
tmp.Printf( _T("/History/File%d"), (int)i );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
wxString res;
|
|
|
|
conf->Read( tmp, &res );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
if (!res.empty())
|
|
|
|
AddToHistory( res );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::MakeHistory()
|
|
|
|
{
|
|
|
|
wxMenuBar *mb = GetMenuBar();
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
wxASSERT( mb );
|
|
|
|
|
|
|
|
int max = m_history.GetCount();
|
|
|
|
if (max > HISTORY_ENTRIES)
|
|
|
|
max = HISTORY_ENTRIES;
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
for (int i = 0; i < max; i++)
|
|
|
|
{
|
|
|
|
wxMenu *menu = NULL;
|
|
|
|
mb->FindItem( ID_LAST_1 + i, &menu );
|
|
|
|
wxASSERT( menu );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
wxFileName fname( m_history[(size_t)i] );
|
|
|
|
menu->SetLabel( ID_LAST_1 + i, fname.GetFullName() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::AddToHistory( const wxString &fname )
|
|
|
|
{
|
|
|
|
// Fill menu with history index
|
|
|
|
int index = m_history.Index( fname );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
if (index != wxNOT_FOUND)
|
2004-05-25 15:25:01 -04:00
|
|
|
m_history.RemoveAt( (size_t) index );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
m_history.Insert( fname, 0 );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
// Update menu
|
|
|
|
MakeHistory();
|
2002-04-07 10:50:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::CreateMyMenuBar()
|
|
|
|
{
|
|
|
|
wxMenu *file_menu = new wxMenu;
|
2003-08-14 13:35:49 -04:00
|
|
|
file_menu->Append( ID_ABOUT, _T("About..."), _T("Program info") );
|
2002-04-07 10:50:00 -04:00
|
|
|
file_menu->AppendSeparator();
|
2003-08-14 13:35:49 -04:00
|
|
|
file_menu->Append( ID_NEW, _T("New..."), _T("New text") );
|
|
|
|
file_menu->Append( ID_OPEN, _T("Open..."), _T("Open text") );
|
|
|
|
file_menu->Append( ID_SAVE, _T("Save"), _T("Save text") );
|
|
|
|
file_menu->Append( ID_SAVEAS, _T("Save as..."), _T("Save text as...") );
|
2002-04-07 10:50:00 -04:00
|
|
|
file_menu->AppendSeparator();
|
2003-08-14 13:35:49 -04:00
|
|
|
file_menu->Append( ID_QUIT, _T("Quit..."), _T("Quit program") );
|
2002-04-10 12:01:39 -04:00
|
|
|
|
|
|
|
wxMenu *edit_menu = new wxMenu;
|
2003-08-14 13:35:49 -04:00
|
|
|
edit_menu->Append( ID_COPY, _T("Copy") );
|
|
|
|
edit_menu->Append( ID_CUT, _T("Cut") );
|
|
|
|
edit_menu->Append( ID_PASTE, _T("Paste") );
|
2002-04-10 12:01:39 -04:00
|
|
|
edit_menu->AppendSeparator();
|
2003-08-14 13:35:49 -04:00
|
|
|
edit_menu->Append( ID_DELETE, _T("Delete") );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
wxMenu *history_menu = new wxMenu;
|
2003-08-14 13:35:49 -04:00
|
|
|
history_menu->Append( ID_LAST_1, _T("No file.") );
|
|
|
|
history_menu->Append( ID_LAST_2, _T("No file.") );
|
|
|
|
history_menu->Append( ID_LAST_3, _T("No file.") );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-07 10:50:00 -04:00
|
|
|
wxMenuBar *menu_bar = new wxMenuBar();
|
2003-08-14 13:35:49 -04:00
|
|
|
menu_bar->Append( file_menu, _T("&File") );
|
|
|
|
menu_bar->Append( edit_menu, _T("&Edit") );
|
|
|
|
menu_bar->Append( history_menu, _T("&History") );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-07 10:50:00 -04:00
|
|
|
SetMenuBar( menu_bar );
|
|
|
|
}
|
|
|
|
|
2003-12-11 06:25:46 -05:00
|
|
|
void MyFrame::OnCopy( wxCommandEvent& WXUNUSED(event) )
|
2002-04-08 17:48:29 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-12-11 06:25:46 -05:00
|
|
|
void MyFrame::OnCut( wxCommandEvent& WXUNUSED(event) )
|
2002-04-08 17:48:29 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-12-11 06:25:46 -05:00
|
|
|
void MyFrame::OnPaste( wxCommandEvent& WXUNUSED(event) )
|
2002-04-08 17:48:29 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-12-11 06:25:46 -05:00
|
|
|
void MyFrame::OnDelete( wxCommandEvent& WXUNUSED(event) )
|
2002-04-08 17:48:29 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
void MyFrame::OnLastFiles( wxCommandEvent &event )
|
2002-04-08 17:48:29 -04:00
|
|
|
{
|
2002-04-10 12:01:39 -04:00
|
|
|
if (!Discard()) return;
|
2002-04-08 17:48:29 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
if (!m_filename.empty())
|
|
|
|
AddToHistory( m_filename );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
size_t index = event.GetId() - ID_LAST_1;
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2003-12-11 06:25:46 -05:00
|
|
|
if( index < m_history.GetCount() )
|
|
|
|
{
|
2004-07-19 11:36:01 -04:00
|
|
|
m_filename = m_history[index];
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2004-07-19 11:36:01 -04:00
|
|
|
m_text->Clear();
|
|
|
|
m_text->LoadFile( m_filename );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
|
|
|
SetStatusText( m_filename );
|
|
|
|
#endif // wxUSE_STATUSBAR
|
2003-12-11 06:25:46 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxMessageBox(
|
|
|
|
_T("This entry is empty. It should be filled once you will start opening."),
|
|
|
|
_T("Empty entry"),
|
|
|
|
wxOK | wxICON_INFORMATION,
|
|
|
|
this
|
|
|
|
);
|
|
|
|
}
|
2002-04-08 17:48:29 -04:00
|
|
|
}
|
|
|
|
|
2003-12-11 06:25:46 -05:00
|
|
|
void MyFrame::OnNew( wxCommandEvent& WXUNUSED(event) )
|
2002-04-07 10:50:00 -04:00
|
|
|
{
|
2002-04-08 17:48:29 -04:00
|
|
|
if (!Discard()) return;
|
|
|
|
|
2002-04-07 10:50:00 -04:00
|
|
|
m_text->Clear();
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
if (!m_filename.empty())
|
|
|
|
AddToHistory( m_filename );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
m_filename = wxEmptyString;
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2005-08-24 13:47:11 -04:00
|
|
|
SetStatusText( wxEmptyString );
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2002-04-07 10:50:00 -04:00
|
|
|
}
|
|
|
|
|
2003-12-11 06:25:46 -05:00
|
|
|
void MyFrame::OnOpen( wxCommandEvent& WXUNUSED(event) )
|
2002-04-07 10:50:00 -04:00
|
|
|
{
|
2005-08-24 13:47:11 -04:00
|
|
|
#if wxUSE_FILEDLG
|
2002-04-10 12:01:39 -04:00
|
|
|
if (!Discard()) return;
|
|
|
|
|
2005-08-24 13:47:11 -04:00
|
|
|
wxFileDialog dialog( this, _T("Open text"), wxEmptyString, wxEmptyString,
|
2003-08-14 13:35:49 -04:00
|
|
|
_T("Text file (*.txt)|*.txt|Any file (*)|*"),
|
2006-05-28 19:32:12 -04:00
|
|
|
wxFD_OPEN|wxFD_FILE_MUST_EXIST );
|
2002-04-07 16:46:55 -04:00
|
|
|
if (dialog.ShowModal() == wxID_OK)
|
|
|
|
{
|
|
|
|
m_text->Clear();
|
|
|
|
|
|
|
|
#ifdef __WXX11__
|
2005-04-07 10:39:17 -04:00
|
|
|
// requires wxUSE_UNIV_TEXTCTRL to be set to 0
|
|
|
|
#if 0
|
2002-04-07 16:46:55 -04:00
|
|
|
wxFileName fname( dialog.GetPath() );
|
2003-08-14 13:35:49 -04:00
|
|
|
if ((fname.GetExt() == _T("cpp")) ||
|
|
|
|
(fname.GetExt() == _T("c")) ||
|
|
|
|
(fname.GetExt() == _T("h")) ||
|
|
|
|
(fname.GetExt() == _T("cxx")) ||
|
|
|
|
(fname.GetExt() == _T("hxx")))
|
2002-04-07 16:46:55 -04:00
|
|
|
{
|
|
|
|
m_text->SetLanguage( wxSOURCE_LANG_CPP );
|
|
|
|
}
|
|
|
|
else
|
2003-08-14 13:35:49 -04:00
|
|
|
if (fname.GetExt() == _T("py"))
|
2002-04-07 16:46:55 -04:00
|
|
|
{
|
|
|
|
m_text->SetLanguage( wxSOURCE_LANG_PYTHON );
|
|
|
|
}
|
|
|
|
else
|
2003-08-14 13:35:49 -04:00
|
|
|
if ((fname.GetExt() == _T("pl")) ||
|
|
|
|
(fname.GetExt() == _T("pm")))
|
2002-04-07 16:46:55 -04:00
|
|
|
{
|
|
|
|
m_text->SetLanguage( wxSOURCE_LANG_PYTHON );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_text->SetLanguage( wxSOURCE_LANG_NONE );
|
|
|
|
}
|
2005-04-07 10:39:17 -04:00
|
|
|
#endif
|
2002-04-07 16:46:55 -04:00
|
|
|
#endif
|
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
m_filename = dialog.GetPath();
|
|
|
|
m_text->LoadFile( m_filename );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2002-04-10 12:01:39 -04:00
|
|
|
SetStatusText( m_filename );
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2002-04-07 16:46:55 -04:00
|
|
|
}
|
2005-08-24 13:47:11 -04:00
|
|
|
#endif // wxUSE_FILEDLG
|
2002-04-07 10:50:00 -04:00
|
|
|
}
|
|
|
|
|
2003-12-11 06:25:46 -05:00
|
|
|
void MyFrame::OnSave( wxCommandEvent& WXUNUSED(event) )
|
2002-04-07 10:50:00 -04:00
|
|
|
{
|
2002-09-03 16:36:58 -04:00
|
|
|
Save();
|
2002-04-07 10:50:00 -04:00
|
|
|
}
|
|
|
|
|
2003-12-11 06:25:46 -05:00
|
|
|
void MyFrame::OnSaveAs( wxCommandEvent& WXUNUSED(event) )
|
2002-04-07 10:50:00 -04:00
|
|
|
{
|
2005-08-24 13:47:11 -04:00
|
|
|
#if wxUSE_FILEDLG
|
|
|
|
wxFileDialog dialog( this, _T("Open text"), wxEmptyString, wxEmptyString,
|
2003-08-14 13:35:49 -04:00
|
|
|
_T("Text file (*.txt)|*.txt|Any file (*)|*"),
|
2006-05-28 19:32:12 -04:00
|
|
|
wxFD_SAVE|wxFD_OVERWRITE_PROMPT );
|
2002-04-10 12:01:39 -04:00
|
|
|
if (dialog.ShowModal() == wxID_OK)
|
|
|
|
{
|
|
|
|
m_filename = dialog.GetPath();
|
|
|
|
m_text->SaveFile( m_filename );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2002-04-10 12:01:39 -04:00
|
|
|
SetStatusText( m_filename );
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
2002-04-10 12:01:39 -04:00
|
|
|
}
|
2005-08-24 13:47:11 -04:00
|
|
|
#endif // wxUSE_FILEDLG
|
2002-04-07 10:50:00 -04:00
|
|
|
}
|
|
|
|
|
2003-12-11 06:25:46 -05:00
|
|
|
void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
|
2002-04-07 10:50:00 -04:00
|
|
|
{
|
2003-08-14 13:35:49 -04:00
|
|
|
wxMessageDialog dialog( this, _T("Welcome to wxEdit\n(C)opyright Robert Roebling"),
|
|
|
|
_T("About wxEdit"), wxOK|wxICON_INFORMATION );
|
2002-04-07 10:50:00 -04:00
|
|
|
dialog.ShowModal();
|
|
|
|
}
|
|
|
|
|
2003-12-11 06:25:46 -05:00
|
|
|
void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) )
|
2002-04-07 10:50:00 -04:00
|
|
|
{
|
2004-05-25 15:25:01 -04:00
|
|
|
Close( true );
|
2002-04-07 10:50:00 -04:00
|
|
|
}
|
|
|
|
|
2002-04-08 17:48:29 -04:00
|
|
|
bool MyFrame::Save()
|
|
|
|
{
|
2002-09-03 16:36:58 -04:00
|
|
|
wxCommandEvent event;
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-09-03 16:36:58 -04:00
|
|
|
if (m_filename.empty())
|
|
|
|
OnSaveAs( event );
|
|
|
|
else
|
|
|
|
m_text->SaveFile( m_filename );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2004-05-25 15:25:01 -04:00
|
|
|
return true;
|
2002-04-08 17:48:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MyFrame::Discard()
|
2002-04-07 10:50:00 -04:00
|
|
|
{
|
2002-04-08 17:48:29 -04:00
|
|
|
if (m_text->IsModified())
|
|
|
|
{
|
2003-08-14 13:35:49 -04:00
|
|
|
wxMessageDialog dialog( this, _T("Text has been\nmodified! Save?"),
|
|
|
|
_T("wxEdit"), wxYES_NO|wxCANCEL|wxICON_EXCLAMATION );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-08 17:48:29 -04:00
|
|
|
int ret = dialog.ShowModal();
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-08 17:48:29 -04:00
|
|
|
if (ret == wxID_CANCEL)
|
2004-05-25 15:25:01 -04:00
|
|
|
return false;
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-08 17:48:29 -04:00
|
|
|
if (ret == wxID_YES)
|
|
|
|
{
|
|
|
|
if (!Save())
|
2004-05-25 15:25:01 -04:00
|
|
|
return false;
|
2002-04-08 17:48:29 -04:00
|
|
|
}
|
|
|
|
}
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2004-05-25 15:25:01 -04:00
|
|
|
return true;
|
2002-04-08 17:48:29 -04:00
|
|
|
}
|
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
void MyFrame::OnUpdateUI( wxUpdateUIEvent &event )
|
|
|
|
{
|
|
|
|
switch (event.GetId())
|
|
|
|
{
|
|
|
|
case ID_COPY:
|
2004-05-25 15:25:01 -04:00
|
|
|
event.Enable( false );
|
2002-04-10 12:01:39 -04:00
|
|
|
break;
|
|
|
|
case ID_CUT:
|
2004-05-25 15:25:01 -04:00
|
|
|
event.Enable( false );
|
2002-04-10 12:01:39 -04:00
|
|
|
break;
|
|
|
|
case ID_PASTE:
|
2004-05-25 15:25:01 -04:00
|
|
|
event.Enable( false );
|
2002-04-10 12:01:39 -04:00
|
|
|
break;
|
|
|
|
case ID_DELETE:
|
2002-08-24 06:01:47 -04:00
|
|
|
#ifdef __WXUNIVERSAL__
|
2002-04-10 12:01:39 -04:00
|
|
|
event.Enable( m_text->HasSelection() );
|
2002-08-24 06:01:47 -04:00
|
|
|
#else
|
|
|
|
{
|
|
|
|
long selFrom, selTo;
|
|
|
|
m_text->GetSelection(& selFrom, & selTo);
|
|
|
|
event.Enable( selFrom != selTo );
|
|
|
|
}
|
2004-10-06 16:54:57 -04:00
|
|
|
#endif
|
2002-04-10 12:01:39 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-11 06:25:46 -05:00
|
|
|
void MyFrame::OnCloseWindow( wxCloseEvent& WXUNUSED(event) )
|
2002-04-08 17:48:29 -04:00
|
|
|
{
|
2002-04-10 12:01:39 -04:00
|
|
|
// Save changes?
|
2004-10-06 16:54:57 -04:00
|
|
|
if (!Discard()) return;
|
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
// Add current to history
|
|
|
|
if (!m_filename.empty())
|
|
|
|
AddToHistory( m_filename );
|
2002-04-08 17:48:29 -04:00
|
|
|
|
2004-10-06 16:54:57 -04:00
|
|
|
// Write .ini file
|
2002-04-10 12:01:39 -04:00
|
|
|
wxConfig *conf = (wxConfig*) wxConfig::Get();
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
int max = HISTORY_ENTRIES;
|
|
|
|
if (m_history.GetCount() < (size_t)max)
|
|
|
|
max = m_history.GetCount();
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2003-08-14 13:35:49 -04:00
|
|
|
conf->Write( _T("/History/Count"), max );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
for (int i = 0; i < max; i++)
|
|
|
|
{
|
|
|
|
wxString tmp;
|
2003-08-14 13:35:49 -04:00
|
|
|
tmp.Printf( _T("/History/File%d"), (int)i );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
conf->Write( tmp, m_history[(size_t)i] );
|
|
|
|
}
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2002-04-10 12:01:39 -04:00
|
|
|
// Flush and delete config
|
|
|
|
delete wxConfig::Set( NULL );
|
|
|
|
|
|
|
|
// Finally destroy window and quit
|
2002-04-07 10:50:00 -04:00
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// MyApp
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
2003-08-14 13:35:49 -04:00
|
|
|
SetVendorName(_T("Free world"));
|
|
|
|
SetAppName(_T("wxEdit"));
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2004-05-25 15:25:01 -04:00
|
|
|
MyFrame *frame = new MyFrame( NULL, wxID_ANY, _T("wxEdit"), wxPoint(20,20), wxSize(500,340) );
|
|
|
|
frame->Show( true );
|
2004-10-06 16:54:57 -04:00
|
|
|
|
2004-05-25 15:25:01 -04:00
|
|
|
return true;
|
2002-04-07 10:50:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int MyApp::OnExit()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|