File indexing completed on 2024-04-21 12:44:13
0001 /************************************************************************** 0002 * Copyright (C) 2010 by Michel Ludwig (michel.ludwig@kdemail.net) * 0003 ***************************************************************************/ 0004 0005 /************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or modify * 0008 * it under the terms of the GNU General Public License as published by * 0009 * the Free Software Foundation; either version 2 of the License, or * 0010 * (at your option) any later version. * 0011 * * 0012 ***************************************************************************/ 0013 0014 #include "editorcommands.h" 0015 0016 #include <QTimer> 0017 0018 #include "kiledocmanager.h" 0019 #include "kileinfo.h" 0020 0021 EditorCommands::EditorCommands(KileInfo *info) 0022 : KTextEditor::Command(QStringList() << "w" << "wa" << "wq" << "q" << "wqa") 0023 , m_ki(info) 0024 { 0025 } 0026 0027 EditorCommands::~EditorCommands() 0028 { 0029 } 0030 0031 bool EditorCommands::exec(KTextEditor::View *view, const QString &cmd, QString &msg, 0032 const KTextEditor::Range &range) 0033 { 0034 Q_UNUSED(range) 0035 0036 if(cmd == "w" || cmd == "wa") { 0037 if(cmd == "wa") { 0038 bool result = m_ki->docManager()->fileSaveAll(); 0039 msg = result ? i18n("All documents saved to disk.") 0040 : i18n("Saving of all documents failed."); 0041 return result; 0042 } 0043 else { 0044 bool result = m_ki->docManager()->fileSave(view); 0045 msg = result ? i18n("Document saved to disk.") 0046 : i18n("Saving document failed."); 0047 return result; 0048 } 0049 } 0050 else if(cmd == "q" || cmd == "wq" || cmd == "wqa") { 0051 if(cmd == "wq" || cmd == "wqa") { 0052 bool result = true; 0053 if(cmd == "wq") { 0054 result = m_ki->docManager()->fileSave(view); 0055 } 0056 else { 0057 result = m_ki->docManager()->fileSaveAll(); 0058 } 0059 if(!result) { 0060 msg = i18n("Saving failed and quitting canceled."); 0061 return false; 0062 } 0063 } 0064 QTimer::singleShot(0, m_ki->mainWindow(), SLOT(close())); 0065 return true; 0066 } 0067 0068 return false; 0069 } 0070 0071 bool EditorCommands::help(KTextEditor::View *view, const QString &cmd, QString &msg) 0072 { 0073 Q_UNUSED(view); 0074 0075 if(cmd == "w" || cmd == "wa") { 0076 msg = "<p><b>w/wa</b>: Save document(s) to disk.</p>" 0077 "<p><b>w</b> only saves the current document, whereas " 0078 "<b>wa</b> saves all the documents.</p>"; 0079 return true; 0080 } 0081 else if(cmd == "q" || cmd == "wq" || cmd == "wqa") { 0082 msg = "<p><b>q/wq/wqa</b>: Quit Kile</p>" 0083 "<p><b>wq</b> additionally saves the current document to disk " 0084 "before quitting, whereas <b>wqa</b> saves all the documents " 0085 "before exiting.</p>"; 0086 return true; 0087 } 0088 0089 return false; 0090 }