-
-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use columns for file name, directory, and state when files are shown as a list in TreeViews. #664
Changes from all commits
1d6d53b
c416cc6
d54bb20
1bad8fa
7bb4a7a
1f3e81a
ad5cfe3
9636a11
d598ac2
986cbf1
c836908
73e3cf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ | |
#include "StatePushButton.h" | ||
#include "TreeProxy.h" | ||
#include "TreeView.h" | ||
#include "ViewDelegate.h" | ||
#include "Debug.h" | ||
#include "conf/Settings.h" | ||
#include "DiffView/DiffView.h" | ||
|
@@ -68,6 +67,21 @@ class SegmentedButton : public QWidget { | |
|
||
} // namespace | ||
|
||
QAction *DoubleTreeWidget::setupAppearanceAction(const char *name, | ||
Setting::Id id, | ||
bool defaultValue) { | ||
QAction *action = new QAction(tr(name)); | ||
action->setCheckable(true); | ||
action->setChecked(Settings::instance()->value(id, defaultValue).toBool()); | ||
connect(action, &QAction::triggered, this, [this, id](bool checked) { | ||
Settings::instance()->setValue(id, checked); | ||
mSelectedFile.filename = | ||
""; // When switching view, it is not possible to restore | ||
RepoView::parentView(this)->refresh(); | ||
}); | ||
return action; | ||
} | ||
|
||
DoubleTreeWidget::DoubleTreeWidget(const git::Repository &repo, QWidget *parent) | ||
: ContentWidget(parent) { | ||
// first column | ||
|
@@ -82,39 +96,21 @@ DoubleTreeWidget::DoubleTreeWidget(const git::Repository &repo, QWidget *parent) | |
ContextMenuButton *contextButton = new ContextMenuButton(this); | ||
QMenu *contextMenu = new QMenu(this); | ||
contextButton->setMenu(contextMenu); | ||
QAction *singleTree = new QAction(tr("Single Tree View")); | ||
singleTree->setCheckable(true); | ||
singleTree->setChecked( | ||
Settings::instance() | ||
->value(Setting::Id::ShowChangedFilesInSingleView, false) | ||
.toBool()); | ||
connect(singleTree, &QAction::triggered, this, [this](bool checked) { | ||
Settings::instance()->setValue(Setting::Id::ShowChangedFilesInSingleView, | ||
checked); | ||
RepoView::parentView(this)->refresh(); | ||
}); | ||
QAction *listView = new QAction(tr("List View")); | ||
listView->setCheckable(true); | ||
listView->setChecked(Settings::instance() | ||
->value(Setting::Id::ShowChangedFilesAsList, false) | ||
.toBool()); | ||
connect(listView, &QAction::triggered, this, [this](bool checked) { | ||
Settings::instance()->setValue(Setting::Id::ShowChangedFilesAsList, | ||
checked); | ||
RepoView::parentView(this)->refresh(); | ||
}); | ||
QAction *hideUntrackedFiles = new QAction(tr("Hide Untracked Files")); | ||
hideUntrackedFiles->setCheckable(true); | ||
hideUntrackedFiles->setChecked( | ||
RepoView::parentView(parent)->repo().appConfig().value<bool>( | ||
"untracked.hide", false)); | ||
connect(hideUntrackedFiles, &QAction::triggered, this, [this](bool checked) { | ||
RepoView::parentView(this)->repo().appConfig().setValue("untracked.hide", | ||
checked); | ||
RepoView::parentView(this)->refresh(); | ||
}); | ||
|
||
QAction *singleTree = setupAppearanceAction( | ||
"Single View", Setting::Id::ShowChangedFilesInSingleView); | ||
QAction *listView = | ||
setupAppearanceAction("List View", Setting::Id::ShowChangedFilesAsList); | ||
QAction *multiColumn = setupAppearanceAction( | ||
"Multi Column", Setting::Id::ShowChangedFilesMultiColumn, true); | ||
RepoView::parentView(this)->refresh(); // apply read settings | ||
|
||
QAction *hideUntrackedFiles = setupAppearanceAction( | ||
"Hide Untracked Files", Setting::Id::HideUntracked, false); | ||
|
||
contextMenu->addAction(singleTree); | ||
contextMenu->addAction(listView); | ||
contextMenu->addAction(multiColumn); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this just an option when the list view is active? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes this is true, not sure how to handle it. Shall we mark it as this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can think of 2 possibilities to resolve this:
The first possibility keeps the UI as you have it and just enforces the semantics. The second restores the original context menu options and makes the multi-column setting be a "meta" setting for the list view - i.e. the user has to decide which kind of list view is desired and be willing to use it consistently. It would be nice to resolve this somehow now but it could be cleaned up with a later submission too. I'm OK with either. |
||
contextMenu->addAction(hideUntrackedFiles); | ||
QHBoxLayout *buttonLayout = new QHBoxLayout(); | ||
buttonLayout->addStretch(); | ||
|
@@ -160,13 +156,8 @@ DoubleTreeWidget::DoubleTreeWidget(const git::Repository &repo, QWidget *parent) | |
repoView->updateSubmodules(submodules, recursive, init, | ||
force_checkout); | ||
}); | ||
TreeProxy *treewrapperStaged = new TreeProxy(true, this); | ||
treewrapperStaged->setSourceModel(mDiffTreeModel); | ||
stagedFiles->setModel(treewrapperStaged); | ||
stagedFiles->setHeaderHidden(true); | ||
ViewDelegate *stagedDelegate = new ViewDelegate(); | ||
stagedDelegate->setDrawArrow(false); | ||
stagedFiles->setItemDelegateForColumn(0, stagedDelegate); | ||
|
||
stagedFiles->setModel(new TreeProxy(true, mDiffTreeModel, this)); | ||
|
||
QHBoxLayout *hBoxLayout = new QHBoxLayout(); | ||
QLabel *label = new QLabel(kStagedFiles); | ||
|
@@ -192,13 +183,7 @@ DoubleTreeWidget::DoubleTreeWidget(const git::Repository &repo, QWidget *parent) | |
showFileContextMenu(pos, repoView, unstagedFiles, false); | ||
}); | ||
|
||
TreeProxy *treewrapperUnstaged = new TreeProxy(false, this); | ||
treewrapperUnstaged->setSourceModel(mDiffTreeModel); | ||
unstagedFiles->setModel(treewrapperUnstaged); | ||
unstagedFiles->setHeaderHidden(true); | ||
ViewDelegate *unstagedDelegate = new ViewDelegate(); | ||
unstagedDelegate->setDrawArrow(false); | ||
unstagedFiles->setItemDelegateForColumn(0, unstagedDelegate); | ||
unstagedFiles->setModel(new TreeProxy(false, mDiffTreeModel, this)); | ||
|
||
hBoxLayout = new QHBoxLayout(); | ||
mUnstagedCommitedFiles = new QLabel(kUnstagedFiles); | ||
|
@@ -417,12 +402,6 @@ void DoubleTreeWidget::setDiff(const git::Diff &diff, const QString &file, | |
TreeProxy *proxy = static_cast<TreeProxy *>(unstagedFiles->model()); | ||
DiffTreeModel *model = static_cast<DiffTreeModel *>(proxy->sourceModel()); | ||
model->setDiff(diff); | ||
// do not expand if to many files exist, it takes really long | ||
// So do it only when there are less than 100 | ||
if (diff.isValid() && diff.count() < fileCountExpansionThreshold) | ||
unstagedFiles->expandAll(); | ||
else | ||
unstagedFiles->collapseAll(); | ||
|
||
// Single tree & list view. | ||
bool singleTree = | ||
|
@@ -432,15 +411,24 @@ void DoubleTreeWidget::setDiff(const git::Diff &diff, const QString &file, | |
bool listView = Settings::instance() | ||
->value(Setting::Id::ShowChangedFilesAsList, false) | ||
.toBool(); | ||
const bool multiColumn = | ||
Settings::instance() | ||
->value(Setting::Id::ShowChangedFilesMultiColumn, true) | ||
.toBool(); | ||
|
||
// Widget modifications. | ||
model->enableListView(listView); | ||
model->setMultiColumn(multiColumn); | ||
stagedFiles->setRootIsDecorated(!listView); | ||
unstagedFiles->setRootIsDecorated(!listView); | ||
// mUnstagedCommitedFiles->setVisible(!singleTree); | ||
collapseButtonStagedFiles->setVisible(!listView); | ||
collapseButtonUnstagedFiles->setVisible(!listView); | ||
|
||
unstagedFiles->updateView(); // Must be before expandAll/collapseAll is done, | ||
// otherwise the collapse counter is wrong | ||
stagedFiles->updateView(); | ||
|
||
// If statusDiff, there exist no staged/unstaged, but only | ||
// the commited files must be shown | ||
if (!diff.isValid() || diff.isStatusDiff()) { | ||
|
@@ -457,6 +445,13 @@ void DoubleTreeWidget::setDiff(const git::Diff &diff, const QString &file, | |
mStagedWidget->setVisible(false); | ||
} | ||
|
||
// do not expand if to many files exist, it takes really long | ||
// So do it only when there are less than 100 | ||
if (diff.isValid() && diff.count() < fileCountExpansionThreshold) | ||
unstagedFiles->expandAll(); | ||
else | ||
unstagedFiles->collapseAll(); | ||
|
||
// Clear editor. | ||
mEditor->clear(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this. :-)