changeset 325:5fa5c908ca00 filelist_right_button_menu

Add right-button menus (not yet functional, but hopefully with the right things in them)
author Chris Cannam
date Thu, 10 Mar 2011 21:04:58 +0000
parents 306ffd913071
children 6e1fdda1dff2
files filestates.cpp filestates.h filestatuswidget.cpp filestatuswidget.h
diffstat 4 files changed, 41 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/filestates.cpp	Thu Mar 10 18:45:50 2011 +0000
+++ b/filestates.cpp	Thu Mar 10 21:04:58 2011 +0000
@@ -184,6 +184,17 @@
     return activitiesSupportedBy(s).contains(a);
 }
 
+int FileStates::activityGroup(Activity a)
+{
+    switch (a) {
+    case Annotate: case Diff: return 0;
+    case Commit: case Revert: return 1;
+    case Add: case Remove: return 2;
+    case RedoMerge: case MarkResolved: return 3;
+    case Ignore: case UnIgnore: return 4;
+    }
+}
+
 bool FileStates::supportsActivity(QString file, Activity a) const
 {
     return supportsActivity(stateOf(file), a);
--- a/filestates.h	Thu Mar 10 18:45:50 2011 +0000
+++ b/filestates.h	Thu Mar 10 21:04:58 2011 +0000
@@ -68,12 +68,16 @@
 
         Annotate,
         Diff,
+
         Commit,
         Revert,
+
         Add,
         Remove,
+
         RedoMerge,
         MarkResolved,
+
         Ignore,
         UnIgnore,
 
@@ -85,6 +89,7 @@
 
     static bool supportsActivity(State s, Activity a);
     static Activities activitiesSupportedBy(State s);
+    static int activityGroup(Activity a);
     
     bool supportsActivity(QString file, Activity a) const;
     QStringList filesSupportingActivity(Activity) const;
--- a/filestatuswidget.cpp	Thu Mar 10 18:45:50 2011 +0000
+++ b/filestatuswidget.cpp	Thu Mar 10 21:04:58 2011 +0000
@@ -57,6 +57,17 @@
     m_simpleLabels[FileStates::Unknown] = tr("Untracked:");
     m_simpleLabels[FileStates::Ignored] = tr("Ignored:");
 
+    m_actionLabels[FileStates::Annotate] = tr("Annotate");
+    m_actionLabels[FileStates::Diff] = tr("Diff");
+    m_actionLabels[FileStates::Commit] = tr("Commit...");
+    m_actionLabels[FileStates::Revert] = tr("Revert");
+    m_actionLabels[FileStates::Add] = tr("Add");
+    m_actionLabels[FileStates::Remove] = tr("Remove");
+    m_actionLabels[FileStates::RedoMerge] = tr("Redo Merge");
+    m_actionLabels[FileStates::MarkResolved] = tr("Mark Resolved");
+    m_actionLabels[FileStates::Ignore] = tr("Ignore");
+    m_actionLabels[FileStates::UnIgnore] = tr("Stop Ignoring");
+
     m_descriptions[FileStates::Clean] = tr("You have not changed these files.");
     m_descriptions[FileStates::Modified] = tr("You have changed these files since you last committed them.");
     m_descriptions[FileStates::Added] = tr("These files will be added to version control next time you commit them.");
@@ -107,7 +118,19 @@
         connect(w, SIGNAL(itemSelectionChanged()),
                 this, SLOT(itemSelectionChanged()));
 
-        w->insertAction(0, new QAction(tr("Commit"), w));
+        FileStates::Activities activities = m_fileStates.activitiesSupportedBy(s);
+        int prevGroup = -1;
+        foreach (FileStates::Activity a, activities) {
+            int group = FileStates::activityGroup(a);
+            if (group != prevGroup && prevGroup != -1) {
+                QAction *sep = new QAction("", w);
+                sep->setSeparator(true);
+                w->insertAction(0, sep);
+            }
+            prevGroup = group;
+            QAction *act = new QAction(m_actionLabels[a], w);
+            w->insertAction(0, act);
+        }
         w->setContextMenuPolicy(Qt::ActionsContextMenu);
 
         boxlayout->addItem(new QSpacerItem(2, 2), 3, 0);
--- a/filestatuswidget.h	Thu Mar 10 18:45:50 2011 +0000
+++ b/filestatuswidget.h	Thu Mar 10 21:04:58 2011 +0000
@@ -84,6 +84,7 @@
     QMap<FileStates::State, QString> m_simpleLabels;
     QMap<FileStates::State, QString> m_descriptions;
     QMap<FileStates::State, QListWidget *> m_stateListMap;
+    QMap<FileStates::Activity, QString> m_actionLabels;
     QString m_highlightExplanation;
 
     QFileInfo *m_dateReference;