kmail

snippetitem.cpp
1/***************************************************************************
2 * snippet feature from tdevelop/plugins/snippet/ *
3 * *
4 * Copyright (C) 2007 by Robert Gruber *
5 * rgruber@users.sourceforge.net *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 ***************************************************************************/
13
14#include "snippetitem.h"
15
16#include <tdeaction.h>
17
18#include <tqstring.h>
19
20SnippetItem::SnippetItem(TQListView * parent, TQString name, TQString text )
21 : TQListViewItem( parent, name ), action(0)
22{
23 strName = name;
24 strText = text;
25 iParent = -1;
26 setOpen( true );
27}
28
29SnippetItem::SnippetItem(TQListViewItem * parent, TQString name, TQString text)
30 : TQListViewItem( parent, name ), action(0)
31{
32 strName = name;
33 strText = text;
34 iParent = ((SnippetGroup *)parent)->getId();
35 setOpen( true );
36}
37
38SnippetItem::~SnippetItem()
39{
40 if ( action ) {
41 action->unplugAll();
42 delete action;
43 }
44}
45
46
50TQString SnippetItem::getName()
51{
52 return strName;
53}
54
55
59TQString SnippetItem::getText()
60{
61 return strText;
62}
63
64
68void SnippetItem::setText(TQString text)
69{
70 strText = text;
71}
72
73
77void SnippetItem::setName(TQString name)
78{
79 strName = name;
80}
81
82void SnippetItem::resetParent()
83{
84 SnippetGroup * group = dynamic_cast<SnippetGroup*>(parent());
85 if (group)
86 iParent = group->getId();
87}
88
89
90TDEAction* SnippetItem::getAction()
91{
92 return action;
93}
94
95void SnippetItem::setAction(TDEAction * anAction)
96{
97 action = anAction;
98}
99
100void SnippetItem::slotExecute()
101{
102 emit execute( this );
103}
104
105
106SnippetItem * SnippetItem::findItemByName(TQString name, TQPtrList<SnippetItem> &list)
107{
108 for ( SnippetItem * item = list.first(); item; item = list.next() ) { //write the snippet-list
109 if (item->getName() == name)
110 return item;
111 }
112 return NULL;
113}
114
115SnippetGroup * SnippetItem::findGroupById(int id, TQPtrList<SnippetItem> &list)
116{
117 for ( SnippetItem * item = list.first(); item; item = list.next() ) { //write the snippet-list
118 SnippetGroup * group = dynamic_cast<SnippetGroup*>(item);
119 if (group && group->getId() == id)
120 return group;
121 }
122 return NULL;
123}
124
125
126/* * * * * * * * * * * * * * * * * * * *
127Deklaration for class SnippetGroup
128* * * * * * * * * * * * * * * * * * * */
129
130int SnippetGroup::iMaxId = 1;
131
132SnippetGroup::SnippetGroup(TQListView * parent, TQString name, int id)
133 : SnippetItem(parent, name, i18n("GROUP"))
134{
135 if (id > 0) {
136 iId = id;
137 if (id >= iMaxId)
138 iMaxId = id+1;
139 } else {
140 iId = iMaxId;
141 iMaxId++;
142 }
143}
144
145SnippetGroup::~SnippetGroup()
146{
147}
148
149void SnippetGroup::setId(int id)
150{
151 iId = id;
152 if (iId >= iMaxId)
153 iMaxId = iId+1;
154}
155
156#include "snippetitem.moc"
This class represents one group in the listview.
Definition: snippetitem.h:71
This class represents one CodeSnippet-Item in the listview.
Definition: snippetitem.h:32