Update of /cvsroot/mahogany/M/src/gui
In directory sc8-pr-cvs1:/tmp/cvs-serv5682/src/gui

Modified Files:
        wxComposeView.cpp 
Log Message:
added popup menu for the attachments in the composer (bug 828)

Index: wxComposeView.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/gui/wxComposeView.cpp,v
retrieving revision 1.346
retrieving revision 1.347
diff -b -u -2 -r1.346 -r1.347
--- wxComposeView.cpp   30 Sep 2003 13:46:19 -0000      1.346
+++ wxComposeView.cpp   1 Oct 2003 00:35:13 -0000       1.347
@@ -615,4 +615,30 @@
 
 // ----------------------------------------------------------------------------
+// AttachmentMenu is the popup menu shown when an attachment is right clicked
+// ----------------------------------------------------------------------------
+
+class AttachmentMenu : public wxMenu
+{
+public:
+   // win is the window we're shown in and the part is the attachment we're
+   // shown for
+   AttachmentMenu(wxWindow *win, EditorContentPart *part);
+
+   // callbacks
+   void OnCommandEvent(wxCommandEvent &event);
+
+   // operations: this is static as it's also reused from
+   // MessageEditor::EditAttachmentProperties()
+   static void ShowAttachmentProperties(wxWindow *win, EditorContentPart *part);
+
+private:
+   wxWindow *m_window;
+   EditorContentPart *m_part;
+
+   DECLARE_EVENT_TABLE()
+   DECLARE_NO_COPY_CLASS(AttachmentMenu)
+};
+
+// ----------------------------------------------------------------------------
 // event tables &c
 // ----------------------------------------------------------------------------
@@ -661,4 +687,92 @@
 
 // ============================================================================
+// AttachmentMenu implementation
+// ============================================================================
+
+BEGIN_EVENT_TABLE(AttachmentMenu, wxMenu)
+   EVT_MENU(-1, AttachmentMenu::OnCommandEvent)
+END_EVENT_TABLE()
+
+AttachmentMenu::AttachmentMenu(wxWindow *win, EditorContentPart *part)
+{
+   m_window = win;
+   m_part = part;
+
+   // create the menu items
+   Append(WXMENU_MIME_INFO, _("&Properties..."));
+   AppendSeparator();
+#if 0 // TODO
+   Append(WXMENU_MIME_OPEN, _("&Open"));
+   Append(WXMENU_MIME_OPEN_WITH, _("Open &with..."));
+#endif
+   Append(WXMENU_MIME_VIEW_AS_TEXT, _("&View as text"));
+}
+
+/* static */
+void
+AttachmentMenu::ShowAttachmentProperties(wxWindow *win, EditorContentPart *part)
+{
+   CHECK_RET( part, _T("no attachment to edit in ShowAttachmentProperties()") );
+
+   AttachmentProperties props;
+   props.filename = part->GetFileName();
+   props.name = part->GetName();
+   props.SetDisposition(part->GetDisposition());
+   props.mimetype = part->GetMimeType();
+
+   if ( ShowAttachmentDialog(win, &props) )
+   {
+      part->SetFile(props.filename);
+      part->SetName(props.name);
+      part->SetMimeType(props.mimetype.GetFull());
+      part->SetDisposition(props.GetDisposition());
+   }
+   //else: cancelled by user or nothing changed
+}
+
+void
+AttachmentMenu::OnCommandEvent(wxCommandEvent &event)
+{
+   switch ( event.GetId() )
+   {
+      default:
+         FAIL_MSG( _T("unexpected menu command in AttachmentMenu") );
+         // fall through
+
+      case WXMENU_MIME_INFO:
+         ShowAttachmentProperties(m_window, m_part);
+         break;
+
+      case WXMENU_MIME_VIEW_AS_TEXT:
+         {
+            const String& filename = m_part->GetFileName();
+            wxFile file(filename);
+            if ( !file.IsOpened() )
+            {
+               wxLogError(_("Failed to open attachment."));
+               break;
+            }
+
+            wxString content;
+            const off_t len = file.Length();
+            if ( file.Read(wxStringBuffer(content, len + 1), len) != len )
+            {
+               wxLogError(_("Failed to read attachment data."));
+               break;
+            }
+
+            MDialog_ShowText
+            (
+               GetFrame(m_window),
+               wxString::Format(_("Attached file \"%s\""), filename.c_str()),
+               content,
+               _T("AttachView")
+            );
+         }
+         break;
+   }
+}
+
+// ============================================================================
 // implementation
 // ============================================================================
@@ -4452,21 +4566,28 @@
 MessageEditor::EditAttachmentProperties(EditorContentPart *part)
 {
-   CHECK_RET( part, _T("no attachment to edit in EditAttachmentProperties") );
+   AttachmentMenu::ShowAttachmentProperties(GetWindow(), part);
+}
 
-   AttachmentProperties props;
-   props.filename = part->GetFileName();
-   props.name = part->GetName();
-   props.SetDisposition(part->GetDisposition());
-   props.mimetype = part->GetMimeType();
+void
+MessageEditor::ShowAttachmentMenu(EditorContentPart *part, const wxPoint& pt)
+{
+   CHECK_RET( part, _T("no attachment to show menu for in ShowAttachmentMenu") );
 
-   if ( ShowAttachmentDialog(GetWindow(), &props) )
+   if ( part->GetFileName().empty() )
    {
-      part->SetFile(props.filename);
-      part->SetName(props.name);
-      part->SetMimeType(props.mimetype.GetFull());
-      part->SetDisposition(props.GetDisposition());
+      // this is not an attachment at all?
+      return;
    }
-   //else: cancelled by user or nothing changed
+
+   wxWindow *win = GetWindow();
+   CHECK_RET( win, _T("can't show attachment menu without parent window") );
+
+   AttachmentMenu menu(win, part);
+   win->PopupMenu(&menu, pt);
 }
+
+// ----------------------------------------------------------------------------
+// trivial MessageEditor accessors
+// ----------------------------------------------------------------------------
 
 Profile *MessageEditor::GetProfile() const



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to