comparison filestatuswidget.cpp @ 94:44ed7766d55a

* Clear selections when Esc pressed; some refactoring
author Chris Cannam
date Wed, 24 Nov 2010 14:41:52 +0000
parents dfb7a274b90f
children d1be9712818a
comparison
equal deleted inserted replaced
93:dfb7a274b90f 94:44ed7766d55a
47 m_remoteURLLabel = new QLabel; 47 m_remoteURLLabel = new QLabel;
48 layout->addWidget(m_remoteURLLabel, row, 1); 48 layout->addWidget(m_remoteURLLabel, row, 1);
49 49
50 layout->setColumnStretch(1, 20); 50 layout->setColumnStretch(1, 20);
51 51
52 QStringList labels; 52 QMap<FileStates::State, QString> labels;
53 labels << tr("Modified files:") 53 labels[FileStates::Clean] = tr("Unmodified files:");
54 << tr("Added files:") 54 labels[FileStates::Modified] = tr("Modified files:");
55 << tr("Removed files:") 55 labels[FileStates::Added] = tr("Added files:");
56 << tr("New untracked files:") 56 labels[FileStates::Removed] = tr("Removed files:");
57 << tr("Missing files:"); 57 labels[FileStates::Missing] = tr("Missing files:");
58 labels[FileStates::Unknown] = tr("Untracked files:");
58 59
59 QList<QListWidget **> lists; 60 for (int i = int(FileStates::FirstState);
60 lists << &m_modifiedList 61 i <= int(FileStates::LastState); ++i) {
61 << &m_addedList
62 << &m_removedList
63 << &m_unknownList
64 << &m_missingList;
65 62
66 for (int i = 0; i < labels.size(); ++i) { 63 FileStates::State s = FileStates::State(i);
67 64
68 QWidget *box = new QWidget; 65 QWidget *box = new QWidget;
69 QGridLayout *boxlayout = new QGridLayout; 66 QGridLayout *boxlayout = new QGridLayout;
70 box->setLayout(boxlayout); 67 box->setLayout(boxlayout);
71 68
72 boxlayout->addWidget(new QLabel(labels[i]), 0, 0); 69 boxlayout->addWidget(new QLabel(labels[s]), 0, 0);
73 70
74 *lists[i] = new QListWidget; 71 QListWidget *w = new QListWidget;
75 (*lists[i])->setSelectionMode(QListWidget::ExtendedSelection); 72 m_stateListMap[s] = w;
76 boxlayout->addWidget(*lists[i], 1, 0); 73 w->setSelectionMode(QListWidget::ExtendedSelection);
74 boxlayout->addWidget(w, 1, 0);
77 75
78 layout->addWidget(box, ++row, 0, 1, 2); 76 layout->addWidget(box, ++row, 0, 1, 2);
79 box->hide(); 77 box->hide();
80 } 78 }
81 79
83 } 81 }
84 82
85 FileStatusWidget::~FileStatusWidget() 83 FileStatusWidget::~FileStatusWidget()
86 { 84 {
87 delete m_dateReference; 85 delete m_dateReference;
86 }
87
88 void FileStatusWidget::clearSelections()
89 {
90 foreach (QListWidget *w, m_stateListMap) {
91 w->clearSelection();
92 }
88 } 93 }
89 94
90 void 95 void
91 FileStatusWidget::setLocalPath(QString p) 96 FileStatusWidget::setLocalPath(QString p)
92 { 97 {
130 } 135 }
131 136
132 void 137 void
133 FileStatusWidget::updateWidgets() 138 FileStatusWidget::updateWidgets()
134 { 139 {
135 FileStates &sp = m_fileStates; 140 foreach (FileStates::State s, m_stateListMap.keys()) {
136 QMap<QStringList *, QListWidget *> listmap; 141 QListWidget *w = m_stateListMap[s];
137 listmap[&sp.modified] = m_modifiedList; 142 w->clear();
138 listmap[&sp.added] = m_addedList; 143 QStringList sl = m_fileStates.getFilesInState(s);
139 listmap[&sp.removed] = m_removedList; 144 w->addItems(sl);
140 listmap[&sp.missing] = m_missingList; 145 w->parentWidget()->setVisible(!sl.empty());
141 listmap[&sp.unknown] = m_unknownList;
142
143 foreach (QStringList *sl, listmap.keys()) {
144 listmap[sl]->clear();
145 listmap[sl]->addItems(*sl);
146 listmap[sl]->parentWidget()->setVisible(!sl->empty());
147 } 146 }
148 147
149 if (m_dateReference) { 148 if (m_dateReference) {
150 // Highlight untracked files that have appeared since the 149 // Highlight untracked files that have appeared since the
151 // last interaction with the repo 150 // last interaction with the repo
152 QDateTime refTime = m_dateReference->lastModified(); 151 QDateTime refTime = m_dateReference->lastModified();
153 DEBUG << "reference time: " << refTime << endl; 152 DEBUG << "reference time: " << refTime << endl;
154 for (int i = 0; i < m_unknownList->count(); ++i) { 153 QListWidget *ul = m_stateListMap[FileStates::Unknown];
155 QString fn(m_localPath + "/" + m_unknownList->item(i)->text()); 154 for (int i = 0; i < ul->count(); ++i) {
155 QString fn(m_localPath + "/" + ul->item(i)->text());
156 DEBUG << "comparing with " << fn << endl; 156 DEBUG << "comparing with " << fn << endl;
157 QFileInfo fi(fn); 157 QFileInfo fi(fn);
158 if (fi.exists() && fi.lastModified() > refTime) { 158 if (fi.exists() && fi.lastModified() > refTime) {
159 DEBUG << "file " << fn << " is newer (" << fi.lastModified() 159 DEBUG << "file " << fn << " is newer (" << fi.lastModified()
160 << ") than reference" << endl; 160 << ") than reference" << endl;
161 highlightFile(m_unknownList, i); 161 highlightFile(ul, i);
162 } 162 }
163 } 163 }
164 } 164 }
165 } 165 }
166 166