Changeset View
Changeset View
Standalone View
Standalone View
src/cantor_part.cpp
Show All 35 Lines | |||||
36 | #include <KZip> | 36 | #include <KZip> | ||
37 | #include <KToggleAction> | 37 | #include <KToggleAction> | ||
38 | #include <KService> | 38 | #include <KService> | ||
39 | #include <KServiceTypeTrader> | 39 | #include <KServiceTypeTrader> | ||
40 | #include <KRun> | 40 | #include <KRun> | ||
41 | #include <QProgressDialog> | 41 | #include <QProgressDialog> | ||
42 | #include <KMessageBox> | 42 | #include <KMessageBox> | ||
43 | #include <KNS3/UploadDialog> | 43 | #include <KNS3/UploadDialog> | ||
44 | #include <KXMLGUIFactory> | ||||
44 | 45 | | |||
45 | #include <QElapsedTimer> | 46 | #include <QElapsedTimer> | ||
46 | #include <QFile> | 47 | #include <QFile> | ||
47 | #include <QTextStream> | 48 | #include <QTextStream> | ||
48 | #include <QTextEdit> | 49 | #include <QTextEdit> | ||
49 | #include <QTimer> | 50 | #include <QTimer> | ||
50 | #include <QPrinter> | 51 | #include <QPrinter> | ||
51 | #include <QPrintPreviewDialog> | 52 | #include <QPrintPreviewDialog> | ||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | 119 | { | |||
137 | Cantor::Backend* b=Cantor::Backend::getBackend(backendName); | 138 | Cantor::Backend* b=Cantor::Backend::getBackend(backendName); | ||
138 | if(!b) | 139 | if(!b) | ||
139 | { | 140 | { | ||
140 | KMessageBox::error(parentWidget, i18n("Backend %1 is not installed", backendName), i18n("Error - Cantor")); | 141 | KMessageBox::error(parentWidget, i18n("Backend %1 is not installed", backendName), i18n("Error - Cantor")); | ||
141 | setWidget(new QWidget(parentWidget)); | 142 | setWidget(new QWidget(parentWidget)); | ||
142 | return; | 143 | return; | ||
143 | } | 144 | } | ||
144 | 145 | | |||
146 | if (b && !b->isEnabled() && backendName != QLatin1String("null")) | ||||
147 | { | ||||
148 | KMessageBox::information(parentWidget, i18n("There are some problems with the %1 backend,\n"\ | ||||
149 | "please check your configuration or install the needed packages.\n" | ||||
150 | "You will only be able to view this worksheet.", backendName), i18n("Cantor")); | ||||
151 | setWidget(new QWidget(parentWidget)); | ||||
152 | return; | ||||
153 | } | ||||
154 | | ||||
145 | qDebug()<<"Backend "<<b->name()<<" offers extensions: "<<b->extensions(); | 155 | qDebug()<<"Backend "<<b->name()<<" offers extensions: "<<b->extensions(); | ||
146 | 156 | | |||
147 | 157 | | |||
148 | auto* collection = actionCollection(); | 158 | auto* collection = actionCollection(); | ||
149 | 159 | | |||
150 | //central widget | 160 | //central widget | ||
151 | QWidget* widget = new QWidget(parentWidget); | 161 | QWidget* widget = new QWidget(parentWidget); | ||
152 | QVBoxLayout* layout = new QVBoxLayout(widget); | 162 | QVBoxLayout* layout = new QVBoxLayout(widget); | ||
Show All 21 Lines | |||||
174 | QAction* savePlain = new QAction(i18n("Save Plain Text"), collection); | 184 | QAction* savePlain = new QAction(i18n("Save Plain Text"), collection); | ||
175 | collection->addAction(QLatin1String("file_save_plain"), savePlain); | 185 | collection->addAction(QLatin1String("file_save_plain"), savePlain); | ||
176 | savePlain->setIcon(QIcon::fromTheme(QLatin1String("document-save"))); | 186 | savePlain->setIcon(QIcon::fromTheme(QLatin1String("document-save"))); | ||
177 | connect(savePlain, SIGNAL(triggered()), this, SLOT(fileSavePlain())); | 187 | connect(savePlain, SIGNAL(triggered()), this, SLOT(fileSavePlain())); | ||
178 | 188 | | |||
179 | QAction* undo = KStandardAction::undo(m_worksheet, SIGNAL(undo()), collection); | 189 | QAction* undo = KStandardAction::undo(m_worksheet, SIGNAL(undo()), collection); | ||
180 | undo->setPriority(QAction::LowPriority); | 190 | undo->setPriority(QAction::LowPriority); | ||
181 | connect(m_worksheet, SIGNAL(undoAvailable(bool)), undo, SLOT(setEnabled(bool))); | 191 | connect(m_worksheet, SIGNAL(undoAvailable(bool)), undo, SLOT(setEnabled(bool))); | ||
192 | m_editActions.push_back(undo); | ||||
182 | 193 | | |||
183 | QAction* redo = KStandardAction::redo(m_worksheet, SIGNAL(redo()), collection); | 194 | QAction* redo = KStandardAction::redo(m_worksheet, SIGNAL(redo()), collection); | ||
184 | redo->setPriority(QAction::LowPriority); | 195 | redo->setPriority(QAction::LowPriority); | ||
185 | connect(m_worksheet, SIGNAL(redoAvailable(bool)), redo, SLOT(setEnabled(bool))); | 196 | connect(m_worksheet, SIGNAL(redoAvailable(bool)), redo, SLOT(setEnabled(bool))); | ||
197 | m_editActions.push_back(redo); | ||||
186 | 198 | | |||
187 | QAction* cut = KStandardAction::cut(m_worksheet, SIGNAL(cut()), collection); | 199 | QAction* cut = KStandardAction::cut(m_worksheet, SIGNAL(cut()), collection); | ||
188 | cut->setPriority(QAction::LowPriority); | 200 | cut->setPriority(QAction::LowPriority); | ||
189 | connect(m_worksheet, SIGNAL(cutAvailable(bool)), cut, SLOT(setEnabled(bool))); | 201 | connect(m_worksheet, SIGNAL(cutAvailable(bool)), cut, SLOT(setEnabled(bool))); | ||
202 | m_editActions.push_back(cut); | ||||
190 | 203 | | |||
191 | QAction* copy = KStandardAction::copy(m_worksheet, SIGNAL(copy()), collection); | 204 | QAction* copy = KStandardAction::copy(m_worksheet, SIGNAL(copy()), collection); | ||
192 | copy->setPriority(QAction::LowPriority); | 205 | copy->setPriority(QAction::LowPriority); | ||
193 | connect(m_worksheet, SIGNAL(copyAvailable(bool)), copy, SLOT(setEnabled(bool))); | 206 | connect(m_worksheet, SIGNAL(copyAvailable(bool)), copy, SLOT(setEnabled(bool))); | ||
194 | 207 | | |||
195 | QAction* paste = KStandardAction::paste(m_worksheet, SLOT(paste()), collection); | 208 | QAction* paste = KStandardAction::paste(m_worksheet, SIGNAL(paste()), collection); | ||
196 | paste->setPriority(QAction::LowPriority); | 209 | paste->setPriority(QAction::LowPriority); | ||
197 | connect(m_worksheet, SIGNAL(pasteAvailable(bool)), paste, SLOT(setEnabled(bool))); | 210 | connect(m_worksheet, SIGNAL(pasteAvailable(bool)), paste, SLOT(setEnabled(bool))); | ||
211 | m_editActions.push_back(paste); | ||||
198 | 212 | | |||
199 | QAction* find = KStandardAction::find(this, SLOT(showSearchBar()), collection); | 213 | QAction* find = KStandardAction::find(this, SLOT(showSearchBar()), collection); | ||
200 | find->setPriority(QAction::LowPriority); | 214 | find->setPriority(QAction::LowPriority); | ||
201 | 215 | | |||
202 | QAction* replace = KStandardAction::replace(this, SLOT(showExtendedSearchBar()), collection); | 216 | QAction* replace = KStandardAction::replace(this, SLOT(showExtendedSearchBar()), collection); | ||
203 | replace->setPriority(QAction::LowPriority); | 217 | replace->setPriority(QAction::LowPriority); | ||
218 | m_editActions.push_back(replace); | ||||
204 | 219 | | |||
205 | m_findNext = KStandardAction::findNext(this, SLOT(findNext()), collection); | 220 | m_findNext = KStandardAction::findNext(this, SLOT(findNext()), collection); | ||
206 | m_findNext->setEnabled(false); | 221 | m_findNext->setEnabled(false); | ||
207 | 222 | | |||
208 | m_findPrev = KStandardAction::findPrev(this, SLOT(findPrev()), collection); | 223 | m_findPrev = KStandardAction::findPrev(this, SLOT(findPrev()), collection); | ||
209 | m_findPrev->setEnabled(false); | 224 | m_findPrev->setEnabled(false); | ||
210 | 225 | | |||
211 | QAction* latexExport = new QAction(i18n("Export to LaTeX"), collection); | 226 | QAction* latexExport = new QAction(i18n("Export to LaTeX"), collection); | ||
Show All 11 Lines | |||||
223 | KStandardAction::zoomOut(m_worksheetview, SLOT(zoomOut()), collection); | 238 | KStandardAction::zoomOut(m_worksheetview, SLOT(zoomOut()), collection); | ||
224 | KStandardAction::actualSize(m_worksheetview, SLOT(actualSize()), collection); | 239 | KStandardAction::actualSize(m_worksheetview, SLOT(actualSize()), collection); | ||
225 | 240 | | |||
226 | m_evaluate = new QAction(i18n("Evaluate Worksheet"), collection); | 241 | m_evaluate = new QAction(i18n("Evaluate Worksheet"), collection); | ||
227 | collection->addAction(QLatin1String("evaluate_worksheet"), m_evaluate); | 242 | collection->addAction(QLatin1String("evaluate_worksheet"), m_evaluate); | ||
228 | m_evaluate->setIcon(QIcon::fromTheme(QLatin1String("system-run"))); | 243 | m_evaluate->setIcon(QIcon::fromTheme(QLatin1String("system-run"))); | ||
229 | collection->setDefaultShortcut(m_evaluate, Qt::CTRL+Qt::Key_E); | 244 | collection->setDefaultShortcut(m_evaluate, Qt::CTRL+Qt::Key_E); | ||
230 | connect(m_evaluate, SIGNAL(triggered()), this, SLOT(evaluateOrInterrupt())); | 245 | connect(m_evaluate, SIGNAL(triggered()), this, SLOT(evaluateOrInterrupt())); | ||
246 | m_editActions.push_back(m_evaluate); | ||||
231 | 247 | | |||
232 | m_typeset = new KToggleAction(i18n("Typeset using LaTeX"), collection); | 248 | m_typeset = new KToggleAction(i18n("Typeset using LaTeX"), collection); | ||
233 | m_typeset->setChecked(Settings::self()->typesetDefault()); | 249 | m_typeset->setChecked(Settings::self()->typesetDefault()); | ||
234 | // Disable until login, because we use session command for this action | 250 | // Disable until login, because we use session command for this action | ||
235 | m_typeset->setEnabled(false); | 251 | m_typeset->setEnabled(false); | ||
236 | collection->addAction(QLatin1String("enable_typesetting"), m_typeset); | 252 | collection->addAction(QLatin1String("enable_typesetting"), m_typeset); | ||
237 | connect(m_typeset, SIGNAL(toggled(bool)), this, SLOT(enableTypesetting(bool))); | 253 | connect(m_typeset, SIGNAL(toggled(bool)), this, SLOT(enableTypesetting(bool))); | ||
238 | 254 | | |||
Show All 16 Lines | |||||
255 | m_animateWorksheet->setChecked(Settings::self()->animationDefault()); | 271 | m_animateWorksheet->setChecked(Settings::self()->animationDefault()); | ||
256 | collection->addAction(QLatin1String("enable_animations"), m_animateWorksheet); | 272 | collection->addAction(QLatin1String("enable_animations"), m_animateWorksheet); | ||
257 | connect(m_animateWorksheet, SIGNAL(toggled(bool)), m_worksheet, SLOT(enableAnimations(bool))); | 273 | connect(m_animateWorksheet, SIGNAL(toggled(bool)), m_worksheet, SLOT(enableAnimations(bool))); | ||
258 | 274 | | |||
259 | QAction* restart = new QAction(i18n("Restart Backend"), collection); | 275 | QAction* restart = new QAction(i18n("Restart Backend"), collection); | ||
260 | collection->addAction(QLatin1String("restart_backend"), restart); | 276 | collection->addAction(QLatin1String("restart_backend"), restart); | ||
261 | restart->setIcon(QIcon::fromTheme(QLatin1String("system-reboot"))); | 277 | restart->setIcon(QIcon::fromTheme(QLatin1String("system-reboot"))); | ||
262 | connect(restart, SIGNAL(triggered()), this, SLOT(restartBackend())); | 278 | connect(restart, SIGNAL(triggered()), this, SLOT(restartBackend())); | ||
279 | m_editActions.push_back(restart); | ||||
263 | 280 | | |||
264 | QAction* evaluateCurrent = new QAction(QIcon::fromTheme(QLatin1String("media-playback-start")), i18n("Evaluate Entry"), collection); | 281 | QAction* evaluateCurrent = new QAction(QIcon::fromTheme(QLatin1String("media-playback-start")), i18n("Evaluate Entry"), collection); | ||
265 | collection->addAction(QLatin1String("evaluate_current"), evaluateCurrent); | 282 | collection->addAction(QLatin1String("evaluate_current"), evaluateCurrent); | ||
266 | collection->setDefaultShortcut(evaluateCurrent, Qt::SHIFT + Qt::Key_Return); | 283 | collection->setDefaultShortcut(evaluateCurrent, Qt::SHIFT + Qt::Key_Return); | ||
267 | connect(evaluateCurrent, SIGNAL(triggered()), m_worksheet, SLOT(evaluateCurrentEntry())); | 284 | connect(evaluateCurrent, SIGNAL(triggered()), m_worksheet, SLOT(evaluateCurrentEntry())); | ||
285 | m_editActions.push_back(evaluateCurrent); | ||||
268 | 286 | | |||
269 | QAction* insertCommandEntry = new QAction(QIcon::fromTheme(QLatin1String("run-build")), i18n("Insert Command Entry"), collection); | 287 | QAction* insertCommandEntry = new QAction(QIcon::fromTheme(QLatin1String("run-build")), i18n("Insert Command Entry"), collection); | ||
270 | collection->addAction(QLatin1String("insert_command_entry"), insertCommandEntry); | 288 | collection->addAction(QLatin1String("insert_command_entry"), insertCommandEntry); | ||
271 | collection->setDefaultShortcut(insertCommandEntry, Qt::CTRL + Qt::Key_Return); | 289 | collection->setDefaultShortcut(insertCommandEntry, Qt::CTRL + Qt::Key_Return); | ||
272 | connect(insertCommandEntry, SIGNAL(triggered()), m_worksheet, SLOT(insertCommandEntry())); | 290 | connect(insertCommandEntry, SIGNAL(triggered()), m_worksheet, SLOT(insertCommandEntry())); | ||
291 | m_editActions.push_back(insertCommandEntry); | ||||
273 | 292 | | |||
274 | QAction* insertTextEntry = new QAction(QIcon::fromTheme(QLatin1String("draw-text")), i18n("Insert Text Entry"), collection); | 293 | QAction* insertTextEntry = new QAction(QIcon::fromTheme(QLatin1String("draw-text")), i18n("Insert Text Entry"), collection); | ||
275 | collection->addAction(QLatin1String("insert_text_entry"), insertTextEntry); | 294 | collection->addAction(QLatin1String("insert_text_entry"), insertTextEntry); | ||
276 | connect(insertTextEntry, SIGNAL(triggered()), m_worksheet, SLOT(insertTextEntry())); | 295 | connect(insertTextEntry, SIGNAL(triggered()), m_worksheet, SLOT(insertTextEntry())); | ||
296 | m_editActions.push_back(insertTextEntry); | ||||
277 | 297 | | |||
278 | #ifdef Discount_FOUND | 298 | #ifdef Discount_FOUND | ||
279 | QAction* insertMarkdownEntry = new QAction(QIcon::fromTheme(QLatin1String("text-x-markdown")), i18n("Insert Markdown Entry"), collection); | 299 | QAction* insertMarkdownEntry = new QAction(QIcon::fromTheme(QLatin1String("text-x-markdown")), i18n("Insert Markdown Entry"), collection); | ||
280 | collection->addAction(QLatin1String("insert_markdown_entry"), insertMarkdownEntry); | 300 | collection->addAction(QLatin1String("insert_markdown_entry"), insertMarkdownEntry); | ||
281 | connect(insertMarkdownEntry, SIGNAL(triggered()), m_worksheet, SLOT(insertMarkdownEntry())); | 301 | connect(insertMarkdownEntry, SIGNAL(triggered()), m_worksheet, SLOT(insertMarkdownEntry())); | ||
302 | m_editActions.push_back(insertMarkdownEntry); | ||||
282 | #endif | 303 | #endif | ||
283 | 304 | | |||
284 | #ifdef WITH_EPS | 305 | #ifdef WITH_EPS | ||
285 | QAction* insertLatexEntry = new QAction(QIcon::fromTheme(QLatin1String("text-x-tex")), i18n("Insert Latex Entry"), collection); | 306 | QAction* insertLatexEntry = new QAction(QIcon::fromTheme(QLatin1String("text-x-tex")), i18n("Insert Latex Entry"), collection); | ||
286 | collection->addAction(QLatin1String("insert_latex_entry"), insertLatexEntry); | 307 | collection->addAction(QLatin1String("insert_latex_entry"), insertLatexEntry); | ||
287 | connect(insertLatexEntry, SIGNAL(triggered()), m_worksheet, SLOT(insertLatexEntry())); | 308 | connect(insertLatexEntry, SIGNAL(triggered()), m_worksheet, SLOT(insertLatexEntry())); | ||
309 | m_editActions.push_back(insertLatexEntry); | ||||
288 | #endif | 310 | #endif | ||
289 | 311 | | |||
290 | QAction* insertPageBreakEntry = new QAction(QIcon::fromTheme(QLatin1String("go-next-view-page")), i18n("Insert Page Break"), collection); | 312 | QAction* insertPageBreakEntry = new QAction(QIcon::fromTheme(QLatin1String("go-next-view-page")), i18n("Insert Page Break"), collection); | ||
291 | collection->addAction(QLatin1String("insert_page_break_entry"), insertPageBreakEntry); | 313 | collection->addAction(QLatin1String("insert_page_break_entry"), insertPageBreakEntry); | ||
292 | connect(insertPageBreakEntry, SIGNAL(triggered()), m_worksheet, SLOT(insertPageBreakEntry())); | 314 | connect(insertPageBreakEntry, SIGNAL(triggered()), m_worksheet, SLOT(insertPageBreakEntry())); | ||
315 | m_editActions.push_back(insertPageBreakEntry); | ||||
293 | 316 | | |||
294 | QAction* insertImageEntry = new QAction(QIcon::fromTheme(QLatin1String("image-x-generic")), i18n("Insert Image"), collection); | 317 | QAction* insertImageEntry = new QAction(QIcon::fromTheme(QLatin1String("image-x-generic")), i18n("Insert Image"), collection); | ||
295 | collection->addAction(QLatin1String("insert_image_entry"), insertImageEntry); | 318 | collection->addAction(QLatin1String("insert_image_entry"), insertImageEntry); | ||
296 | connect(insertImageEntry, SIGNAL(triggered()), m_worksheet, SLOT(insertImageEntry())); | 319 | connect(insertImageEntry, SIGNAL(triggered()), m_worksheet, SLOT(insertImageEntry())); | ||
320 | m_editActions.push_back(insertImageEntry); | ||||
297 | 321 | | |||
298 | QAction* removeCurrent = new QAction(QIcon::fromTheme(QLatin1String("edit-delete")), i18n("Remove current Entry"), collection); | 322 | QAction* removeCurrent = new QAction(QIcon::fromTheme(QLatin1String("edit-delete")), i18n("Remove current Entry"), collection); | ||
299 | collection->addAction(QLatin1String("remove_current"), removeCurrent); | 323 | collection->addAction(QLatin1String("remove_current"), removeCurrent); | ||
300 | collection->setDefaultShortcut(removeCurrent, Qt::ShiftModifier + Qt::Key_Delete); | 324 | collection->setDefaultShortcut(removeCurrent, Qt::ShiftModifier + Qt::Key_Delete); | ||
301 | connect(removeCurrent, SIGNAL(triggered()), m_worksheet, SLOT(removeCurrentEntry())); | 325 | connect(removeCurrent, SIGNAL(triggered()), m_worksheet, SLOT(removeCurrentEntry())); | ||
326 | m_editActions.push_back(removeCurrent); | ||||
302 | 327 | | |||
303 | m_showBackendHelp = new QAction(i18n("Show %1 Help", b->name()) , collection); | 328 | m_showBackendHelp = new QAction(i18n("Show %1 Help", b->name()) , collection); | ||
304 | m_showBackendHelp->setIcon(QIcon::fromTheme(QLatin1String("help-contents"))); | 329 | m_showBackendHelp->setIcon(QIcon::fromTheme(QLatin1String("help-contents"))); | ||
305 | collection->addAction(QLatin1String("backend_help"), m_showBackendHelp); | 330 | collection->addAction(QLatin1String("backend_help"), m_showBackendHelp); | ||
306 | connect(m_showBackendHelp, SIGNAL(triggered()), this, SLOT(showBackendHelp())); | 331 | connect(m_showBackendHelp, SIGNAL(triggered()), this, SLOT(showBackendHelp())); | ||
307 | 332 | | |||
308 | // Disabled, because uploading to kde store from program don't work | 333 | // Disabled, because uploading to kde store from program don't work | ||
309 | // See https://phabricator.kde.org/T9980 for details | 334 | // See https://phabricator.kde.org/T9980 for details | ||
Show All 12 Lines | |||||
322 | showEditor->setEnabled(b->extensions().contains(QLatin1String("ScriptExtension"))); | 347 | showEditor->setEnabled(b->extensions().contains(QLatin1String("ScriptExtension"))); | ||
323 | 348 | | |||
324 | QAction* showCompletion = new QAction(i18n("Show Completion"), collection); | 349 | QAction* showCompletion = new QAction(i18n("Show Completion"), collection); | ||
325 | collection->addAction(QLatin1String("show_completion"), showCompletion); | 350 | collection->addAction(QLatin1String("show_completion"), showCompletion); | ||
326 | QList<QKeySequence> showCompletionShortcuts; | 351 | QList<QKeySequence> showCompletionShortcuts; | ||
327 | showCompletionShortcuts << Qt::Key_Tab << Qt::CTRL + Qt::Key_Space; | 352 | showCompletionShortcuts << Qt::Key_Tab << Qt::CTRL + Qt::Key_Space; | ||
328 | collection->setDefaultShortcuts(showCompletion, showCompletionShortcuts); | 353 | collection->setDefaultShortcuts(showCompletion, showCompletionShortcuts); | ||
329 | connect(showCompletion, SIGNAL(triggered()), m_worksheet, SLOT(showCompletion())); | 354 | connect(showCompletion, SIGNAL(triggered()), m_worksheet, SLOT(showCompletion())); | ||
355 | m_editActions.push_back(showCompletion); | ||||
330 | 356 | | |||
331 | // set our XML-UI resource file | 357 | // set our XML-UI resource file | ||
332 | setXMLFile(QLatin1String("cantor_part.rc")); | 358 | setXMLFile(QLatin1String("cantor_part.rc")); | ||
333 | 359 | | |||
334 | // we are read-write by default | 360 | // we are read-write by default | ||
335 | setReadWrite(true); | 361 | setReadWrite(true); | ||
336 | 362 | | |||
337 | // we are not modified since we haven't done anything yet | 363 | // we are not modified since we haven't done anything yet | ||
Show All 16 Lines | |||||
354 | void CantorPart::setReadWrite(bool rw) | 380 | void CantorPart::setReadWrite(bool rw) | ||
355 | { | 381 | { | ||
356 | // notify your internal widget of the read-write state | 382 | // notify your internal widget of the read-write state | ||
357 | m_worksheetview->setInteractive(rw); | 383 | m_worksheetview->setInteractive(rw); | ||
358 | 384 | | |||
359 | ReadWritePart::setReadWrite(rw); | 385 | ReadWritePart::setReadWrite(rw); | ||
360 | } | 386 | } | ||
361 | 387 | | |||
388 | void CantorPart::setReadOnly() | ||||
389 | { | ||||
390 | for (QAction* action : m_editActions) | ||||
391 | action->setEnabled(false); | ||||
392 | | ||||
393 | if (m_showBackendHelp) | ||||
394 | { | ||||
395 | m_showBackendHelp->setEnabled(false); | ||||
396 | m_showBackendHelp->setVisible(false); | ||||
asemke: are these disconnects really required? Will it be possible for worksheet to send these signals… | |||||
397 | } | ||||
398 | } | ||||
399 | | ||||
362 | void CantorPart::setModified(bool modified) | 400 | void CantorPart::setModified(bool modified) | ||
363 | { | 401 | { | ||
364 | // get a handle on our Save action and make sure it is valid | 402 | // get a handle on our Save action and make sure it is valid | ||
365 | if (!m_save) | 403 | if (!m_save) | ||
366 | return; | 404 | return; | ||
367 | 405 | | |||
368 | // if so, we either enable or disable it based on the current state | 406 | // if so, we either enable or disable it based on the current state | ||
369 | m_save->setEnabled(modified); | 407 | m_save->setEnabled(modified); | ||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | |||||
431 | } | 469 | } | ||
432 | 470 | | |||
433 | void CantorPart::fileSaveAs() | 471 | void CantorPart::fileSaveAs() | ||
434 | { | 472 | { | ||
435 | // this slot is called whenever the File->Save As menu is selected | 473 | // this slot is called whenever the File->Save As menu is selected | ||
436 | QString worksheetFilter = i18n("Cantor Worksheet (*.cws)"); | 474 | QString worksheetFilter = i18n("Cantor Worksheet (*.cws)"); | ||
437 | QString filter = worksheetFilter; | 475 | QString filter = worksheetFilter; | ||
438 | 476 | | |||
477 | if (!m_worksheet->isReadOnly()) | ||||
478 | { | ||||
439 | //if the backend supports scripts, also append their scriptFile endings to the filter | 479 | //if the backend supports scripts, also append their scriptFile endings to the filter | ||
440 | Cantor::Backend * const backend=m_worksheet->session()->backend(); | 480 | Cantor::Backend * const backend=m_worksheet->session()->backend(); | ||
441 | if (backend->extensions().contains(QLatin1String("ScriptExtension"))) | 481 | if (backend->extensions().contains(QLatin1String("ScriptExtension"))) | ||
442 | { | 482 | { | ||
443 | Cantor::ScriptExtension* e=dynamic_cast<Cantor::ScriptExtension*>(backend->extension(QLatin1String("ScriptExtension"))); | 483 | Cantor::ScriptExtension* e=dynamic_cast<Cantor::ScriptExtension*>(backend->extension(QLatin1String("ScriptExtension"))); | ||
444 | filter+=QLatin1String(";;")+e->scriptFileFilter(); | 484 | filter+=QLatin1String(";;")+e->scriptFileFilter(); | ||
445 | } | 485 | } | ||
486 | } | ||||
446 | 487 | | |||
447 | QString selectedFilter; | 488 | QString selectedFilter; | ||
448 | QString file_name = QFileDialog::getSaveFileName(widget(), i18n("Save as"), QString(), filter, &selectedFilter); | 489 | QString file_name = QFileDialog::getSaveFileName(widget(), i18n("Save as"), QString(), filter, &selectedFilter); | ||
449 | if (file_name.isEmpty()) | 490 | if (file_name.isEmpty()) | ||
450 | return; | 491 | return; | ||
451 | 492 | | |||
452 | //depending on user's selection, save as a worksheet or as a plain script file | 493 | //depending on user's selection, save as a worksheet or as a plain script file | ||
453 | if (selectedFilter == worksheetFilter) | 494 | if (selectedFilter == worksheetFilter) | ||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | |||||
573 | { | 614 | { | ||
574 | qDebug()<<"Error: "<<message; | 615 | qDebug()<<"Error: "<<message; | ||
575 | initialized(); | 616 | initialized(); | ||
576 | showImportantStatusMessage(i18n("Session Error: %1", message)); | 617 | showImportantStatusMessage(i18n("Session Error: %1", message)); | ||
577 | } | 618 | } | ||
578 | 619 | | |||
579 | void CantorPart::initialized() | 620 | void CantorPart::initialized() | ||
580 | { | 621 | { | ||
622 | if (!m_worksheet->isReadOnly()) | ||||
623 | { | ||||
581 | connect(m_worksheet->session(), SIGNAL(statusChanged(Cantor::Session::Status)), this, SLOT(worksheetStatusChanged(Cantor::Session::Status))); | 624 | connect(m_worksheet->session(), SIGNAL(statusChanged(Cantor::Session::Status)), this, SLOT(worksheetStatusChanged(Cantor::Session::Status))); | ||
582 | connect(m_worksheet->session(), SIGNAL(loginStarted()),this, SLOT(worksheetSessionLoginStarted())); | 625 | connect(m_worksheet->session(), SIGNAL(loginStarted()),this, SLOT(worksheetSessionLoginStarted())); | ||
583 | connect(m_worksheet->session(), SIGNAL(loginDone()),this, SLOT(worksheetSessionLoginDone())); | 626 | connect(m_worksheet->session(), SIGNAL(loginDone()),this, SLOT(worksheetSessionLoginDone())); | ||
584 | connect(m_worksheet->session(), SIGNAL(error(QString)), this, SLOT(showSessionError(QString))); | 627 | connect(m_worksheet->session(), SIGNAL(error(QString)), this, SLOT(showSessionError(QString))); | ||
585 | 628 | | |||
586 | loadAssistants(); | 629 | loadAssistants(); | ||
587 | m_panelHandler->setSession(m_worksheet->session()); | 630 | m_panelHandler->setSession(m_worksheet->session()); | ||
588 | adjustGuiToSession(); | 631 | adjustGuiToSession(); | ||
589 | 632 | | |||
590 | if (m_worksheet->isEmpty()) | 633 | if (m_worksheet->isEmpty()) | ||
591 | m_worksheet->appendCommandEntry(); | 634 | m_worksheet->appendCommandEntry(); | ||
635 | } | ||||
636 | else | ||||
637 | { | ||||
638 | setReadOnly(); | ||||
639 | // Clear assistants | ||||
640 | for (KXMLGUIClient* client: childClients()) | ||||
641 | { | ||||
642 | Cantor::Assistant* assistant = dynamic_cast<Cantor::Assistant*>(client); | ||||
643 | if (assistant) | ||||
644 | { | ||||
645 | factory()->removeClient(client); | ||||
646 | removeChildClient(client); | ||||
647 | assistant->deleteLater(); | ||||
648 | } | ||||
649 | } | ||||
650 | } | ||||
592 | 651 | | |||
593 | m_worksheetview->setEnabled(true); | 652 | m_worksheetview->setEnabled(true); | ||
594 | m_worksheetview->setFocus(); | 653 | m_worksheetview->setFocus(); | ||
595 | 654 | | |||
596 | setStatusMessage(i18n("Initialization complete")); | 655 | setStatusMessage(i18n("Initialization complete")); | ||
597 | updateCaption(); | 656 | updateCaption(); | ||
598 | } | 657 | } | ||
599 | 658 | | |||
Show All 33 Lines | |||||
633 | { | 692 | { | ||
634 | QString filename=url().fileName(); | 693 | QString filename=url().fileName(); | ||
635 | //strip away the extension | 694 | //strip away the extension | ||
636 | filename=filename.left(filename.lastIndexOf(QLatin1Char('.'))); | 695 | filename=filename.left(filename.lastIndexOf(QLatin1Char('.'))); | ||
637 | 696 | | |||
638 | if (filename.isEmpty()) | 697 | if (filename.isEmpty()) | ||
639 | filename=i18n("Unnamed"); | 698 | filename=i18n("Unnamed"); | ||
640 | 699 | | |||
700 | if (!m_worksheet->isReadOnly()) | ||||
641 | emit setCaption(filename, QIcon::fromTheme(m_worksheet->session()->backend()->icon())); | 701 | emit setCaption(filename, QIcon::fromTheme(m_worksheet->session()->backend()->icon())); | ||
702 | else | ||||
703 | emit setCaption(filename+QLatin1Char(' ')+i18n("[read-only]"), QIcon()); | ||||
642 | } | 704 | } | ||
643 | 705 | | |||
644 | void CantorPart::pluginsChanged() | 706 | void CantorPart::pluginsChanged() | ||
645 | { | 707 | { | ||
646 | for (auto* plugin : m_panelHandler->plugins()) | 708 | for (auto* plugin : m_panelHandler->plugins()) | ||
647 | connect(plugin, SIGNAL(requestRunCommand(QString)), this, SLOT(runCommand(QString))); | 709 | connect(plugin, SIGNAL(requestRunCommand(QString)), this, SLOT(runCommand(QString))); | ||
648 | } | 710 | } | ||
649 | 711 | | |||
▲ Show 20 Lines • Show All 259 Lines • Show Last 20 Lines |
are these disconnects really required? Will it be possible for worksheet to send these signals if it's read-only?