changeset 324:306ffd913071 filelist_right_button_menu

Introduce "activities" enum and functions
author Chris Cannam
date Thu, 10 Mar 2011 18:45:50 +0000
parents adb14d3f780f
children 5fa5c908ca00
files filestates.cpp filestates.h filestatuswidget.cpp
diffstat 3 files changed, 132 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/filestates.cpp	Thu Mar 10 15:33:02 2011 +0000
+++ b/filestates.cpp	Thu Mar 10 18:45:50 2011 +0000
@@ -63,7 +63,7 @@
 QStringList *FileStates::stateToBucket(State s)
 {
     switch (s) {
-    case Clean: return &m_clean; // not implemented yet
+    case Clean: return &m_clean;
     case Modified: return &m_modified;
     case Added: return &m_added;
     case Unknown: return &m_unknown;
@@ -112,14 +112,19 @@
           << m_unknown.size() << " unknown" << endl;
 }
 
-QStringList FileStates::getFilesInState(State s) const
+QStringList FileStates::filesInState(State s) const
 {
     QStringList *sl = const_cast<FileStates *>(this)->stateToBucket(s);
     if (sl) return *sl;
     else return QStringList();
 }
 
-FileStates::State FileStates::getStateOfFile(QString file) const
+bool FileStates::isInState(QString file, State s) const
+{
+    return filesInState(s).contains(file);
+}
+
+FileStates::State FileStates::stateOf(QString file) const
 {
     if (m_stateMap.contains(file)) {
         return m_stateMap[file];
@@ -131,3 +136,71 @@
             << endl;
     return Unknown;
 }
+
+FileStates::Activities FileStates::activitiesSupportedBy(State s)
+{
+    Activities a;
+
+    switch (s) {
+
+    case Modified:
+        a << Annotate << Diff << Commit << Revert << Remove;
+        break;
+
+    case Added:
+        a << Commit << Revert << Remove;
+        break;
+        
+    case Removed:
+        a << Commit << Revert << Add;
+        break;
+
+    case InConflict:
+        a << Annotate << Diff << RedoMerge << MarkResolved;
+        break;
+
+    case Missing:
+        a << Revert << Remove;
+        break;
+        
+    case Unknown:
+        a << Add << Ignore;
+        break;
+
+    case Clean:
+        a << Remove << Annotate;
+        break;
+
+    case Ignored:
+        a << UnIgnore;
+        break;
+    }
+
+    return a;
+}
+
+bool FileStates::supportsActivity(State s, Activity a)
+{
+    return activitiesSupportedBy(s).contains(a);
+}
+
+bool FileStates::supportsActivity(QString file, Activity a) const
+{
+    return supportsActivity(stateOf(file), a);
+}
+
+QStringList FileStates::filesSupportingActivity(Activity a) const
+{
+    QStringList f;
+    for (int i = int(FirstState); i <= int(LastState); ++i) {
+        State s = (State)i;
+        f << filesInState(s);
+    }
+    return f;
+}
+
+FileStates::Activities FileStates::activitiesSupportedBy(QString file) const
+{
+    return activitiesSupportedBy(stateOf(file));
+}
+
--- a/filestates.h	Thu Mar 10 15:33:02 2011 +0000
+++ b/filestates.h	Thu Mar 10 18:45:50 2011 +0000
@@ -47,10 +47,11 @@
 
     void parseStates(QString text);
 
-    void clearBuckets();
+    bool isInState(QString file, State s) const;
+    QStringList filesInState(State s) const;
+    State stateOf(QString file) const;
 
-    QStringList getFilesInState(State) const;
-
+/*!!! -- to remove: */
     QStringList modified() const { return m_modified; }
     QStringList added() const { return m_added; }
     QStringList unknown() const { return m_unknown; }
@@ -60,7 +61,34 @@
     QStringList clean() const { return m_clean; }
     QStringList ignored() const { return m_ignored; }
 
-    State getStateOfFile(QString file) const;
+    enum Activity {
+
+        // These are in the order in which they want to be listed in
+        // the context menu
+
+        Annotate,
+        Diff,
+        Commit,
+        Revert,
+        Add,
+        Remove,
+        RedoMerge,
+        MarkResolved,
+        Ignore,
+        UnIgnore,
+
+        FirstActivity = Commit,
+        LastActivity = UnIgnore
+    };
+
+    typedef QList<Activity> Activities;
+
+    static bool supportsActivity(State s, Activity a);
+    static Activities activitiesSupportedBy(State s);
+    
+    bool supportsActivity(QString file, Activity a) const;
+    QStringList filesSupportingActivity(Activity) const;
+    Activities activitiesSupportedBy(QString file) const;
 
 private:
     QStringList m_modified;
@@ -73,6 +101,8 @@
     QStringList m_ignored;
     QMap<QString, State> m_stateMap;
 
+    void clearBuckets();
+
     State charToState(QChar, bool * = 0);
     QStringList *stateToBucket(State);
 };
--- a/filestatuswidget.cpp	Thu Mar 10 15:33:02 2011 +0000
+++ b/filestatuswidget.cpp	Thu Mar 10 18:45:50 2011 +0000
@@ -263,7 +263,7 @@
 {
     QStringList files;
     foreach (QString f, m_selectedFiles) {
-        switch (m_fileStates.getStateOfFile(f)) {
+        switch (m_fileStates.stateOf(f)) {
         case FileStates::Added:
         case FileStates::Modified:
         case FileStates::Removed:
@@ -278,9 +278,9 @@
 QStringList FileStatusWidget::getAllCommittableFiles() const
 {
     QStringList files;
-    files << m_fileStates.getFilesInState(FileStates::Modified);
-    files << m_fileStates.getFilesInState(FileStates::Added);
-    files << m_fileStates.getFilesInState(FileStates::Removed);
+    files << m_fileStates.filesInState(FileStates::Modified);
+    files << m_fileStates.filesInState(FileStates::Added);
+    files << m_fileStates.filesInState(FileStates::Removed);
     return files;
 }
 
@@ -288,7 +288,7 @@
 {
     QStringList files;
     foreach (QString f, m_selectedFiles) {
-        switch (m_fileStates.getStateOfFile(f)) {
+        switch (m_fileStates.stateOf(f)) {
         case FileStates::Added:
         case FileStates::Modified:
         case FileStates::Removed:
@@ -305,11 +305,11 @@
 QStringList FileStatusWidget::getAllRevertableFiles() const
 {
     QStringList files;
-    files << m_fileStates.getFilesInState(FileStates::Modified);
-    files << m_fileStates.getFilesInState(FileStates::Added);
-    files << m_fileStates.getFilesInState(FileStates::Removed);
-    files << m_fileStates.getFilesInState(FileStates::Missing);
-    files << m_fileStates.getFilesInState(FileStates::InConflict);
+    files << m_fileStates.filesInState(FileStates::Modified);
+    files << m_fileStates.filesInState(FileStates::Added);
+    files << m_fileStates.filesInState(FileStates::Removed);
+    files << m_fileStates.filesInState(FileStates::Missing);
+    files << m_fileStates.filesInState(FileStates::InConflict);
     return files;
 }
 
@@ -317,7 +317,7 @@
 {
     QStringList files;
     foreach (QString f, m_selectedFiles) {
-        switch (m_fileStates.getStateOfFile(f)) {
+        switch (m_fileStates.stateOf(f)) {
         case FileStates::InConflict:
             files.push_back(f);
             break;
@@ -330,7 +330,7 @@
 QStringList FileStatusWidget::getAllUnresolvedFiles() const
 {
     QStringList files;
-    files << m_fileStates.getFilesInState(FileStates::InConflict);
+    files << m_fileStates.filesInState(FileStates::InConflict);
     return files;
 }
 
@@ -338,7 +338,7 @@
 {
     QStringList files;
     foreach (QString f, m_selectedFiles) {
-        switch (m_fileStates.getStateOfFile(f)) {
+        switch (m_fileStates.stateOf(f)) {
         case FileStates::Unknown:
         case FileStates::Removed:
             files.push_back(f);
@@ -352,8 +352,8 @@
 QStringList FileStatusWidget::getAllAddableFiles() const
 {
     QStringList files;
-    files << m_fileStates.getFilesInState(FileStates::Removed);
-    files << m_fileStates.getFilesInState(FileStates::Unknown);
+    files << m_fileStates.filesInState(FileStates::Removed);
+    files << m_fileStates.filesInState(FileStates::Unknown);
     return files;
 }
 
@@ -361,7 +361,7 @@
 {
     QStringList files;
     foreach (QString f, m_selectedFiles) {
-        switch (m_fileStates.getStateOfFile(f)) {
+        switch (m_fileStates.stateOf(f)) {
         case FileStates::Clean:
         case FileStates::Added:
         case FileStates::Modified:
@@ -378,11 +378,11 @@
 QStringList FileStatusWidget::getAllRemovableFiles() const
 {
     QStringList files;
-    files << m_fileStates.getFilesInState(FileStates::Clean);
-    files << m_fileStates.getFilesInState(FileStates::Added);
-    files << m_fileStates.getFilesInState(FileStates::Modified);
-    files << m_fileStates.getFilesInState(FileStates::Missing);
-    files << m_fileStates.getFilesInState(FileStates::InConflict);
+    files << m_fileStates.filesInState(FileStates::Clean);
+    files << m_fileStates.filesInState(FileStates::Added);
+    files << m_fileStates.filesInState(FileStates::Modified);
+    files << m_fileStates.filesInState(FileStates::Missing);
+    files << m_fileStates.filesInState(FileStates::InConflict);
     return files;
 }
 
@@ -435,7 +435,7 @@
 
         QListWidget *w = m_stateListMap[s];
         w->clear();
-        QStringList files = m_fileStates.getFilesInState(s);
+        QStringList files = m_fileStates.filesInState(s);
 
         QStringList highPriority, lowPriority;