[kde-doc-english] [trojita] src/Gui: GUI: Composer: sync the action state with the current selection harder

Jan Kundrát jkt at flaska.net
Fri Aug 9 16:30:14 UTC 2013


Git commit c3949b41e201b8ef8737cfcdda3fd5a5cb77cd4a by Jan Kundrát.
Committed on 08/08/2013 at 13:24.
Pushed by jkt into branch 'master'.

GUI: Composer: sync the action state with the current selection harder

Looks like the slots connected to currentChanged and rowsInserted are not
enough; it was clearly visible when dropping message/rfc822 attachments to the
view -- the checkbox for "Send inline" was not selected.

Switching to custom context menu processing effectively fixes this problem as we
now have precise control on action state.

I'm still leaving these slots in place because it makes sense to manipulate the
action state anyway -- suppose there was e.g. a "Delete" key assigned to
removing attachments...

M  +15   -6    src/Gui/ComposerAttachmentsList.cpp
M  +1    -0    src/Gui/ComposerAttachmentsList.h

http://commits.kde.org/trojita/c3949b41e201b8ef8737cfcdda3fd5a5cb77cd4a

diff --git a/src/Gui/ComposerAttachmentsList.cpp b/src/Gui/ComposerAttachmentsList.cpp
index 8e2748c..5cf1e8f 100644
--- a/src/Gui/ComposerAttachmentsList.cpp
+++ b/src/Gui/ComposerAttachmentsList.cpp
@@ -25,6 +25,7 @@
 #include <QDragEnterEvent>
 #include <QDebug>
 #include <QInputDialog>
+#include <QMenu>
 #include "Composer/MessageComposer.h"
 #include "Imap/Model/ItemRoles.h"
 
@@ -37,11 +38,12 @@ ComposerAttachmentsList::ComposerAttachmentsList(QWidget *parent):
     setDragDropOverwriteMode( false );
     setDragEnabled(true);
     setDropIndicatorShown(false);
-    setContextMenuPolicy(Qt::ActionsContextMenu);
+    setContextMenuPolicy(Qt::CustomContextMenu);
+    connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
 
     m_actionSendInline = new QAction(tr("Send Inline"), this);
     m_actionSendInline->setCheckable(true);
-    connect(m_actionSendInline, SIGNAL(toggled(bool)), this, SLOT(slotToggledContentDispositionInline(bool)));
+    connect(m_actionSendInline, SIGNAL(triggered(bool)), this, SLOT(slotToggledContentDispositionInline(bool)));
     addAction(m_actionSendInline);
 
     m_actionRename = new QAction(tr("Rename..."), this);
@@ -124,10 +126,10 @@ void ComposerAttachmentsList::slotRenameAttachment()
 void ComposerAttachmentsList::onAttachmentNumberChanged()
 {
     Q_ASSERT(model());
-    bool hasAttachments = model()->rowCount() > 0;
-    m_actionRemoveAttachment->setEnabled(hasAttachments);
-    m_actionSendInline->setEnabled(hasAttachments);
-    m_actionRename->setEnabled(hasAttachments);
+    bool current = currentIndex().isValid();
+    m_actionRemoveAttachment->setEnabled(current);
+    m_actionSendInline->setEnabled(current);
+    m_actionRename->setEnabled(current);
     onCurrentChanged();
 }
 
@@ -150,3 +152,10 @@ void ComposerAttachmentsList::onCurrentChanged()
         break;
     }
 }
+
+void ComposerAttachmentsList::showContextMenu(const QPoint &pos)
+{
+    // Sometimes currentChanged() is not enough -- we really want to to have these actions to reflect the current selection, if any
+    onAttachmentNumberChanged();
+    QMenu::exec(actions(), mapToGlobal(pos), 0, this);
+}
diff --git a/src/Gui/ComposerAttachmentsList.h b/src/Gui/ComposerAttachmentsList.h
index a45d486..5b99c42 100644
--- a/src/Gui/ComposerAttachmentsList.h
+++ b/src/Gui/ComposerAttachmentsList.h
@@ -51,6 +51,7 @@ public slots:
     void slotRenameAttachment();
     void onAttachmentNumberChanged();
     void onCurrentChanged();
+    void showContextMenu(const QPoint &pos);
 private:
     bool m_dragging, m_dragInside;
     Composer::MessageComposer *m_composer;



More information about the kde-doc-english mailing list