scide: refactoring - move LineIndicator to separate source file
[supercollider.git] / editors / sc-ide / widgets / sessions_dialog.hpp
blob9dd9cbd977341b40817608ee219768bf5e083c76
1 /*
2 SuperCollider Qt IDE
3 Copyright (c) 2012 Jakob Leben & Tim Blechmann
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef SCIDE_WIDGETS_SESSIONS_DIALOG_HPP_INCLUDED
22 #define SCIDE_WIDGETS_SESSIONS_DIALOG_HPP_INCLUDED
24 #include "../core/session_manager.hpp"
26 #include <QDialog>
27 #include <QListWidget>
28 #include <QPushButton>
29 #include <QDialogButtonBox>
30 #include <QHBoxLayout>
31 #include <QVBoxLayout>
32 #include <QInputDialog>
33 #include <QMessageBox>
35 namespace ScIDE {
37 class SessionsDialog : public QDialog
39 Q_OBJECT
41 public:
42 SessionsDialog ( SessionManager *mng, QWidget *parent = 0 ):
43 QDialog(parent),
44 mMng(mng)
46 setWindowTitle("Sessions");
48 mList = new QListWidget;
50 QPushButton *removeBtn = new QPushButton(tr("Delete"));
51 QPushButton *renameBtn = new QPushButton(tr("Rename..."));
53 QDialogButtonBox *dialogBtns = new QDialogButtonBox(QDialogButtonBox::Ok);
56 QHBoxLayout *contentBox = new QHBoxLayout;
57 QVBoxLayout *btnBox = new QVBoxLayout;
58 btnBox->addWidget(renameBtn);
59 btnBox->addWidget(removeBtn);
60 btnBox->addStretch();
61 contentBox->addWidget(mList);
62 contentBox->addLayout(btnBox);
64 QVBoxLayout *layout = new QVBoxLayout;
65 layout->addLayout(contentBox);
66 layout->addWidget(dialogBtns);
68 setLayout(layout);
70 connect(removeBtn, SIGNAL(clicked()), this, SLOT(removeCurrent()));
71 connect(renameBtn, SIGNAL(clicked()), this, SLOT(renameCurrent()));
72 connect(dialogBtns, SIGNAL(accepted()), this, SLOT(accept()));
74 updateSessions();
77 private slots:
78 void removeCurrent()
80 QListWidgetItem *item = mList->currentItem();
81 if (!item)
82 return;
84 QString name = item->text();
86 if ( QMessageBox::warning (
87 this,
88 tr("Delete Session"),
89 tr("Are you sure you want to delete session '%1'?").arg(name),
90 QMessageBox::Yes | QMessageBox::No,
91 QMessageBox::Yes
92 ) == QMessageBox::Yes )
94 mMng->removeSession(name);
95 updateSessions();
99 void renameCurrent()
101 QListWidgetItem *item = mList->currentItem();
102 if (!item)
103 return;
105 QString oldName = item->text();
106 QString newName = QInputDialog::getText (
107 this,
108 tr("Rename Session"),
109 tr("Enter a new name for the session:"),
110 QLineEdit::Normal,
111 oldName
113 if (newName.isEmpty() || newName == oldName )
114 return;
116 mMng->renameSession(oldName, newName);
117 updateSessions();
120 private:
121 void updateSessions()
123 mList->clear();
124 QStringList sessions = mMng->availableSessions();
125 mList->addItems(sessions);
128 QListWidget *mList;
129 SessionManager *mMng;
132 } // namespace ScIDE
134 #endif