~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to parts/documentation/docutils.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2004 by Alexander Dymo                                  *
 
3
 *   cloudtemple@mksat.net                                                 *
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU General Public License as published by  *
 
7
 *   the Free Software Foundation; either version 2 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 *                                                                         *
 
10
 *   This program is distributed in the hope that it will be useful,       *
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
13
 *   GNU General Public License for more details.                          *
 
14
 *                                                                         *
 
15
 *   You should have received a copy of the GNU General Public License     *
 
16
 *   along with this program; if not, write to the                         *
 
17
 *   Free Software Foundation, Inc.,                                       *
 
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 
19
 ***************************************************************************/
 
20
#include "docutils.h"
 
21
 
 
22
#include <kurlrequester.h>
 
23
#include <kurlcompletion.h>
 
24
#include <klineedit.h>
 
25
#include <kcombobox.h>
 
26
#include <kpopupmenu.h>
 
27
#include <klocale.h>
 
28
#include <kstringhandler.h>
 
29
 
 
30
#include <kdevpartcontroller.h>
 
31
 
 
32
#include "kdevdocumentationplugin.h"
 
33
#include "documentation_part.h"
 
34
 
 
35
QString DocUtils::noEnvURL(const QString &url)
 
36
{
 
37
    return KURLCompletion::replacedPath(url, true, true);
 
38
}
 
39
 
 
40
KURL DocUtils::noEnvURL(const KURL &url)
 
41
{
 
42
    QString replaced = KURLCompletion::replacedPath(url.url(), true, true);
 
43
    KURL kurl(replaced);
 
44
    kurl.setQuery(url.query());
 
45
    kurl.setRef(url.ref());
 
46
    return kurl;
 
47
}
 
48
 
 
49
QString DocUtils::envURL(KURLRequester *req)
 
50
{
 
51
    if (req->lineEdit())
 
52
        return req->lineEdit()->text();
 
53
    else if (req->comboBox())
 
54
        return req->comboBox()->currentText();
 
55
    else
 
56
        return req->url();
 
57
}
 
58
 
 
59
void DocUtils::docItemPopup(DocumentationPart *part, DocumentationItem *docItem,
 
60
    const QPoint &pos, bool showBookmark, bool showSearch, int titleCol)
 
61
{
 
62
    docItemPopup(part, docItem->text(titleCol), docItem->url(), pos, showBookmark, showSearch);
 
63
}
 
64
 
 
65
void DocUtils::docItemPopup(DocumentationPart *part, IndexItem *docItem, const QPoint &pos,
 
66
    bool showBookmark, bool showSearch)
 
67
{
 
68
    //FIXME: index item can have more than one url, what to do?
 
69
    KURL url;
 
70
    if (docItem->urls().count() > 0)
 
71
        url = docItem->urls().first().second;
 
72
    docItemPopup(part, docItem->text(), url, pos, showBookmark, showSearch);
 
73
}
 
74
 
 
75
void DocUtils::docItemPopup(DocumentationPart *part, const QString &title, const KURL &url,
 
76
    const QPoint &pos, bool showBookmark, bool showSearch)
 
77
{
 
78
    KPopupMenu menu;
 
79
    menu.insertTitle(i18n("Documentation"));
 
80
    menu.insertItem(i18n("Open in Current Tab"), 1);
 
81
    menu.insertItem(i18n("Open in New Tab"), 2);
 
82
    if (showBookmark)
 
83
    {
 
84
        menu.insertSeparator();   
 
85
        menu.insertItem(i18n("Bookmark This Location"), 3);
 
86
    }
 
87
    if (showSearch)
 
88
    {
 
89
        menu.insertSeparator();
 
90
        menu.insertItem(QString("%1: %2").arg(i18n("Search")).arg(KStringHandler::csqueeze(title,20)), 4);
 
91
    }
 
92
    
 
93
    switch (menu.exec(pos))
 
94
    {
 
95
        case 1: part->partController()->showDocument(url); break;
 
96
        case 2: part->partController()->showDocument(url, true); break;
 
97
        case 3: part->emitBookmarkLocation(title, url); break;
 
98
        case 4: part->searchInDocumentation(title); break;
 
99
    }
 
100
}