Delete & extract buttons in attachment list will now only be enabled if at least one item is selected.

Originally committed to SVN as r480.
This commit is contained in:
Rodrigo Braz Monteiro 2006-07-08 23:18:07 +00:00
parent caa2dbb01b
commit 7674f3cec9
2 changed files with 30 additions and 4 deletions

View File

@ -53,15 +53,21 @@ DialogAttachments::DialogAttachments(wxWindow *parent)
: wxDialog(parent,-1,_("Attachment List"),wxDefaultPosition,wxDefaultSize) : wxDialog(parent,-1,_("Attachment List"),wxDefaultPosition,wxDefaultSize)
{ {
// List view // List view
listView = new wxListView(this,-1,wxDefaultPosition,wxSize(500,200)); listView = new wxListView(this,ATTACHMENT_LIST,wxDefaultPosition,wxSize(500,200));
UpdateList(); UpdateList();
// Buttons
extractButton = new wxButton(this,BUTTON_EXTRACT,_("E&xtract"));
deleteButton = new wxButton(this,BUTTON_DELETE,_("&Delete"));
extractButton->Enable(false);
deleteButton->Enable(false);
// Buttons sizer // Buttons sizer
wxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL); wxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
buttonSizer->Add(new wxButton(this,BUTTON_ATTACH_FONT,_("Attach &Font")),1,0,0); buttonSizer->Add(new wxButton(this,BUTTON_ATTACH_FONT,_("Attach &Font")),1,0,0);
buttonSizer->Add(new wxButton(this,BUTTON_ATTACH_GRAPHICS,_("Attach &Graphics")),1,0,0); buttonSizer->Add(new wxButton(this,BUTTON_ATTACH_GRAPHICS,_("Attach &Graphics")),1,0,0);
buttonSizer->Add(new wxButton(this,BUTTON_EXTRACT,_("E&xtract")),1,0,0); buttonSizer->Add(extractButton,1,0,0);
buttonSizer->Add(new wxButton(this,BUTTON_DELETE,_("&Delete")),1,0,0); buttonSizer->Add(deleteButton,1,0,0);
buttonSizer->Add(new wxButton(this,BUTTON_CLOSE,_("&Close")),1,wxLEFT,5); buttonSizer->Add(new wxButton(this,BUTTON_CLOSE,_("&Close")),1,wxLEFT,5);
// Main sizer // Main sizer
@ -114,6 +120,9 @@ BEGIN_EVENT_TABLE(DialogAttachments,wxDialog)
EVT_BUTTON(BUTTON_EXTRACT,DialogAttachments::OnExtract) EVT_BUTTON(BUTTON_EXTRACT,DialogAttachments::OnExtract)
EVT_BUTTON(BUTTON_DELETE,DialogAttachments::OnDelete) EVT_BUTTON(BUTTON_DELETE,DialogAttachments::OnDelete)
EVT_BUTTON(BUTTON_CLOSE,DialogAttachments::OnClose) EVT_BUTTON(BUTTON_CLOSE,DialogAttachments::OnClose)
EVT_LIST_ITEM_SELECTED(ATTACHMENT_LIST,DialogAttachments::OnListClick)
EVT_LIST_ITEM_DESELECTED(ATTACHMENT_LIST,DialogAttachments::OnListClick)
EVT_LIST_ITEM_FOCUSED(ATTACHMENT_LIST,DialogAttachments::OnListClick)
END_EVENT_TABLE() END_EVENT_TABLE()
@ -236,3 +245,15 @@ void DialogAttachments::OnDelete(wxCommandEvent &event) {
void DialogAttachments::OnClose(wxCommandEvent &event) { void DialogAttachments::OnClose(wxCommandEvent &event) {
EndModal(0); EndModal(0);
} }
//////////////////////////
// List selection changed
void DialogAttachments::OnListClick(wxListEvent &event) {
// Check if any is selected
bool hasSel = listView->GetFirstSelected() != -1;
// Set status
extractButton->Enable(hasSel);
deleteButton->Enable(hasSel);
}

View File

@ -45,6 +45,7 @@
////////////// //////////////
// Prototypes // Prototypes
class wxListView; class wxListView;
class wxListEvent;
////////////////////// //////////////////////
@ -52,12 +53,15 @@ class wxListView;
class DialogAttachments : public wxDialog { class DialogAttachments : public wxDialog {
private: private:
wxListView *listView; wxListView *listView;
wxButton *extractButton;
wxButton *deleteButton;
void OnAttachFont(wxCommandEvent &event); void OnAttachFont(wxCommandEvent &event);
void OnAttachGraphics(wxCommandEvent &event); void OnAttachGraphics(wxCommandEvent &event);
void OnExtract(wxCommandEvent &event); void OnExtract(wxCommandEvent &event);
void OnDelete(wxCommandEvent &event); void OnDelete(wxCommandEvent &event);
void OnClose(wxCommandEvent &event); void OnClose(wxCommandEvent &event);
void OnListClick(wxListEvent &event);
void UpdateList(); void UpdateList();
@ -76,5 +80,6 @@ enum {
BUTTON_ATTACH_GRAPHICS, BUTTON_ATTACH_GRAPHICS,
BUTTON_EXTRACT, BUTTON_EXTRACT,
BUTTON_DELETE, BUTTON_DELETE,
BUTTON_CLOSE BUTTON_CLOSE,
ATTACHMENT_LIST
}; };