File indexing completed on 2024-05-12 05:52:08
0001 /* 0002 SPDX-FileCopyrightText: 2005 Christoph Cullmann <cullmann@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QDialog> 0010 0011 class QPushButton; 0012 class QTreeWidget; 0013 class QTreeWidgetItem; 0014 class KateSessionChooserItem; 0015 0016 #include "katesession.h" 0017 #include "ui_katesessionmanagedialog.h" 0018 0019 class KateSessionManageDialog : public QDialog, public Ui::KateSessionManageDialogUi 0020 { 0021 Q_OBJECT 0022 0023 public: 0024 /** 0025 * The normal ctor for manage mode 0026 */ 0027 explicit KateSessionManageDialog(QWidget *parent); 0028 0029 /** 0030 * The special ctor for chooser mode 0031 * Set a different window title, enables some extra widget and try to select 0032 * the @p lastSession in the session list. 0033 */ 0034 KateSessionManageDialog(QWidget *parent, const QString &lastSession); 0035 0036 protected Q_SLOTS: 0037 /** 0038 * Re-implemented to save in chooser mode users choice when needed and to 0039 * exit the dialog with a return code of @c 0/1 fitting to the code of 0040 * @p result to indicate that the user chose a session to open not. 0041 * @see KateSessionManager::chooseSession() 0042 * @param result has to be one of enum @c ResultCode 0043 */ 0044 void done(int result) override; 0045 0046 /** 0047 * To update the button states 0048 */ 0049 void selectionChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); 0050 0051 /** 0052 * Close the dialog and open the selected session 0053 */ 0054 void openSession(); 0055 0056 /** 0057 * Use the selected session as template for a new session 0058 */ 0059 void openSessionAsTemplate(); 0060 0061 /** 0062 * Open new anonymous session 0063 */ 0064 void openNewSession(); 0065 0066 /** 0067 * Copy the selected session 0068 */ 0069 void copySession(); 0070 0071 /** 0072 * Try to rename the session hold by @c m_editByUser 0073 * @see editDone(), editBegin(), m_editByUser 0074 */ 0075 void editApply(); 0076 0077 /** 0078 * Open the inline editor on the selected session, set @c m_editByUser to 0079 * the selected session and connect @c QTreeWidget::itemChanged signal to 0080 * @c editApply(). 0081 * @see editDone(), editApply(), m_editByUser 0082 */ 0083 void editBegin(); 0084 0085 /** 0086 * Finish the edit process, reset intern settings. 0087 * Calling this function without to call @c editApply() will abort edit. 0088 */ 0089 void editDone(); 0090 0091 /** 0092 * To close the dialog 0093 */ 0094 void closeDialog(); 0095 0096 /** 0097 * Slot for the delete button 0098 * @see m_deleteList, deleteSessions() 0099 */ 0100 void updateDeleteList(); 0101 0102 /** 0103 * Update the list of sessions in @c m_sessionList and trigger some needed 0104 * actions belong to the editing of session names. 0105 */ 0106 void updateSessionList(); 0107 0108 /** 0109 * To enable/disable not useful buttons 0110 */ 0111 void dontAskToggled(); 0112 0113 /** 0114 * Slot for @c m_filterField 0115 */ 0116 void filterChanged(); 0117 0118 private: 0119 /** 0120 * Result codes used to call @c done() 0121 */ 0122 enum ResultCode { 0123 ResultQuit = QDialog::Rejected, 0124 ResultOpen, 0125 ResultNew, 0126 }; 0127 0128 /** 0129 * Re-implemented to avoid crash when in edit state 0130 */ 0131 void closeEvent(QCloseEvent *event) override; 0132 0133 /** 0134 * Disables all buttons on the "normal" button stack page and the close button 0135 */ 0136 void disableButtons(); 0137 0138 /** 0139 * To handle the rename process 0140 */ 0141 bool eventFilter(QObject *object, QEvent *event) override; 0142 0143 /** 0144 * @return current selected item in @c m_sessionList or @c nullptr 0145 */ 0146 KateSessionChooserItem *currentSessionItem() const; 0147 0148 /** 0149 * @return current selected session in @c m_sessionList or empty @c KateSession::Ptr() 0150 */ 0151 KateSession::Ptr currentSelectedSession() const; 0152 0153 /** 0154 * Display @p item in a striking way to indicate that the session represent 0155 * by @p item will be deleted 0156 */ 0157 static void markItemAsToBeDeleted(QTreeWidgetItem *item); 0158 0159 /** 0160 * The item which is currently edited by the user or @c nullptr to indicate 0161 * that nothing is on edit. 0162 */ 0163 KateSessionChooserItem *m_editByUser = nullptr; 0164 0165 /** 0166 * Used by @c updateSessionList() to choose a new current item 0167 */ 0168 QString m_preferredSession; 0169 0170 /** 0171 * Used in dtor to do some savings or not 0172 */ 0173 bool m_chooserMode = false; 0174 0175 /** 0176 * Will filled with sessions to be deleted by @c updateDeleteList() and process 0177 * by @c deleteSessions() 0178 */ 0179 QSet<KateSession::Ptr> m_deleteList; 0180 };