Commit 4b0260eb authored by Raphael Rosch's avatar Raphael Rosch Committed by Christoph Cullmann

Add sortable columns to session manager dialog, and remove previous sorting code

Summary:
I really like the new session manager dialog (session chooser) but when I went to click on the column headers to sort, it didn't work. So I wondered how hard it would be to implement and just went for it.

I know the diff is supposed to be done with arc, but I don't yet have that all set up, and I wanted to get you the patch over as soon as possible. I hope that's ok.

One thing that does not work properly is the sorting by number of open files, since that requires numeric sort which was beyond my current abilities, maybe someone else can take that up for the next round, once this simple patch is in.

I also corrected a couple spelling mistakes, which accounts for the extra lines.

Test Plan:
Apply patch (should apply cleanly to most recent master).
Compile.
Run kate.

Reviewers: #kate, dhaumann, cullmann

Reviewed By: #kate, cullmann

Subscribers: kwrite-devel

Tags: #kate

Differential Revision: https://phabricator.kde.org/D27180
parent b86fdca7
......@@ -35,6 +35,7 @@ public:
QString docs;
docs.setNum(s->documents());
setText(1, docs);
setText(2, s->timestamp().toString(QString::fromStdString("yyyy-MM-dd hh:mm:ss")));
}
KateSession::Ptr session;
......
......@@ -47,7 +47,6 @@ KateSessionManageDialog::KateSessionManageDialog(QWidget *parent)
m_filterBox->installEventFilter(this);
connect(m_filterBox, &QLineEdit::textChanged, this, &KateSessionManageDialog::filterChanged);
connect(m_sortButton, &QPushButton::clicked, this, &KateSessionManageDialog::changeSortOrder);
connect(m_newButton, &QPushButton::clicked, this, &KateSessionManageDialog::openNewSession);
......@@ -67,8 +66,6 @@ KateSessionManageDialog::KateSessionManageDialog(QWidget *parent)
connect(m_closeButton, &QPushButton::clicked, this, &KateSessionManageDialog::closeDialog);
connect(KateApp::self()->sessionManager(), &KateSessionManager::sessionListChanged, this, &KateSessionManageDialog::updateSessionList);
changeSortOrder(); // Set order to SortAlphabetical, set button text and fill session list
}
KateSessionManageDialog::KateSessionManageDialog(QWidget *parent, const QString &lastSession)
......@@ -79,8 +76,8 @@ KateSessionManageDialog::KateSessionManageDialog(QWidget *parent, const QString
m_chooserMode = true;
connect(m_dontAskCheckBox, &QCheckBox::toggled, this, &KateSessionManageDialog::dontAskToggled);
m_prefferedSession = lastSession;
changeSortOrder(); // Set order to SortChronological
m_preferredSession = lastSession;
updateSessionList();
}
KateSessionManageDialog::~KateSessionManageDialog()
......@@ -92,24 +89,6 @@ void KateSessionManageDialog::dontAskToggled()
m_templateButton->setEnabled(!m_dontAskCheckBox->isChecked());
}
void KateSessionManageDialog::changeSortOrder()
{
switch (m_sortOrder) {
case SortAlphabetical:
m_sortOrder = SortChronological;
m_sortButton->setText(i18n("Sort Alphabetical"));
// m_sortButton->setIcon(QIcon::fromTheme(QStringLiteral("FIXME")));
break;
case SortChronological:
m_sortOrder = SortAlphabetical;
m_sortButton->setText(i18n("Sort Last Used"));
// m_sortButton->setIcon(QIcon::fromTheme(QStringLiteral("FIXME")));
break;
}
updateSessionList();
}
void KateSessionManageDialog::filterChanged()
{
static QPointer<QTimer> delay;
......@@ -203,7 +182,6 @@ void KateSessionManageDialog::disableButtons()
m_renameButton->setEnabled(false);
m_deleteButton->setEnabled(false);
m_closeButton->setEnabled(false);
m_sortButton->setEnabled(false);
m_filterBox->setEnabled(false);
}
......@@ -241,7 +219,6 @@ void KateSessionManageDialog::editDone()
m_newButton->setEnabled(true);
m_dontAskCheckBox->setEnabled(true);
m_closeButton->setEnabled(true);
m_sortButton->setEnabled(true);
m_filterBox->setEnabled(true);
m_sessionList->setFocus();
......@@ -265,7 +242,7 @@ void KateSessionManageDialog::copySession()
return;
}
m_prefferedSession = KateApp::self()->sessionManager()->copySession(item->session);
m_preferredSession = KateApp::self()->sessionManager()->copySession(item->session);
m_sessionList->setFocus(); // Only needed when user abort
}
......@@ -358,16 +335,12 @@ void KateSessionManageDialog::updateSessionList()
m_sessionList->clear();
KateSessionList slist = KateApp::self()->sessionManager()->sessionList();
switch (m_sortOrder) {
case SortAlphabetical:
std::sort(slist.begin(), slist.end(), KateSession::compareByName);
break;
case SortChronological:
std::sort(slist.begin(), slist.end(), KateSession::compareByTimeDesc);
break;
}
// SortAlphabetical:
// std::sort(slist.begin(), slist.end(), KateSession::compareByName);
// SortChronological:
// std::sort(slist.begin(), slist.end(), KateSession::compareByTimeDesc);
KateSessionChooserItem *prefferedItem = nullptr;
KateSessionChooserItem *preferredItem = nullptr;
KateSessionChooserItem *currSessionItem = nullptr;
KateSessionChooserItem *activeSessionItem = nullptr;
......@@ -383,25 +356,29 @@ void KateSessionManageDialog::updateSessionList()
currSessionItem = item;
} else if (session == activeSession) {
activeSessionItem = item;
} else if (session->name() == m_prefferedSession) {
prefferedItem = item;
m_prefferedSession.clear();
} else if (session->name() == m_preferredSession) {
preferredItem = item;
m_preferredSession.clear();
}
if (m_deleteList.contains(session)) {
markItemAsToBeDeleted(item);
}
}
m_sessionList->resizeColumnToContents(1); // Minimize "Files" column
if (!prefferedItem) {
prefferedItem = currSessionItem ? currSessionItem : activeSessionItem;
m_sessionList->header()->setStretchLastSection(false);
m_sessionList->header()->setSectionResizeMode(0, QHeaderView::Stretch); // stretch "Session Name" column
m_sessionList->resizeColumnToContents(1); // Fit "Files" column
m_sessionList->resizeColumnToContents(2); // Fit "Last update" column
m_sessionList->sortByColumn(2); // sort by "Last update" column.. don't worry, it only sorts when the model data changes.
if (!preferredItem) {
preferredItem = currSessionItem ? currSessionItem : activeSessionItem;
}
if (prefferedItem) {
m_sessionList->setCurrentItem(prefferedItem);
m_sessionList->scrollToItem(prefferedItem);
if (preferredItem) {
m_sessionList->setCurrentItem(preferredItem);
m_sessionList->scrollToItem(preferredItem);
} else if (m_sessionList->topLevelItemCount() > 0) {
m_sessionList->setCurrentItem(m_sessionList->topLevelItem(0));
}
......
......@@ -126,11 +126,6 @@ protected Q_SLOTS:
*/
void dontAskToggled();
/**
* To change the sort order of the session list
*/
void changeSortOrder();
/**
* Slot for @c m_filterField
*/
......@@ -146,14 +141,6 @@ private:
ResultNew,
};
/**
* Sort order of the session list
*/
enum SortOrder {
SortAlphabetical,
SortChronological,
};
/**
* Re-implemented to avoid crash when in edit state
*/
......@@ -194,12 +181,7 @@ private:
/**
* Used by @c updateSessionList() to choose a new current item
*/
QString m_prefferedSession;
/**
* How the list of sessions has to be ordered
*/
int m_sortOrder = SortChronological;
QString m_preferredSession;
/**
* Used in dtor to do some savings or not
......
......@@ -34,19 +34,6 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_sortButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">Sort</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
......@@ -57,6 +44,9 @@
<property name="itemsExpandable">
<bool>false</bool>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<property name="allColumnsShowFocus">
<bool>true</bool>
</property>
......@@ -73,6 +63,11 @@
<set>AlignLeading|AlignVCenter</set>
</property>
</column>
<column>
<property name="text">
<string>Last opened</string>
</property>
</column>
</widget>
</item>
</layout>
......@@ -235,7 +230,6 @@
<tabstop>m_closeButton</tabstop>
<tabstop>m_filterBox</tabstop>
<tabstop>m_sessionList</tabstop>
<tabstop>m_sortButton</tabstop>
<tabstop>m_openButton</tabstop>
</tabstops>
<resources/>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment