[kde-doc-english] [kde-workspace] kmenuedit: GUI: review popup menu content

Julien Borderie frajibe at gmail.com
Thu Mar 14 21:40:59 UTC 2013


Git commit 0c143b4199ff925044e2779ac1e35e5729256710 by Julien Borderie.
Committed on 14/03/2013 at 22:36.
Pushed by jborderie into branch 'master'.

GUI: review popup menu content

Clarify some code associated to actions.

M  +4    -4    kmenuedit/kmenuedit.cpp
M  +6    -6    kmenuedit/kmenueditui.rc
M  +52   -61   kmenuedit/treeview.cpp
M  +9    -1    kmenuedit/treeview.h

http://commits.kde.org/kde-workspace/0c143b4199ff925044e2779ac1e35e5729256710

diff --git a/kmenuedit/kmenuedit.cpp b/kmenuedit/kmenuedit.cpp
index d04fe1b..e191f40 100644
--- a/kmenuedit/kmenuedit.cpp
+++ b/kmenuedit/kmenuedit.cpp
@@ -74,15 +74,15 @@ void KMenuEdit::setupActions()
 {
     KAction *action = 0;
 
-    action = actionCollection()->addAction("newsubmenu");
+    action = actionCollection()->addAction(NEW_SUBMENU_ACTION_NAME);
     action->setIcon(KIcon("menu_new"));
     action->setText(i18n("&New Submenu..."));
     action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_N));
-    action = actionCollection()->addAction("newitem");
+    action = actionCollection()->addAction(NEW_ITEM_ACTION_NAME);
     action->setIcon(KIcon("document-new")) ;
     action->setText(i18n("New &Item..."));
     action->setShortcuts(KStandardShortcut::openNew());
-    action = actionCollection()->addAction("newsep");
+    action = actionCollection()->addAction(NEW_SEPARATOR_ACTION_NAME);
     action->setIcon(KIcon("menu_new_sep"));
     action->setText(i18n("New S&eparator"));
     action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_I));
@@ -197,7 +197,7 @@ void KMenuEdit::slotChangeView()
 
     delete m_actionDelete;
 
-    m_actionDelete = actionCollection()->addAction("delete");
+    m_actionDelete = actionCollection()->addAction(DELETE_ACTION_NAME);
     m_actionDelete->setIcon(KIcon("edit-delete"));
     m_actionDelete->setText(i18n("&Delete"));
     m_actionDelete->setShortcut(QKeySequence(Qt::Key_Delete));
diff --git a/kmenuedit/kmenueditui.rc b/kmenuedit/kmenueditui.rc
index 8b8ac01..f7ebd0c 100644
--- a/kmenuedit/kmenueditui.rc
+++ b/kmenuedit/kmenueditui.rc
@@ -4,9 +4,9 @@
 <MenuBar>
 
 <Menu name="file" noMerge="1"><text>&File</text>
- <Action name="newitem"/>
- <Action name="newsubmenu" />
- <Action name="newsep" />
+ <Action name="new_item"/>
+ <Action name="new_submenu" />
+ <Action name="new_separator" />
  <Separator/>
  <Action name="file_save"/>
  <Separator/>
@@ -33,9 +33,9 @@
 <ToolBar name="mainToolBar" noMerge="1" fullWidth="true"><text>Main Toolbar</text>
  <Action name="file_save"/>
  <Separator/>
- <Action name="newitem"/>
- <Action name="newsubmenu"/>
- <Action name="newsep" />
+ <Action name="new_item"/>
+ <Action name="new_submenu"/>
+ <Action name="new_separator" />
  <Separator/>
  <Action name="move_up"/>
  <Action name="move_down"/>
diff --git a/kmenuedit/treeview.cpp b/kmenuedit/treeview.cpp
index 445a052..390cc7c 100644
--- a/kmenuedit/treeview.cpp
+++ b/kmenuedit/treeview.cpp
@@ -239,7 +239,7 @@ static QPixmap appIcon(const QString &iconName)
 
 
 TreeView::TreeView( KActionCollection *ac, QWidget *parent, const char *name )
-    : QTreeWidget(parent), m_ac(ac), m_rmb(0), m_clipboard(0),
+    : QTreeWidget(parent), m_ac(ac), m_popupMenu(0), m_clipboard(0),
       m_clipboardFolderInfo(0), m_clipboardEntryInfo(0),
       m_layoutDirty(false),
       m_detailedMenuEntries(true), m_detailedEntriesNamesFirst(true)
@@ -257,15 +257,20 @@ TreeView::TreeView( KActionCollection *ac, QWidget *parent, const char *name )
     setHeaderLabels(QStringList() << QString(""));
     header()->hide();
 
-    connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
-            SLOT(itemSelected(QTreeWidgetItem*)));
+    // listen for creation
+    connect(m_ac->action(NEW_ITEM_ACTION_NAME), SIGNAL(activated()), SLOT(newitem()));
+    connect(m_ac->action(NEW_SUBMENU_ACTION_NAME), SIGNAL(activated()), SLOT(newsubmenu()));
+    connect(m_ac->action(NEW_SEPARATOR_ACTION_NAME), SIGNAL(activated()), SLOT(newsep()));
 
-    // connect actions
-    connect(m_ac->action("newitem"), SIGNAL(activated()), SLOT(newitem()));
-    connect(m_ac->action("newsubmenu"), SIGNAL(activated()), SLOT(newsubmenu()));
-    connect(m_ac->action("newsep"), SIGNAL(activated()), SLOT(newsep()));
+    // listen for copy
+    connect(m_ac->action(CUT_ACTION_NAME), SIGNAL(activated()), SLOT(cut()));
+    connect(m_ac->action(COPY_ACTION_NAME), SIGNAL(activated()), SLOT(copy()));
+    connect(m_ac->action(PASTE_ACTION_NAME), SIGNAL(activated()), SLOT(paste()));
 
-    // map sorting actions
+    // listen for deleting
+    connect(m_ac->action(DELETE_ACTION_NAME), SIGNAL(activated()), SLOT(del()));
+
+    // listen for sorting
     m_sortSignalMapper = new QSignalMapper(this);
     QAction *action = m_ac->action(SORT_BY_NAME_ACTION_NAME);
     connect(action, SIGNAL(activated()), m_sortSignalMapper, SLOT(map()));
@@ -285,6 +290,10 @@ TreeView::TreeView( KActionCollection *ac, QWidget *parent, const char *name )
     connect(m_ac->action(MOVE_UP_ACTION_NAME), SIGNAL(activated()), SLOT(moveUpItem()));
     connect(m_ac->action(MOVE_DOWN_ACTION_NAME), SIGNAL(activated()), SLOT(moveDownItem()));
 
+    // listen for selection
+    connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
+            SLOT(itemSelected(QTreeWidgetItem*)));
+
     m_menuFile = new MenuFile(KStandardDirs::locateLocal("xdgconf-menu", "applications-kmenuedit.menu"));
     m_rootFolder = new MenuFolderInfo;
     m_separator = new MenuSeparatorInfo;
@@ -299,52 +308,33 @@ TreeView::~TreeView()
 
 void TreeView::setViewMode(bool showHidden)
 {
-    delete m_rmb;
-
-    // setup rmb menu
-    m_rmb = new QMenu(this);
-    QAction *action;
-
-    action = m_ac->action(MOVE_UP_ACTION_NAME);
-    m_rmb->addAction( action );
-
-    action = m_ac->action(MOVE_DOWN_ACTION_NAME);
-    m_rmb->addAction( action );
-
-    m_rmb->addSeparator();
-
-    action = m_ac->action("edit_cut");
-    m_rmb->addAction( action );
-    action->setEnabled(false);
-    connect(action, SIGNAL(activated()), SLOT(cut()));
-
-    action = m_ac->action("edit_copy");
-    m_rmb->addAction( action );
-    action->setEnabled(false);
-    connect(action, SIGNAL(activated()), SLOT(copy()));
-
-    action = m_ac->action("edit_paste");
-    m_rmb->addAction( action );
-    action->setEnabled(false);
-    connect(action, SIGNAL(activated()), SLOT(paste()));
-
-    m_rmb->addSeparator();
+    // setup popup menu
+    delete m_popupMenu;
+    m_popupMenu = new QMenu(this);
 
-    action = m_ac->action("delete");
-    m_rmb->addAction( action );
-    action->setEnabled(false);
-    connect(action, SIGNAL(activated()), SLOT(del()));
+    // creation
+    m_popupMenu->addAction(m_ac->action(NEW_ITEM_ACTION_NAME));
+    m_popupMenu->addAction(m_ac->action(NEW_SUBMENU_ACTION_NAME));
+    m_popupMenu->addAction(m_ac->action(NEW_SEPARATOR_ACTION_NAME));
+    m_popupMenu->addSeparator();
 
-    m_rmb->addSeparator();
+    // copy
+    m_popupMenu->addAction(m_ac->action(CUT_ACTION_NAME));
+    m_popupMenu->addAction(m_ac->action(COPY_ACTION_NAME));
+    m_popupMenu->addAction(m_ac->action(PASTE_ACTION_NAME));
+    m_popupMenu->addSeparator();
 
-    m_rmb->addAction( m_ac->action("newitem") );
-    m_rmb->addAction( m_ac->action("newsubmenu") );
-    m_rmb->addAction( m_ac->action("newsep") );
+    // delete
+    m_popupMenu->addAction( m_ac->action(DELETE_ACTION_NAME));
+    m_popupMenu->addSeparator();
 
-    m_rmb->addSeparator();
+    // move
+    m_popupMenu->addAction(m_ac->action(MOVE_UP_ACTION_NAME));
+    m_popupMenu->addAction(m_ac->action(MOVE_DOWN_ACTION_NAME));
+    m_popupMenu->addSeparator();
 
-    action = m_ac->action(SORT_ACTION_NAME);
-    m_rmb->addAction(action);
+    // sort
+    m_popupMenu->addAction(m_ac->action(SORT_ACTION_NAME));
 
     m_showHidden = showHidden;
     readMenuFolderInfo();
@@ -671,11 +661,12 @@ void TreeView::itemSelected(QTreeWidgetItem *item)
     }
 
     // change actions activation
-    m_ac->action("edit_cut")->setEnabled(selected);
-    m_ac->action("edit_copy")->setEnabled(selected);
+    m_ac->action(CUT_ACTION_NAME)->setEnabled(selected);
+    m_ac->action(COPY_ACTION_NAME)->setEnabled(selected);
+    m_ac->action(PASTE_ACTION_NAME)->setEnabled(m_clipboard != 0);
 
-    if (m_ac->action("delete")) {
-        m_ac->action("delete")->setEnabled(selected && !dselected);
+    if (m_ac->action(DELETE_ACTION_NAME)) {
+        m_ac->action(DELETE_ACTION_NAME)->setEnabled(selected && !dselected);
     }
 
     m_ac->action(SORT_BY_NAME_ACTION_NAME)->setEnabled(selected && _item->isDirectory() && (_item->childCount() > 0));
@@ -1123,8 +1114,8 @@ QTreeWidgetItem *TreeView::selectedItem()
 
 void TreeView::contextMenuEvent(QContextMenuEvent *event)
 {
-    if (m_rmb && itemAt(event->pos())) {
-        m_rmb->exec(event->globalPos());
+    if (m_popupMenu && itemAt(event->pos())) {
+        m_popupMenu->exec(event->globalPos());
     }
 }
 
@@ -1370,7 +1361,7 @@ void TreeView::copy( bool cutting )
            del(item, false);
     }
 
-    m_ac->action("edit_paste")->setEnabled(true);
+    m_ac->action(PASTE_ACTION_NAME)->setEnabled(true);
 }
 
 
diff --git a/kmenuedit/treeview.h b/kmenuedit/treeview.h
index 1f9588d..a03828c 100644
--- a/kmenuedit/treeview.h
+++ b/kmenuedit/treeview.h
@@ -41,6 +41,14 @@ class MenuEntryInfo;
 class MenuSeparatorInfo;
 class KShortcut;
 
+static const QString SAVE_ACTION_NAME = "file_save";
+static const QString NEW_ITEM_ACTION_NAME = "new_item";
+static const QString NEW_SUBMENU_ACTION_NAME = "new_submenu";
+static const QString NEW_SEPARATOR_ACTION_NAME = "new_separator";
+static const QString CUT_ACTION_NAME = "edit_cut";
+static const QString COPY_ACTION_NAME = "edit_copy";
+static const QString PASTE_ACTION_NAME = "edit_paste";
+static const QString DELETE_ACTION_NAME = "delete";
 static const QString SORT_ACTION_NAME = "sort";
 static const QString SORT_BY_NAME_ACTION_NAME = "sort_by_name";
 static const QString SORT_BY_DESCRIPTION_ACTION_NAME = "sort_by_description";
@@ -197,7 +205,7 @@ protected:
 
 private:
     KActionCollection *m_ac;
-    QMenu             *m_rmb;
+    QMenu             *m_popupMenu;
     int                m_clipboard;
     MenuFolderInfo    *m_clipboardFolderInfo;
     MenuEntryInfo     *m_clipboardEntryInfo;


More information about the kde-doc-english mailing list