OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / libs / utils / reloadpromptutils.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "reloadpromptutils.h"
35
36 #include <QtCore/QCoreApplication>
37 #include <QtCore/QDir>
38 #include <QtGui/QMessageBox>
39 #include <QtGui/QPushButton>
40 #include <QtGui/QAbstractButton>
41
42 using namespace Utils;
43
44 QTCREATOR_UTILS_EXPORT Utils::ReloadPromptAnswer
45     Utils::reloadPrompt(const QString &fileName, bool modified, QWidget *parent)
46 {
47
48     const QString title = QCoreApplication::translate("Utils::reloadPrompt", "File Changed");
49     QString msg;
50
51     if (modified)
52         msg = QCoreApplication::translate("Utils::reloadPrompt",
53                                           "The unsaved file <i>%1</i> has been changed outside Qt Creator. Do you want to reload it and discard your changes?");
54     else
55         msg = QCoreApplication::translate("Utils::reloadPrompt",
56                                           "The file <i>%1</i> has changed outside Qt Creator. Do you want to reload it?");
57     msg = msg.arg(QFileInfo(fileName).fileName());
58     return reloadPrompt(title, msg, QDir::toNativeSeparators(fileName), parent);
59 }
60
61 QTCREATOR_UTILS_EXPORT Utils::ReloadPromptAnswer
62     Utils::reloadPrompt(const QString &title, const QString &prompt, const QString &details, QWidget *parent)
63 {
64     QMessageBox msg(parent);
65     msg.setStandardButtons(QMessageBox::Yes|QMessageBox::YesToAll|QMessageBox::No|QMessageBox::NoToAll);
66     msg.setDefaultButton(QMessageBox::YesToAll);
67     msg.setWindowTitle(title);
68     msg.setText(prompt);
69     msg.setDetailedText(details);
70
71     switch (msg.exec()) {
72     case QMessageBox::Yes:
73         return  ReloadCurrent;
74     case QMessageBox::YesToAll:
75         return ReloadAll;
76     case QMessageBox::No:
77         return ReloadSkipCurrent;
78     default:
79         break;
80     }
81     return ReloadNone;
82 }
83
84 QTCREATOR_UTILS_EXPORT Utils::FileDeletedPromptAnswer
85         Utils::fileDeletedPrompt(const QString &fileName, QWidget *parent)
86 {
87     const QString title = QCoreApplication::translate("Utils::fileDeletedPrompt", "File has been removed");
88     QString msg;
89      msg = QCoreApplication::translate("Utils::fileDeletedPrompt",
90                                       "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));
91     QMessageBox box(QMessageBox::Question, title, msg, QMessageBox::NoButton, parent);
92     QPushButton *close = box.addButton(QCoreApplication::translate("Utils::fileDeletedPrompt", "Close"), QMessageBox::RejectRole);
93     QPushButton *saveas = box.addButton(QCoreApplication::translate("Utils::fileDeletedPrompt", "Save as..."), QMessageBox::ActionRole);
94     QPushButton *save = box.addButton(QCoreApplication::translate("Utils::fileDeletedPrompt", "Save"), QMessageBox::AcceptRole);
95     box.setDefaultButton(saveas);
96     box.exec();
97     QAbstractButton *clickedbutton = box.clickedButton();
98     if (clickedbutton == close) {
99         return FileDeletedClose;
100     } else if (clickedbutton == saveas) {
101         return FileDeletedSaveAs;
102     } else if (clickedbutton == save) {
103         return FileDeletedSave;
104     }
105     return FileDeletedClose;
106 }