summaryrefslogtreecommitdiffstats
path: root/parts/fileview/filegroupsconfigwidget.cpp
blob: 277bab4e04a6d685ca4b75fbf189f9dc7e7f6a71 (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
/***************************************************************************
 *   Copyright (C) 2001-2002 by Bernd Gehrmann                             *
 *   bernd@kdevelop.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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "filegroupsconfigwidget.h"

#include <tqlistview.h>
#include <knotifyclient.h>
#include <klocale.h>

#include "domutil.h"
#include "addfilegroupdlg.h"
#include "filegroupspart.h"


FileGroupsConfigWidget::FileGroupsConfigWidget(FileGroupsPart *part,
                                               TQWidget *tqparent, const char *name)
    : FileGroupsConfigWidgetBase(tqparent, name)
{
    m_part = part;

    listview->setSorting(-1);
    
    readConfig();
}


FileGroupsConfigWidget::~FileGroupsConfigWidget()
{}


void FileGroupsConfigWidget::readConfig()
{
    TQDomDocument &dom = *m_part->projectDom();
    DomUtil::PairList list = DomUtil::readPairListEntry(dom, "/kdevfileview/groups",
                                                        "group", "name", "pattern");

    TQListViewItem *lastItem = 0;

    DomUtil::PairList::ConstIterator it;
    for (it = list.begin(); it != list.end(); ++it) {
        TQListViewItem *newItem = new TQListViewItem(listview, (*it).first, (*it).second);
        if (lastItem)
            newItem->moveItem(lastItem);
        lastItem = newItem;
    }
}


void FileGroupsConfigWidget::storeConfig()
{
    DomUtil::PairList list;
    
    TQListViewItem *item = listview->firstChild();
    while (item) {
        list << DomUtil::Pair(item->text(0), item->text(1));
        item = item->nextSibling();
    }

    DomUtil::writePairListEntry(*m_part->projectDom(), "/kdevfileview/groups",
                                "group", "name", "pattern", list);
}


void FileGroupsConfigWidget::addGroup()
{
    AddFileGroupDialog dlg;
    dlg.setCaption(i18n("Add File Group"));
    if (!dlg.exec())
        return;

    (void) new TQListViewItem(listview, dlg.title(), dlg.pattern());
}


void FileGroupsConfigWidget::editGroup()
{
    if (listview->childCount()==0 || listview->currentItem()==0)
        return;
    AddFileGroupDialog dlg(listview->currentItem()->text(0),listview->currentItem()->text(1));
    dlg.setCaption(i18n("Edit File Group"));
    if (!dlg.exec() || dlg.title().isEmpty() || dlg.pattern().isEmpty())
        return;
    listview->currentItem()->setText(0,dlg.title());
    listview->currentItem()->setText(1,dlg.pattern());
}


void FileGroupsConfigWidget::removeGroup()
{
    delete listview->currentItem();
}


void FileGroupsConfigWidget::moveUp()
{
    if (listview->currentItem() == listview->firstChild()) {
        KNotifyClient::beep();
        return;
    }

    TQListViewItem *item = listview->firstChild();
    while (item->nextSibling() != listview->currentItem())
        item = item->nextSibling();
    item->moveItem(listview->currentItem());
}


void FileGroupsConfigWidget::moveDown()
{
   if (listview->currentItem()->nextSibling() == 0) {
        KNotifyClient::beep();
        return;
   }

   listview->currentItem()->moveItem(listview->currentItem()->nextSibling());
}


void FileGroupsConfigWidget::accept()
{
    storeConfig();
    m_part->refresh();
}

#include "filegroupsconfigwidget.moc"