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

« back to all changes in this revision

Viewing changes to kdevdesigner/src/kdevdesigner.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

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
 
 
21
 
#include "kdevdesigner.h"
22
 
 
23
 
#include <kxmlguiclient.h>
24
 
#include <kkeydialog.h>
25
 
#include <kfiledialog.h>
26
 
#include <kconfig.h>
27
 
#include <kurl.h>
28
 
#include <kdebug.h>
29
 
 
30
 
#include <kedittoolbar.h>
31
 
 
32
 
#include <kaction.h>
33
 
#include <kstdaction.h>
34
 
 
35
 
#include <klibloader.h>
36
 
#include <kmessagebox.h>
37
 
#include <kstatusbar.h>
38
 
#include <klocale.h>
39
 
 
40
 
KDevDesigner::KDevDesigner()
41
 
    : KParts::MainWindow( 0L, "KDevDesigner" )
42
 
{
43
 
    // set the shell's ui resource file
44
 
    setXMLFile("kdevdesigner_shell.rc");
45
 
 
46
 
    // then, setup our actions
47
 
    setupActions();
48
 
    
49
 
    // and a status bar
50
 
    statusBar()->show();
51
 
 
52
 
    // this routine will find and load our Part.  it finds the Part by
53
 
    // name which is a bad idea usually.. but it's alright in this
54
 
    // case since our Part is made for this Shell
55
 
    KLibFactory *factory = KLibLoader::self()->factory("libkdevdesignerpart");
56
 
    if (factory)
57
 
    {
58
 
        // now that the Part is loaded, we cast it to a Part to get
59
 
        // our hands on it
60
 
        QStringList args;
61
 
        args.append("in shell");
62
 
        m_part = static_cast<KParts::ReadWritePart *>(factory->create(this,
63
 
                                "kdevdesigner_part", "KParts::ReadWritePart", args));
64
 
 
65
 
        if (m_part)
66
 
        {
67
 
            // tell the KParts::MainWindow that this is indeed the main widget
68
 
            setCentralWidget(m_part->widget());
69
 
 
70
 
            // and integrate the part's GUI with the shell's
71
 
            createGUI(m_part);
72
 
        }
73
 
    }
74
 
    else
75
 
    {
76
 
        // if we couldn't find our Part, we exit since the Shell by
77
 
        // itself can't do anything useful
78
 
        KMessageBox::error(this, i18n("Could not find the KDevDesigner part."));
79
 
        kapp->quit();
80
 
        // we return here, cause kapp->quit() only means "exit the
81
 
        // next time we enter the event loop...
82
 
        return;
83
 
    }
84
 
    
85
 
    // apply the saved mainwindow settings, if any, and ask the mainwindow
86
 
    // to automatically save settings if changed: window size, toolbar
87
 
    // position, icon size, etc.
88
 
    setAutoSaveSettings();
89
 
}
90
 
 
91
 
KDevDesigner::~KDevDesigner()
92
 
{
93
 
}
94
 
 
95
 
void KDevDesigner::load(const KURL& url)
96
 
{
97
 
    m_part->openURL( url );
98
 
}
99
 
 
100
 
void KDevDesigner::setupActions()
101
 
{
102
 
/*    KStdAction::openNew(this, SLOT(fileNew()), actionCollection());
103
 
    KStdAction::open(this, SLOT(fileOpen()), actionCollection());*/
104
 
 
105
 
    KStdAction::quit(kapp, SLOT(quit()), actionCollection());
106
 
    
107
 
    m_toolbarAction = KStdAction::showToolbar(this, SLOT(optionsShowToolbar()), actionCollection());
108
 
    m_statusbarAction = KStdAction::showStatusbar(this, SLOT(optionsShowStatusbar()), actionCollection());
109
 
 
110
 
    KStdAction::keyBindings(this, SLOT(optionsConfigureKeys()), actionCollection());
111
 
    KStdAction::configureToolbars(this, SLOT(optionsConfigureToolbars()), actionCollection());
112
 
}
113
 
 
114
 
void KDevDesigner::saveProperties(KConfig* /*config*/)
115
 
{
116
 
    // the 'config' object points to the session managed
117
 
    // config file.  anything you write here will be available
118
 
    // later when this app is restored
119
 
}
120
 
 
121
 
void KDevDesigner::readProperties(KConfig* /*config*/)
122
 
{
123
 
    // the 'config' object points to the session managed
124
 
    // config file.  this function is automatically called whenever
125
 
    // the app is being restored.  read in here whatever you wrote
126
 
    // in 'saveProperties'
127
 
}
128
 
 
129
 
void KDevDesigner::fileNew()
130
 
{
131
 
    // this slot is called whenever the File->New menu is selected,
132
 
    // the New shortcut is pressed (usually CTRL+N) or the New toolbar
133
 
    // button is clicked
134
 
 
135
 
    // About this function, the style guide (
136
 
    // http://developer.kde.org/documentation/standards/kde/style/basics/index.html )
137
 
    // says that it should open a new window if the document is _not_
138
 
    // in its initial state.  This is what we do here..
139
 
    if ( ! m_part->url().isEmpty() || m_part->isModified() )
140
 
    {
141
 
        (new KDevDesigner)->show();
142
 
    };
143
 
}
144
 
 
145
 
 
146
 
void KDevDesigner::optionsShowToolbar()
147
 
{
148
 
    // this is all very cut and paste code for showing/hiding the
149
 
    // toolbar
150
 
    if (m_toolbarAction->isChecked())
151
 
        toolBar()->show();
152
 
    else
153
 
        toolBar()->hide();
154
 
}
155
 
 
156
 
void KDevDesigner::optionsShowStatusbar()
157
 
{
158
 
    // this is all very cut and paste code for showing/hiding the
159
 
    // statusbar
160
 
    if (m_statusbarAction->isChecked())
161
 
        statusBar()->show();
162
 
    else
163
 
        statusBar()->hide();
164
 
}
165
 
 
166
 
void KDevDesigner::optionsConfigureKeys()
167
 
{
168
 
    KKeyDialog::configureKeys(m_part->actionCollection(), "kdevdesigner_part.rc");
169
 
}
170
 
 
171
 
void KDevDesigner::optionsConfigureToolbars()
172
 
{
173
 
    saveMainWindowSettings(KGlobal::config(), autoSaveGroup());
174
 
 
175
 
    // use the standard toolbar editor
176
 
    KEditToolbar dlg(factory());
177
 
    connect(&dlg, SIGNAL(newToolbarConfig()),
178
 
            this, SLOT(applyNewToolbarConfig()));
179
 
    dlg.exec();
180
 
}
181
 
 
182
 
void KDevDesigner::applyNewToolbarConfig()
183
 
{
184
 
    applyMainWindowSettings(KGlobal::config(), autoSaveGroup());
185
 
}
186
 
 
187
 
void KDevDesigner::fileOpen()
188
 
{
189
 
    // this slot is called whenever the File->Open menu is selected,
190
 
    // the Open shortcut is pressed (usually CTRL+O) or the Open toolbar
191
 
    // button is clicked
192
 
    KURL url =
193
 
        KFileDialog::getOpenURL( QString::null, QString::null, this );
194
 
 
195
 
    if (url.isEmpty() == false)
196
 
    {
197
 
        // About this function, the style guide (
198
 
        // http://developer.kde.org/documentation/standards/kde/style/basics/index.html )
199
 
        // says that it should open a new window if the document is _not_
200
 
        // in its initial state.  This is what we do here..
201
 
        if ( m_part->url().isEmpty() && ! m_part->isModified() )
202
 
        {
203
 
            // we open the file in this window...
204
 
            load( url );
205
 
        }
206
 
        else
207
 
        {
208
 
            // we open the file in a new window...
209
 
            KDevDesigner* newWin = new KDevDesigner;
210
 
            newWin->load( url );
211
 
            newWin->show();
212
 
        }
213
 
    }
214
 
}
215
 
 
216
 
#include "kdevdesigner.moc"