Mercurial > hg > easyhg
comparison filestatuswidget.cpp @ 326:6e1fdda1dff2 filelist_right_button_menu
Implement right-button menu functions for file lists; convert the toolbar-button functions (apart from Add and Remove) to modal only on working copy state rather than selection state
author | Chris Cannam |
---|---|
date | Fri, 11 Mar 2011 15:33:16 +0000 |
parents | 5fa5c908ca00 |
children | ea62eb083ed4 |
comparison
equal
deleted
inserted
replaced
325:5fa5c908ca00 | 326:6e1fdda1dff2 |
---|---|
55 m_simpleLabels[FileStates::Missing] = tr("Missing:"); | 55 m_simpleLabels[FileStates::Missing] = tr("Missing:"); |
56 m_simpleLabels[FileStates::InConflict] = tr("In Conflict:"); | 56 m_simpleLabels[FileStates::InConflict] = tr("In Conflict:"); |
57 m_simpleLabels[FileStates::Unknown] = tr("Untracked:"); | 57 m_simpleLabels[FileStates::Unknown] = tr("Untracked:"); |
58 m_simpleLabels[FileStates::Ignored] = tr("Ignored:"); | 58 m_simpleLabels[FileStates::Ignored] = tr("Ignored:"); |
59 | 59 |
60 m_actionLabels[FileStates::Annotate] = tr("Annotate"); | 60 m_actionLabels[FileStates::Annotate] = tr("Show annotated version"); |
61 m_actionLabels[FileStates::Diff] = tr("Diff"); | 61 m_actionLabels[FileStates::Diff] = tr("Diff to parent"); |
62 m_actionLabels[FileStates::Commit] = tr("Commit..."); | 62 m_actionLabels[FileStates::Commit] = tr("Commit..."); |
63 m_actionLabels[FileStates::Revert] = tr("Revert"); | 63 m_actionLabels[FileStates::Revert] = tr("Revert to last commit"); |
64 m_actionLabels[FileStates::Add] = tr("Add"); | 64 m_actionLabels[FileStates::Add] = tr("Add to version control"); |
65 m_actionLabels[FileStates::Remove] = tr("Remove"); | 65 m_actionLabels[FileStates::Remove] = tr("Remove from version control"); |
66 m_actionLabels[FileStates::RedoMerge] = tr("Redo Merge"); | 66 m_actionLabels[FileStates::RedoMerge] = tr("Redo merge"); |
67 m_actionLabels[FileStates::MarkResolved] = tr("Mark Resolved"); | 67 m_actionLabels[FileStates::MarkResolved] = tr("Mark resolved"); |
68 m_actionLabels[FileStates::Ignore] = tr("Ignore"); | 68 m_actionLabels[FileStates::Ignore] = tr("Ignore"); |
69 m_actionLabels[FileStates::UnIgnore] = tr("Stop Ignoring"); | 69 m_actionLabels[FileStates::UnIgnore] = tr("Stop ignoring"); |
70 | 70 |
71 m_descriptions[FileStates::Clean] = tr("You have not changed these files."); | 71 m_descriptions[FileStates::Clean] = tr("You have not changed these files."); |
72 m_descriptions[FileStates::Modified] = tr("You have changed these files since you last committed them."); | 72 m_descriptions[FileStates::Modified] = tr("You have changed these files since you last committed them."); |
73 m_descriptions[FileStates::Added] = tr("These files will be added to version control next time you commit them."); | 73 m_descriptions[FileStates::Added] = tr("These files will be added to version control next time you commit them."); |
74 m_descriptions[FileStates::Removed] = tr("These files will be removed from version control next time you commit them.<br>" | 74 m_descriptions[FileStates::Removed] = tr("These files will be removed from version control next time you commit them.<br>" |
119 this, SLOT(itemSelectionChanged())); | 119 this, SLOT(itemSelectionChanged())); |
120 | 120 |
121 FileStates::Activities activities = m_fileStates.activitiesSupportedBy(s); | 121 FileStates::Activities activities = m_fileStates.activitiesSupportedBy(s); |
122 int prevGroup = -1; | 122 int prevGroup = -1; |
123 foreach (FileStates::Activity a, activities) { | 123 foreach (FileStates::Activity a, activities) { |
124 // Skip activities which are not yet implemented | |
125 if (a == FileStates::Annotate || | |
126 a == FileStates::Ignore || | |
127 a == FileStates::UnIgnore) { | |
128 continue; | |
129 } | |
124 int group = FileStates::activityGroup(a); | 130 int group = FileStates::activityGroup(a); |
125 if (group != prevGroup && prevGroup != -1) { | 131 if (group != prevGroup && prevGroup != -1) { |
126 QAction *sep = new QAction("", w); | 132 QAction *sep = new QAction("", w); |
127 sep->setSeparator(true); | 133 sep->setSeparator(true); |
128 w->insertAction(0, sep); | 134 w->insertAction(0, sep); |
129 } | 135 } |
130 prevGroup = group; | 136 prevGroup = group; |
131 QAction *act = new QAction(m_actionLabels[a], w); | 137 QAction *act = new QAction(m_actionLabels[a], w); |
138 act->setProperty("state", s); | |
139 act->setProperty("activity", a); | |
140 connect(act, SIGNAL(triggered()), this, SLOT(menuActionActivated())); | |
132 w->insertAction(0, act); | 141 w->insertAction(0, act); |
133 } | 142 } |
134 w->setContextMenuPolicy(Qt::ActionsContextMenu); | 143 w->setContextMenuPolicy(Qt::ActionsContextMenu); |
135 | 144 |
136 boxlayout->addItem(new QSpacerItem(2, 2), 3, 0); | 145 boxlayout->addItem(new QSpacerItem(2, 2), 3, 0); |
199 (tr("<qt>You have no uncommitted changes.</qt>")); | 208 (tr("<qt>You have no uncommitted changes.</qt>")); |
200 } | 209 } |
201 } | 210 } |
202 | 211 |
203 | 212 |
204 | 213 void FileStatusWidget::menuActionActivated() |
205 //!!! So, we want a right-button menu on each list view. With which options? | 214 { |
206 // | 215 QAction *act = qobject_cast<QAction *>(sender()); |
207 // Modified -- commit, revert, remove, diff, annotate | 216 if (!act) return; |
208 // Added -- commit, revert, remove | 217 |
209 // Removed -- commit, revert, add | 218 FileStates::State state = (FileStates::State) |
210 // InConflict -- merge, mark resolved (can't do revert for a single file during merge? or can we?), annotate? | 219 act->property("state").toUInt(); |
211 // Missing -- remove, restore | 220 FileStates::Activity activity = (FileStates::Activity) |
212 // Unknown -- add, ignore (!) | 221 act->property("activity").toUInt(); |
213 // Clean -- remove, annotate | 222 |
214 // Ignored -- un-ignore? but how?, edit .hgignore | 223 DEBUG << "menuActionActivated: state = " << state << ", activity = " |
215 // | 224 << activity << endl; |
216 // or by function: | 225 |
217 // | 226 if (!FileStates::supportsActivity(state, activity)) { |
218 // commit -- Modified, Added, Removed | 227 std::cerr << "WARNING: FileStatusWidget::menuActionActivated: " |
219 // revert -- Modified, Added, Removed, InConflict, Missing (but call it restore?) | 228 << "Action state " << state << " does not support activity " |
220 // diff -- Modified | 229 << activity << std::endl; |
221 // remove -- Clean, Modified, Missing, Added | 230 return; |
222 // add -- Unknown, Removed | 231 } |
223 // merge (redo) -- InConflict | 232 |
224 // mark resolved -- InConflict | 233 QStringList files = getSelectedFilesInState(state); |
225 // annotate -- Clean, Modified, Added?, Removed?, Missing? | 234 |
226 // ignore -- Unknown | 235 switch (activity) { |
227 // un-ignore (?), edit hgignore -- Ignored | 236 case FileStates::Annotate: emit annotateFiles(files); break; |
228 | 237 case FileStates::Diff: emit diffFiles(files); break; |
238 case FileStates::Commit: emit commitFiles(files); break; | |
239 case FileStates::Revert: emit revertFiles(files); break; | |
240 case FileStates::Add: emit addFiles(files); break; | |
241 case FileStates::Remove: emit removeFiles(files); break; | |
242 case FileStates::RedoMerge: emit redoFileMerges(files); break; | |
243 case FileStates::MarkResolved: emit markFilesResolved(files); break; | |
244 case FileStates::Ignore: emit ignoreFiles(files); break; | |
245 case FileStates::UnIgnore: emit unIgnoreFiles(files); break; | |
246 } | |
247 } | |
229 | 248 |
230 | 249 |
231 void FileStatusWidget::itemSelectionChanged() | 250 void FileStatusWidget::itemSelectionChanged() |
232 { | 251 { |
233 DEBUG << "FileStatusWidget::itemSelectionChanged" << endl; | 252 DEBUG << "FileStatusWidget::itemSelectionChanged" << endl; |
265 } | 284 } |
266 } | 285 } |
267 | 286 |
268 bool FileStatusWidget::haveChangesToCommit() const | 287 bool FileStatusWidget::haveChangesToCommit() const |
269 { | 288 { |
270 return !m_fileStates.added().empty() || | 289 return !getAllCommittableFiles().empty(); |
271 !m_fileStates.removed().empty() || | |
272 !m_fileStates.modified().empty(); | |
273 } | 290 } |
274 | 291 |
275 bool FileStatusWidget::haveSelection() const | 292 bool FileStatusWidget::haveSelection() const |
276 { | 293 { |
277 return !m_selectedFiles.empty(); | 294 return !m_selectedFiles.empty(); |
278 } | 295 } |
279 | 296 |
280 QStringList FileStatusWidget::getAllSelectedFiles() const | 297 QStringList FileStatusWidget::getSelectedFilesInState(FileStates::State s) const |
281 { | |
282 return m_selectedFiles; | |
283 } | |
284 | |
285 QStringList FileStatusWidget::getSelectedCommittableFiles() const | |
286 { | 298 { |
287 QStringList files; | 299 QStringList files; |
288 foreach (QString f, m_selectedFiles) { | 300 foreach (QString f, m_selectedFiles) { |
289 switch (m_fileStates.stateOf(f)) { | 301 if (m_fileStates.stateOf(f) == s) files.push_back(f); |
290 case FileStates::Added: | |
291 case FileStates::Modified: | |
292 case FileStates::Removed: | |
293 files.push_back(f); | |
294 break; | |
295 default: break; | |
296 } | |
297 } | 302 } |
298 return files; | 303 return files; |
299 } | 304 } |
300 | 305 |
301 QStringList FileStatusWidget::getAllCommittableFiles() const | 306 QStringList FileStatusWidget::getSelectedFilesSupportingActivity(FileStates::Activity a) const |
302 { | |
303 QStringList files; | |
304 files << m_fileStates.filesInState(FileStates::Modified); | |
305 files << m_fileStates.filesInState(FileStates::Added); | |
306 files << m_fileStates.filesInState(FileStates::Removed); | |
307 return files; | |
308 } | |
309 | |
310 QStringList FileStatusWidget::getSelectedRevertableFiles() const | |
311 { | 307 { |
312 QStringList files; | 308 QStringList files; |
313 foreach (QString f, m_selectedFiles) { | 309 foreach (QString f, m_selectedFiles) { |
314 switch (m_fileStates.stateOf(f)) { | 310 if (m_fileStates.supportsActivity(f, a)) files.push_back(f); |
315 case FileStates::Added: | |
316 case FileStates::Modified: | |
317 case FileStates::Removed: | |
318 case FileStates::Missing: | |
319 case FileStates::InConflict: | |
320 files.push_back(f); | |
321 break; | |
322 default: break; | |
323 } | |
324 } | 311 } |
325 return files; | 312 return files; |
313 } | |
314 | |
315 QStringList FileStatusWidget::getAllCommittableFiles() const | |
316 { | |
317 return m_fileStates.filesSupportingActivity(FileStates::Commit); | |
326 } | 318 } |
327 | 319 |
328 QStringList FileStatusWidget::getAllRevertableFiles() const | 320 QStringList FileStatusWidget::getAllRevertableFiles() const |
329 { | 321 { |
330 QStringList files; | 322 return m_fileStates.filesSupportingActivity(FileStates::Revert); |
331 files << m_fileStates.filesInState(FileStates::Modified); | |
332 files << m_fileStates.filesInState(FileStates::Added); | |
333 files << m_fileStates.filesInState(FileStates::Removed); | |
334 files << m_fileStates.filesInState(FileStates::Missing); | |
335 files << m_fileStates.filesInState(FileStates::InConflict); | |
336 return files; | |
337 } | |
338 | |
339 QStringList FileStatusWidget::getSelectedUnresolvedFiles() const | |
340 { | |
341 QStringList files; | |
342 foreach (QString f, m_selectedFiles) { | |
343 switch (m_fileStates.stateOf(f)) { | |
344 case FileStates::InConflict: | |
345 files.push_back(f); | |
346 break; | |
347 default: break; | |
348 } | |
349 } | |
350 return files; | |
351 } | 323 } |
352 | 324 |
353 QStringList FileStatusWidget::getAllUnresolvedFiles() const | 325 QStringList FileStatusWidget::getAllUnresolvedFiles() const |
354 { | 326 { |
355 QStringList files; | 327 return m_fileStates.filesInState(FileStates::InConflict); |
356 files << m_fileStates.filesInState(FileStates::InConflict); | |
357 return files; | |
358 } | 328 } |
359 | 329 |
360 QStringList FileStatusWidget::getSelectedAddableFiles() const | 330 QStringList FileStatusWidget::getSelectedAddableFiles() const |
361 { | 331 { |
362 QStringList files; | 332 return getSelectedFilesSupportingActivity(FileStates::Add); |
363 foreach (QString f, m_selectedFiles) { | |
364 switch (m_fileStates.stateOf(f)) { | |
365 case FileStates::Unknown: | |
366 case FileStates::Removed: | |
367 files.push_back(f); | |
368 break; | |
369 default: break; | |
370 } | |
371 } | |
372 return files; | |
373 } | |
374 | |
375 QStringList FileStatusWidget::getAllAddableFiles() const | |
376 { | |
377 QStringList files; | |
378 files << m_fileStates.filesInState(FileStates::Removed); | |
379 files << m_fileStates.filesInState(FileStates::Unknown); | |
380 return files; | |
381 } | 333 } |
382 | 334 |
383 QStringList FileStatusWidget::getSelectedRemovableFiles() const | 335 QStringList FileStatusWidget::getSelectedRemovableFiles() const |
384 { | 336 { |
385 QStringList files; | 337 return getSelectedFilesSupportingActivity(FileStates::Remove); |
386 foreach (QString f, m_selectedFiles) { | |
387 switch (m_fileStates.stateOf(f)) { | |
388 case FileStates::Clean: | |
389 case FileStates::Added: | |
390 case FileStates::Modified: | |
391 case FileStates::Missing: | |
392 case FileStates::InConflict: | |
393 files.push_back(f); | |
394 break; | |
395 default: break; | |
396 } | |
397 } | |
398 return files; | |
399 } | |
400 | |
401 QStringList FileStatusWidget::getAllRemovableFiles() const | |
402 { | |
403 QStringList files; | |
404 files << m_fileStates.filesInState(FileStates::Clean); | |
405 files << m_fileStates.filesInState(FileStates::Added); | |
406 files << m_fileStates.filesInState(FileStates::Modified); | |
407 files << m_fileStates.filesInState(FileStates::Missing); | |
408 files << m_fileStates.filesInState(FileStates::InConflict); | |
409 return files; | |
410 } | 338 } |
411 | 339 |
412 QString | 340 QString |
413 FileStatusWidget::localPath() const | 341 FileStatusWidget::localPath() const |
414 { | 342 { |
487 } | 415 } |
488 | 416 |
489 foreach (QString file, highPriority) { | 417 foreach (QString file, highPriority) { |
490 QListWidgetItem *item = new QListWidgetItem(file); | 418 QListWidgetItem *item = new QListWidgetItem(file); |
491 w->addItem(item); | 419 w->addItem(item); |
492 item->setForeground(QColor("#d40000")); //!!! and a nice gold star | 420 item->setForeground(QColor("#d40000")); |
493 item->setSelected(selectedFiles.contains(file)); | 421 item->setSelected(selectedFiles.contains(file)); |
494 } | 422 } |
495 | 423 |
496 foreach (QString file, lowPriority) { | 424 foreach (QString file, lowPriority) { |
497 QListWidgetItem *item = new QListWidgetItem(file); | 425 QListWidgetItem *item = new QListWidgetItem(file); |