File indexing completed on 2024-04-21 15:55:24
0001 /*********************************************************************************** 0002 Copyright (C) 2011-2012 by Holger Danielsson (holger.danielsson@versanet.de) 0003 (C) 2017 by Michel Ludwig (michel.ludwig@kdemail.net) 0004 ***********************************************************************************/ 0005 0006 /*************************************************************************** 0007 * * 0008 * This program is free software; you can redistribute it and/or modify * 0009 * it under the terms of the GNU General Public License as published by * 0010 * the Free Software Foundation; either version 2 of the License, or * 0011 * (at your option) any later version. * 0012 * * 0013 ***************************************************************************/ 0014 0015 #ifndef USERMENU_H 0016 #define USERMENU_H 0017 0018 #include <QList> 0019 #include <QDomDocument> 0020 0021 #include <KProcess> 0022 #include <KActionCollection> 0023 #include <KTextEditor/Document> 0024 #include <KTextEditor/View> 0025 0026 #include "kileinfo.h" 0027 0028 #include "usermenu/usermenudata.h" 0029 0030 0031 namespace KileMenu { 0032 0033 class UserMenu : public QObject 0034 { 0035 Q_OBJECT 0036 0037 public: 0038 enum MenuLocation { StandAloneLocation = 0x00, LaTeXMenuLocation = 0x01 }; 0039 0040 UserMenu(KileInfo *ki, QObject *receiver); 0041 ~UserMenu(); 0042 0043 void installXmlMenufile(); 0044 void removeXmlMenufile(); 0045 QString xmlFile() const { 0046 return m_currentXmlFile; 0047 } 0048 bool isEmpty(); 0049 0050 bool installXml(const QString &filename); 0051 void refreshActionProperties(); 0052 void removeShortcuts(); 0053 0054 void updateGUI(); 0055 void updateKeyBindings(); 0056 0057 QMenu* getMenuItem(); 0058 0059 inline MenuLocation getUserMenuLocation() const 0060 { 0061 switch(KileConfig::userMenuLocation()) { 0062 case 0: 0063 return StandAloneLocation; 0064 default: 0065 return LaTeXMenuLocation; 0066 } 0067 } 0068 0069 QList<QAction *> contextMenuActions() const { 0070 return m_actionlistContextMenu; 0071 } 0072 QList<QAction *> menuActions() const { 0073 return m_actionlist; 0074 } 0075 0076 static QString selectUserMenuDir(); 0077 0078 public Q_SLOTS: 0079 void installXmlFile(const QString &filename); 0080 void removeXmlFile(); 0081 0082 private Q_SLOTS: 0083 void slotUserMenuAction(); 0084 void slotProcessOutput(); 0085 void slotProcessExited(int /* exitCode */, QProcess::ExitStatus exitStatus); 0086 0087 Q_SIGNALS: 0088 void sendText(const QString&); 0089 void triggered(); 0090 void updateStatus(); 0091 0092 private: 0093 KileInfo *m_ki; 0094 QObject * m_receiver; 0095 QString m_currentXmlFile; 0096 0097 QAction *m_wizardAction1, *m_latexAction1; 0098 QAction *m_wizardAction2, *m_latexAction2; 0099 QMenu *m_latexMenuEntry; 0100 0101 int m_actionsContextMenu; 0102 QList<QAction *> m_actionlistContextMenu; 0103 QList<QAction *> m_actionlist; 0104 QList<UserMenuData> m_menudata; 0105 0106 KActionCollection *m_actioncollection; 0107 0108 KProcess *m_proc; 0109 QString m_procOutput; 0110 KTextEditor::View *m_procView; 0111 const UserMenuData *m_procMenudata; 0112 0113 void addSpecialActionsToMenus(); 0114 void updateUsermenuPosition(); 0115 void setStandAloneMenuVisible(bool state, bool show); 0116 QAction *createAction(const QString &name); 0117 void clear(); 0118 0119 void installXmlSubmenu(const QDomElement &element, QMenu *parentmenu, int &actionnumber); 0120 void installXmlMenuentry(const QDomElement &element, QMenu *parentmenu, int &actionnumber); 0121 0122 void removeActionProperties(); 0123 void updateXmlFile(const QString &filename); 0124 bool updateXmlSubmenu(QDomDocument &doc, QDomElement &element, int &actionnumber); 0125 bool updateXmlMenuentry(QDomDocument &doc, QDomElement &element, int &actionnumber); 0126 0127 void execActionText(KTextEditor::View *view, const UserMenuData &menudata); 0128 void execActionFileContent(KTextEditor::View *view, const UserMenuData &menudata); 0129 void execActionProgramOutput(KTextEditor::View *view, const UserMenuData &menudata); 0130 0131 void insertText(KTextEditor::View *view, const QString &text, bool replaceSelection, bool selectInsertion); 0132 bool str2bool(const QString &value); 0133 0134 }; 0135 0136 } 0137 0138 #endif