| 1 |
#include "virtual_folder_picker_ctrl.h" |
| 2 |
#include "VirtualDirectorySelectorDlg.h" |
| 3 |
#include <event_notifier.h> |
| 4 |
#include <workspace.h> |
| 5 |
#include <wx/filedlg.h> |
| 6 |
#include <wx/filename.h> |
| 7 |
|
| 8 |
const wxEventType wxEVT_VIRTUAL_FOLDER_PICKED = wxNewEventType(); |
| 9 |
|
| 10 |
VirtualFolderPickerCtrl::VirtualFolderPickerCtrl(wxWindow* parent, const wxString& path) |
| 11 |
: wxTextCtrl(parent, wxID_ANY, path, wxDefaultPosition, wxDefaultSize, wxTE_RICH2 | wxTE_PROCESS_ENTER) |
| 12 |
, m_virtualFolder(path) |
| 13 |
{ |
| 14 |
this->Connect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(VirtualFolderPickerCtrl::OnTextEnter), NULL, this); |
| 15 |
this->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(VirtualFolderPickerCtrl::OnMouseLeft), NULL, this); |
| 16 |
SetEditable(true); |
| 17 |
wxTextCtrl::ChangeValue(path); |
| 18 |
SetEditable(false); |
| 19 |
} |
| 20 |
|
| 21 |
VirtualFolderPickerCtrl::~VirtualFolderPickerCtrl() |
| 22 |
{ |
| 23 |
this->Disconnect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(VirtualFolderPickerCtrl::OnTextEnter), NULL, this); |
| 24 |
this->Disconnect(wxEVT_LEFT_DOWN, wxMouseEventHandler(VirtualFolderPickerCtrl::OnMouseLeft), NULL, this); |
| 25 |
} |
| 26 |
|
| 27 |
void VirtualFolderPickerCtrl::OnTextEnter(wxCommandEvent& e) { DoNotify(); } |
| 28 |
|
| 29 |
void VirtualFolderPickerCtrl::OnMouseLeft(wxMouseEvent& event) { DoEdit(); } |
| 30 |
|
| 31 |
void VirtualFolderPickerCtrl::DoEdit() |
| 32 |
{ |
| 33 |
wxString str = wxTextCtrl::GetValue(); |
| 34 |
str.Trim().Trim(false); |
| 35 |
|
| 36 |
VirtualDirectorySelectorDlg selector(EventNotifier::Get()->TopFrame(), clCxxWorkspaceST::Get(), m_virtualFolder); |
| 37 |
if(selector.ShowModal() == wxID_OK) { |
| 38 |
m_virtualFolder = selector.GetVirtualDirectoryPath(); |
| 39 |
SetEditable(true); |
| 40 |
wxTextCtrl::ChangeValue(m_virtualFolder); |
| 41 |
SetEditable(false); |
| 42 |
DoNotify(); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
void VirtualFolderPickerCtrl::DoNotify() |
| 47 |
{ |
| 48 |
wxCommandEvent event(wxEVT_VIRTUAL_FOLDER_PICKED); |
| 49 |
event.SetString(GetValue()); |
| 50 |
event.SetEventObject(this); |
| 51 |
GetEventHandler()->AddPendingEvent(event); |
| 52 |
} |