From 7674f3cec9eebe28620f6c6fc4ca5057f8e65bee Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Sat, 8 Jul 2006 23:18:07 +0000 Subject: [PATCH] Delete & extract buttons in attachment list will now only be enabled if at least one item is selected. Originally committed to SVN as r480. --- core/dialog_attachments.cpp | 27 ++++++++++++++++++++++++--- core/dialog_attachments.h | 7 ++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/core/dialog_attachments.cpp b/core/dialog_attachments.cpp index ecdbadd4b..f5f33cbae 100644 --- a/core/dialog_attachments.cpp +++ b/core/dialog_attachments.cpp @@ -53,15 +53,21 @@ DialogAttachments::DialogAttachments(wxWindow *parent) : wxDialog(parent,-1,_("Attachment List"),wxDefaultPosition,wxDefaultSize) { // List view - listView = new wxListView(this,-1,wxDefaultPosition,wxSize(500,200)); + listView = new wxListView(this,ATTACHMENT_LIST,wxDefaultPosition,wxSize(500,200)); 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 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_GRAPHICS,_("Attach &Graphics")),1,0,0); - buttonSizer->Add(new wxButton(this,BUTTON_EXTRACT,_("E&xtract")),1,0,0); - buttonSizer->Add(new wxButton(this,BUTTON_DELETE,_("&Delete")),1,0,0); + buttonSizer->Add(extractButton,1,0,0); + buttonSizer->Add(deleteButton,1,0,0); buttonSizer->Add(new wxButton(this,BUTTON_CLOSE,_("&Close")),1,wxLEFT,5); // Main sizer @@ -114,6 +120,9 @@ BEGIN_EVENT_TABLE(DialogAttachments,wxDialog) EVT_BUTTON(BUTTON_EXTRACT,DialogAttachments::OnExtract) EVT_BUTTON(BUTTON_DELETE,DialogAttachments::OnDelete) 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() @@ -236,3 +245,15 @@ void DialogAttachments::OnDelete(wxCommandEvent &event) { void DialogAttachments::OnClose(wxCommandEvent &event) { 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); +} diff --git a/core/dialog_attachments.h b/core/dialog_attachments.h index 9c8198aed..a7296601c 100644 --- a/core/dialog_attachments.h +++ b/core/dialog_attachments.h @@ -45,6 +45,7 @@ ////////////// // Prototypes class wxListView; +class wxListEvent; ////////////////////// @@ -52,12 +53,15 @@ class wxListView; class DialogAttachments : public wxDialog { private: wxListView *listView; + wxButton *extractButton; + wxButton *deleteButton; void OnAttachFont(wxCommandEvent &event); void OnAttachGraphics(wxCommandEvent &event); void OnExtract(wxCommandEvent &event); void OnDelete(wxCommandEvent &event); void OnClose(wxCommandEvent &event); + void OnListClick(wxListEvent &event); void UpdateList(); @@ -76,5 +80,6 @@ enum { BUTTON_ATTACH_GRAPHICS, BUTTON_EXTRACT, BUTTON_DELETE, - BUTTON_CLOSE + BUTTON_CLOSE, + ATTACHMENT_LIST };