~ubuntu-branches/ubuntu/vivid/kate/vivid-updates

« back to all changes in this revision

Viewing changes to kate/src/katemainwindow.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-12-04 16:49:41 UTC
  • mfrom: (1.6.6)
  • Revision ID: package-import@ubuntu.com-20141204164941-l3qbvsly83hhlw2v
Tags: 4:14.11.97-0ubuntu1
* New upstream release
* Update build-deps and use pkg-kde v3 for Qt 5 build
* kate-data now kate5-data for co-installability

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
 
3
   Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
 
4
   Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk>
 
5
   Copyright (C) 2007 Flavio Castelli <flavio.castelli@gmail.com>
 
6
 
 
7
   This library is free software; you can redistribute it and/or
 
8
   modify it under the terms of the GNU Library General Public
 
9
   License version 2 as published by the Free Software Foundation.
 
10
 
 
11
   This library is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
   Library General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU Library General Public License
 
17
   along with this library; see the file COPYING.LIB.  If not, write to
 
18
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
19
   Boston, MA 02110-1301, USA.
 
20
*/
 
21
 
 
22
//BEGIN Includes
 
23
#include "katemainwindow.h"
 
24
 
 
25
#include "kateconfigdialog.h"
 
26
#include "katedocmanager.h"
 
27
#include "katepluginmanager.h"
 
28
#include "kateconfigplugindialogpage.h"
 
29
#include "kateviewmanager.h"
 
30
#include "kateapp.h"
 
31
#include "katesavemodifieddialog.h"
 
32
#include "katemwmodonhddialog.h"
 
33
#include "katesessionsaction.h"
 
34
#include "katesessionmanager.h"
 
35
#include "kateviewspace.h"
 
36
#include "katequickopen.h"
 
37
#include "kateupdatedisabler.h"
 
38
#include "katedebug.h"
 
39
 
 
40
#include <KActionMenu>
 
41
#include <KAboutApplicationDialog>
 
42
#include <KEditToolBar>
 
43
#include <KShortcutsDialog>
 
44
#include <KMessageBox>
 
45
#include <KOpenWithDialog>
 
46
#include <KStandardAction>
 
47
#include <KMimeTypeTrader>
 
48
#include <KMultiTabBar>
 
49
#include <khelpclient.h>
 
50
#include <KRun>
 
51
#include <KRecentFilesAction>
 
52
#include <KToggleFullScreenAction>
 
53
#include <KActionCollection>
 
54
#include <KAboutData>
 
55
#include <KWindowSystem>
 
56
#include <KToolBar>
 
57
#include <KLocalizedString>
 
58
#include <KConfigGroup>
 
59
#include <KSharedConfig>
 
60
#include <kwindowconfig.h>
 
61
#include <KXMLGUIFactory>
 
62
 
 
63
#include <KIO/Job>
 
64
#include <KFileItem>
 
65
 
 
66
#include <QDesktopWidget>
 
67
#include <QEvent>
 
68
#include <QList>
 
69
#include <QMimeData>
 
70
#include <QMimeDatabase>
 
71
#include <QDragEnterEvent>
 
72
#include <QDropEvent>
 
73
#include <QApplication>
 
74
#include <QMenu>
 
75
#include <QMenuBar>
 
76
#include <QToolButton>
 
77
#include <QTimer>
 
78
#include <QFontDatabase>
 
79
 
 
80
#include <ktexteditor/sessionconfiginterface.h>
 
81
//END
 
82
 
 
83
KateMwModOnHdDialog *KateMainWindow::s_modOnHdDialog = 0;
 
84
 
 
85
KateContainerStackedLayout::KateContainerStackedLayout(QWidget *parent)
 
86
    : QStackedLayout(parent)
 
87
{}
 
88
 
 
89
QSize KateContainerStackedLayout::sizeHint() const
 
90
{
 
91
    if (currentWidget()) {
 
92
        return currentWidget()->sizeHint();
 
93
    }
 
94
    return QStackedLayout::sizeHint();
 
95
}
 
96
 
 
97
QSize KateContainerStackedLayout::minimumSize() const
 
98
{
 
99
    if (currentWidget()) {
 
100
        return currentWidget()->minimumSize();
 
101
    }
 
102
    return QStackedLayout::minimumSize();
 
103
}
 
104
 
 
105
KateMainWindow::KateMainWindow(KConfig *sconfig, const QString &sgroup)
 
106
    : KateMDI::MainWindow(0)
 
107
    , m_modignore(false)
 
108
    , m_wrapper(new KTextEditor::MainWindow(this))
 
109
{
 
110
    /**
 
111
     * we don't want any flicker here
 
112
     */
 
113
    KateUpdateDisabler disableUpdates (this);
 
114
 
 
115
    /**
 
116
     * get and set config revision
 
117
     */
 
118
    static const int currentConfigRevision = 10;
 
119
    const int readConfigRevision = KConfigGroup(KSharedConfig::openConfig(), "General").readEntry("Config Revision", 0);
 
120
    KConfigGroup(KSharedConfig::openConfig(), "General").writeEntry("Config Revision", currentConfigRevision);
 
121
    const bool firstStart = readConfigRevision < currentConfigRevision;
 
122
 
 
123
    // start session restore if needed
 
124
    startRestore(sconfig, sgroup);
 
125
 
 
126
    // setup most important actions first, needed by setupMainWindow
 
127
    setupImportantActions();
 
128
 
 
129
    // setup the most important widgets
 
130
    setupMainWindow();
 
131
 
 
132
    // setup the actions
 
133
    setupActions();
 
134
 
 
135
    setStandardToolBarMenuEnabled(true);
 
136
    setXMLFile(QStringLiteral("kateui.rc"));
 
137
    createShellGUI(true);
 
138
 
 
139
    //qCDebug(LOG_KATE) << "****************************************************************************" << sconfig;
 
140
 
 
141
    // register mainwindow in app
 
142
    KateApp::self()->addMainWindow(this);
 
143
 
 
144
    // enable plugin guis
 
145
    KateApp::self()->pluginManager()->enableAllPluginsGUI(this, sconfig);
 
146
 
 
147
    // caption update
 
148
    Q_FOREACH (auto doc, KateApp::self()->documentManager()->documentList()) {
 
149
        slotDocumentCreated(doc);
 
150
    }
 
151
 
 
152
    connect(KateApp::self()->documentManager(), SIGNAL(documentCreated(KTextEditor::Document*)), this, SLOT(slotDocumentCreated(KTextEditor::Document*)));
 
153
 
 
154
    readOptions();
 
155
 
 
156
    if (sconfig) {
 
157
        m_viewManager->restoreViewConfiguration(KConfigGroup(sconfig, sgroup));
 
158
    }
 
159
 
 
160
    finishRestore();
 
161
 
 
162
    m_fileOpenRecent->loadEntries(KConfigGroup(sconfig, "Recent Files"));
 
163
 
 
164
    setAcceptDrops(true);
 
165
 
 
166
    connect(KateApp::self()->sessionManager(), SIGNAL(sessionChanged()), this, SLOT(updateCaption()));
 
167
 
 
168
    connect(this, SIGNAL(sigShowPluginConfigPage(KTextEditor::Plugin*,uint)), this, SLOT(showPluginConfigPage(KTextEditor::Plugin*,uint)));
 
169
 
 
170
    // prior to this there was (possibly) no view, therefore not context menu.
 
171
    // Hence, we have to take care of the menu bar here
 
172
    toggleShowMenuBar(false);
 
173
 
 
174
    // on first start: deactivate toolbar
 
175
    if (firstStart)
 
176
        toolBar(QLatin1String("mainToolBar"))->hide();
 
177
}
 
178
 
 
179
KateMainWindow::~KateMainWindow()
 
180
{
 
181
    // first, save our fallback window size ;)
 
182
    KConfigGroup cfg(KSharedConfig::openConfig(), "MainWindow");
 
183
    KWindowConfig::saveWindowSize(windowHandle(), cfg);
 
184
 
 
185
    // save other options ;=)
 
186
    saveOptions();
 
187
 
 
188
    // unregister mainwindow in app
 
189
    KateApp::self()->removeMainWindow(this);
 
190
 
 
191
    // disable all plugin guis, delete all pluginViews
 
192
    KateApp::self()->pluginManager()->disableAllPluginsGUI(this);
 
193
 
 
194
    // delete the view manager, before KateMainWindow's wrapper is dead
 
195
    delete m_viewManager;
 
196
    m_viewManager = 0;
 
197
 
 
198
    // kill the wrapper object, now that all views are dead
 
199
    delete m_wrapper;
 
200
    m_wrapper = 0;
 
201
}
 
202
 
 
203
QSize KateMainWindow::sizeHint() const
 
204
{
 
205
    /**
 
206
     * have some useful size hint, else we have mini windows per default
 
207
     */
 
208
    return (QSize(640, 480).expandedTo(minimumSizeHint()));
 
209
}
 
210
 
 
211
void KateMainWindow::setupImportantActions()
 
212
{
 
213
    m_paShowStatusBar = KStandardAction::showStatusbar(this, SLOT(toggleShowStatusBar()), actionCollection());
 
214
    m_paShowStatusBar->setWhatsThis(i18n("Use this command to show or hide the view's statusbar"));
 
215
    m_paShowMenuBar = KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
 
216
 
 
217
    m_paShowTabBar = new KToggleAction(i18n("Show &Tabs"), this);
 
218
    actionCollection()->addAction(QStringLiteral("settings_show_tab_bar"), m_paShowTabBar);
 
219
    connect(m_paShowTabBar, SIGNAL(toggled(bool)), this, SLOT(toggleShowTabBar()));
 
220
    m_paShowTabBar->setWhatsThis(i18n("Use this command to show or hide the tabs for the views"));
 
221
 
 
222
    m_paShowPath = new KToggleAction(i18n("Sho&w Path in Titlebar"), this);
 
223
    actionCollection()->addAction(QStringLiteral("settings_show_full_path"), m_paShowPath);
 
224
    connect(m_paShowPath, SIGNAL(toggled(bool)), this, SLOT(updateCaption()));
 
225
    m_paShowPath->setWhatsThis(i18n("Show the complete document path in the window caption"));
 
226
 
 
227
    QAction * a = actionCollection()->addAction(KStandardAction::Back, QStringLiteral("view_prev_tab"));
 
228
    a->setText(i18n("&Previous Tab"));
 
229
    a->setWhatsThis(i18n("Focus the previous tab."));
 
230
    connect(a, SIGNAL(triggered()), this, SLOT(slotFocusPrevTab()));
 
231
 
 
232
    a = actionCollection()->addAction(KStandardAction::Forward, QStringLiteral("view_next_tab"));
 
233
    a->setText(i18n("&Next Tab"));
 
234
    a->setWhatsThis(i18n("Focus the next tab."));
 
235
    connect(a, SIGNAL(triggered()), this, SLOT(slotFocusNextTab()));
 
236
 
 
237
    // the quick open action is used by the KateViewSpace "quick open button"
 
238
    a = actionCollection()->addAction(QStringLiteral("view_quick_open"));
 
239
    a->setIcon(QIcon::fromTheme(QStringLiteral("quickopen")));
 
240
    a->setText(i18n("&Quick Open"));
 
241
    actionCollection()->setDefaultShortcut(a, QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_O));
 
242
    connect(a, SIGNAL(triggered()), this, SLOT(slotQuickOpen()));
 
243
    a->setWhatsThis(i18n("Open a form to quick open documents."));
 
244
}
 
245
 
 
246
void KateMainWindow::setupMainWindow()
 
247
{
 
248
    setToolViewStyle(KMultiTabBar::KDEV3ICON);
 
249
 
 
250
    /**
 
251
     * create central stacked widget with its children
 
252
     */
 
253
    m_mainStackedWidget = new QStackedWidget(centralWidget());
 
254
    centralWidget()->layout()->addWidget(m_mainStackedWidget);
 
255
    (static_cast<QBoxLayout *>(centralWidget()->layout()))->setStretchFactor(m_mainStackedWidget, 100);
 
256
 
 
257
    m_quickOpen = new KateQuickOpen(m_mainStackedWidget, this);
 
258
    m_mainStackedWidget->addWidget(m_quickOpen);
 
259
 
 
260
    m_viewManager = new KateViewManager(m_mainStackedWidget, this);
 
261
    m_mainStackedWidget->addWidget(m_viewManager);
 
262
 
 
263
    // make view manager default visible!
 
264
    m_mainStackedWidget->setCurrentWidget(m_viewManager);
 
265
 
 
266
    m_bottomViewBarContainer = new QWidget(centralWidget());
 
267
    centralWidget()->layout()->addWidget(m_bottomViewBarContainer);
 
268
    m_bottomContainerStack = new KateContainerStackedLayout(m_bottomViewBarContainer);
 
269
}
 
270
 
 
271
void KateMainWindow::setupActions()
 
272
{
 
273
    QAction *a;
 
274
 
 
275
    actionCollection()->addAction(KStandardAction::New, QStringLiteral("file_new"), m_viewManager, SLOT(slotDocumentNew()))
 
276
    ->setWhatsThis(i18n("Create a new document"));
 
277
    actionCollection()->addAction(KStandardAction::Open, QStringLiteral("file_open"), m_viewManager, SLOT(slotDocumentOpen()))
 
278
    ->setWhatsThis(i18n("Open an existing document for editing"));
 
279
 
 
280
    m_fileOpenRecent = KStandardAction::openRecent(m_viewManager, SLOT(openUrl(QUrl)), this);
 
281
    m_fileOpenRecent->setMaxItems(KateConfigDialog::recentFilesMaxCount());
 
282
    actionCollection()->addAction(m_fileOpenRecent->objectName(), m_fileOpenRecent);
 
283
    m_fileOpenRecent->setWhatsThis(i18n("This lists files which you have opened recently, and allows you to easily open them again."));
 
284
 
 
285
    a = actionCollection()->addAction(QStringLiteral("file_save_all"));
 
286
    a->setIcon(QIcon::fromTheme(QStringLiteral("document-save-all")));
 
287
    a->setText(i18n("Save A&ll"));
 
288
    actionCollection()->setDefaultShortcut(a, QKeySequence(Qt::CTRL + Qt::Key_L));
 
289
    connect(a, SIGNAL(triggered()), KateApp::self()->documentManager(), SLOT(saveAll()));
 
290
    a->setWhatsThis(i18n("Save all open, modified documents to disk."));
 
291
 
 
292
    a = actionCollection()->addAction(QStringLiteral("file_reload_all"));
 
293
    a->setText(i18n("&Reload All"));
 
294
    connect(a, SIGNAL(triggered()), KateApp::self()->documentManager(), SLOT(reloadAll()));
 
295
    a->setWhatsThis(i18n("Reload all open documents."));
 
296
 
 
297
    a = actionCollection()->addAction(QStringLiteral("file_close_orphaned"));
 
298
    a->setText(i18n("Close Orphaned"));
 
299
    connect(a, SIGNAL(triggered()), KateApp::self()->documentManager(), SLOT(closeOrphaned()));
 
300
    a->setWhatsThis(i18n("Close all documents in the file list that could not be reopened, because they are not accessible anymore."));
 
301
 
 
302
    actionCollection()->addAction(KStandardAction::Close, QStringLiteral("file_close"), m_viewManager, SLOT(slotDocumentClose()))
 
303
    ->setWhatsThis(i18n("Close the current document."));
 
304
 
 
305
    a = actionCollection()->addAction(QStringLiteral("file_close_other"));
 
306
    a->setText(i18n("Close Other"));
 
307
    connect(a, SIGNAL(triggered()), this, SLOT(slotDocumentCloseOther()));
 
308
    a->setWhatsThis(i18n("Close other open documents."));
 
309
 
 
310
    a = actionCollection()->addAction(QStringLiteral("file_close_all"));
 
311
    a->setText(i18n("Clos&e All"));
 
312
    connect(a, SIGNAL(triggered()), this, SLOT(slotDocumentCloseAll()));
 
313
    a->setWhatsThis(i18n("Close all open documents."));
 
314
 
 
315
    a = actionCollection()->addAction(KStandardAction::Quit, QStringLiteral("file_quit"));
 
316
    // Qt::QueuedConnection: delay real shutdown, as we are inside menu action handling (bug #185708)
 
317
    connect(a, SIGNAL(triggered()), this, SLOT(slotFileQuit()), Qt::QueuedConnection);
 
318
    a->setWhatsThis(i18n("Close this window"));
 
319
 
 
320
    a = actionCollection()->addAction(QStringLiteral("view_new_view"));
 
321
    a->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
 
322
    a->setText(i18n("&New Window"));
 
323
    connect(a, SIGNAL(triggered()), this, SLOT(newWindow()));
 
324
    a->setWhatsThis(i18n("Create a new Kate view (a new window with the same document list)."));
 
325
 
 
326
    m_showFullScreenAction = KStandardAction::fullScreen(0, 0, this, this);
 
327
    actionCollection()->addAction(m_showFullScreenAction->objectName(), m_showFullScreenAction);
 
328
    connect(m_showFullScreenAction, SIGNAL(toggled(bool)), this, SLOT(slotFullScreen(bool)));
 
329
 
 
330
    documentOpenWith = new KActionMenu(i18n("Open W&ith"), this);
 
331
    actionCollection()->addAction(QStringLiteral("file_open_with"), documentOpenWith);
 
332
    documentOpenWith->setWhatsThis(i18n("Open the current document using another application registered for its file type, or an application of your choice."));
 
333
    connect(documentOpenWith->menu(), SIGNAL(aboutToShow()), this, SLOT(mSlotFixOpenWithMenu()));
 
334
    connect(documentOpenWith->menu(), SIGNAL(triggered(QAction*)), this, SLOT(slotOpenWithMenuAction(QAction*)));
 
335
 
 
336
    a = KStandardAction::keyBindings(this, SLOT(editKeys()), actionCollection());
 
337
    a->setWhatsThis(i18n("Configure the application's keyboard shortcut assignments."));
 
338
 
 
339
    a = KStandardAction::configureToolbars(this, SLOT(slotEditToolbars()), actionCollection());
 
340
    a->setWhatsThis(i18n("Configure which items should appear in the toolbar(s)."));
 
341
 
 
342
    QAction *settingsConfigure = KStandardAction::preferences(this, SLOT(slotConfigure()), actionCollection());
 
343
    settingsConfigure->setWhatsThis(i18n("Configure various aspects of this application and the editing component."));
 
344
 
 
345
    if (KateApp::self()->pluginManager()->pluginList().count() > 0) {
 
346
        a = actionCollection()->addAction(QStringLiteral("help_plugins_contents"));
 
347
        a->setText(i18n("&Plugins Handbook"));
 
348
        connect(a, SIGNAL(triggered()), this, SLOT(pluginHelp()));
 
349
        a->setWhatsThis(i18n("This shows help files for various available plugins."));
 
350
    }
 
351
 
 
352
    a = actionCollection()->addAction(QStringLiteral("help_about_editor"));
 
353
    a->setText(i18n("&About Editor Component"));
 
354
    connect(a, SIGNAL(triggered()), this, SLOT(aboutEditor()));
 
355
 
 
356
    connect(m_viewManager, SIGNAL(viewChanged(KTextEditor::View*)), this, SLOT(slotWindowActivated()));
 
357
    connect(m_viewManager, SIGNAL(viewChanged(KTextEditor::View*)), this, SLOT(slotUpdateOpenWith()));
 
358
    connect(m_viewManager, SIGNAL(viewChanged(KTextEditor::View*)), this, SLOT(slotUpdateBottomViewBar()));
 
359
 
 
360
    // re-route signals to our wrapper
 
361
    connect(m_viewManager, SIGNAL(viewChanged(KTextEditor::View*)), m_wrapper, SIGNAL(viewChanged(KTextEditor::View*)));
 
362
    connect(m_viewManager, SIGNAL(viewCreated(KTextEditor::View*)), m_wrapper, SIGNAL(viewCreated(KTextEditor::View*)));
 
363
    connect(this, SIGNAL(unhandledShortcutOverride(QEvent*)), m_wrapper, SIGNAL(unhandledShortcutOverride(QEvent*)));
 
364
 
 
365
    slotWindowActivated();
 
366
 
 
367
    // session actions
 
368
    a = actionCollection()->addAction(QStringLiteral("sessions_new"));
 
369
    a->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
 
370
    a->setText(i18nc("Menu entry Session->New", "&New"));
 
371
    // Qt::QueuedConnection to avoid deletion of code that is executed when reducing the amount of mainwindows. (bug #227008)
 
372
    connect(a, SIGNAL(triggered()), KateApp::self()->sessionManager(), SLOT(sessionNew()), Qt::QueuedConnection);
 
373
    a = actionCollection()->addAction(QStringLiteral("sessions_open"));
 
374
    a->setIcon(QIcon::fromTheme(QStringLiteral("document-open")));
 
375
    a->setText(i18n("&Open Session"));
 
376
    // Qt::QueuedConnection to avoid deletion of code that is executed when reducing the amount of mainwindows. (bug #227008)
 
377
    connect(a, SIGNAL(triggered()), KateApp::self()->sessionManager(), SLOT(sessionOpen()), Qt::QueuedConnection);
 
378
    a = actionCollection()->addAction(QStringLiteral("sessions_save"));
 
379
    a->setIcon(QIcon::fromTheme(QStringLiteral("document-save")));
 
380
    a->setText(i18n("&Save Session"));
 
381
    connect(a, SIGNAL(triggered()), KateApp::self()->sessionManager(), SLOT(sessionSave()));
 
382
    a = actionCollection()->addAction(QStringLiteral("sessions_save_as"));
 
383
    a->setIcon(QIcon::fromTheme(QStringLiteral("document-save-as")));
 
384
    a->setText(i18n("Save Session &As..."));
 
385
    connect(a, SIGNAL(triggered()), KateApp::self()->sessionManager(), SLOT(sessionSaveAs()));
 
386
    a = actionCollection()->addAction(QStringLiteral("sessions_manage"));
 
387
    a->setIcon(QIcon::fromTheme(QStringLiteral("view-choose")));
 
388
    a->setText(i18n("&Manage Sessions..."));
 
389
    // Qt::QueuedConnection to avoid deletion of code that is executed when reducing the amount of mainwindows. (bug #227008)
 
390
    connect(a, SIGNAL(triggered()), KateApp::self()->sessionManager(), SLOT(sessionManage()), Qt::QueuedConnection);
 
391
 
 
392
    // quick open menu ;)
 
393
    a = new KateSessionsAction(i18n("&Quick Open Session"), this);
 
394
    actionCollection()->addAction(QStringLiteral("sessions_list"), a);
 
395
}
 
396
 
 
397
void KateMainWindow::slotDocumentCloseAll()
 
398
{
 
399
    if (KateApp::self()->documentManager()->documentList().size() >= 1 && KMessageBox::warningContinueCancel(this,
 
400
            i18n("This will close all open documents. Are you sure you want to continue?"),
 
401
            i18n("Close all documents"),
 
402
            KStandardGuiItem::cont(),
 
403
            KStandardGuiItem::cancel(),
 
404
            QStringLiteral("closeAll")) != KMessageBox::Cancel) {
 
405
        if (queryClose_internal()) {
 
406
            KateApp::self()->documentManager()->closeAllDocuments(false);
 
407
        }
 
408
    }
 
409
}
 
410
 
 
411
void KateMainWindow::slotDocumentCloseOther(KTextEditor::Document *document)
 
412
{
 
413
    if (queryClose_internal(document)) {
 
414
        KateApp::self()->documentManager()->closeOtherDocuments(document);
 
415
    }
 
416
}
 
417
 
 
418
void KateMainWindow::slotDocumentCloseSelected(const QList<KTextEditor::Document *> &docList)
 
419
{
 
420
    QList<KTextEditor::Document *> documents;
 
421
    foreach(KTextEditor::Document * doc, docList) {
 
422
        if (queryClose_internal(doc)) {
 
423
            documents.append(doc);
 
424
        }
 
425
    }
 
426
 
 
427
    KateApp::self()->documentManager()->closeDocuments(documents);
 
428
}
 
429
 
 
430
void KateMainWindow::slotDocumentCloseOther()
 
431
{
 
432
    if (queryClose_internal(m_viewManager->activeView()->document())) {
 
433
        KateApp::self()->documentManager()->closeOtherDocuments(m_viewManager->activeView()->document());
 
434
    }
 
435
}
 
436
 
 
437
bool KateMainWindow::queryClose_internal(KTextEditor::Document *doc)
 
438
{
 
439
    int documentCount = KateApp::self()->documentManager()->documentList().size();
 
440
 
 
441
    if (! showModOnDiskPrompt()) {
 
442
        return false;
 
443
    }
 
444
 
 
445
    QList<KTextEditor::Document *> modifiedDocuments = KateApp::self()->documentManager()->modifiedDocumentList();
 
446
    modifiedDocuments.removeAll(doc);
 
447
    bool shutdown = (modifiedDocuments.count() == 0);
 
448
 
 
449
    if (!shutdown) {
 
450
        shutdown = KateSaveModifiedDialog::queryClose(this, modifiedDocuments);
 
451
    }
 
452
 
 
453
    if (KateApp::self()->documentManager()->documentList().size() > documentCount) {
 
454
        KMessageBox::information(this,
 
455
                                 i18n("New file opened while trying to close Kate, closing aborted."),
 
456
                                 i18n("Closing Aborted"));
 
457
        shutdown = false;
 
458
    }
 
459
 
 
460
    return shutdown;
 
461
}
 
462
 
 
463
/**
 
464
 * queryClose(), take care that after the last mainwindow the stuff is closed
 
465
 */
 
466
bool KateMainWindow::queryClose()
 
467
{
 
468
    // session saving, can we close all views ?
 
469
    // just test, not close them actually
 
470
    if (qApp->isSavingSession()) {
 
471
        return queryClose_internal();
 
472
    }
 
473
 
 
474
    // normal closing of window
 
475
    // allow to close all windows until the last without restrictions
 
476
    if (KateApp::self()->mainWindowsCount() > 1) {
 
477
        return true;
 
478
    }
 
479
 
 
480
    // last one: check if we can close all documents, try run
 
481
    // and save docs if we really close down !
 
482
    if (queryClose_internal()) {
 
483
        KateApp::self()->sessionManager()->saveActiveSession(true);
 
484
        return true;
 
485
    }
 
486
 
 
487
    return false;
 
488
}
 
489
 
 
490
void KateMainWindow::newWindow()
 
491
{
 
492
    KateApp::self()->newMainWindow(KateApp::self()->sessionManager()->activeSession()->config());
 
493
}
 
494
 
 
495
void KateMainWindow::slotEditToolbars()
 
496
{
 
497
    KConfigGroup cfg(KSharedConfig::openConfig(), "MainWindow");
 
498
    saveMainWindowSettings(cfg);
 
499
 
 
500
    KEditToolBar dlg(factory());
 
501
 
 
502
    connect(&dlg, SIGNAL(newToolBarConfig()), this, SLOT(slotNewToolbarConfig()));
 
503
    dlg.exec();
 
504
}
 
505
 
 
506
void KateMainWindow::slotNewToolbarConfig()
 
507
{
 
508
    applyMainWindowSettings(KConfigGroup(KSharedConfig::openConfig(), "MainWindow"));
 
509
}
 
510
 
 
511
void KateMainWindow::slotFileQuit()
 
512
{
 
513
    KateApp::self()->shutdownKate(this);
 
514
}
 
515
 
 
516
void KateMainWindow::slotFileClose()
 
517
{
 
518
    m_viewManager->slotDocumentClose();
 
519
}
 
520
 
 
521
void KateMainWindow::slotOpenDocument(QUrl url)
 
522
{
 
523
    m_viewManager->openUrl(url,
 
524
                           QString(),
 
525
                           true,
 
526
                           false);
 
527
}
 
528
 
 
529
void KateMainWindow::readOptions()
 
530
{
 
531
    KSharedConfig::Ptr config = KSharedConfig::openConfig();
 
532
 
 
533
    const KConfigGroup generalGroup(config, "General");
 
534
    m_modNotification = generalGroup.readEntry("Modified Notification", false);
 
535
    KateApp::self()->documentManager()->setSaveMetaInfos(generalGroup.readEntry("Save Meta Infos", true));
 
536
    KateApp::self()->documentManager()->setDaysMetaInfos(generalGroup.readEntry("Days Meta Infos", 30));
 
537
 
 
538
    m_paShowPath->setChecked(generalGroup.readEntry("Show Full Path in Title", false));
 
539
    m_paShowStatusBar->setChecked(generalGroup.readEntry("Show Status Bar", true));
 
540
    m_paShowMenuBar->setChecked(generalGroup.readEntry("Show Menu Bar", true));
 
541
    m_paShowTabBar->setChecked(generalGroup.readEntry("Show Tab Bar", true));
 
542
 
 
543
    // emit signal to hide/show statusbars
 
544
    toggleShowStatusBar();
 
545
    toggleShowTabBar();
 
546
}
 
547
 
 
548
void KateMainWindow::saveOptions()
 
549
{
 
550
    KSharedConfig::Ptr config = KSharedConfig::openConfig();
 
551
 
 
552
    KConfigGroup generalGroup(config, "General");
 
553
 
 
554
    generalGroup.writeEntry("Save Meta Infos", KateApp::self()->documentManager()->getSaveMetaInfos());
 
555
 
 
556
    generalGroup.writeEntry("Days Meta Infos", KateApp::self()->documentManager()->getDaysMetaInfos());
 
557
 
 
558
    generalGroup.writeEntry("Show Full Path in Title", m_paShowPath->isChecked());
 
559
    generalGroup.writeEntry("Show Status Bar", m_paShowStatusBar->isChecked());
 
560
    generalGroup.writeEntry("Show Menu Bar", m_paShowMenuBar->isChecked());
 
561
    generalGroup.writeEntry("Show Tab Bar", m_paShowTabBar->isChecked());
 
562
}
 
563
 
 
564
void KateMainWindow::toggleShowMenuBar(bool showMessage)
 
565
{
 
566
    if (m_paShowMenuBar->isChecked()) {
 
567
        menuBar()->show();
 
568
        removeMenuBarActionFromContextMenu();
 
569
    } else {
 
570
        if (showMessage) {
 
571
            const QString accel = m_paShowMenuBar->shortcut().toString();
 
572
            KMessageBox::information(this, i18n("This will hide the menu bar completely."
 
573
                                                " You can show it again by typing %1.", accel),
 
574
                                     i18n("Hide menu bar"), QLatin1String("HideMenuBarWarning"));
 
575
        }
 
576
        menuBar()->hide();
 
577
        addMenuBarActionToContextMenu();
 
578
    }
 
579
}
 
580
 
 
581
void KateMainWindow::addMenuBarActionToContextMenu()
 
582
{
 
583
    if (m_viewManager->activeView()) {
 
584
        m_viewManager->activeView()->contextMenu()->addAction(m_paShowMenuBar);
 
585
    }
 
586
}
 
587
 
 
588
void KateMainWindow::removeMenuBarActionFromContextMenu()
 
589
{
 
590
    if (m_viewManager->activeView()) {
 
591
        m_viewManager->activeView()->contextMenu()->removeAction(m_paShowMenuBar);
 
592
    }
 
593
}
 
594
 
 
595
void KateMainWindow::toggleShowStatusBar()
 
596
{
 
597
    emit statusBarToggled();
 
598
}
 
599
 
 
600
bool KateMainWindow::showStatusBar()
 
601
{
 
602
    return m_paShowStatusBar->isChecked();
 
603
}
 
604
 
 
605
void KateMainWindow::toggleShowTabBar()
 
606
{
 
607
    emit tabBarToggled();
 
608
}
 
609
 
 
610
bool KateMainWindow::showTabBar()
 
611
{
 
612
    return m_paShowTabBar->isChecked();
 
613
}
 
614
 
 
615
void KateMainWindow::slotWindowActivated()
 
616
{
 
617
    if (m_viewManager->activeView()) {
 
618
        updateCaption(m_viewManager->activeView()->document());
 
619
    }
 
620
 
 
621
    // show view manager in any case
 
622
    if (m_mainStackedWidget->currentWidget() != m_viewManager) {
 
623
        m_mainStackedWidget->setCurrentWidget(m_viewManager);
 
624
    }
 
625
 
 
626
    // update proxy
 
627
    centralWidget()->setFocusProxy(m_viewManager->activeView());
 
628
}
 
629
 
 
630
void KateMainWindow::slotUpdateOpenWith()
 
631
{
 
632
    if (m_viewManager->activeView()) {
 
633
        documentOpenWith->setEnabled(!m_viewManager->activeView()->document()->url().isEmpty());
 
634
    } else {
 
635
        documentOpenWith->setEnabled(false);
 
636
    }
 
637
}
 
638
 
 
639
void KateMainWindow::dragEnterEvent(QDragEnterEvent *event)
 
640
{
 
641
    if (!event->mimeData()) {
 
642
        return;
 
643
    }
 
644
    const bool accept = event->mimeData()->hasUrls() || event->mimeData()->hasText();
 
645
    event->setAccepted(accept);
 
646
}
 
647
 
 
648
void KateMainWindow::dropEvent(QDropEvent *event)
 
649
{
 
650
    slotDropEvent(event);
 
651
}
 
652
 
 
653
void KateMainWindow::slotDropEvent(QDropEvent *event)
 
654
{
 
655
    if (event->mimeData() == 0) {
 
656
        return;
 
657
    }
 
658
 
 
659
    //
 
660
    // are we dropping files?
 
661
    //
 
662
 
 
663
    if (event->mimeData()->hasUrls()) {
 
664
        QList<QUrl> textlist = event->mimeData()->urls();
 
665
 
 
666
        // Try to get the KTextEditor::View that sent this, and activate it, so that the file opens in the
 
667
        // view where it was dropped
 
668
        KTextEditor::View *kVsender = qobject_cast<KTextEditor::View *>(QObject::sender());
 
669
        if (kVsender != 0) {
 
670
            QWidget *parent = kVsender->parentWidget();
 
671
            if (parent != 0) {
 
672
                KateViewSpace *vs = qobject_cast<KateViewSpace *>(parent->parentWidget());
 
673
                if (vs != 0) {
 
674
                    m_viewManager->setActiveSpace(vs);
 
675
                }
 
676
            }
 
677
        }
 
678
 
 
679
        foreach(const QUrl & url, textlist) {
 
680
            // if url has no file component, try and recursively scan dir
 
681
            KFileItem kitem(url);
 
682
            kitem.setDelayedMimeTypes(true);
 
683
            if (kitem.isDir()) {
 
684
                KIO::ListJob *list_job = KIO::listRecursive(url, KIO::DefaultFlags, false);
 
685
                connect(list_job, SIGNAL(entries(KIO::Job*,KIO::UDSEntryList)),
 
686
                        this, SLOT(slotListRecursiveEntries(KIO::Job*,KIO::UDSEntryList)));
 
687
            } else {
 
688
                m_viewManager->openUrl(url);
 
689
            }
 
690
        }
 
691
    }
 
692
    //
 
693
    // or are we dropping text?
 
694
    //
 
695
    else if (event->mimeData()->hasText()) {
 
696
        KTextEditor::Document *doc =
 
697
            KateApp::self()->documentManager()->createDoc();
 
698
        doc->setText(event->mimeData()->text());
 
699
        m_viewManager->activateView(doc);
 
700
    }
 
701
}
 
702
 
 
703
void KateMainWindow::slotListRecursiveEntries(KIO::Job *job, const KIO::UDSEntryList &list)
 
704
{
 
705
    const QUrl dir = static_cast<KIO::SimpleJob *>(job)->url();
 
706
    foreach(const KIO::UDSEntry & entry, list) {
 
707
        QUrl currentUrl = dir.resolved(QUrl(entry.stringValue(KIO::UDSEntry::UDS_NAME)));
 
708
 
 
709
        if (!entry.isDir()) {
 
710
            m_viewManager->openUrl(currentUrl);
 
711
        }
 
712
    }
 
713
}
 
714
 
 
715
void KateMainWindow::editKeys()
 
716
{
 
717
    KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this);
 
718
 
 
719
    QList<KXMLGUIClient *> clients = guiFactory()->clients();
 
720
 
 
721
    foreach(KXMLGUIClient * client, clients) {
 
722
        // FIXME there appear to be invalid clients after session switching
 
723
//     qCDebug(LOG_KATE)<<"adding client to shortcut editor";
 
724
//     qCDebug(LOG_KATE)<<client;
 
725
//     qCDebug(LOG_KATE)<<client->actionCollection();
 
726
//     qCDebug(LOG_KATE)<<client->componentData().aboutData();
 
727
//     qCDebug(LOG_KATE)<<client->componentData().aboutData()->programName();
 
728
        dlg.addCollection(client->actionCollection(), client->componentName());
 
729
    }
 
730
    dlg.configure();
 
731
 
 
732
    QList<KTextEditor::Document *>  l = KateApp::self()->documentManager()->documentList();
 
733
    for (int i = 0; i < l.count(); i++) {
 
734
//     qCDebug(LOG_KATE)<<"reloading Keysettings for document "<<i;
 
735
        l.at(i)->reloadXML();
 
736
        QList<KTextEditor::View *> l1 = l.at(i)->views();
 
737
        for (int i1 = 0; i1 < l1.count(); i1++) {
 
738
            l1.at(i1)->reloadXML();
 
739
//       qCDebug(LOG_KATE)<<"reloading Keysettings for view "<<i<<"/"<<i1;
 
740
        }
 
741
    }
 
742
}
 
743
 
 
744
void KateMainWindow::openUrl(const QString &name)
 
745
{
 
746
    m_viewManager->openUrl(QUrl(name));
 
747
}
 
748
 
 
749
void KateMainWindow::slotConfigure()
 
750
{
 
751
    showPluginConfigPage(0, 0);
 
752
}
 
753
 
 
754
void KateMainWindow::showPluginConfigPage(KTextEditor::Plugin *configpageinterface, uint id)
 
755
{
 
756
    if (!m_viewManager->activeView()) {
 
757
        return;
 
758
    }
 
759
 
 
760
    KateConfigDialog *dlg = new KateConfigDialog(this, m_viewManager->activeView());
 
761
    if (configpageinterface) {
 
762
        dlg->showAppPluginPage(configpageinterface, id);
 
763
    }
 
764
 
 
765
    if (dlg->exec() == QDialog::Accepted) {
 
766
        m_fileOpenRecent->setMaxItems(KateConfigDialog::recentFilesMaxCount());
 
767
    }
 
768
 
 
769
    delete dlg;
 
770
 
 
771
    m_viewManager->reactivateActiveView(); // gui (toolbars...) needs to be updated, because
 
772
    // of possible changes that the configure dialog
 
773
    // could have done on it, specially for plugins.
 
774
}
 
775
 
 
776
QUrl KateMainWindow::activeDocumentUrl()
 
777
{
 
778
    // anders: i make this one safe, as it may be called during
 
779
    // startup (by the file selector)
 
780
    KTextEditor::View *v = m_viewManager->activeView();
 
781
    if (v) {
 
782
        return v->document()->url();
 
783
    }
 
784
    return QUrl();
 
785
}
 
786
 
 
787
void KateMainWindow::mSlotFixOpenWithMenu()
 
788
{
 
789
    // dh: in bug #307699, this slot is called when launching the Kate application
 
790
    // unfortunately, noone ever could reproduce except users.
 
791
    KTextEditor::View *activeView = m_viewManager->activeView();
 
792
    if (! activeView) {
 
793
        return;
 
794
    }
 
795
 
 
796
    // cleanup menu
 
797
    QMenu *menu = documentOpenWith->menu();
 
798
    menu->clear();
 
799
 
 
800
    // get a list of appropriate services.
 
801
    QMimeDatabase db;
 
802
    QMimeType mime = db.mimeTypeForName(activeView->document()->mimeType());
 
803
    //qCDebug(LOG_KATE) << "mime type: " << mime.name();
 
804
 
 
805
    QAction *a = 0;
 
806
    KService::List offers = KMimeTypeTrader::self()->query(mime.name(), QStringLiteral("Application"));
 
807
    // add all default open-with-actions except "Kate"
 
808
    for (KService::List::Iterator it = offers.begin(); it != offers.end(); ++it) {
 
809
        KService::Ptr service = *it;
 
810
        if (service->name() == QStringLiteral("Kate")) {
 
811
            continue;
 
812
        }
 
813
        a = menu->addAction(QIcon::fromTheme(service->icon()), service->name());
 
814
        a->setData(service->entryPath());
 
815
    }
 
816
    // append "Other..." to call the KDE "open with" dialog.
 
817
    a = documentOpenWith->menu()->addAction(i18n("&Other..."));
 
818
    a->setData(QString());
 
819
}
 
820
 
 
821
void KateMainWindow::slotOpenWithMenuAction(QAction *a)
 
822
{
 
823
    QList<QUrl> list;
 
824
    list.append(m_viewManager->activeView()->document()->url());
 
825
 
 
826
    const QString openWith = a->data().toString();
 
827
    if (openWith.isEmpty()) {
 
828
        // display "open with" dialog
 
829
        KOpenWithDialog dlg(list);
 
830
        if (dlg.exec()) {
 
831
            KRun::run(*dlg.service(), list, this);
 
832
        }
 
833
        return;
 
834
    }
 
835
 
 
836
    KService::Ptr app = KService::serviceByDesktopPath(openWith);
 
837
    if (app) {
 
838
        KRun::run(*app, list, this);
 
839
    } else {
 
840
        KMessageBox::error(this, i18n("Application '%1' not found.", openWith), i18n("Application not found"));
 
841
    }
 
842
}
 
843
 
 
844
void KateMainWindow::pluginHelp()
 
845
{
 
846
    KHelpClient::invokeHelp(QString(), QStringLiteral("kate-plugins"));
 
847
}
 
848
 
 
849
void KateMainWindow::aboutEditor()
 
850
{
 
851
    KAboutApplicationDialog ad(KTextEditor::Editor::instance()->aboutData(), this);
 
852
    ad.exec();
 
853
}
 
854
 
 
855
void KateMainWindow::slotFullScreen(bool t)
 
856
{
 
857
    KToggleFullScreenAction::setFullScreen(this, t);
 
858
    QMenuBar *mb = menuBar();
 
859
    if (t) {
 
860
 
 
861
            QToolButton *b = new QToolButton(mb);
 
862
            b->setDefaultAction(m_showFullScreenAction);
 
863
            b->setSizePolicy(QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Ignored));
 
864
            b->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
 
865
            mb->setCornerWidget(b,Qt::TopRightCorner);
 
866
            b->setVisible(true);
 
867
            b->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
 
868
    } else {
 
869
        QWidget *w=mb->cornerWidget(Qt::TopRightCorner);
 
870
        if (w) w->deleteLater();
 
871
    }
 
872
 
 
873
}
 
874
 
 
875
bool KateMainWindow::showModOnDiskPrompt()
 
876
{
 
877
    KTextEditor::Document *doc;
 
878
 
 
879
    DocVector list;
 
880
    list.reserve(KateApp::self()->documentManager()->documentList().size());
 
881
    foreach(doc, KateApp::self()->documentManager()->documentList()) {
 
882
        if (KateApp::self()->documentManager()->documentInfo(doc)->modifiedOnDisc) {
 
883
            list.append(doc);
 
884
        }
 
885
    }
 
886
 
 
887
    if (!list.isEmpty() && !m_modignore) {
 
888
        KateMwModOnHdDialog mhdlg(list, this);
 
889
        m_modignore = true;
 
890
        bool res = mhdlg.exec();
 
891
        m_modignore = false;
 
892
 
 
893
        return res;
 
894
    }
 
895
    return true;
 
896
}
 
897
 
 
898
void KateMainWindow::slotDocumentCreated(KTextEditor::Document *doc)
 
899
{
 
900
    connect(doc, SIGNAL(modifiedChanged(KTextEditor::Document*)), this, SLOT(updateCaption(KTextEditor::Document*)));
 
901
    connect(doc, SIGNAL(readWriteChanged(KTextEditor::Document*)), this, SLOT(updateCaption(KTextEditor::Document*)));
 
902
    connect(doc, SIGNAL(documentNameChanged(KTextEditor::Document*)), this, SLOT(updateCaption(KTextEditor::Document*)));
 
903
    connect(doc, SIGNAL(documentUrlChanged(KTextEditor::Document*)), this, SLOT(updateCaption(KTextEditor::Document*)));
 
904
    connect(doc, SIGNAL(documentNameChanged(KTextEditor::Document*)), this, SLOT(slotUpdateOpenWith()));
 
905
 
 
906
    updateCaption(doc);
 
907
}
 
908
 
 
909
void KateMainWindow::updateCaption()
 
910
{
 
911
    if (m_viewManager->activeView()) {
 
912
        updateCaption(m_viewManager->activeView()->document());
 
913
    }
 
914
}
 
915
 
 
916
void KateMainWindow::updateCaption(KTextEditor::Document *doc)
 
917
{
 
918
    if (!m_viewManager->activeView()) {
 
919
        setCaption(QString(), false);
 
920
        return;
 
921
    }
 
922
 
 
923
    // block signals from inactive docs
 
924
    if (!((KTextEditor::Document *)m_viewManager->activeView()->document() == doc)) {
 
925
        return;
 
926
    }
 
927
 
 
928
    QString c;
 
929
    if (m_viewManager->activeView()->document()->url().isEmpty() || (!m_paShowPath || !m_paShowPath->isChecked())) {
 
930
        c = ((KTextEditor::Document *)m_viewManager->activeView()->document())->documentName();
 
931
    } else {
 
932
        c = m_viewManager->activeView()->document()->url().toString();
 
933
    }
 
934
 
 
935
    QString sessName = KateApp::self()->sessionManager()->activeSession()->name();
 
936
    if (!sessName.isEmpty()) {
 
937
        sessName = QString::fromLatin1("%1: ").arg(sessName);
 
938
    }
 
939
 
 
940
    QString readOnlyCaption;
 
941
    if (!m_viewManager->activeView()->document()->isReadWrite()) {
 
942
        readOnlyCaption = i18n(" [read only]");
 
943
    }
 
944
 
 
945
    setCaption(sessName + c + readOnlyCaption + QStringLiteral(" [*]"),
 
946
               m_viewManager->activeView()->document()->isModified());
 
947
}
 
948
 
 
949
void KateMainWindow::saveProperties(KConfigGroup &config)
 
950
{
 
951
    saveSession(config);
 
952
 
 
953
    // store all plugin view states
 
954
    int id = KateApp::self()->mainWindowID(this);
 
955
    foreach(const KatePluginInfo & item, KateApp::self()->pluginManager()->pluginList()) {
 
956
        if (item.plugin && pluginViews().contains(item.plugin)) {
 
957
            if (auto interface = qobject_cast<KTextEditor::SessionConfigInterface *> (pluginViews().value(item.plugin))) {
 
958
                KConfigGroup group(config.config(), QString::fromLatin1("Plugin:%1:MainWindow:%2").arg(item.saveName()).arg(id));
 
959
                interface->writeSessionConfig(group);
 
960
            }
 
961
        }
 
962
    }
 
963
 
 
964
    m_fileOpenRecent->saveEntries(KConfigGroup(config.config(), "Recent Files"));
 
965
    m_viewManager->saveViewConfiguration(config);
 
966
}
 
967
 
 
968
void KateMainWindow::readProperties(const KConfigGroup &config)
 
969
{
 
970
    // KDE5: TODO startRestore should take a const KConfigBase*, or even just a const KConfigGroup&,
 
971
    // but this propagates down to interfaces/kate/plugin.h so all plugins have to be ported
 
972
    KConfigBase *configBase = const_cast<KConfig *>(config.config());
 
973
    startRestore(configBase, config.name());
 
974
 
 
975
    // perhaps enable plugin guis
 
976
    KateApp::self()->pluginManager()->enableAllPluginsGUI(this, configBase);
 
977
 
 
978
    finishRestore();
 
979
 
 
980
    m_fileOpenRecent->loadEntries(KConfigGroup(config.config(), "Recent Files"));
 
981
    m_viewManager->restoreViewConfiguration(config);
 
982
}
 
983
 
 
984
void KateMainWindow::saveGlobalProperties(KConfig *sessionConfig)
 
985
{
 
986
    KateApp::self()->documentManager()->saveDocumentList(sessionConfig);
 
987
 
 
988
    KConfigGroup cg(sessionConfig, "General");
 
989
    cg.writeEntry("Last Session", KateApp::self()->sessionManager()->activeSession()->name());
 
990
 
 
991
    // save plugin config !!
 
992
    KateApp::self()->pluginManager()->writeConfig(sessionConfig);
 
993
 
 
994
}
 
995
 
 
996
void KateMainWindow::saveWindowConfig(const KConfigGroup &_config)
 
997
{
 
998
    KConfigGroup config(_config);
 
999
    saveMainWindowSettings(config);
 
1000
    KWindowConfig::saveWindowSize(windowHandle(), config);
 
1001
    config.writeEntry("WindowState", int(((KParts::MainWindow *)this)->windowState()));
 
1002
    config.sync();
 
1003
}
 
1004
 
 
1005
void KateMainWindow::restoreWindowConfig(const KConfigGroup &config)
 
1006
{
 
1007
    setWindowState(Qt::WindowNoState);
 
1008
    applyMainWindowSettings(config);
 
1009
    KWindowConfig::restoreWindowSize(windowHandle(), config);
 
1010
    setWindowState(QFlags<Qt::WindowState>(config.readEntry("WindowState", int(Qt::WindowActive))));
 
1011
}
 
1012
 
 
1013
void KateMainWindow::slotUpdateBottomViewBar()
 
1014
{
 
1015
    //qCDebug(LOG_KATE)<<"slotUpdateHorizontalViewBar()"<<endl;
 
1016
    KTextEditor::View *view = m_viewManager->activeView();
 
1017
    BarState bs = m_bottomViewBarMapping[view];
 
1018
    if (bs.bar() && bs.state()) {
 
1019
        m_bottomContainerStack->setCurrentWidget(bs.bar());
 
1020
        m_bottomContainerStack->currentWidget()->show();
 
1021
        m_bottomViewBarContainer->show();
 
1022
    } else {
 
1023
        QWidget *wid = m_bottomContainerStack->currentWidget();
 
1024
        if (wid) {
 
1025
            wid->hide();
 
1026
        }
 
1027
        //qCDebug(LOG_KATE)<<wid<<"hiding container"<<endl;
 
1028
        m_bottomViewBarContainer->hide();
 
1029
    }
 
1030
}
 
1031
 
 
1032
void KateMainWindow::queueModifiedOnDisc(KTextEditor::Document *doc)
 
1033
{
 
1034
    if (!m_modNotification) {
 
1035
        return;
 
1036
    }
 
1037
 
 
1038
    if (s_modOnHdDialog == 0) {
 
1039
        DocVector list;
 
1040
        list.append(doc);
 
1041
 
 
1042
        s_modOnHdDialog = new KateMwModOnHdDialog(list, this);
 
1043
        m_modignore = true;
 
1044
        KWindowSystem::setOnAllDesktops(s_modOnHdDialog->winId(), true);
 
1045
        s_modOnHdDialog->exec();
 
1046
        delete s_modOnHdDialog; // s_modOnHdDialog is set to 0 in destructor of KateMwModOnHdDialog (jowenn!!!)
 
1047
        m_modignore = false;
 
1048
    } else {
 
1049
        s_modOnHdDialog->addDocument(doc);
 
1050
    }
 
1051
}
 
1052
 
 
1053
bool KateMainWindow::event(QEvent *e)
 
1054
{
 
1055
    if (e->type() == QEvent::ShortcutOverride) {
 
1056
        QKeyEvent *k = static_cast<QKeyEvent *>(e);
 
1057
        emit unhandledShortcutOverride(k);
 
1058
    }
 
1059
    return KateMDI::MainWindow::event(e);
 
1060
}
 
1061
 
 
1062
QObject *KateMainWindow::pluginView(const QString &name)
 
1063
{
 
1064
    KTextEditor::Plugin *plugin = KateApp::self()->pluginManager()->plugin(name);
 
1065
    if (!plugin) {
 
1066
        return 0;
 
1067
    }
 
1068
 
 
1069
    return m_pluginViews.contains(plugin) ? m_pluginViews.value(plugin) : 0;
 
1070
}
 
1071
 
 
1072
void KateMainWindow::slotFocusPrevTab()
 
1073
{
 
1074
    if (m_viewManager->activeViewSpace()) {
 
1075
        m_viewManager->activeViewSpace()->focusPrevTab();
 
1076
    }
 
1077
}
 
1078
 
 
1079
void KateMainWindow::slotFocusNextTab()
 
1080
{
 
1081
    if (m_viewManager->activeViewSpace()) {
 
1082
        m_viewManager->activeViewSpace()->focusNextTab();
 
1083
    }
 
1084
}
 
1085
 
 
1086
void KateMainWindow::slotQuickOpen()
 
1087
{
 
1088
    /**
 
1089
     * show quick open and pass focus to it
 
1090
     */
 
1091
    m_quickOpen->update();
 
1092
    m_mainStackedWidget->setCurrentWidget(m_quickOpen);
 
1093
    centralWidget()->setFocusProxy(m_quickOpen);
 
1094
    m_quickOpen->setFocus();
 
1095
}
 
1096
 
 
1097
QWidget *KateMainWindow::createToolView(KTextEditor::Plugin *plugin, const QString &identifier, KTextEditor::MainWindow::ToolViewPosition pos, const QIcon &icon, const QString &text)
 
1098
{
 
1099
    // FIXME KF5
 
1100
    return KateMDI::MainWindow::createToolView(plugin, identifier, (KMultiTabBar::KMultiTabBarPosition)(pos), icon.pixmap(QSize(16, 16)), text);
 
1101
}
 
1102
 
 
1103
bool KateMainWindow::moveToolView(QWidget *widget, KTextEditor::MainWindow::ToolViewPosition pos)
 
1104
{
 
1105
    if (!qobject_cast<KateMDI::ToolView *>(widget)) {
 
1106
        return false;
 
1107
    }
 
1108
 
 
1109
    // FIXME KF5
 
1110
    return KateMDI::MainWindow::moveToolView(qobject_cast<KateMDI::ToolView *>(widget), (KMultiTabBar::KMultiTabBarPosition)(pos));
 
1111
}
 
1112
 
 
1113
bool KateMainWindow::showToolView(QWidget *widget)
 
1114
{
 
1115
    if (!qobject_cast<KateMDI::ToolView *>(widget)) {
 
1116
        return false;
 
1117
    }
 
1118
 
 
1119
    return KateMDI::MainWindow::showToolView(qobject_cast<KateMDI::ToolView *>(widget));
 
1120
}
 
1121
 
 
1122
bool KateMainWindow::hideToolView(QWidget *widget)
 
1123
{
 
1124
    if (!qobject_cast<KateMDI::ToolView *>(widget)) {
 
1125
        return false;
 
1126
    }
 
1127
 
 
1128
    return KateMDI::MainWindow::hideToolView(qobject_cast<KateMDI::ToolView *>(widget));
 
1129
}
 
1130