1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "reloadpromptutils.h"
35 #include <QtCore/QCoreApplication>
36 #include <QtCore/QDir>
37 #include <QtGui/QMessageBox>
38 #include <QtGui/QPushButton>
39 #include <QtGui/QAbstractButton>
41 using namespace Utils;
43 QTCREATOR_UTILS_EXPORT Utils::ReloadPromptAnswer
44 Utils::reloadPrompt(const QString &fileName, bool modified, QWidget *parent)
47 const QString title = QCoreApplication::translate("Utils::reloadPrompt", "File Changed");
51 msg = QCoreApplication::translate("Utils::reloadPrompt",
52 "The unsaved file <i>%1</i> has been changed outside Qt Creator. Do you want to reload it and discard your changes?");
54 msg = QCoreApplication::translate("Utils::reloadPrompt",
55 "The file <i>%1</i> has changed outside Qt Creator. Do you want to reload it?");
56 msg = msg.arg(QFileInfo(fileName).fileName());
57 return reloadPrompt(title, msg, QDir::toNativeSeparators(fileName), parent);
60 QTCREATOR_UTILS_EXPORT Utils::ReloadPromptAnswer
61 Utils::reloadPrompt(const QString &title, const QString &prompt, const QString &details, QWidget *parent)
63 QMessageBox msg(parent);
64 msg.setStandardButtons(QMessageBox::Yes|QMessageBox::YesToAll|QMessageBox::No|QMessageBox::NoToAll);
65 msg.setDefaultButton(QMessageBox::YesToAll);
66 msg.setWindowTitle(title);
68 msg.setDetailedText(details);
71 case QMessageBox::Yes:
73 case QMessageBox::YesToAll:
76 return ReloadSkipCurrent;
83 QTCREATOR_UTILS_EXPORT Utils::FileDeletedPromptAnswer
84 Utils::fileDeletedPrompt(const QString &fileName, QWidget *parent)
86 const QString title = QCoreApplication::translate("Utils::fileDeletedPrompt", "File has been removed");
88 msg = QCoreApplication::translate("Utils::fileDeletedPrompt",
89 "The file %1 has been removed outside Qt Creator. Do you want to save it under a different name, or close the editor?").arg(QDir::toNativeSeparators(fileName));
90 QMessageBox box(QMessageBox::Question, title, msg, QMessageBox::NoButton, parent);
91 QPushButton *close = box.addButton(QCoreApplication::translate("Utils::fileDeletedPrompt", "Close"), QMessageBox::RejectRole);
92 QPushButton *saveas = box.addButton(QCoreApplication::translate("Utils::fileDeletedPrompt", "Save as..."), QMessageBox::ActionRole);
93 QPushButton *save = box.addButton(QCoreApplication::translate("Utils::fileDeletedPrompt", "Save"), QMessageBox::AcceptRole);
94 box.setDefaultButton(saveas);
96 QAbstractButton *clickedbutton = box.clickedButton();
97 if (clickedbutton == close) {
98 return FileDeletedClose;
99 } else if (clickedbutton == saveas) {
100 return FileDeletedSaveAs;
101 } else if (clickedbutton == save) {
102 return FileDeletedSave;
104 return FileDeletedClose;