summaryrefslogtreecommitdiffstats
path: root/quanta/utility/tagaction.h
blob: 3a58f603123502394c189a8f63049361c16f765d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/***************************************************************************
                          tagaction.h  -  description
                             -------------------
    begin                : ?
    copyright            : (C) ? Dmitry Poplavsky
                           (C) 2002-2005 Andras Mantia <amantia@kde.org>
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef TAGACTION_H
#define TAGACTION_H

#include <tdeversion.h>
#include <kaction.h>
#include <kactioncollection.h>

#include <tqstring.h>
#include <tqdom.h>

class KMainWindow;
class QuantaView;
class TDEProcess;
class TQDomElement;
class TQFile;
class TQTimer;
class MessageOutput;
class Node;
class NodeModifsSet;
class NodeSelection;

/**
 * An action for inserting an XML tag.
 *
 * @author Dmitry Poplavsky, dima@kde.org
 *         Andras Mantia, amantia@kde.org
 *         Paulo Moura Guedes, moura@tdewebdev.org
 */

class TagAction : public KToggleAction
{
    Q_OBJECT
  

public:
    /**
     * Create an insert from dom element.
     * @param toggle If set to true, the class behaves like a KToggleAction;
     *               Else it behaves like a KAction. This avoids the multi-inheritance problem.
     */
    TagAction(TQDomElement *element, KMainWindow *parentMainWindow, bool toggle = false);
    virtual ~TagAction();

    TQDomElement data() const { return tag; }
    void setModified(bool modified) { m_modified = modified;}
    bool isModified() const {return m_modified;}
    void setOutputFile(TQFile* file);
    void setInputFileName(const TQString& fileName);
    void addArguments(const TQStringList& arguments);
    bool toggable() const {return tag.attribute("toggable") == "true";}
    bool toggled() const {return isChecked();}
    
    /** Activates the action.
      @param blocking in case of script actions, the script is run in blocking mode, if this argument is true
    */
    void execute(bool blocking);
    TQString type();
    /**
     * Remove accelerator from tag action name *
     */
    TQString actionText();

    TQString XMLTagName() const;
    TQString openXMLTagString() const;
    TQString closeXMLTagString() const;

signals:
    void showMessage(const TQString& msg, bool append);
    void clearMessages();
    void showMessagesView();
    void createNewFile();

public slots:
    virtual void slotActivated();
    
    /**
     * We need this information in order to know if queued actions should be applied.
     * It's public because it can be activated by other classes if there are any queued actions.
     */
    virtual bool slotActionActivated(KAction::ActivationReason reason, TQt::ButtonState state);

protected slots:
    virtual void slotGetScriptOutput( TDEProcess *, char *buffer, int buflen );
    virtual void slotGetScriptError( TDEProcess *, char *buffer, int buflen );
    virtual void scriptDone();
    void slotTimeout();
    void slotProcessExited(TDEProcess *);
    virtual bool slotActionActivated();

private:
    void applyTagInSelection(Node* start_node, int start_offset, Node* end_node, int end_offset, 
                             NodeSelection& selection, NodeModifsSet* modifs) const;
    void applyTagInMixedSelection(Node* start_node, int start_offset, Node* end_node, int end_offset, 
                                  NodeSelection& selection, NodeModifsSet* modifs) const;
    void deapplyTagInSelection(Node* start_node, int start_offset, Node* end_node, int end_offset, 
                               NodeSelection& selection, NodeModifsSet* modifs) const;
    void deapplyTagInMixedSelection(Node* start_node, int start_offset, Node* end_node, int end_offset, 
                                    NodeSelection& selection, NodeModifsSet* modifs) const;
    
private:
    TDEProcess *proc;
    bool firstError;
    bool firstOutput;
    bool m_modified;
    bool loopStarted;
    bool m_useInputFile;
    bool m_useOutputFile;
    TQString scriptOutputDest;
    TQString scriptErrorDest;
    TQTimer* timer;
    TQDomElement tag;
    TQFile* m_file;
    KMainWindow *m_parentMainWindow;
    TQString m_inputFileName;
    TQStringList m_argsList;
    uint m_killCount;
    bool const m_toggle;
};


#endif // TAGACTION_H