Mercurial > hg > easyhg
diff 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 |
line wrap: on
line diff
--- a/filestatuswidget.cpp Thu Mar 10 21:04:58 2011 +0000 +++ b/filestatuswidget.cpp Fri Mar 11 15:33:16 2011 +0000 @@ -57,16 +57,16 @@ 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::Annotate] = tr("Show annotated version"); + m_actionLabels[FileStates::Diff] = tr("Diff to parent"); 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::Revert] = tr("Revert to last commit"); + m_actionLabels[FileStates::Add] = tr("Add to version control"); + m_actionLabels[FileStates::Remove] = tr("Remove from version control"); + 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_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."); @@ -121,6 +121,12 @@ FileStates::Activities activities = m_fileStates.activitiesSupportedBy(s); int prevGroup = -1; foreach (FileStates::Activity a, activities) { + // Skip activities which are not yet implemented + if (a == FileStates::Annotate || + a == FileStates::Ignore || + a == FileStates::UnIgnore) { + continue; + } int group = FileStates::activityGroup(a); if (group != prevGroup && prevGroup != -1) { QAction *sep = new QAction("", w); @@ -129,6 +135,9 @@ } prevGroup = group; QAction *act = new QAction(m_actionLabels[a], w); + act->setProperty("state", s); + act->setProperty("activity", a); + connect(act, SIGNAL(triggered()), this, SLOT(menuActionActivated())); w->insertAction(0, act); } w->setContextMenuPolicy(Qt::ActionsContextMenu); @@ -201,31 +210,41 @@ } +void FileStatusWidget::menuActionActivated() +{ + QAction *act = qobject_cast<QAction *>(sender()); + if (!act) return; + + FileStates::State state = (FileStates::State) + act->property("state").toUInt(); + FileStates::Activity activity = (FileStates::Activity) + act->property("activity").toUInt(); -//!!! So, we want a right-button menu on each list view. With which options? -// -// Modified -- commit, revert, remove, diff, annotate -// Added -- commit, revert, remove -// Removed -- commit, revert, add -// InConflict -- merge, mark resolved (can't do revert for a single file during merge? or can we?), annotate? -// Missing -- remove, restore -// Unknown -- add, ignore (!) -// Clean -- remove, annotate -// Ignored -- un-ignore? but how?, edit .hgignore -// -// or by function: -// -// commit -- Modified, Added, Removed -// revert -- Modified, Added, Removed, InConflict, Missing (but call it restore?) -// diff -- Modified -// remove -- Clean, Modified, Missing, Added -// add -- Unknown, Removed -// merge (redo) -- InConflict -// mark resolved -- InConflict -// annotate -- Clean, Modified, Added?, Removed?, Missing? -// ignore -- Unknown -// un-ignore (?), edit hgignore -- Ignored + DEBUG << "menuActionActivated: state = " << state << ", activity = " + << activity << endl; + if (!FileStates::supportsActivity(state, activity)) { + std::cerr << "WARNING: FileStatusWidget::menuActionActivated: " + << "Action state " << state << " does not support activity " + << activity << std::endl; + return; + } + + QStringList files = getSelectedFilesInState(state); + + switch (activity) { + case FileStates::Annotate: emit annotateFiles(files); break; + case FileStates::Diff: emit diffFiles(files); break; + case FileStates::Commit: emit commitFiles(files); break; + case FileStates::Revert: emit revertFiles(files); break; + case FileStates::Add: emit addFiles(files); break; + case FileStates::Remove: emit removeFiles(files); break; + case FileStates::RedoMerge: emit redoFileMerges(files); break; + case FileStates::MarkResolved: emit markFilesResolved(files); break; + case FileStates::Ignore: emit ignoreFiles(files); break; + case FileStates::UnIgnore: emit unIgnoreFiles(files); break; + } +} void FileStatusWidget::itemSelectionChanged() @@ -267,9 +286,7 @@ bool FileStatusWidget::haveChangesToCommit() const { - return !m_fileStates.added().empty() || - !m_fileStates.removed().empty() || - !m_fileStates.modified().empty(); + return !getAllCommittableFiles().empty(); } bool FileStatusWidget::haveSelection() const @@ -277,136 +294,47 @@ return !m_selectedFiles.empty(); } -QStringList FileStatusWidget::getAllSelectedFiles() const -{ - return m_selectedFiles; -} - -QStringList FileStatusWidget::getSelectedCommittableFiles() const +QStringList FileStatusWidget::getSelectedFilesInState(FileStates::State s) const { QStringList files; foreach (QString f, m_selectedFiles) { - switch (m_fileStates.stateOf(f)) { - case FileStates::Added: - case FileStates::Modified: - case FileStates::Removed: - files.push_back(f); - break; - default: break; - } + if (m_fileStates.stateOf(f) == s) files.push_back(f); } return files; -} +} + +QStringList FileStatusWidget::getSelectedFilesSupportingActivity(FileStates::Activity a) const +{ + QStringList files; + foreach (QString f, m_selectedFiles) { + if (m_fileStates.supportsActivity(f, a)) files.push_back(f); + } + return files; +} QStringList FileStatusWidget::getAllCommittableFiles() const { - QStringList files; - files << m_fileStates.filesInState(FileStates::Modified); - files << m_fileStates.filesInState(FileStates::Added); - files << m_fileStates.filesInState(FileStates::Removed); - return files; -} - -QStringList FileStatusWidget::getSelectedRevertableFiles() const -{ - QStringList files; - foreach (QString f, m_selectedFiles) { - switch (m_fileStates.stateOf(f)) { - case FileStates::Added: - case FileStates::Modified: - case FileStates::Removed: - case FileStates::Missing: - case FileStates::InConflict: - files.push_back(f); - break; - default: break; - } - } - return files; + return m_fileStates.filesSupportingActivity(FileStates::Commit); } QStringList FileStatusWidget::getAllRevertableFiles() const { - QStringList files; - 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; -} - -QStringList FileStatusWidget::getSelectedUnresolvedFiles() const -{ - QStringList files; - foreach (QString f, m_selectedFiles) { - switch (m_fileStates.stateOf(f)) { - case FileStates::InConflict: - files.push_back(f); - break; - default: break; - } - } - return files; + return m_fileStates.filesSupportingActivity(FileStates::Revert); } QStringList FileStatusWidget::getAllUnresolvedFiles() const { - QStringList files; - files << m_fileStates.filesInState(FileStates::InConflict); - return files; + return m_fileStates.filesInState(FileStates::InConflict); } QStringList FileStatusWidget::getSelectedAddableFiles() const { - QStringList files; - foreach (QString f, m_selectedFiles) { - switch (m_fileStates.stateOf(f)) { - case FileStates::Unknown: - case FileStates::Removed: - files.push_back(f); - break; - default: break; - } - } - return files; -} - -QStringList FileStatusWidget::getAllAddableFiles() const -{ - QStringList files; - files << m_fileStates.filesInState(FileStates::Removed); - files << m_fileStates.filesInState(FileStates::Unknown); - return files; + return getSelectedFilesSupportingActivity(FileStates::Add); } QStringList FileStatusWidget::getSelectedRemovableFiles() const { - QStringList files; - foreach (QString f, m_selectedFiles) { - switch (m_fileStates.stateOf(f)) { - case FileStates::Clean: - case FileStates::Added: - case FileStates::Modified: - case FileStates::Missing: - case FileStates::InConflict: - files.push_back(f); - break; - default: break; - } - } - return files; -} - -QStringList FileStatusWidget::getAllRemovableFiles() const -{ - QStringList files; - 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; + return getSelectedFilesSupportingActivity(FileStates::Remove); } QString @@ -489,7 +417,7 @@ foreach (QString file, highPriority) { QListWidgetItem *item = new QListWidgetItem(file); w->addItem(item); - item->setForeground(QColor("#d40000")); //!!! and a nice gold star + item->setForeground(QColor("#d40000")); item->setSelected(selectedFiles.contains(file)); }