Changeset View
Changeset View
Standalone View
Standalone View
kwrite/kwrite.cpp
Context not available. | |||||
57 | #include <QFileDialog> | 57 | #include <QFileDialog> | ||
---|---|---|---|---|---|
58 | #include <QFileOpenEvent> | 58 | #include <QFileOpenEvent> | ||
59 | 59 | | |||
60 | QList<KTextEditor::Document *> KWrite::docList; | 60 | #include "kwriteapplication.h" | ||
61 | QList<KWrite *> KWrite::winList; | | |||
62 | 61 | | |||
63 | KWrite::KWrite(KTextEditor::Document *doc) | 62 | KWrite::KWrite(KTextEditor::Document *doc, KWriteApplication *app) | ||
64 | : m_view(nullptr) | 63 | : m_view(nullptr) | ||
65 | , m_recentFiles(nullptr) | 64 | , m_recentFiles(nullptr) | ||
66 | , m_paShowPath(nullptr) | 65 | , m_paShowPath(nullptr) | ||
67 | , m_paShowMenuBar(nullptr) | 66 | , m_paShowMenuBar(nullptr) | ||
68 | , m_paShowStatusBar(nullptr) | 67 | , m_paShowStatusBar(nullptr) | ||
69 | , m_activityResource(nullptr) | 68 | , m_activityResource(nullptr) | ||
69 | , m_app(app) | ||||
70 | { | 70 | { | ||
71 | if (!doc) { | 71 | if (!doc) { | ||
72 | doc = KTextEditor::Editor::instance()->createDocument(nullptr); | 72 | doc = KTextEditor::Editor::instance()->createDocument(nullptr); | ||
Context not available. | |||||
76 | qobject_cast<KTextEditor::ModificationInterface *>(doc)->setModifiedOnDiskWarning(true); | 76 | qobject_cast<KTextEditor::ModificationInterface *>(doc)->setModifiedOnDiskWarning(true); | ||
77 | } | 77 | } | ||
78 | 78 | | |||
79 | docList.append(doc); | 79 | m_app->addDocument(doc); | ||
80 | } | 80 | } | ||
81 | 81 | | |||
82 | m_application = new KTextEditor::Application(this); | | |||
83 | KTextEditor::Editor::instance()->setApplication(m_application); | | |||
84 | | ||||
85 | m_view = doc->createView(this); | 82 | m_view = doc->createView(this); | ||
86 | 83 | | |||
87 | setCentralWidget(m_view); | 84 | setCentralWidget(m_view); | ||
Context not available. | |||||
109 | 106 | | |||
110 | readConfig(); | 107 | readConfig(); | ||
111 | 108 | | |||
112 | winList.append(this); | | |||
113 | | ||||
114 | documentNameChanged(); | 109 | documentNameChanged(); | ||
115 | show(); | 110 | show(); | ||
116 | 111 | | |||
Context not available. | |||||
127 | { | 122 | { | ||
128 | guiFactory()->removeClient(m_view); | 123 | guiFactory()->removeClient(m_view); | ||
129 | 124 | | |||
130 | winList.removeAll(this); | | |||
131 | | ||||
132 | KTextEditor::Document *doc = m_view->document(); | 125 | KTextEditor::Document *doc = m_view->document(); | ||
133 | delete m_view; | 126 | delete m_view; | ||
134 | 127 | | |||
135 | // kill document, if last view is closed | 128 | // kill document, if last view is closed | ||
136 | if (doc->views().isEmpty()) { | 129 | if (doc->views().isEmpty()) { | ||
137 | docList.removeAll(doc); | 130 | m_app->removeDocument(doc); | ||
138 | delete doc; | 131 | delete doc; | ||
139 | } | 132 | } | ||
140 | 133 | | |||
Context not available. | |||||
247 | 240 | | |||
248 | void KWrite::slotNew() | 241 | void KWrite::slotNew() | ||
249 | { | 242 | { | ||
250 | new KWrite(); | 243 | m_app->newWindow(); | ||
251 | } | 244 | } | ||
252 | 245 | | |||
253 | void KWrite::slotOpen() | 246 | void KWrite::slotOpen() | ||
Context not available. | |||||
265 | } | 258 | } | ||
266 | 259 | | |||
267 | if (m_view->document()->isModified() || !m_view->document()->url().isEmpty()) { | 260 | if (m_view->document()->isModified() || !m_view->document()->url().isEmpty()) { | ||
268 | KWrite *t = new KWrite(); | 261 | KWrite *t = m_app->newWindow(); | ||
269 | t->loadURL(url); | 262 | t->loadURL(url); | ||
270 | } else { | 263 | } else { | ||
271 | loadURL(url); | 264 | loadURL(url); | ||
Context not available. | |||||
284 | 277 | | |||
285 | void KWrite::newView() | 278 | void KWrite::newView() | ||
286 | { | 279 | { | ||
287 | new KWrite(m_view->document()); | 280 | m_app->newWindow(m_view->document()); | ||
288 | } | 281 | } | ||
289 | 282 | | |||
290 | void KWrite::toggleMenuBar(bool showMessage) | 283 | void KWrite::toggleMenuBar(bool showMessage) | ||
Context not available. | |||||
440 | { | 433 | { | ||
441 | writeConfig(); | 434 | writeConfig(); | ||
442 | 435 | | |||
443 | config.writeEntry("DocumentNumber", docList.indexOf(m_view->document()) + 1); | 436 | config.writeEntry("DocumentNumber", m_app->documents().indexOf(m_view->document()) + 1); | ||
444 | 437 | | |||
445 | KConfigGroup cg(&config, QStringLiteral("General Options")); | 438 | KConfigGroup cg(&config, QStringLiteral("General Options")); | ||
446 | m_view->writeSessionConfig(cg); | 439 | m_view->writeSessionConfig(cg); | ||
Context not available. | |||||
448 | 441 | | |||
449 | void KWrite::saveGlobalProperties(KConfig *config) //save documents | 442 | void KWrite::saveGlobalProperties(KConfig *config) //save documents | ||
450 | { | 443 | { | ||
451 | config->group("Number").writeEntry("NumberOfDocuments", docList.count()); | 444 | config->group("Number").writeEntry("NumberOfDocuments", m_app->documents().count()); | ||
452 | 445 | | |||
453 | for (int z = 1; z <= docList.count(); z++) { | 446 | for (int z = 1; z <= m_app->documents().count(); z++) { | ||
454 | QString buf = QStringLiteral("Document %1").arg(z); | 447 | QString buf = QStringLiteral("Document %1").arg(z); | ||
455 | KConfigGroup cg(config, buf); | 448 | KConfigGroup cg(config, buf); | ||
456 | KTextEditor::Document *doc = docList.at(z - 1); | 449 | KTextEditor::Document *doc = m_app->documents().at(z - 1); | ||
457 | doc->writeSessionConfig(cg); | 450 | doc->writeSessionConfig(cg); | ||
458 | } | 451 | } | ||
459 | 452 | | |||
460 | for (int z = 1; z <= winList.count(); z++) { | 453 | for (int z = 1; z <= m_app->windows().count(); z++) { | ||
461 | QString buf = QStringLiteral("Window %1").arg(z); | 454 | QString buf = QStringLiteral("Window %1").arg(z); | ||
462 | KConfigGroup cg(config, buf); | 455 | KConfigGroup cg(config, buf); | ||
463 | cg.writeEntry("DocumentNumber", docList.indexOf(winList.at(z - 1)->view()->document()) + 1); | 456 | cg.writeEntry("DocumentNumber", m_app->documents().indexOf(m_app->windows().at(z - 1)->view()->document()) + 1); | ||
464 | } | | |||
465 | } | | |||
466 | | ||||
467 | //restore session | | |||
468 | void KWrite::restore() | | |||
469 | { | | |||
470 | KConfig *config = KConfigGui::sessionConfig(); | | |||
471 | | ||||
472 | if (!config) { | | |||
473 | return; | | |||
474 | } | | |||
475 | | ||||
476 | int docs, windows; | | |||
477 | QString buf; | | |||
478 | KTextEditor::Document *doc; | | |||
479 | KWrite *t; | | |||
480 | | ||||
481 | KConfigGroup numberConfig(config, "Number"); | | |||
482 | docs = numberConfig.readEntry("NumberOfDocuments", 0); | | |||
483 | windows = numberConfig.readEntry("NumberOfWindows", 0); | | |||
484 | | ||||
485 | for (int z = 1; z <= docs; z++) { | | |||
486 | buf = QStringLiteral("Document %1").arg(z); | | |||
487 | KConfigGroup cg(config, buf); | | |||
488 | doc = KTextEditor::Editor::instance()->createDocument(nullptr); | | |||
489 | doc->readSessionConfig(cg); | | |||
490 | docList.append(doc); | | |||
491 | } | | |||
492 | | ||||
493 | for (int z = 1; z <= windows; z++) { | | |||
494 | buf = QStringLiteral("Window %1").arg(z); | | |||
495 | KConfigGroup cg(config, buf); | | |||
496 | t = new KWrite(docList.at(cg.readEntry("DocumentNumber", 0) - 1)); | | |||
497 | t->restore(config, z); | | |||
498 | } | 457 | } | ||
499 | } | 458 | } | ||
500 | 459 | | |||
Context not available. | |||||
562 | */ | 521 | */ | ||
563 | return KParts::MainWindow::eventFilter(obj, event); | 522 | return KParts::MainWindow::eventFilter(obj, event); | ||
564 | } | 523 | } | ||
565 | | ||||
566 | bool KWrite::quit() | | |||
567 | { | | |||
568 | return close(); | | |||
569 | } | | |||
Context not available. |