Thread: [Ktutorial-commits] SF.net SVN: ktutorial:[131] trunk/ktutorial/ktutorial-editor/src
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2010-03-09 08:05:31
|
Revision: 131 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=131&view=rev Author: danxuliu Date: 2010-03-09 08:05:23 +0000 (Tue, 09 Mar 2010) Log Message: ----------- -Add actions to set the tutorial information, the step data, add steps and remove steps. -Enable or disable some actions based on the selected step. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-09 05:25:28 UTC (rev 130) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-09 08:05:23 UTC (rev 131) @@ -23,24 +23,129 @@ #include <KAction> #include <KActionCollection> #include <KApplication> +#include <KLocalizedString> +#include "Step.h" +#include "Tutorial.h" +#include "view/EditionDialog.h" +#include "view/StepDataWidget.h" +#include "view/TreeModel.h" +#include "view/TutorialInformationWidget.h" +#include "view/TutorialTreeItem.h" +#include "view/TutorialTreeSelectionManager.h" + //public: KTutorialEditor::KTutorialEditor(): KXmlGuiWindow(0) { - QTreeView* treeView = new QTreeView(); - treeView->setObjectName("centralTreeView"); - treeView->setHeaderHidden(true); + mTreeView = new QTreeView(); + mTreeView->setObjectName("centralTreeView"); + setCentralWidget(mTreeView); - setCentralWidget(treeView); + setupTutorialToBeEdited(); setupActions(); - //Don't use a status bar (which is setupGUI default behavior) - setupGUI(ToolBar | Keys | Save | Create); + setupGUI(); } //private: +void KTutorialEditor::setupTutorialToBeEdited() { + mTutorial = new Tutorial(this); + + TutorialTreeItem* tutorialTreeItem = new TutorialTreeItem(mTutorial); + TreeModel* model = new TreeModel(tutorialTreeItem, mTreeView); + + QAbstractItemModel* oldModel = mTreeView->model(); + mTreeView->setModel(model); + delete oldModel; + + TutorialTreeSelectionManager* selectionManager = + new TutorialTreeSelectionManager(mTreeView->selectionModel(), this); + connect(selectionManager, SIGNAL(stepSelected(Step*)), + this, SLOT(selectStep(Step*))); +} + void KTutorialEditor::setupActions() { KStandardAction::quit(kapp, SLOT(quit()), actionCollection()); + + KAction* action = new KAction(this); + action->setText(i18nc("@action", "Set information...")); + action->setStatusTip(i18nc("@info:status", "Set the name and description " +"of the tutorial.")); + actionCollection()->addAction("setTutorialInformation", action); + connect(action, SIGNAL(triggered(bool)), + this, SLOT(setTutorialInformation())); + + action = new KAction(this); + action->setText(i18nc("@action", "Add step...")); + action->setStatusTip(i18nc("@info:status", "Add a new step to the " +"tutorial.")); + actionCollection()->addAction("addStep", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(addStep())); + + action = new KAction(this); + action->setText(i18nc("@action", "Set data...")); + action->setStatusTip(i18nc("@info:status", "Set the name and text of the " +"currently selected step.")); + action->setEnabled(false); + actionCollection()->addAction("setStepData", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(setStepData())); + + action = new KAction(this); + action->setText(i18nc("@action", "Remove step")); + action->setStatusTip(i18nc("@info:status", "Removes the currently selected " +"step from the tutorial.")); + action->setEnabled(false); + actionCollection()->addAction("removeStep", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(removeStep())); } + +void KTutorialEditor::showEditionDialog(EditionWidget* editionWidget) { + EditionDialog* dialog = new EditionDialog(editionWidget, this); + dialog->setObjectName("editionDialog"); + dialog->exec(); + dialog->deleteLater(); +} + +//private slots: + +void KTutorialEditor::selectStep(Step* step) { + mCurrentStep = step; + + if (mCurrentStep) { + actionCollection()->action("setStepData")->setEnabled(true); + actionCollection()->action("removeStep")->setEnabled(true); + } else { + actionCollection()->action("setStepData")->setEnabled(false); + actionCollection()->action("removeStep")->setEnabled(false); + } +} + +void KTutorialEditor::setTutorialInformation() { + showEditionDialog(new TutorialInformationWidget(mTutorial)); +} + +void KTutorialEditor::addStep() { + Step* step = new Step(); + mTutorial->addStep(step); + + showEditionDialog(new StepDataWidget(step)); +} + +void KTutorialEditor::setStepData() { + Q_ASSERT(mCurrentStep); + + showEditionDialog(new StepDataWidget(mCurrentStep)); +} + +void KTutorialEditor::removeStep() { + Q_ASSERT(mCurrentStep); + + //When the step is removed, mCurrentStep is changed because the selected + //item in the tree view changes. As mCurrentStep is one of the valid steps + //in the tutorial, deleting it leads to a crash the next time it is used. + Step* stepToRemove = mCurrentStep; + mTutorial->removeStep(stepToRemove); + stepToRemove->deleteLater(); +} Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-09 05:25:28 UTC (rev 130) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-09 08:05:23 UTC (rev 131) @@ -21,6 +21,11 @@ #include <KXmlGuiWindow> +class EditionWidget; +class QTreeView; +class Step; +class Tutorial; + /** * KTutorial editor main window. * It wires up all the components in the application. @@ -37,10 +42,69 @@ private: /** + * The main tree view that shows the tutorial. + */ + QTreeView* mTreeView; + + /** + * The tutorial being edited. + */ + Tutorial* mTutorial; + + /** + * The currently selected step. + */ + Step* mCurrentStep; + + /** + * Sets up the tutorial to be edited. + * It creates a new tutorial, prepares the tree view to represent it and + * handles the selection of items. + */ + void setupTutorialToBeEdited(); + + /** * Sets up all the actions used in the application. */ void setupActions(); + /** + * Shows an EditionDialog for the given EditionWidget. + * + * @param editionWidget The EditionWidget to wrap. + */ + void showEditionDialog(EditionWidget* editionWidget); + +private Q_SLOTS: + + /** + * Sets the current step and enables or disables the actions that depend on + * a step as needed. + * + * @param step The step to select, or null to deselect the current one. + */ + void selectStep(Step* step); + + /** + * Shows a TutorialInformationWidget for the tutorial. + */ + void setTutorialInformation(); + + /** + * Adds a new step to the tutorial and shows a StepDataWidget for it. + */ + void addStep(); + + /** + * Shows a StepDataWidget for the current step. + */ + void setStepData(); + + /** + * Removes the current step from the tutorial. + */ + void removeStep(); + }; #endif Modified: trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc =================================================================== --- trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-03-09 05:25:28 UTC (rev 130) +++ trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-03-09 08:05:23 UTC (rev 131) @@ -1,4 +1,18 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> <gui name="ktutorial-editor" version="1"> + <MenuBar> + <Menu name="edit"> + <Menu name="editTutorials"> + <Text>Tutorial</Text> + <Action name="setTutorialInformation"/> + </Menu> + <Menu name="editSteps"> + <Text>Step</Text> + <Action name="addStep"/> + <Action name="setStepData"/> + <Action name="removeStep"/> + </Menu> + </Menu> + </MenuBar> </gui> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-09 20:38:54
|
Revision: 139 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=139&view=rev Author: danxuliu Date: 2010-03-09 20:38:48 +0000 (Tue, 09 Mar 2010) Log Message: ----------- Fix Krazy2 i18n argument issues. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc trunk/ktutorial/ktutorial-editor/src/main.cpp trunk/ktutorial/ktutorial-editor/src/view/StepCustomCodeWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp trunk/ktutorial/ktutorial-editor/src/view/TutorialCustomCodeWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.ui trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp Modified: trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc =================================================================== --- trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-03-09 20:07:44 UTC (rev 138) +++ trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-03-09 20:38:48 UTC (rev 139) @@ -4,14 +4,14 @@ <MenuBar> <Menu name="edit"> <Menu name="editTutorials"> - <Text context="@item:inmenu">Tutorial</Text> + <Text context="@title:menu">Tutorial</Text> <Action name="setTutorialInformation"/> <Action name="setTutorialLicense"/> <Action name="setTutorialSetup"/> <Action name="setTutorialTearDown"/> </Menu> <Menu name="editSteps"> - <Text context="@item:inmenu">Step</Text> + <Text context="@title:menu Noun, a step in a tutorial">Step</Text> <Action name="addStep"/> <Action name="setStepData"/> <Action name="setStepSetup"/> Modified: trunk/ktutorial/ktutorial-editor/src/main.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/main.cpp 2010-03-09 20:07:44 UTC (rev 138) +++ trunk/ktutorial/ktutorial-editor/src/main.cpp 2010-03-09 20:38:48 UTC (rev 139) @@ -26,8 +26,8 @@ KAboutData aboutData("ktutorial-editor", 0, ki18nc("@title", "KTutorial editor"), "0.1", - ki18nc("@info", "An editor to create tutorials for " - "<application>KTutorial</application>."), + ki18nc("@title", "An editor to create tutorials for " + "<application>KTutorial</application>."), KAboutData::License_GPL_V3, ki18nc("@info:credit", "Copyright (c) 2010 Daniel Calviño Sánchez")); aboutData.addAuthor(ki18nc("@info:credit", "Daniel Calviño Sánchez"), Modified: trunk/ktutorial/ktutorial-editor/src/view/StepCustomCodeWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/StepCustomCodeWidget.cpp 2010-03-09 20:07:44 UTC (rev 138) +++ trunk/ktutorial/ktutorial-editor/src/view/StepCustomCodeWidget.cpp 2010-03-09 20:38:48 UTC (rev 139) @@ -36,7 +36,7 @@ if (type == Setup) { ui->customCodeTextEdit->setText(step->customSetupCode()); - ui->customCodeGroupBox->setTitle(i18nc("@ŧitle", "Step setup code")); + ui->customCodeGroupBox->setTitle(i18nc("@title", "Step setup code")); setWindowTitle(i18nc("@title", "Set the step setup code")); setWhatsThis(i18nc("@info:whatsthis", "<para>Set the code to be " "executed when the tutorials passes to the step.</para>" @@ -46,7 +46,7 @@ "exported to.</para>")); } else { ui->customCodeTextEdit->setText(step->customTearDownCode()); - ui->customCodeGroupBox->setTitle(i18nc("@ŧitle", + ui->customCodeGroupBox->setTitle(i18nc("@title", "Step tear down code")); setWindowTitle(i18nc("@title", "Set the step tear down code")); setWhatsThis(i18nc("@info:whatsthis", "<para>Set the code to be " Modified: trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp 2010-03-09 20:07:44 UTC (rev 138) +++ trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp 2010-03-09 20:38:48 UTC (rev 139) @@ -42,10 +42,10 @@ QString StepTreeItem::text() const { if (mStepId.isEmpty()) { - return i18nc("@item", "Step"); + return i18nc("@item Noun, a step in a tutorial", "Step"); } - return i18nc("@item", "Step %1", mStepId); + return i18nc("@item Noun, a step in a tutorial", "Step %1", mStepId); } Step* StepTreeItem::step() const { Modified: trunk/ktutorial/ktutorial-editor/src/view/TutorialCustomCodeWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TutorialCustomCodeWidget.cpp 2010-03-09 20:07:44 UTC (rev 138) +++ trunk/ktutorial/ktutorial-editor/src/view/TutorialCustomCodeWidget.cpp 2010-03-09 20:38:48 UTC (rev 139) @@ -36,7 +36,7 @@ if (type == Setup) { ui->customCodeTextEdit->setText(tutorial->customSetupCode()); - ui->customCodeGroupBox->setTitle(i18nc("@ŧitle", + ui->customCodeGroupBox->setTitle(i18nc("@title", "Tutorial setup code")); setWindowTitle(i18nc("@title", "Set the tutorial setup code")); setWhatsThis(i18nc("@info:whatsthis", "<para>Set the code to be " @@ -47,7 +47,7 @@ "exported to.</para>")); } else { ui->customCodeTextEdit->setText(tutorial->customTearDownCode()); - ui->customCodeGroupBox->setTitle(i18nc("@ŧitle", + ui->customCodeGroupBox->setTitle(i18nc("@title", "Tutorial tear down code")); setWindowTitle(i18nc("@title", "Set the tutorial tear down code")); setWhatsThis(i18nc("@info:whatsthis", "<para>Set the code to be " Modified: trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.ui =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.ui 2010-03-09 20:07:44 UTC (rev 138) +++ trunk/ktutorial/ktutorial-editor/src/view/TutorialInformationWidget.ui 2010-03-09 20:38:48 UTC (rev 139) @@ -29,7 +29,7 @@ <item> <widget class="QLabel" name="nameLabel"> <property name="text"> - <string comment="@label:textbox">Name:</string> + <string comment="@label:textbox Noun, the name of a tutorial">Name:</string> </property> <property name="buddy"> <cstring>nameLineEdit</cstring> Modified: trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp 2010-03-09 20:07:44 UTC (rev 138) +++ trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp 2010-03-09 20:38:48 UTC (rev 139) @@ -84,7 +84,8 @@ } } else { TreeItemUtil::addFlatItemIfNeeded(this, mNameItem, childIndex); - mNameItem->setText(i18nc("@item", "Name: %1", tutorial->name())); + mNameItem->setText(i18nc("@item Noun, the name of a tutorial", + "Name: %1", tutorial->name())); mTutorialId = tutorial->id(); emit dataChanged(this); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-19 18:16:01
|
Revision: 167 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=167&view=rev Author: danxuliu Date: 2010-03-19 18:15:55 +0000 (Fri, 19 Mar 2010) Log Message: ----------- Add action to export a tutorial from the File menu. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc Modified: trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-19 18:14:11 UTC (rev 166) +++ trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-19 18:15:55 UTC (rev 167) @@ -25,10 +25,10 @@ # As everything but a tiny initialization code is in a library, the build system # for the tests can be easily set up. kde4_add_library(ktutorial_editor ${ktutorial_editor_SRCS}) -target_link_libraries(ktutorial_editor ktutorial_editor_serialization ktutorial_editor_view) +target_link_libraries(ktutorial_editor ktutorial_editor_serialization ktutorial_editor_view ${KDE4_KIO_LIBS}) kde4_add_executable(ktutorial-editor main.cpp) -target_link_libraries(ktutorial-editor ktutorial_editor ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS}) +target_link_libraries(ktutorial-editor ktutorial_editor) ####### Install the editor ####### Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-19 18:14:11 UTC (rev 166) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-19 18:15:55 UTC (rev 167) @@ -24,11 +24,16 @@ #include <KAction> #include <KActionCollection> #include <KApplication> +#include <KFileDialog> +#include <KFileFilterCombo> #include <KLocalizedString> +#include <KMessageBox> +#include <KIO/NetAccess> #include "Reaction.h" #include "Step.h" #include "Tutorial.h" +#include "serialization/Serialization.h" #include "view/ActionListWidget.h" #include "view/EditionDialog.h" #include "view/LicenseWidget.h" @@ -94,12 +99,20 @@ } void KTutorialEditor::setupActions() { + KAction* action = new KAction(this); + action->setText(i18nc("@action", "Export...")); + action->setStatusTip(i18nc("@info:status", "Exports the tutorial to a " +"script.")); + action->setIcon(KIcon("document-export")); + actionCollection()->addAction("exportTutorial", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(exportTutorial())); + KStandardAction::quit(kapp, SLOT(quit()), actionCollection()); ActionListWidget* actionListWidget = new ActionListWidget(mTutorialActionDock); - KAction* action = new KAction(this); + action = new KAction(this); action->setText(i18nc("@action", "Set information...")); action->setStatusTip(i18nc("@info:status", "Set the name and description " "of the tutorial.")); @@ -271,6 +284,32 @@ } } +void KTutorialEditor::exportTutorial() { + KUrl url; + QPointer<KFileDialog> dialog = new KFileDialog(url, QString(), this); + + dialog->setSelection(mTutorial->id()); + dialog->setCaption(i18nc("@title", "Export Tutorial")); + dialog->setOperationMode(KFileDialog::Saving); + dialog->setConfirmOverwrite(true); + dialog->setFilter(Serialization::availableExporterTypes()); + dialog->filterWidget()->setEditable(false); + + if (dialog->exec() == QDialog::Rejected) { + return; + } + + if (!Serialization::exportTutorial(mTutorial, dialog->currentFilter(), + dialog->selectedUrl())) { + QString text = i18nc("@label", "There was a problem when trying to " +"save the exported tutorial:<nl/>%1", KIO::NetAccess::lastErrorString()); + QString caption = i18nc("@title:window", "Exported tutorial could not " +"be saved"); + KMessageBox::error(this, text, caption); + return; + } +} + void KTutorialEditor::setTutorialInformation() { showEditionDialog(new TutorialInformationWidget(mTutorial)); } Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-19 18:14:11 UTC (rev 166) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-19 18:15:55 UTC (rev 167) @@ -121,6 +121,12 @@ void selectReaction(Reaction* reaction); /** + * Shows a KFileDialog to select the file to save the exported tutorial in. + * An error message is shown if the tutorial couldn't be saved. + */ + void exportTutorial(); + + /** * Shows a TutorialInformationWidget for the tutorial. */ void setTutorialInformation(); Modified: trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc =================================================================== --- trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-03-19 18:14:11 UTC (rev 166) +++ trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-03-19 18:15:55 UTC (rev 167) @@ -2,6 +2,9 @@ <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> <gui name="ktutorial-editor" version="1"> <MenuBar> + <Menu name="file"> + <Action name="exportTutorial"/> + </Menu> <Menu name="edit"> <Menu name="editTutorials"> <Text context="@title:menu">Tutorial</Text> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-19 18:37:39
|
Revision: 169 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=169&view=rev Author: danxuliu Date: 2010-03-19 18:37:33 +0000 (Fri, 19 Mar 2010) Log Message: ----------- Fix Krazy2 i18ncheckarg issues Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/serialization/Serialization.cpp trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.ui trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.ui Modified: trunk/ktutorial/ktutorial-editor/src/serialization/Serialization.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/serialization/Serialization.cpp 2010-03-19 18:31:07 UTC (rev 168) +++ trunk/ktutorial/ktutorial-editor/src/serialization/Serialization.cpp 2010-03-19 18:37:33 UTC (rev 169) @@ -65,7 +65,7 @@ QStringList Serialization::availableExporterTypeList() { QStringList types; - types << i18nc("@item:combobox A KFileDialog filter", + types << i18nc("@item:inlistbox A KFileDialog filter", "*.js|Javascript file"); return types; } Modified: trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.ui =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.ui 2010-03-19 18:31:07 UTC (rev 168) +++ trunk/ktutorial/ktutorial-editor/src/view/NewWaitForWidget.ui 2010-03-19 18:37:33 UTC (rev 169) @@ -26,7 +26,7 @@ <item> <widget class="QLabel" name="waitForTypeLabel"> <property name="text"> - <string>Type:</string> + <string comment="@label:listbox">Type:</string> </property> <property name="buddy"> <cstring>waitForTypeComboBox</cstring> Modified: trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.ui =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.ui 2010-03-19 18:31:07 UTC (rev 168) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.ui 2010-03-19 18:37:33 UTC (rev 169) @@ -28,7 +28,7 @@ <item> <widget class="QLabel" name="emitterNameLabel"> <property name="text"> - <string>Emitter name:</string> + <string comment="@label:textbox">Emitter name:</string> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> @@ -41,7 +41,7 @@ <item> <widget class="QLabel" name="signalNameLabel"> <property name="text"> - <string>Signal name:</string> + <string comment="@label:textbox">Signal name:</string> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-19 18:46:36
|
Revision: 170 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=170&view=rev Author: danxuliu Date: 2010-03-19 18:46:23 +0000 (Fri, 19 Mar 2010) Log Message: ----------- Fix Krazy2 spelling issues Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.cpp trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.h trunk/ktutorial/ktutorial-editor/src/view/ReactionTreeItem.cpp Modified: trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.cpp 2010-03-19 18:37:33 UTC (rev 169) +++ trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.cpp 2010-03-19 18:46:23 UTC (rev 170) @@ -419,7 +419,7 @@ indentedCode += indentation() + lines[i] + '\n'; } - //If the code ends with '\n', the splitted code will contain an empty end + //If the code ends with '\n', the split code will contain an empty end //element that should be ignored if (!code.endsWith('\n')) { indentedCode += indentation() + lines[lines.count()-1] + '\n'; Modified: trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.h 2010-03-19 18:37:33 UTC (rev 169) +++ trunk/ktutorial/ktutorial-editor/src/serialization/JavascriptExporter.h 2010-03-19 18:46:23 UTC (rev 170) @@ -89,7 +89,7 @@ QHash<QString, int> mVariables; /** - * The curren indentation level. + * The current indentation level. * Increment and decrement it when entering and exiting a code block. */ int mIndentationLevel; @@ -237,7 +237,7 @@ * Adds a new function to mPendingFunctions. * The body will be automatically indented. * - * It is used to queue the writting of functions with custom code specified + * It is used to queue the writing of functions with custom code specified * in reactions, as reactions are written into the setup function of its * step. * Modified: trunk/ktutorial/ktutorial-editor/src/view/ReactionTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/ReactionTreeItem.cpp 2010-03-19 18:37:33 UTC (rev 169) +++ trunk/ktutorial/ktutorial-editor/src/view/ReactionTreeItem.cpp 2010-03-19 18:46:23 UTC (rev 170) @@ -37,7 +37,7 @@ mResponseCustomCodeItem = 0; mResponseNextStepItem = 0; - //Add two dummy childs, as update method expects always to child items + //Add two dummy children, as update method expects always to child items appendChild(new TextTreeItem(this)); appendChild(new TextTreeItem(this)); update(reaction); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-22 18:31:04
|
Revision: 176 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=176&view=rev Author: danxuliu Date: 2010-03-22 18:30:57 +0000 (Mon, 22 Mar 2010) Log Message: ----------- When a step or reaction is added, if the dialog to set the data is cancelled the step or the reaction is removed. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-22 18:13:49 UTC (rev 175) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-22 18:30:57 UTC (rev 176) @@ -245,11 +245,13 @@ mReactionActionDock->toggleViewAction()); } -void KTutorialEditor::showEditionDialog(EditionWidget* editionWidget) { +int KTutorialEditor::showEditionDialog(EditionWidget* editionWidget) { EditionDialog* dialog = new EditionDialog(editionWidget, this); dialog->setObjectName("editionDialog"); - dialog->exec(); + int dialogCode = dialog->exec(); dialog->deleteLater(); + + return dialogCode; } //private slots: @@ -332,7 +334,9 @@ Step* step = new Step(); mTutorial->addStep(step); - showEditionDialog(new StepDataWidget(step)); + if (showEditionDialog(new StepDataWidget(step)) == QDialog::Rejected) { + mTutorial->removeStep(step); + } } void KTutorialEditor::setStepData() { @@ -368,7 +372,9 @@ Reaction* reaction = new Reaction(); mCurrentStep->addReaction(reaction); - showEditionDialog(new ReactionWidget(reaction)); + if (showEditionDialog(new ReactionWidget(reaction)) == QDialog::Rejected) { + mCurrentStep->removeReaction(reaction); + } } void KTutorialEditor::setReactionData() { Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-22 18:13:49 UTC (rev 175) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-22 18:30:57 UTC (rev 176) @@ -98,8 +98,10 @@ * Shows an EditionDialog for the given EditionWidget. * * @param editionWidget The EditionWidget to wrap. + * @return QDialog::Accepted if the dialog was accepted, or + * QDialog::Rejected if the dialog was rejected. */ - void showEditionDialog(EditionWidget* editionWidget); + int showEditionDialog(EditionWidget* editionWidget); private Q_SLOTS: @@ -148,6 +150,7 @@ /** * Adds a new step to the tutorial and shows a StepDataWidget for it. + * The step is removed if the dialog is cancelled. */ void addStep(); @@ -174,6 +177,7 @@ /** * Adds a new reaction to the current step and shows a ReactionWidget for * it. + * The reaction is removed if the dialog is cancelled. */ void addReaction(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-22 18:39:52
|
Revision: 177 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=177&view=rev Author: danxuliu Date: 2010-03-22 18:39:46 +0000 (Mon, 22 Mar 2010) Log Message: ----------- After a second thought, the behavior in the previous commit was rather silly. Instead of always adding and removing when cancelled, only add when accepted! Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-22 18:30:57 UTC (rev 176) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-22 18:39:46 UTC (rev 177) @@ -332,10 +332,11 @@ void KTutorialEditor::addStep() { Step* step = new Step(); - mTutorial->addStep(step); - if (showEditionDialog(new StepDataWidget(step)) == QDialog::Rejected) { - mTutorial->removeStep(step); + if (showEditionDialog(new StepDataWidget(step)) == QDialog::Accepted) { + mTutorial->addStep(step); + } else { + delete step; } } @@ -370,10 +371,11 @@ Q_ASSERT(mCurrentStep); Reaction* reaction = new Reaction(); - mCurrentStep->addReaction(reaction); - if (showEditionDialog(new ReactionWidget(reaction)) == QDialog::Rejected) { - mCurrentStep->removeReaction(reaction); + if (showEditionDialog(new ReactionWidget(reaction)) == QDialog::Accepted) { + mCurrentStep->addReaction(reaction); + } else { + delete reaction; } } Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-22 18:30:57 UTC (rev 176) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-22 18:39:46 UTC (rev 177) @@ -149,8 +149,8 @@ void setTutorialTearDown(); /** - * Adds a new step to the tutorial and shows a StepDataWidget for it. - * The step is removed if the dialog is cancelled. + * Adds a new step to the tutorial after showing a StepDataWidget for it. + * The step isn't added if the dialog is cancelled. */ void addStep(); @@ -175,9 +175,9 @@ void removeStep(); /** - * Adds a new reaction to the current step and shows a ReactionWidget for - * it. - * The reaction is removed if the dialog is cancelled. + * Adds a new reaction to the current step after showing a ReactionWidget + * for it. + * The reaction isn't added if the dialog is cancelled. */ void addReaction(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-23 07:32:01
|
Revision: 184 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=184&view=rev Author: danxuliu Date: 2010-03-23 07:31:55 +0000 (Tue, 23 Mar 2010) Log Message: ----------- Add desktop file for KTutorial editor Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt Added Paths: ----------- trunk/ktutorial/ktutorial-editor/src/ktutorial-editor.desktop Modified: trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-23 00:56:41 UTC (rev 183) +++ trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-23 07:31:55 UTC (rev 184) @@ -33,4 +33,5 @@ ####### Install the editor ####### install(TARGETS ktutorial-editor DESTINATION ${BIN_INSTALL_DIR}) +install(FILES ktutorial-editor.desktop DESTINATION ${XDG_APPS_INSTALL_DIR}) install(FILES ktutorial-editorui.rc DESTINATION ${DATA_INSTALL_DIR}/ktutorial-editor) Added: trunk/ktutorial/ktutorial-editor/src/ktutorial-editor.desktop =================================================================== --- trunk/ktutorial/ktutorial-editor/src/ktutorial-editor.desktop (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/ktutorial-editor.desktop 2010-03-23 07:31:55 UTC (rev 184) @@ -0,0 +1,9 @@ +[Desktop Entry] +Name=KTutorial editor +Name[es]=KTutorial editor +GenericName=Editor for KTutorial tutorials +GenericName[es]=Editor para tutoriales de KTutorial +Exec=ktutorial-editor +Type=Application +Categories=Qt;KDE;Development;Documentation; +Terminal=false This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-27 04:25:20
|
Revision: 199 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=199&view=rev Author: danxuliu Date: 2010-03-27 04:25:13 +0000 (Sat, 27 Mar 2010) Log Message: ----------- Add action to create a new tutorial, replacing the current one Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-26 21:03:26 UTC (rev 198) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-27 04:25:13 UTC (rev 199) @@ -48,12 +48,16 @@ //public: -KTutorialEditor::KTutorialEditor(): KXmlGuiWindow(0) { +KTutorialEditor::KTutorialEditor(): KXmlGuiWindow(0), + mTutorial(0), + mCurrentStep(0), + mCurrentReaction(0) { + mTreeView = new QTreeView(); mTreeView->setObjectName("centralTreeView"); setCentralWidget(mTreeView); - setupTutorialToBeEdited(); + setTutorialToBeEdited(); setupDocks(); @@ -64,22 +68,41 @@ //private: -void KTutorialEditor::setupTutorialToBeEdited() { - mTutorial = new Tutorial(this); +void KTutorialEditor::setTutorialToBeEdited(Tutorial* tutorial) { + if (!tutorial) { + tutorial = new Tutorial(this); + } - TutorialTreeItem* tutorialTreeItem = new TutorialTreeItem(mTutorial); + //Clear the selection model to ensure that the actions are disabled as + //needed when the selection model is replaced + if (mTreeView->selectionModel()) { + mTreeView->selectionModel()->clear(); + } + + TutorialTreeItem* tutorialTreeItem = new TutorialTreeItem(tutorial); TreeModel* model = new TreeModel(tutorialTreeItem, mTreeView); + //Neither the old model nor the old selection model are deleted by the + //QTreeView when a new model is set (which creates a new selection model), + //so it must be done explicitly + QItemSelectionModel* oldSelectionModel = mTreeView->selectionModel(); QAbstractItemModel* oldModel = mTreeView->model(); mTreeView->setModel(model); + delete oldSelectionModel; delete oldModel; + //Parent object is set to the selection model, so the manager is also + //deleted when the selection model it watches is deleted TutorialTreeSelectionManager* selectionManager = - new TutorialTreeSelectionManager(mTreeView->selectionModel(), this); + new TutorialTreeSelectionManager(mTreeView->selectionModel(), + mTreeView->selectionModel()); connect(selectionManager, SIGNAL(stepSelected(Step*)), this, SLOT(selectStep(Step*))); connect(selectionManager, SIGNAL(reactionSelected(Reaction*)), this, SLOT(selectReaction(Reaction*))); + + delete mTutorial; + mTutorial = tutorial; } void KTutorialEditor::setupDocks() { @@ -99,6 +122,8 @@ } void KTutorialEditor::setupActions() { + KStandardAction::openNew(this, SLOT(newTutorial()), actionCollection()); + KAction* action = new KAction(this); action->setText(i18nc("@action", "Export...")); action->setStatusTip(i18nc("@info:status", "Exports the tutorial to a " @@ -286,6 +311,10 @@ } } +void KTutorialEditor::newTutorial() { + setTutorialToBeEdited(); +} + void KTutorialEditor::exportTutorial() { KUrl url; QPointer<KFileDialog> dialog = new KFileDialog(url, QString(), this); Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-26 21:03:26 UTC (rev 198) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-27 04:25:13 UTC (rev 199) @@ -78,11 +78,15 @@ Reaction* mCurrentReaction; /** - * Sets up the tutorial to be edited. + * Sets the tutorial to be edited. * It creates a new tutorial, prepares the tree view to represent it and * handles the selection of items. + * + * If the tutorial is null, a new empty tutorial is set. + * + * @param tutorial The tutorial to set. */ - void setupTutorialToBeEdited(); + void setTutorialToBeEdited(Tutorial* tutorial = 0); /** * Sets up the dock widgets. @@ -123,6 +127,11 @@ void selectReaction(Reaction* reaction); /** + * Creates a new empty tutorial replacing the current one, if any. + */ + void newTutorial(); + + /** * Shows a KFileDialog to select the file to save the exported tutorial in. * An error message is shown if the tutorial couldn't be saved. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-27 07:05:54
|
Revision: 200 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=200&view=rev Author: danxuliu Date: 2010-03-27 07:05:48 +0000 (Sat, 27 Mar 2010) Log Message: ----------- Add actions to save and load a tutorial from XML Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-27 04:25:13 UTC (rev 199) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-27 07:05:48 UTC (rev 200) @@ -63,6 +63,10 @@ setupActions(); + //Setting the url enables/disables File->Save action, so it has to be + //set after it is created + setTutorialUrl(KUrl()); + setupGUI(); } @@ -105,6 +109,24 @@ mTutorial = tutorial; } +void KTutorialEditor::setTutorialUrl(const KUrl& url) { + mTutorialUrl = url; + + if (url.isEmpty()) { + actionCollection()->action("file_save")->setEnabled(false); + + setCaption(""); + } else { + actionCollection()->action("file_save")->setEnabled(true); + + QString caption = url.prettyUrl(); + if (caption.length() > 64) { + caption = "..." + caption.right(64); + } + setCaption(caption); + } +} + void KTutorialEditor::setupDocks() { mTutorialActionDock = new QDockWidget(i18nc("@title", "Edit tutorial"), this); @@ -124,6 +146,12 @@ void KTutorialEditor::setupActions() { KStandardAction::openNew(this, SLOT(newTutorial()), actionCollection()); + KStandardAction::open(this, SLOT(openTutorial()), actionCollection()); + + KStandardAction::save(this, SLOT(saveTutorial()), actionCollection()); + + KStandardAction::saveAs(this, SLOT(saveTutorialAs()), actionCollection()); + KAction* action = new KAction(this); action->setText(i18nc("@action", "Export...")); action->setStatusTip(i18nc("@info:status", "Exports the tutorial to a " @@ -313,8 +341,84 @@ void KTutorialEditor::newTutorial() { setTutorialToBeEdited(); + setTutorialUrl(KUrl()); } +void KTutorialEditor::openTutorial() { + KUrl url = mTutorialUrl; + QPointer<KFileDialog> dialog = new KFileDialog(url, QString(), this); + + dialog->setCaption(i18nc("@title", "Open Tutorial")); + dialog->setOperationMode(KFileDialog::Opening); + dialog->setFilter(i18nc("@item:inlistbox A KFileDialog filter", + "*.xml|XML file")); + + if (dialog->exec() == QDialog::Rejected) { + return; + } + + Tutorial* tutorial; + try { + tutorial = Serialization::loadTutorial(dialog->selectedUrl()); + } catch (IOException e) { + QString text = i18nc("@label", "There was a problem when trying to " +"open the file:<nl/>%1", e.message()); + QString caption = i18nc("@title:window", "File could not be read"); + KMessageBox::error(this, text, caption); + return; + } catch (DeserializationException e) { + QString text = i18nc("@label", "There was a problem when trying to " +"load the tutorial:<nl/>%1", e.message()); + QString caption = i18nc("@title:window", "Tutorial could not be " +"loaded"); + KMessageBox::error(this, text, caption); + return; + } + + setTutorialToBeEdited(tutorial); + setTutorialUrl(dialog->selectedUrl()); +} + +void KTutorialEditor::saveTutorial() { + try { + Serialization::saveTutorial(mTutorial, mTutorialUrl); + } catch (IOException e) { + QString text = i18nc("@label", "There was a problem when trying to " +"save the tutorial:<nl/>%1", e.message()); + QString caption = i18nc("@title:window", "Tutorial could not be saved"); + KMessageBox::error(this, text, caption); + } +} + +void KTutorialEditor::saveTutorialAs() { + KUrl url = mTutorialUrl; + QPointer<KFileDialog> dialog = new KFileDialog(url, QString(), this); + + dialog->setSelection(mTutorial->id()); + dialog->setCaption(i18nc("@title", "Save Tutorial")); + dialog->setOperationMode(KFileDialog::Saving); + dialog->setConfirmOverwrite(true); + dialog->setFilter(i18nc("@item:inlistbox A KFileDialog filter", + "*.xml|XML file")); + dialog->filterWidget()->setEditable(false); + + if (dialog->exec() == QDialog::Rejected) { + return; + } + + try { + Serialization::saveTutorial(mTutorial, dialog->selectedUrl()); + } catch (IOException e) { + QString text = i18nc("@label", "There was a problem when trying to " +"save the tutorial:<nl/>%1", e.message()); + QString caption = i18nc("@title:window", "Tutorial could not be saved"); + KMessageBox::error(this, text, caption); + return; + } + + setTutorialUrl(dialog->selectedUrl()); +} + void KTutorialEditor::exportTutorial() { KUrl url; QPointer<KFileDialog> dialog = new KFileDialog(url, QString(), this); Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-27 04:25:13 UTC (rev 199) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-27 07:05:48 UTC (rev 200) @@ -20,6 +20,7 @@ #define KTUTORIALEDITOR_H #include <KXmlGuiWindow> +#include <KUrl> class EditionWidget; class QTreeView; @@ -68,6 +69,11 @@ Tutorial* mTutorial; /** + * The URL to save the tutorial to. + */ + KUrl mTutorialUrl; + + /** * The currently selected step. */ Step* mCurrentStep; @@ -89,6 +95,16 @@ void setTutorialToBeEdited(Tutorial* tutorial = 0); /** + * Sets the URL to save the tutorial to. + * An empty URL disables Save action, otherwise it is enabled. + * The caption (window title) is updated with the URL. The URL in the + * caption is shown truncated if it is too lengthy. + * + * @param url The URL to save the tutorial to. + */ + void setTutorialUrl(const KUrl& url); + + /** * Sets up the dock widgets. */ void setupDocks(); @@ -128,10 +144,31 @@ /** * Creates a new empty tutorial replacing the current one, if any. + * The tutorial URL is cleared. */ void newTutorial(); /** + * Shows a KFileDialog to select the file to open the tutorial from. + * The tutorial URL is updated. + * An error message is shown if the tutorial couldn't be opened. + */ + void openTutorial(); + + /** + * Saves the tutorial to the tutorial URL. + * An error message is shown if the tutorial couldn't be saved. + */ + void saveTutorial(); + + /** + * Shows a KFileDialog to select the file to save the tutorial to. + * The tutorial URL is updated. + * An error message is shown if the tutorial couldn't be saved. + */ + void saveTutorialAs(); + + /** * Shows a KFileDialog to select the file to save the exported tutorial in. * An error message is shown if the tutorial couldn't be saved. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-29 17:17:50
|
Revision: 210 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=210&view=rev Author: danxuliu Date: 2010-03-29 17:17:44 +0000 (Mon, 29 Mar 2010) Log Message: ----------- Enable or disable Save action and set caption based on the undo stack state. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-29 06:46:22 UTC (rev 209) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-29 17:17:44 UTC (rev 210) @@ -61,15 +61,14 @@ setCentralWidget(mTreeView); mUndoStack = new KUndoStack(this); - setTutorialToBeEdited(); + connect(mUndoStack, SIGNAL(cleanChanged(bool)), + this, SLOT(handleUndoStackCleanChanged(bool))); setupDocks(); setupActions(); - //Setting the url enables/disables File->Save action, so it has to be - //set after it is created - setTutorialUrl(KUrl()); + newTutorial(); setupGUI(); } @@ -115,24 +114,6 @@ mTutorial = tutorial; } -void KTutorialEditor::setTutorialUrl(const KUrl& url) { - mTutorialUrl = url; - - if (url.isEmpty()) { - actionCollection()->action("file_save")->setEnabled(false); - - setCaption(""); - } else { - actionCollection()->action("file_save")->setEnabled(true); - - QString caption = url.prettyUrl(); - if (caption.length() > 64) { - caption = "..." + caption.right(64); - } - setCaption(caption); - } -} - void KTutorialEditor::setupDocks() { mTutorialActionDock = new QDockWidget(i18nc("@title", "Edit tutorial"), this); @@ -308,6 +289,20 @@ mReactionActionDock->toggleViewAction()); } +QString KTutorialEditor::captionFromTutorialUrl() { + if (mTutorialUrl.isEmpty()) { + return i18nc("@title:window Window title for KTutorial editor when the \ +tutorial has no associated URL", "New file"); + } + + QString caption = mTutorialUrl.prettyUrl(); + if (caption.length() > 64) { + caption = "..." + caption.right(64); + } + + return caption; +} + int KTutorialEditor::showEditionDialog(CommandWidget* commandWidget) { commandWidget->setUndoStack(mUndoStack); @@ -351,9 +346,23 @@ } } +void KTutorialEditor::handleUndoStackCleanChanged(bool clean) { + QString caption = captionFromTutorialUrl(); + if (clean && !mTutorialUrl.isEmpty()) { + actionCollection()->action("file_save")->setEnabled(false); + setCaption(caption); + } else { + actionCollection()->action("file_save")->setEnabled(true); + setCaption(i18nc("@title:window Wrapper for the window title when the \ +tutorial was modified but not saved yet", "%1 [not saved]", caption)); + } +} + void KTutorialEditor::newTutorial() { setTutorialToBeEdited(); - setTutorialUrl(KUrl()); + mTutorialUrl = KUrl(); + //Force unclean state, as clearing the stack returns it to the clean state + handleUndoStackCleanChanged(false); } void KTutorialEditor::openTutorial() { @@ -388,10 +397,19 @@ } setTutorialToBeEdited(tutorial); - setTutorialUrl(dialog->selectedUrl()); + mTutorialUrl = dialog->selectedUrl(); + mUndoStack->setClean(); + //Force clean state, as setting an empty stack as clean would not emit + //cleanChanged() + handleUndoStackCleanChanged(true); } void KTutorialEditor::saveTutorial() { + if (mTutorialUrl.isEmpty()) { + saveTutorialAs(); + return; + } + try { Serialization::saveTutorial(mTutorial, mTutorialUrl); } catch (IOException e) { @@ -399,7 +417,10 @@ "save the tutorial:<nl/>%1", e.message()); QString caption = i18nc("@title:window", "Tutorial could not be saved"); KMessageBox::error(this, text, caption); + return; } + + mUndoStack->setClean(); } void KTutorialEditor::saveTutorialAs() { @@ -428,7 +449,11 @@ return; } - setTutorialUrl(dialog->selectedUrl()); + mTutorialUrl = dialog->selectedUrl(); + mUndoStack->setClean(); + //Force clean state, as setting an empty stack as clean would not emit + //cleanChanged() + handleUndoStackCleanChanged(true); } void KTutorialEditor::exportTutorial() { Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-29 06:46:22 UTC (rev 209) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-29 17:17:44 UTC (rev 210) @@ -102,16 +102,6 @@ void setTutorialToBeEdited(Tutorial* tutorial = 0); /** - * Sets the URL to save the tutorial to. - * An empty URL disables Save action, otherwise it is enabled. - * The caption (window title) is updated with the URL. The URL in the - * caption is shown truncated if it is too lengthy. - * - * @param url The URL to save the tutorial to. - */ - void setTutorialUrl(const KUrl& url); - - /** * Sets up the dock widgets. */ void setupDocks(); @@ -122,6 +112,15 @@ void setupActions(); /** + * Returns a caption (window title) string based on the tutorial URL. + * The caption contains the URL, which is truncated if it is too lengthy. If + * the URL is empty, "New file" is returned. + * + * @return A caption string based on the tutorial URL. + */ + QString captionFromTutorialUrl(); + + /** * Shows an EditionDialog for the given CommandWidget. * The undo stack used in the CommandWidget is mUndoStack. * @@ -151,27 +150,46 @@ void selectReaction(Reaction* reaction); /** + * Modifies the caption and enables or disables Save action based on the + * clean state of the stack. + * When the stack is not clean or the tutorial does not have an associated + * URL, "[not saved]" is added after the caption (the URL or "New file", + * depending on the case). Otherwise, the caption is the URL associated to + * the tutorial. + * + * When the stack is clean and the tutorial has an associated URL, the Save + * action is disabled. Otherwise, it is enabled, so if there is no + * associated URL the Save action is always kept enabled, even if the stack + * is clean. + * + * @param clean Whether the undo stack entered clean state or not. + */ + void handleUndoStackCleanChanged(bool clean); + + /** * Creates a new empty tutorial replacing the current one, if any. - * The tutorial URL is cleared. + * The tutorial URL is cleared and an unclean state is forced. */ void newTutorial(); /** * Shows a KFileDialog to select the file to open the tutorial from. - * The tutorial URL is updated. + * The tutorial URL is updated and a clean state is forced. * An error message is shown if the tutorial couldn't be opened. */ void openTutorial(); /** * Saves the tutorial to the tutorial URL. + * A clean state is set. If there is no tutorial URL it behaves like + * saveTutorialAs(). * An error message is shown if the tutorial couldn't be saved. */ void saveTutorial(); /** * Shows a KFileDialog to select the file to save the tutorial to. - * The tutorial URL is updated. + * The tutorial URL is updated and a clean state is forced. * An error message is shown if the tutorial couldn't be saved. */ void saveTutorialAs(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-29 22:24:52
|
Revision: 211 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=211&view=rev Author: danxuliu Date: 2010-03-29 22:24:45 +0000 (Mon, 29 Mar 2010) Log Message: ----------- Warn the user when a tutorial is going to be closed and the changes were not saved yet. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-29 17:17:44 UTC (rev 210) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-29 22:24:45 UTC (rev 211) @@ -73,9 +73,42 @@ setupGUI(); } +//protected: + +bool KTutorialEditor::queryClose() { + return queryCloseTutorial(); +} + //private: +bool KTutorialEditor::queryCloseTutorial() { + if (mUndoStack->isClean()) { + return true; + } + + QString text = i18nc("@label", "The tutorial has been modified.<nl/>" +"Do you want to save your changes or discard them?"); + QString caption = i18nc("@title:window", "Close tutorial"); + int button = KMessageBox::warningYesNoCancel(this, text, caption, + KStandardGuiItem::save(), + KStandardGuiItem::discard()); + + if (button == KMessageBox::Cancel) { + return false; + } + + if (button == KMessageBox::Yes) { + return saveTutorial(); + } + + return true; +} + void KTutorialEditor::setTutorialToBeEdited(Tutorial* tutorial) { + if (!queryCloseTutorial()) { + return; + } + if (!tutorial) { tutorial = new Tutorial(this); } @@ -147,7 +180,7 @@ actionCollection()->addAction("exportTutorial", action); connect(action, SIGNAL(triggered(bool)), this, SLOT(exportTutorial())); - KStandardAction::quit(kapp, SLOT(quit()), actionCollection()); + KStandardAction::quit(this, SLOT(close()), actionCollection()); mUndoStack->createUndoAction(actionCollection()); @@ -404,10 +437,9 @@ handleUndoStackCleanChanged(true); } -void KTutorialEditor::saveTutorial() { +bool KTutorialEditor::saveTutorial() { if (mTutorialUrl.isEmpty()) { - saveTutorialAs(); - return; + return saveTutorialAs(); } try { @@ -417,13 +449,15 @@ "save the tutorial:<nl/>%1", e.message()); QString caption = i18nc("@title:window", "Tutorial could not be saved"); KMessageBox::error(this, text, caption); - return; + return false; } mUndoStack->setClean(); + + return true; } -void KTutorialEditor::saveTutorialAs() { +bool KTutorialEditor::saveTutorialAs() { KUrl url = mTutorialUrl; QPointer<KFileDialog> dialog = new KFileDialog(url, QString(), this); @@ -436,7 +470,7 @@ dialog->filterWidget()->setEditable(false); if (dialog->exec() == QDialog::Rejected) { - return; + return false; } try { @@ -446,7 +480,7 @@ "save the tutorial:<nl/>%1", e.message()); QString caption = i18nc("@title:window", "Tutorial could not be saved"); KMessageBox::error(this, text, caption); - return; + return false; } mTutorialUrl = dialog->selectedUrl(); @@ -454,6 +488,8 @@ //Force clean state, as setting an empty stack as clean would not emit //cleanChanged() handleUndoStackCleanChanged(true); + + return true; } void KTutorialEditor::exportTutorial() { Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-29 17:17:44 UTC (rev 210) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-29 22:24:45 UTC (rev 211) @@ -43,6 +43,19 @@ */ KTutorialEditor(); +protected: + + /** + * Called before the window is closed, either by the user or indirectly by + * the session manager. + * It checks whether the tutorial can be closed or not. + * + * Reimplemented from KMainWindow::queryClose(). + * + * @return True if the window can be closed, false otherwise. + */ + virtual bool queryClose(); + private: /** @@ -91,12 +104,23 @@ Reaction* mCurrentReaction; /** + * Checks whether the tutorial can be closed or not. + * If the tutorial is not clean, the user is asked if it has to be saved or + * not, or if the close operation should be cancelled. + * + * @return True if the tutorial can be closed, false otherwise. + */ + bool queryCloseTutorial(); + + /** * Sets the tutorial to be edited. * It creates a new tutorial, prepares the tree view to represent it and * handles the selection of items. * * If the tutorial is null, a new empty tutorial is set. * + * Nothing is done if the previous tutorial should not be closed. + * * @param tutorial The tutorial to set. */ void setTutorialToBeEdited(Tutorial* tutorial = 0); @@ -184,15 +208,19 @@ * A clean state is set. If there is no tutorial URL it behaves like * saveTutorialAs(). * An error message is shown if the tutorial couldn't be saved. + * + * @return True if the tutorial was successfully saved, false otherwise. */ - void saveTutorial(); + bool saveTutorial(); /** * Shows a KFileDialog to select the file to save the tutorial to. * The tutorial URL is updated and a clean state is forced. * An error message is shown if the tutorial couldn't be saved. + * + * @return True if the tutorial was successfully saved, false otherwise. */ - void saveTutorialAs(); + bool saveTutorialAs(); /** * Shows a KFileDialog to select the file to save the exported tutorial in. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-29 22:43:32
|
Revision: 212 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=212&view=rev Author: danxuliu Date: 2010-03-29 22:43:26 +0000 (Mon, 29 Mar 2010) Log Message: ----------- Make caption consistent with clean state: new tutorials start now showing a clean state and they no longer show "[not saved]" in the caption when they enter in an clean state (due to an undo). The editor doesn't warn the user before closing a new empty tutorial, so it shouldn't show "[not saved]" in the caption either. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-29 22:24:45 UTC (rev 211) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-29 22:43:26 UTC (rev 212) @@ -381,21 +381,23 @@ void KTutorialEditor::handleUndoStackCleanChanged(bool clean) { QString caption = captionFromTutorialUrl(); - if (clean && !mTutorialUrl.isEmpty()) { - actionCollection()->action("file_save")->setEnabled(false); + if (clean) { setCaption(caption); } else { - actionCollection()->action("file_save")->setEnabled(true); setCaption(i18nc("@title:window Wrapper for the window title when the \ tutorial was modified but not saved yet", "%1 [not saved]", caption)); } + + if (clean && !mTutorialUrl.isEmpty()) { + actionCollection()->action("file_save")->setEnabled(false); + } else { + actionCollection()->action("file_save")->setEnabled(true); + } } void KTutorialEditor::newTutorial() { setTutorialToBeEdited(); mTutorialUrl = KUrl(); - //Force unclean state, as clearing the stack returns it to the clean state - handleUndoStackCleanChanged(false); } void KTutorialEditor::openTutorial() { Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-29 22:24:45 UTC (rev 211) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-29 22:43:26 UTC (rev 212) @@ -176,10 +176,9 @@ /** * Modifies the caption and enables or disables Save action based on the * clean state of the stack. - * When the stack is not clean or the tutorial does not have an associated - * URL, "[not saved]" is added after the caption (the URL or "New file", - * depending on the case). Otherwise, the caption is the URL associated to - * the tutorial. + * When the stack is not clean, "[not saved]" is added after the caption + * (the URL or "New file", depending on the case). Otherwise, the caption is + * the URL associated to the tutorial. * * When the stack is clean and the tutorial has an associated URL, the Save * action is disabled. Otherwise, it is enabled, so if there is no @@ -192,7 +191,7 @@ /** * Creates a new empty tutorial replacing the current one, if any. - * The tutorial URL is cleared and an unclean state is forced. + * The tutorial URL is cleared. */ void newTutorial(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-29 23:59:07
|
Revision: 215 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=215&view=rev Author: danxuliu Date: 2010-03-29 23:58:59 +0000 (Mon, 29 Mar 2010) Log Message: ----------- Add a command line option to load a tutorial Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h trunk/ktutorial/ktutorial-editor/src/main.cpp Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-29 23:40:17 UTC (rev 214) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-29 23:58:59 UTC (rev 215) @@ -73,6 +73,33 @@ setupGUI(); } +void KTutorialEditor::loadTutorialFromUrl(const KUrl& url) { + Tutorial* tutorial; + try { + tutorial = Serialization::loadTutorial(url); + } catch (IOException e) { + QString text = i18nc("@label", "There was a problem when trying to " +"open the file:<nl/>%1", e.message()); + QString caption = i18nc("@title:window", "File could not be read"); + KMessageBox::error(this, text, caption); + return; + } catch (DeserializationException e) { + QString text = i18nc("@label", "There was a problem when trying to " +"load the tutorial:<nl/>%1", e.message()); + QString caption = i18nc("@title:window", "Tutorial could not be " +"loaded"); + KMessageBox::error(this, text, caption); + return; + } + + setTutorialToBeEdited(tutorial); + mTutorialUrl = url; + mUndoStack->setClean(); + //Force clean state, as setting an empty stack as clean would not emit + //cleanChanged() + handleUndoStackCleanChanged(true); +} + //protected: bool KTutorialEditor::queryClose() { @@ -416,30 +443,7 @@ return; } - Tutorial* tutorial; - try { - tutorial = Serialization::loadTutorial(dialog->selectedUrl()); - } catch (IOException e) { - QString text = i18nc("@label", "There was a problem when trying to " -"open the file:<nl/>%1", e.message()); - QString caption = i18nc("@title:window", "File could not be read"); - KMessageBox::error(this, text, caption); - return; - } catch (DeserializationException e) { - QString text = i18nc("@label", "There was a problem when trying to " -"load the tutorial:<nl/>%1", e.message()); - QString caption = i18nc("@title:window", "Tutorial could not be " -"loaded"); - KMessageBox::error(this, text, caption); - return; - } - - setTutorialToBeEdited(tutorial); - mTutorialUrl = dialog->selectedUrl(); - mUndoStack->setClean(); - //Force clean state, as setting an empty stack as clean would not emit - //cleanChanged() - handleUndoStackCleanChanged(true); + loadTutorialFromUrl(dialog->selectedUrl()); } bool KTutorialEditor::saveTutorial() { Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-29 23:40:17 UTC (rev 214) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-29 23:58:59 UTC (rev 215) @@ -43,6 +43,15 @@ */ KTutorialEditor(); + /** + * Loads the tutorial to be edited from the given URL. + * The tutorial URL is updated and a clean state is forced. + * An error message is shown if the tutorial couldn't be opened. + * + * @param url The URL to load the tutorial from. + */ + void loadTutorialFromUrl(const KUrl& url); + protected: /** @@ -197,8 +206,7 @@ /** * Shows a KFileDialog to select the file to open the tutorial from. - * The tutorial URL is updated and a clean state is forced. - * An error message is shown if the tutorial couldn't be opened. + * The tutorial is loaded from the URL selected by the user. */ void openTutorial(); Modified: trunk/ktutorial/ktutorial-editor/src/main.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/main.cpp 2010-03-29 23:40:17 UTC (rev 214) +++ trunk/ktutorial/ktutorial-editor/src/main.cpp 2010-03-29 23:58:59 UTC (rev 215) @@ -35,10 +35,20 @@ "dan...@gm..."); KCmdLineArgs::init(argc, argv, &aboutData); + KCmdLineOptions options; + options.add("+[URL]", ki18nc("@info:shell", "The tutorial to open")); + + KCmdLineArgs::addCmdLineOptions(options); + KApplication app; KTutorialEditor* window = new KTutorialEditor(); window->show(); + KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); + if (args->count() == 1) { + window->loadTutorialFromUrl(args->url(0)); + } + return app.exec(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-30 05:03:53
|
Revision: 218 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=218&view=rev Author: danxuliu Date: 2010-03-30 05:03:47 +0000 (Tue, 30 Mar 2010) Log Message: ----------- Add support to save and restore sessions. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h trunk/ktutorial/ktutorial-editor/src/main.cpp Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-30 03:16:07 UTC (rev 217) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-30 05:03:47 UTC (rev 218) @@ -106,6 +106,17 @@ return queryCloseTutorial(); } +void KTutorialEditor::readProperties(const KConfigGroup& configGroup) { + KUrl url = configGroup.readEntry("TutorialUrl"); + if (!url.isEmpty()) { + loadTutorialFromUrl(url); + } +} + +void KTutorialEditor::saveProperties(KConfigGroup& configGroup) { + configGroup.writeEntry("TutorialUrl", mTutorialUrl); +} + //private: bool KTutorialEditor::queryCloseTutorial() { Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-30 03:16:07 UTC (rev 217) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-30 05:03:47 UTC (rev 218) @@ -65,6 +65,26 @@ */ virtual bool queryClose(); + /** + * Restores the session based on the saved state. + * If "TutorialURL" is not empty, the tutorial is loaded from that URL. + * + * Reimplemented from KMainWindow::readProperties(const KConfigGroup&). + * + * @param configGroup The KConfigGroup to read the state from. + */ + virtual void readProperties(const KConfigGroup& configGroup); + + /** + * Saves the state to restore the session. + * The tutorial URL is saved as "TutorialURL". + * + * Reimplemented from KMainWindow::saveProperties(KConfigGroup&). + * + * @param configGroup The KConfigGroup to save the state to. + */ + virtual void saveProperties(KConfigGroup& configGroup); + private: /** Modified: trunk/ktutorial/ktutorial-editor/src/main.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/main.cpp 2010-03-30 03:16:07 UTC (rev 217) +++ trunk/ktutorial/ktutorial-editor/src/main.cpp 2010-03-30 05:03:47 UTC (rev 218) @@ -41,6 +41,10 @@ KCmdLineArgs::addCmdLineOptions(options); KApplication app; + if (app.isSessionRestored()) { + kRestoreMainWindows<KTutorialEditor>(); + return app.exec(); + } KTutorialEditor* window = new KTutorialEditor(); window->show(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-30 07:12:49
|
Revision: 219 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=219&view=rev Author: danxuliu Date: 2010-03-30 07:12:38 +0000 (Tue, 30 Mar 2010) Log Message: ----------- Add "Open Recent" action Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-30 05:03:47 UTC (rev 218) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-30 07:12:38 UTC (rev 219) @@ -28,6 +28,7 @@ #include <KFileFilterCombo> #include <KLocalizedString> #include <KMessageBox> +#include <KRecentFilesAction> #include <KUndoStack> #include <KIO/NetAccess> @@ -73,7 +74,16 @@ setupGUI(); } -void KTutorialEditor::loadTutorialFromUrl(const KUrl& url) { +KTutorialEditor::~KTutorialEditor() { + mRecentFilesAction->saveEntries(KGlobal::config()->group("RecentFiles")); +} + +//public slots: + +//Don't use a reference to the URL, as if it is the argument in +//urlSelected(KUrl) signal emitted by mRecentFilesAction, it is removed in +//mRecentFilesAction->addUrl(KUrl), which leads to a crash +void KTutorialEditor::loadTutorialFromUrl(KUrl url) { Tutorial* tutorial; try { tutorial = Serialization(this).loadTutorial(url); @@ -93,6 +103,7 @@ } setTutorialToBeEdited(tutorial); + mRecentFilesAction->addUrl(url); mTutorialUrl = url; mUndoStack->setClean(); //Force clean state, as setting an empty stack as clean would not emit @@ -206,6 +217,10 @@ KStandardAction::open(this, SLOT(openTutorial()), actionCollection()); + mRecentFilesAction = KStandardAction::openRecent( + this, SLOT(loadTutorialFromUrl(KUrl)), actionCollection()); + mRecentFilesAction->loadEntries(KGlobal::config()->group("RecentFiles")); + KStandardAction::save(this, SLOT(saveTutorial()), actionCollection()); KStandardAction::saveAs(this, SLOT(saveTutorialAs()), actionCollection()); @@ -503,6 +518,7 @@ return false; } + mRecentFilesAction->addUrl(dialog->selectedUrl()); mTutorialUrl = dialog->selectedUrl(); mUndoStack->setClean(); //Force clean state, as setting an empty stack as clean would not emit Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-30 05:03:47 UTC (rev 218) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-30 07:12:38 UTC (rev 219) @@ -24,6 +24,7 @@ class CommandWidget; class EditionWidget; +class KRecentFilesAction; class KUndoStack; class QTreeView; class Reaction; @@ -44,13 +45,22 @@ KTutorialEditor(); /** + * Destroys this KTutorialEditor. + * The entries in the recent files action are saved in the configuration. + */ + virtual ~KTutorialEditor(); + +public Q_SLOTS: + + /** * Loads the tutorial to be edited from the given URL. - * The tutorial URL is updated and a clean state is forced. + * The tutorial URL is updated and added to the recent files action, and a + * clean state is forced. * An error message is shown if the tutorial couldn't be opened. * * @param url The URL to load the tutorial from. */ - void loadTutorialFromUrl(const KUrl& url); + void loadTutorialFromUrl(KUrl url); protected: @@ -108,6 +118,11 @@ QDockWidget* mReactionActionDock; /** + * The "Open Recent" action. + */ + KRecentFilesAction* mRecentFilesAction; + + /** * The stack of undoable commands. */ KUndoStack* mUndoStack; @@ -242,7 +257,8 @@ /** * Shows a KFileDialog to select the file to save the tutorial to. - * The tutorial URL is updated and a clean state is forced. + * The tutorial URL is updated and added to the recent files action, and a + * clean state is forced. * An error message is shown if the tutorial couldn't be saved. * * @return True if the tutorial was successfully saved, false otherwise. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-30 07:25:54
|
Revision: 220 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=220&view=rev Author: danxuliu Date: 2010-03-30 07:25:48 +0000 (Tue, 30 Mar 2010) Log Message: ----------- Fix keeping the tutorial but changing the tutorial URL when the current tutorial was tried to be closed and the user cancelled the operation. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-30 07:12:38 UTC (rev 219) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-30 07:25:48 UTC (rev 220) @@ -84,6 +84,10 @@ //urlSelected(KUrl) signal emitted by mRecentFilesAction, it is removed in //mRecentFilesAction->addUrl(KUrl), which leads to a crash void KTutorialEditor::loadTutorialFromUrl(KUrl url) { + if (!queryCloseTutorial()) { + return; + } + Tutorial* tutorial; try { tutorial = Serialization(this).loadTutorial(url); @@ -154,10 +158,6 @@ } void KTutorialEditor::setTutorialToBeEdited(Tutorial* tutorial) { - if (!queryCloseTutorial()) { - return; - } - if (!tutorial) { tutorial = new Tutorial(this); } @@ -449,6 +449,10 @@ } void KTutorialEditor::newTutorial() { + if (!queryCloseTutorial()) { + return; + } + setTutorialToBeEdited(); mTutorialUrl = KUrl(); //Force clean state, as clearing an empty stack would not emit Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-30 07:12:38 UTC (rev 219) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-30 07:25:48 UTC (rev 220) @@ -58,6 +58,8 @@ * clean state is forced. * An error message is shown if the tutorial couldn't be opened. * + * Nothing is done if the current tutorial, if any, should not be closed. + * * @param url The URL to load the tutorial from. */ void loadTutorialFromUrl(KUrl url); @@ -163,8 +165,6 @@ * * If the tutorial is null, a new empty tutorial is set. * - * Nothing is done if the previous tutorial should not be closed. - * * @param tutorial The tutorial to set. */ void setTutorialToBeEdited(Tutorial* tutorial = 0); @@ -236,6 +236,8 @@ /** * Creates a new empty tutorial replacing the current one, if any. * The tutorial URL is cleared. + * + * Nothing is done if the current tutorial, if any, should not be closed. */ void newTutorial(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-31 06:55:39
|
Revision: 223 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=223&view=rev Author: danxuliu Date: 2010-03-31 06:55:32 +0000 (Wed, 31 Mar 2010) Log Message: ----------- Refactor KTutorialEditor class to extract file related actions to its own class, FileActions. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h Added Paths: ----------- trunk/ktutorial/ktutorial-editor/src/FileActions.cpp trunk/ktutorial/ktutorial-editor/src/FileActions.h Modified: trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-31 05:33:29 UTC (rev 222) +++ trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-31 06:55:32 UTC (rev 223) @@ -11,6 +11,7 @@ set(ktutorial_editor_SRCS Exception.cpp + FileActions.cpp KTutorialEditor.cpp ) Added: trunk/ktutorial/ktutorial-editor/src/FileActions.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/FileActions.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/FileActions.cpp 2010-03-31 06:55:32 UTC (rev 223) @@ -0,0 +1,268 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include "FileActions.h" + +#include <KActionCollection> +#include <KFileDialog> +#include <KFileFilterCombo> +#include <KLocalizedString> +#include <KMessageBox> +#include <KRecentFilesAction> +#include <KStandardAction> + +#include "KTutorialEditor.h" +#include "data/Tutorial.h" +#include "serialization/Serialization.h" + +//public: + +FileActions::FileActions(KTutorialEditor* tutorialEditor): + QObject(tutorialEditor), + mTutorialEditor(tutorialEditor), + mClean(true), + mRecentFilesAction(0) { + + setupActions(); + + connect(tutorialEditor, SIGNAL(cleanChanged(bool)), + this, SLOT(handleUndoStackCleanChanged(bool))); +} + +FileActions::~FileActions() { + mRecentFilesAction->saveEntries(KGlobal::config()->group("RecentFiles")); +} + +const KUrl& FileActions::tutorialUrl() const { + return mTutorialUrl; +} + +bool FileActions::queryCloseTutorial() { + if (mClean) { + return true; + } + + QString text = i18nc("@label", "The tutorial has been modified.<nl/>" +"Do you want to save your changes or discard them?"); + QString caption = i18nc("@title:window", "Close tutorial"); + int button = KMessageBox::warningYesNoCancel(mTutorialEditor, text, caption, + KStandardGuiItem::save(), + KStandardGuiItem::discard()); + + if (button == KMessageBox::Cancel) { + return false; + } + + if (button == KMessageBox::Yes) { + return saveTutorial(); + } + + return true; +} + +//public slots: + +//Don't use a reference to the URL, as if it is the argument in +//urlSelected(KUrl) signal emitted by mRecentFilesAction, it is removed in +//mRecentFilesAction->addUrl(KUrl), which leads to a crash +void FileActions::loadTutorialFromUrl(KUrl url) { + if (!queryCloseTutorial()) { + return; + } + + Tutorial* tutorial; + try { + tutorial = Serialization(mTutorialEditor).loadTutorial(url); + } catch (IOException e) { + QString text = i18nc("@label", "There was a problem when trying to " +"open the file:<nl/>%1", e.message()); + QString caption = i18nc("@title:window", "File could not be read"); + KMessageBox::error(mTutorialEditor, text, caption); + return; + } catch (DeserializationException e) { + QString text = i18nc("@label", "There was a problem when trying to " +"load the tutorial:<nl/>%1", e.message()); + QString caption = i18nc("@title:window", "Tutorial could not be " +"loaded"); + KMessageBox::error(mTutorialEditor, text, caption); + return; + } + + mTutorialEditor->setTutorialToBeEdited(tutorial); + mRecentFilesAction->addUrl(url); + mTutorialUrl = url; + mTutorialEditor->setClean(); +} + +void FileActions::newTutorial() { + if (!queryCloseTutorial()) { + return; + } + + mTutorialEditor->setTutorialToBeEdited(); + mTutorialUrl = KUrl(); + //Force clean state, as clearing an empty stack (in setTutorialToBeEdited()) + //would not emit cleanChanged() + mTutorialEditor->setClean(); +} + +void FileActions::handleUndoStackCleanChanged(bool clean) { + mClean = clean; + + KActionCollection* actionCollection = mTutorialEditor->actionCollection(); + if (clean && !mTutorialUrl.isEmpty()) { + actionCollection->action("file_save")->setEnabled(false); + } else { + actionCollection->action("file_save")->setEnabled(true); + } +} + +//private: + +void FileActions::setupActions() { + KActionCollection* actionCollection = mTutorialEditor->actionCollection(); + + KStandardAction::openNew(this, SLOT(newTutorial()), actionCollection); + + KStandardAction::open(this, SLOT(openTutorial()), actionCollection); + + mRecentFilesAction = KStandardAction::openRecent( + this, SLOT(loadTutorialFromUrl(KUrl)), actionCollection); + mRecentFilesAction->loadEntries(KGlobal::config()->group("RecentFiles")); + + KStandardAction::save(this, SLOT(saveTutorial()), actionCollection); + + KStandardAction::saveAs(this, SLOT(saveTutorialAs()), actionCollection); + + KAction* action = new KAction(this); + action->setText(i18nc("@action", "Export...")); + action->setStatusTip(i18nc("@info:status", "Exports the tutorial to a " +"script.")); + action->setIcon(KIcon("document-export")); + actionCollection->addAction("exportTutorial", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(exportTutorial())); +} + +//private slots: + +void FileActions::openTutorial() { + KUrl url = mTutorialUrl; + QPointer<KFileDialog> dialog = new KFileDialog(url, QString(), + mTutorialEditor); + + dialog->setCaption(i18nc("@title", "Open Tutorial")); + dialog->setOperationMode(KFileDialog::Opening); + dialog->setFilter(i18nc("@item:inlistbox A KFileDialog filter", + "*.xml|XML file")); + + if (dialog->exec() == QDialog::Rejected) { + return; + } + + loadTutorialFromUrl(dialog->selectedUrl()); +} + +bool FileActions::saveTutorial() { + if (mTutorialUrl.isEmpty()) { + return saveTutorialAs(); + } + + const Tutorial* tutorial = mTutorialEditor->tutorial(); + try { + Serialization(mTutorialEditor).saveTutorial(tutorial, mTutorialUrl); + } catch (IOException e) { + QString text = i18nc("@label", "There was a problem when trying to " +"save the tutorial:<nl/>%1", e.message()); + QString caption = i18nc("@title:window", "Tutorial could not be saved"); + KMessageBox::error(mTutorialEditor, text, caption); + return false; + } + + mTutorialEditor->setClean(); + + return true; +} + +bool FileActions::saveTutorialAs() { + const Tutorial* tutorial = mTutorialEditor->tutorial(); + + KUrl url = mTutorialUrl; + QPointer<KFileDialog> dialog = new KFileDialog(url, QString(), + mTutorialEditor); + + dialog->setSelection(tutorial->id()); + dialog->setCaption(i18nc("@title", "Save Tutorial")); + dialog->setOperationMode(KFileDialog::Saving); + dialog->setConfirmOverwrite(true); + dialog->setFilter(i18nc("@item:inlistbox A KFileDialog filter", + "*.xml|XML file")); + dialog->filterWidget()->setEditable(false); + + if (dialog->exec() == QDialog::Rejected) { + return false; + } + + try { + Serialization(mTutorialEditor).saveTutorial(tutorial, + dialog->selectedUrl()); + } catch (IOException e) { + QString text = i18nc("@label", "There was a problem when trying to " +"save the tutorial:<nl/>%1", e.message()); + QString caption = i18nc("@title:window", "Tutorial could not be saved"); + KMessageBox::error(mTutorialEditor, text, caption); + return false; + } + + mRecentFilesAction->addUrl(dialog->selectedUrl()); + mTutorialUrl = dialog->selectedUrl(); + mTutorialEditor->setClean(); + + return true; +} + +void FileActions::exportTutorial() { + const Tutorial* tutorial = mTutorialEditor->tutorial(); + + KUrl url; + QPointer<KFileDialog> dialog = new KFileDialog(url, QString(), + mTutorialEditor); + + dialog->setSelection(tutorial->id()); + dialog->setCaption(i18nc("@title", "Export Tutorial")); + dialog->setOperationMode(KFileDialog::Saving); + dialog->setConfirmOverwrite(true); + dialog->setFilter(Serialization(mTutorialEditor).availableExporterTypes()); + dialog->filterWidget()->setEditable(false); + + if (dialog->exec() == QDialog::Rejected) { + return; + } + + try { + Serialization(mTutorialEditor).exportTutorial(tutorial, + dialog->currentFilter(), + dialog->selectedUrl()); + } catch (IOException e) { + QString text = i18nc("@label", "There was a problem when trying to " +"save the exported tutorial:<nl/>%1", e.message()); + QString caption = i18nc("@title:window", "Exported tutorial could not " +"be saved"); + KMessageBox::error(mTutorialEditor, text, caption); + return; + } +} Property changes on: trunk/ktutorial/ktutorial-editor/src/FileActions.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/FileActions.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/FileActions.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/FileActions.h 2010-03-31 06:55:32 UTC (rev 223) @@ -0,0 +1,182 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#ifndef FILEACTIONS_H +#define FILEACTIONS_H + +#include <QObject> + +#include <KUrl> + +class KActionCollection; +class KRecentFilesAction; +class KTutorialEditor; + +/** + * File related actions. + * FileActions provide the actions that create a new tutorial, open an existing + * tutorial, open one of the recently opened tutorials, save the tutorial or + * export the tutorial. + * + * Note, however, that it does not provide a quit action (as it has more to do + * with the application as a whole than with the files). + * + * FileActions provides also the URL of the current tutorial, and a way to check + * whether it can be closed or not, warning the user if needed. + * + * FileActions works closely with KTutorialEditor. KTutorialEditor is used to + * know the tutorial and whether it is clean or not. FileActions provides the + * tutorial URL and methods to create a new tutorial, load a tutorial from an + * URL and check whether the current tutorial was modified after the last time + * it was saved or not. + * + * The KTutorialEditor window is also used as the parent for every dialog shown + * by the actions. + */ +class FileActions: public QObject { +Q_OBJECT +public: + + /** + * Creates a new FileActions for the given KTutorialEditor. + * All the actions are set up and added to the KTutorialEditor. + * + * @param tutorialEditor The KTutorialEditor to work with. + */ + explicit FileActions(KTutorialEditor* tutorialEditor); + + /** + * Destroys this FileActions. + * The entries in the recent files action are saved in the configuration. + */ + ~FileActions(); + + /** + * Returns the tutorial URL. + * + * @return The tutorial URL. + */ + const KUrl& tutorialUrl() const; + + /** + * Checks whether the current tutorial can be closed or not. + * If the tutorial is not clean, the user is asked if it has to be saved or + * not, or if the close operation should be cancelled. + * + * @return True if the tutorial can be closed, false otherwise. + */ + bool queryCloseTutorial(); + +public Q_SLOTS: + + /** + * Loads the tutorial to be edited from the given URL. + * The tutorial URL is updated and added to the recent files action, and a + * clean state is forced. + * An error message is shown if the tutorial could not be opened. + * + * Nothing is done if the current tutorial, if any, should not be closed. + * + * @param url The URL to load the tutorial from. + */ + void loadTutorialFromUrl(KUrl url); + + /** + * Creates a new empty tutorial replacing the current one, if any. + * The tutorial URL is cleared. + * + * Nothing is done if the current tutorial, if any, should not be closed. + */ + void newTutorial(); + + /** + * Enables or disables Save action based on the clean state of the stack. + * When the stack is clean and the tutorial has an associated URL, the Save + * action is disabled. Otherwise, it is enabled, so if there is no + * associated URL the Save action is always kept enabled, even if the stack + * is clean. + * + * @param clean Whether the undo stack entered clean state or not. + */ + void handleUndoStackCleanChanged(bool clean); + +private: + + /** + * The KTutorialEditor to work with. + */ + KTutorialEditor* mTutorialEditor; + + /** + * The URL to save the tutorial to. + */ + KUrl mTutorialUrl; + + /** + * True if the tutorial was not modified since the last time it was saved, + * false otherwise. + */ + bool mClean; + + /** + * The "Open Recent" action. + */ + KRecentFilesAction* mRecentFilesAction; + + /** + * Sets up all the file related actions. + */ + void setupActions(); + +private Q_SLOTS: + + /** + * Shows a KFileDialog to select the file to open the tutorial from. + * The tutorial is loaded from the URL selected by the user. + */ + void openTutorial(); + + /** + * Saves the tutorial to the tutorial URL. + * A clean state is set. If there is no tutorial URL it behaves like + * saveTutorialAs(). + * An error message is shown if the tutorial could not be saved. + * + * @return True if the tutorial was successfully saved, false otherwise. + */ + bool saveTutorial(); + + /** + * Shows a KFileDialog to select the file to save the tutorial to. + * The tutorial URL is updated and added to the recent files action, and a + * clean state is forced. + * An error message is shown if the tutorial could not be saved. + * + * @return True if the tutorial was successfully saved, false otherwise. + */ + bool saveTutorialAs(); + + /** + * Shows a KFileDialog to select the file to save the exported tutorial in. + * An error message is shown if the tutorial could not be saved. + */ + void exportTutorial(); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/FileActions.h ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-31 05:33:29 UTC (rev 222) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-31 06:55:32 UTC (rev 223) @@ -24,20 +24,15 @@ #include <KAction> #include <KActionCollection> #include <KApplication> -#include <KFileDialog> -#include <KFileFilterCombo> #include <KLocalizedString> -#include <KMessageBox> -#include <KRecentFilesAction> #include <KUndoStack> -#include <KIO/NetAccess> +#include "FileActions.h" #include "commands/StepCommands.h" #include "commands/TutorialCommands.h" #include "data/Reaction.h" #include "data/Step.h" #include "data/Tutorial.h" -#include "serialization/Serialization.h" #include "view/ActionListWidget.h" #include "view/AutoExpandableTreeView.h" #include "view/EditionDialog.h" @@ -64,100 +59,55 @@ mUndoStack = new KUndoStack(this); connect(mUndoStack, SIGNAL(cleanChanged(bool)), + this, SIGNAL(cleanChanged(bool))); + connect(this, SIGNAL(cleanChanged(bool)), this, SLOT(handleUndoStackCleanChanged(bool))); setupDocks(); setupActions(); - newTutorial(); + mFileActions->newTutorial(); setupGUI(); } -KTutorialEditor::~KTutorialEditor() { - mRecentFilesAction->saveEntries(KGlobal::config()->group("RecentFiles")); +Tutorial* KTutorialEditor::tutorial() { + return mTutorial; } -//public slots: - -//Don't use a reference to the URL, as if it is the argument in -//urlSelected(KUrl) signal emitted by mRecentFilesAction, it is removed in -//mRecentFilesAction->addUrl(KUrl), which leads to a crash -void KTutorialEditor::loadTutorialFromUrl(KUrl url) { - if (!queryCloseTutorial()) { - return; - } - - Tutorial* tutorial; - try { - tutorial = Serialization(this).loadTutorial(url); - } catch (IOException e) { - QString text = i18nc("@label", "There was a problem when trying to " -"open the file:<nl/>%1", e.message()); - QString caption = i18nc("@title:window", "File could not be read"); - KMessageBox::error(this, text, caption); - return; - } catch (DeserializationException e) { - QString text = i18nc("@label", "There was a problem when trying to " -"load the tutorial:<nl/>%1", e.message()); - QString caption = i18nc("@title:window", "Tutorial could not be " -"loaded"); - KMessageBox::error(this, text, caption); - return; - } - - setTutorialToBeEdited(tutorial); - mRecentFilesAction->addUrl(url); - mTutorialUrl = url; +void KTutorialEditor::setClean() { mUndoStack->setClean(); + //Force clean state, as setting an empty stack as clean would not emit //cleanChanged() handleUndoStackCleanChanged(true); + mFileActions->handleUndoStackCleanChanged(true); } +void KTutorialEditor::loadTutorialFromUrl(const KUrl& url) { + mFileActions->loadTutorialFromUrl(url); +} + //protected: bool KTutorialEditor::queryClose() { - return queryCloseTutorial(); + return mFileActions->queryCloseTutorial(); } void KTutorialEditor::readProperties(const KConfigGroup& configGroup) { KUrl url = configGroup.readEntry("TutorialUrl"); if (!url.isEmpty()) { - loadTutorialFromUrl(url); + mFileActions->loadTutorialFromUrl(url); } } void KTutorialEditor::saveProperties(KConfigGroup& configGroup) { - configGroup.writeEntry("TutorialUrl", mTutorialUrl); + configGroup.writeEntry("TutorialUrl", mFileActions->tutorialUrl()); } //private: -bool KTutorialEditor::queryCloseTutorial() { - if (mUndoStack->isClean()) { - return true; - } - - QString text = i18nc("@label", "The tutorial has been modified.<nl/>" -"Do you want to save your changes or discard them?"); - QString caption = i18nc("@title:window", "Close tutorial"); - int button = KMessageBox::warningYesNoCancel(this, text, caption, - KStandardGuiItem::save(), - KStandardGuiItem::discard()); - - if (button == KMessageBox::Cancel) { - return false; - } - - if (button == KMessageBox::Yes) { - return saveTutorial(); - } - - return true; -} - void KTutorialEditor::setTutorialToBeEdited(Tutorial* tutorial) { if (!tutorial) { tutorial = new Tutorial(this); @@ -214,26 +164,8 @@ } void KTutorialEditor::setupActions() { - KStandardAction::openNew(this, SLOT(newTutorial()), actionCollection()); + mFileActions = new FileActions(this); - KStandardAction::open(this, SLOT(openTutorial()), actionCollection()); - - mRecentFilesAction = KStandardAction::openRecent( - this, SLOT(loadTutorialFromUrl(KUrl)), actionCollection()); - mRecentFilesAction->loadEntries(KGlobal::config()->group("RecentFiles")); - - KStandardAction::save(this, SLOT(saveTutorial()), actionCollection()); - - KStandardAction::saveAs(this, SLOT(saveTutorialAs()), actionCollection()); - - KAction* action = new KAction(this); - action->setText(i18nc("@action", "Export...")); - action->setStatusTip(i18nc("@info:status", "Exports the tutorial to a " -"script.")); - action->setIcon(KIcon("document-export")); - actionCollection()->addAction("exportTutorial", action); - connect(action, SIGNAL(triggered(bool)), this, SLOT(exportTutorial())); - KStandardAction::quit(this, SLOT(close()), actionCollection()); mUndoStack->createUndoAction(actionCollection()); @@ -243,7 +175,7 @@ ActionListWidget* actionListWidget = new ActionListWidget(mTutorialActionDock); - action = new KAction(this); + KAction* action = new KAction(this); action->setText(i18nc("@action", "Set information...")); action->setStatusTip(i18nc("@info:status", "Set the name and description " "of the tutorial.")); @@ -377,12 +309,12 @@ } QString KTutorialEditor::captionFromTutorialUrl() { - if (mTutorialUrl.isEmpty()) { + if (mFileActions->tutorialUrl().isEmpty()) { return i18nc("@title:window Window title for KTutorial editor when the \ tutorial has no associated URL", "New file"); } - QString caption = mTutorialUrl.prettyUrl(); + QString caption = mFileActions->tutorialUrl().prettyUrl(); if (caption.length() > 64) { caption = "..." + caption.right(64); } @@ -441,126 +373,8 @@ setCaption(i18nc("@title:window Wrapper for the window title when the \ tutorial was modified but not saved yet", "%1 [not saved]", caption)); } - - if (clean && !mTutorialUrl.isEmpty()) { - actionCollection()->action("file_save")->setEnabled(false); - } else { - actionCollection()->action("file_save")->setEnabled(true); - } } -void KTutorialEditor::newTutorial() { - if (!queryCloseTutorial()) { - return; - } - - setTutorialToBeEdited(); - mTutorialUrl = KUrl(); - //Force clean state, as clearing an empty stack would not emit - //cleanChanged() - handleUndoStackCleanChanged(true); -} - -void KTutorialEditor::openTutorial() { - KUrl url = mTutorialUrl; - QPointer<KFileDialog> dialog = new KFileDialog(url, QString(), this); - - dialog->setCaption(i18nc("@title", "Open Tutorial")); - dialog->setOperationMode(KFileDialog::Opening); - dialog->setFilter(i18nc("@item:inlistbox A KFileDialog filter", - "*.xml|XML file")); - - if (dialog->exec() == QDialog::Rejected) { - return; - } - - loadTutorialFromUrl(dialog->selectedUrl()); -} - -bool KTutorialEditor::saveTutorial() { - if (mTutorialUrl.isEmpty()) { - return saveTutorialAs(); - } - - try { - Serialization(this).saveTutorial(mTutorial, mTutorialUrl); - } catch (IOException e) { - QString text = i18nc("@label", "There was a problem when trying to " -"save the tutorial:<nl/>%1", e.message()); - QString caption = i18nc("@title:window", "Tutorial could not be saved"); - KMessageBox::error(this, text, caption); - return false; - } - - mUndoStack->setClean(); - - return true; -} - -bool KTutorialEditor::saveTutorialAs() { - KUrl url = mTutorialUrl; - QPointer<KFileDialog> dialog = new KFileDialog(url, QString(), this); - - dialog->setSelection(mTutorial->id()); - dialog->setCaption(i18nc("@title", "Save Tutorial")); - dialog->setOperationMode(KFileDialog::Saving); - dialog->setConfirmOverwrite(true); - dialog->setFilter(i18nc("@item:inlistbox A KFileDialog filter", - "*.xml|XML file")); - dialog->filterWidget()->setEditable(false); - - if (dialog->exec() == QDialog::Rejected) { - return false; - } - - try { - Serialization(this).saveTutorial(mTutorial, dialog->selectedUrl()); - } catch (IOException e) { - QString text = i18nc("@label", "There was a problem when trying to " -"save the tutorial:<nl/>%1", e.message()); - QString caption = i18nc("@title:window", "Tutorial could not be saved"); - KMessageBox::error(this, text, caption); - return false; - } - - mRecentFilesAction->addUrl(dialog->selectedUrl()); - mTutorialUrl = dialog->selectedUrl(); - mUndoStack->setClean(); - //Force clean state, as setting an empty stack as clean would not emit - //cleanChanged() - handleUndoStackCleanChanged(true); - - return true; -} - -void KTutorialEditor::exportTutorial() { - KUrl url; - QPointer<KFileDialog> dialog = new KFileDialog(url, QString(), this); - - dialog->setSelection(mTutorial->id()); - dialog->setCaption(i18nc("@title", "Export Tutorial")); - dialog->setOperationMode(KFileDialog::Saving); - dialog->setConfirmOverwrite(true); - dialog->setFilter(Serialization(this).availableExporterTypes()); - dialog->filterWidget()->setEditable(false); - - if (dialog->exec() == QDialog::Rejected) { - return; - } - - try { - Serialization(this).exportTutorial(mTutorial, dialog->currentFilter(), - dialog->selectedUrl()); - } catch (IOException e) { - QString text = i18nc("@label", "There was a problem when trying to " -"save the exported tutorial:<nl/>%1", e.message()); - QString caption = i18nc("@title:window", "Exported tutorial could not " -"be saved"); - KMessageBox::error(this, text, caption); - return; - } -} - void KTutorialEditor::setTutorialInformation() { showEditionDialog(new TutorialInformationWidget(mTutorial)); } Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-31 05:33:29 UTC (rev 222) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-31 06:55:32 UTC (rev 223) @@ -24,7 +24,7 @@ class CommandWidget; class EditionWidget; -class KRecentFilesAction; +class FileActions; class KUndoStack; class QTreeView; class Reaction; @@ -45,25 +45,46 @@ KTutorialEditor(); /** - * Destroys this KTutorialEditor. - * The entries in the recent files action are saved in the configuration. + * Returns the tutorial being edited. + * + * @return The tutorial being edited. */ - virtual ~KTutorialEditor(); + Tutorial* tutorial(); -public Q_SLOTS: + /** + * Sets the tutorial as clean (not modified after the last time it was + * saved). + */ + void setClean(); /** * Loads the tutorial to be edited from the given URL. - * The tutorial URL is updated and added to the recent files action, and a - * clean state is forced. - * An error message is shown if the tutorial couldn't be opened. * - * Nothing is done if the current tutorial, if any, should not be closed. - * * @param url The URL to load the tutorial from. + * @see FileActions::loadTutorialFromUrl(KUrl) */ - void loadTutorialFromUrl(KUrl url); + void loadTutorialFromUrl(const KUrl& url); + /** + * Sets the tutorial to be edited. + * It creates a new tutorial, prepares the tree view to represent it and + * handles the selection of items. + * + * If the tutorial is null, a new empty tutorial is set. + * + * @param tutorial The tutorial to set. + */ + void setTutorialToBeEdited(Tutorial* tutorial = 0); + +Q_SIGNALS: + + /** + * Emitted when the clean state changes. + * + * @param clean True if the tutorial is clean, false otherwise. + */ + void cleanChanged(bool clean); + protected: /** @@ -120,9 +141,9 @@ QDockWidget* mReactionActionDock; /** - * The "Open Recent" action. + * The file related actions and data. */ - KRecentFilesAction* mRecentFilesAction; + FileActions* mFileActions; /** * The stack of undoable commands. @@ -135,11 +156,6 @@ Tutorial* mTutorial; /** - * The URL to save the tutorial to. - */ - KUrl mTutorialUrl; - - /** * The currently selected step. */ Step* mCurrentStep; @@ -150,26 +166,6 @@ Reaction* mCurrentReaction; /** - * Checks whether the tutorial can be closed or not. - * If the tutorial is not clean, the user is asked if it has to be saved or - * not, or if the close operation should be cancelled. - * - * @return True if the tutorial can be closed, false otherwise. - */ - bool queryCloseTutorial(); - - /** - * Sets the tutorial to be edited. - * It creates a new tutorial, prepares the tree view to represent it and - * handles the selection of items. - * - * If the tutorial is null, a new empty tutorial is set. - * - * @param tutorial The tutorial to set. - */ - void setTutorialToBeEdited(Tutorial* tutorial = 0); - - /** * Sets up the dock widgets. */ void setupDocks(); @@ -218,62 +214,16 @@ void selectReaction(Reaction* reaction); /** - * Modifies the caption and enables or disables Save action based on the - * clean state of the stack. + * Modifies the caption based on the clean state of the stack. * When the stack is not clean, "[not saved]" is added after the caption * (the URL or "New file", depending on the case). Otherwise, the caption is * the URL associated to the tutorial. * - * When the stack is clean and the tutorial has an associated URL, the Save - * action is disabled. Otherwise, it is enabled, so if there is no - * associated URL the Save action is always kept enabled, even if the stack - * is clean. - * * @param clean Whether the undo stack entered clean state or not. */ void handleUndoStackCleanChanged(bool clean); /** - * Creates a new empty tutorial replacing the current one, if any. - * The tutorial URL is cleared. - * - * Nothing is done if the current tutorial, if any, should not be closed. - */ - void newTutorial(); - - /** - * Shows a KFileDialog to select the file to open the tutorial from. - * The tutorial is loaded from the URL selected by the user. - */ - void openTutorial(); - - /** - * Saves the tutorial to the tutorial URL. - * A clean state is set. If there is no tutorial URL it behaves like - * saveTutorialAs(). - * An error message is shown if the tutorial couldn't be saved. - * - * @return True if the tutorial was successfully saved, false otherwise. - */ - bool saveTutorial(); - - /** - * Shows a KFileDialog to select the file to save the tutorial to. - * The tutorial URL is updated and added to the recent files action, and a - * clean state is forced. - * An error message is shown if the tutorial couldn't be saved. - * - * @return True if the tutorial was successfully saved, false otherwise. - */ - bool saveTutorialAs(); - - /** - * Shows a KFileDialog to select the file to save the exported tutorial in. - * An error message is shown if the tutorial couldn't be saved. - */ - void exportTutorial(); - - /** * Shows a TutorialInformationWidget for the tutorial. */ void setTutorialInformation(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-03-31 16:21:50
|
Revision: 225 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=225&view=rev Author: danxuliu Date: 2010-03-31 16:21:39 +0000 (Wed, 31 Mar 2010) Log Message: ----------- Refactor KTutorialEditor class to extract edition related actions to its own class, EditActions. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h Added Paths: ----------- trunk/ktutorial/ktutorial-editor/src/EditActions.cpp trunk/ktutorial/ktutorial-editor/src/EditActions.h Modified: trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-31 06:58:14 UTC (rev 224) +++ trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-31 16:21:39 UTC (rev 225) @@ -10,6 +10,7 @@ add_subdirectory(view) set(ktutorial_editor_SRCS + EditActions.cpp Exception.cpp FileActions.cpp KTutorialEditor.cpp Added: trunk/ktutorial/ktutorial-editor/src/EditActions.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/EditActions.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/EditActions.cpp 2010-03-31 16:21:39 UTC (rev 225) @@ -0,0 +1,307 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include "EditActions.h" + +#include <KAction> +#include <KActionCollection> +#include <KLocalizedString> +#include <KUndoStack> + +#include "KTutorialEditor.h" +#include "commands/StepCommands.h" +#include "commands/TutorialCommands.h" +#include "data/Reaction.h" +#include "data/Step.h" +#include "view/EditionDialog.h" +#include "view/LicenseWidget.h" +#include "view/ReactionWidget.h" +#include "view/StepCustomCodeWidget.h" +#include "view/StepDataWidget.h" +#include "view/TutorialCustomCodeWidget.h" +#include "view/TutorialInformationWidget.h" + +//public: + +EditActions::EditActions(KTutorialEditor* tutorialEditor): + QObject(tutorialEditor), + mTutorialEditor(tutorialEditor), + mCurrentStep(0), + mCurrentReaction(0) { + + mUndoStack = new KUndoStack(this); + connect(mUndoStack, SIGNAL(cleanChanged(bool)), + this, SIGNAL(cleanChanged(bool))); + + setupActions(); +} + +void EditActions::clearCommands() { + mUndoStack->clear(); +} + +void EditActions::setClean() { + mUndoStack->setClean(); +} + +//public slots: + +void EditActions::selectStep(Step* step) { + mCurrentStep = step; + + KActionCollection* actionCollection = mTutorialEditor->actionCollection(); + if (mCurrentStep) { + actionCollection->action("setStepData")->setEnabled(true); + actionCollection->action("setStepSetup")->setEnabled(true); + actionCollection->action("setStepTearDown")->setEnabled(true); + actionCollection->action("removeStep")->setEnabled(true); + actionCollection->action("addReaction")->setEnabled(true); + } else { + actionCollection->action("setStepData")->setEnabled(false); + actionCollection->action("setStepSetup")->setEnabled(false); + actionCollection->action("setStepTearDown")->setEnabled(false); + actionCollection->action("removeStep")->setEnabled(false); + actionCollection->action("addReaction")->setEnabled(false); + } +} + +void EditActions::selectReaction(Reaction* reaction) { + mCurrentReaction = reaction; + + KActionCollection* actionCollection = mTutorialEditor->actionCollection(); + if (mCurrentReaction) { + actionCollection->action("setReactionData")->setEnabled(true); + actionCollection->action("removeReaction")->setEnabled(true); + } else { + actionCollection->action("setReactionData")->setEnabled(false); + actionCollection->action("removeReaction")->setEnabled(false); + } +} + +//private: + +void EditActions::setupActions() { + KActionCollection* actionCollection = mTutorialEditor->actionCollection(); + + mUndoStack->createUndoAction(actionCollection); + + mUndoStack->createRedoAction(actionCollection); + + KAction* action = new KAction(this); + action->setText(i18nc("@action", "Set information...")); + action->setStatusTip(i18nc("@info:status", "Set the name and description " +"of the tutorial.")); + action->setIcon(KIcon("documentinfo")); + actionCollection->addAction("setTutorialInformation", action); + connect(action, SIGNAL(triggered(bool)), + this, SLOT(setTutorialInformation())); + + action = new KAction(this); + action->setText(i18nc("@action", "Set license...")); + action->setStatusTip(i18nc("@info:status", "Set the license text of the " +"tutorial.")); + action->setIcon(KIcon("document-edit")); + actionCollection->addAction("setTutorialLicense", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(setTutorialLicense())); + + action = new KAction(this); + action->setText(i18nc("@action", "Set setup code...")); + action->setStatusTip(i18nc("@info:status", "Set the custom code to be " +"executed when the tutorial starts.")); + action->setIcon(KIcon("code-function")); + actionCollection->addAction("setTutorialSetup", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(setTutorialSetup())); + + action = new KAction(this); + action->setText(i18nc("@action", "Set tear down code...")); + action->setStatusTip(i18nc("@info:status", "Set the custom code to be " +"executed when the tutorial finishes.")); + action->setIcon(KIcon("code-function")); + actionCollection->addAction("setTutorialTearDown", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(setTutorialTearDown())); + + action = new KAction(this); + action->setText(i18nc("@action", "Add step...")); + action->setStatusTip(i18nc("@info:status", "Add a new step to the " +"tutorial.")); + action->setIcon(KIcon("list-add")); + actionCollection->addAction("addStep", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(addStep())); + + action = new KAction(this); + action->setText(i18nc("@action", "Set data...")); + action->setStatusTip(i18nc("@info:status", "Set the name and text of the " +"currently selected step.")); + action->setIcon(KIcon("document-edit")); + action->setEnabled(false); + actionCollection->addAction("setStepData", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(setStepData())); + + action = new KAction(this); + action->setText(i18nc("@action", "Set setup code...")); + action->setStatusTip(i18nc("@info:status", "Set the custom code to be " +"executed when the tutorial passes to the currently selected step.")); + action->setIcon(KIcon("code-function")); + action->setEnabled(false); + actionCollection->addAction("setStepSetup", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(setStepSetup())); + + action = new KAction(this); + action->setText(i18nc("@action", "Set tear down code...")); + action->setStatusTip(i18nc("@info:status", "Set the custom code to be " +"executed when the tutorial changes from the currently selected step to " +"another step.")); + action->setIcon(KIcon("code-function")); + action->setEnabled(false); + actionCollection->addAction("setStepTearDown", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(setStepTearDown())); + + action = new KAction(this); + action->setText(i18nc("@action", "Remove step")); + action->setStatusTip(i18nc("@info:status", "Removes the currently selected " +"step from the tutorial.")); + action->setIcon(KIcon("list-remove")); + action->setEnabled(false); + actionCollection->addAction("removeStep", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(removeStep())); + + action = new KAction(this); + action->setText(i18nc("@action", "Add reaction...")); + action->setStatusTip(i18nc("@info:status", "Add a new reaction to the " +"selected step.")); + action->setIcon(KIcon("list-add")); + action->setEnabled(false); + actionCollection->addAction("addReaction", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(addReaction())); + + action = new KAction(this); + action->setText(i18nc("@action", "Set data...")); + action->setStatusTip(i18nc("@info:status", "Set the trigger and the " +"response of the currently selected reaction.")); + action->setIcon(KIcon("document-edit")); + action->setEnabled(false); + actionCollection->addAction("setReactionData", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(setReactionData())); + + action = new KAction(this); + action->setText(i18nc("@action", "Remove reaction")); + action->setStatusTip(i18nc("@info:status", "Removes the currently selected " +"reaction from its step.")); + action->setIcon(KIcon("list-remove")); + action->setEnabled(false); + actionCollection->addAction("removeReaction", action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(removeReaction())); +} + +int EditActions::showEditionDialog(CommandWidget* commandWidget) { + commandWidget->setUndoStack(mUndoStack); + + EditionDialog* dialog = new EditionDialog(commandWidget, mTutorialEditor); + dialog->setObjectName("editionDialog"); + int dialogCode = dialog->exec(); + dialog->deleteLater(); + + return dialogCode; +} + +//private slots: + +void EditActions::setTutorialInformation() { + showEditionDialog(new TutorialInformationWidget( + mTutorialEditor->tutorial())); +} + +void EditActions::setTutorialLicense() { + showEditionDialog(new LicenseWidget(mTutorialEditor->tutorial())); +} + +void EditActions::setTutorialSetup() { + showEditionDialog(new TutorialCustomCodeWidget(mTutorialEditor->tutorial(), + TutorialCustomCodeWidget::Setup)); +} + +void EditActions::setTutorialTearDown() { + showEditionDialog(new TutorialCustomCodeWidget(mTutorialEditor->tutorial(), + TutorialCustomCodeWidget::TearDown)); +} + +void EditActions::addStep() { + Step* step = new Step(); + + QUndoCommand* parentCommand = new QUndoCommand(); + parentCommand->setText(i18nc("@action", "Add step")); + TutorialCommands(mTutorialEditor->tutorial()).addStep(step, parentCommand); + + CommandWidget* widget = new StepDataWidget(step); + widget->setParentUndoCommand(parentCommand); + if (showEditionDialog(widget) == QDialog::Rejected) { + delete parentCommand; + } +} + +void EditActions::setStepData() { + Q_ASSERT(mCurrentStep); + + showEditionDialog(new StepDataWidget(mCurrentStep)); +} + +void EditActions::setStepSetup() { + showEditionDialog(new StepCustomCodeWidget(mCurrentStep, + StepCustomCodeWidget::Setup)); +} + +void EditActions::setStepTearDown() { + showEditionDialog(new StepCustomCodeWidget(mCurrentStep, + StepCustomCodeWidget::TearDown)); +} + +void EditActions::removeStep() { + Q_ASSERT(mCurrentStep); + + TutorialCommands tutorialCommands(mTutorialEditor->tutorial()); + mUndoStack->push(tutorialCommands.removeStep(mCurrentStep)); +} + +void EditActions::addReaction() { + Q_ASSERT(mCurrentStep); + + Reaction* reaction = new Reaction(); + + QUndoCommand* parentCommand = new QUndoCommand(); + parentCommand->setText(i18nc("@action", "Add reaction")); + StepCommands(mCurrentStep).addReaction(reaction, parentCommand); + + CommandWidget* widget = new ReactionWidget(reaction); + widget->setParentUndoCommand(parentCommand); + if (showEditionDialog(widget) == QDialog::Rejected) { + delete parentCommand; + } +} + +void EditActions::setReactionData() { + Q_ASSERT(mCurrentReaction); + + showEditionDialog(new ReactionWidget(mCurrentReaction)); +} + +void EditActions::removeReaction() { + Q_ASSERT(mCurrentStep); + + mUndoStack->push(StepCommands(mCurrentStep).removeReaction( + mCurrentReaction)); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/EditActions.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/EditActions.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/EditActions.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/EditActions.h 2010-03-31 16:21:39 UTC (rev 225) @@ -0,0 +1,200 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#ifndef EDITACTIONS_H +#define EDITACTIONS_H + +#include <QObject> + +class CommandWidget; +class KTutorialEditor; +class KUndoStack; +class Reaction; +class Step; + +/** + * Edition related actions. + * EditActions provide the actions to edit a tutorial (set the setup code, add a + * step...), and also actions to undo and redo the edition. + * + * KTutorialEditor notifies EditActions when a step or reaction is selected, so + * it can know which step or reaction have to be edited. EditActions provides + * information about whether the tutorial is clean (not modified after the last + * time it was saved) or not, and allows to clear the command stack (for + * example, when a new file is opened) or set it as clean. + * + * The KTutorialEditor window is also used as the parent for every dialog shown + * by the actions. + */ +class EditActions: public QObject { +Q_OBJECT +public: + + /** + * Creates a new EditActions for the given KTutorialEditor. + * All the actions are set up and added to the KTutorialEditor. + * + * @param tutorialEditor The KTutorialEditor to work with. + */ + explicit EditActions(KTutorialEditor* tutorialEditor); + +public: + + /** + * Clears the stack of undoable commands. + */ + void clearCommands(); + + /** + * Sets the tutorial as clean. + */ + void setClean(); + +public Q_SLOTS: + + /** + * Sets the current step and enables or disables the actions that depend on + * a step as needed. + * + * @param step The step to select, or null to deselect the current one. + */ + void selectStep(Step* step); + + /** + * Sets the current reaction and enables or disables the actions that depend + * on a reaction as needed. + * + * @param reaction The reaction to select, or null to deselect the current + * one. + */ + void selectReaction(Reaction* reaction); + +Q_SIGNALS: + + /** + * Emitted when the clean state changes. + * + * @param clean True if the tutorial is clean, false otherwise. + */ + void cleanChanged(bool clean); + +private: + + /** + * The KTutorialEditor to work with. + */ + KTutorialEditor* mTutorialEditor; + + /** + * The stack of undoable commands. + */ + KUndoStack* mUndoStack; + + /** + * The currently selected step. + */ + Step* mCurrentStep; + + /** + * The currently selected reaction. + */ + Reaction* mCurrentReaction; + + /** + * Sets up all the edit related actions. + */ + void setupActions(); + + /** + * Shows an EditionDialog for the given CommandWidget. + * The undo stack used in the CommandWidget is mUndoStack. + * + * @param commandWidget The CommandWidget to wrap. + * @return QDialog::Accepted if the dialog was accepted, or + * QDialog::Rejected if the dialog was rejected. + */ + int showEditionDialog(CommandWidget* commandWidget); + +private Q_SLOTS: + + /** + * Shows a TutorialInformationWidget for the tutorial. + */ + void setTutorialInformation(); + + /** + * Shows a LicenseWidget for the tutorial. + */ + void setTutorialLicense(); + + /** + * Shows a TutorialCustomCodeWidget for the setup code of the tutorial. + */ + void setTutorialSetup(); + + /** + * Shows a TutorialCustomCodeWidget for the tear down code of the tutorial. + */ + void setTutorialTearDown(); + + /** + * Adds a new step to the tutorial after showing a StepDataWidget for it. + * The step isn't added if the dialog is cancelled. + */ + void addStep(); + + /** + * Shows a StepDataWidget for the current step. + */ + void setStepData(); + + /** + * Shows a StepCustomCodeWidget for the setup code of the current step. + */ + void setStepSetup(); + + /** + * Shows a StepCustomCodeWidget for the tear down code of the current step. + */ + void setStepTearDown(); + + /** + * Removes the current step from the tutorial. + */ + void removeStep(); + + /** + * Adds a new reaction to the current step after showing a ReactionWidget + * for it. + * The reaction isn't added if the dialog is cancelled. + */ + void addReaction(); + + /** + * Shows a ReactionWidget for the current reaction. + */ + void setReactionData(); + + /** + * Removes the current reaction from its step. + */ + void removeReaction(); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/EditActions.h ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-31 06:58:14 UTC (rev 224) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-31 16:21:39 UTC (rev 225) @@ -19,54 +19,45 @@ #include "KTutorialEditor.h" #include <QDockWidget> -#include <QTreeView> #include <KAction> #include <KActionCollection> #include <KApplication> +#include <KConfigGroup> #include <KLocalizedString> -#include <KUndoStack> +#include "EditActions.h" #include "FileActions.h" -#include "commands/StepCommands.h" -#include "commands/TutorialCommands.h" -#include "data/Reaction.h" -#include "data/Step.h" #include "data/Tutorial.h" #include "view/ActionListWidget.h" #include "view/AutoExpandableTreeView.h" -#include "view/EditionDialog.h" -#include "view/LicenseWidget.h" -#include "view/ReactionWidget.h" -#include "view/StepCustomCodeWidget.h" -#include "view/StepDataWidget.h" #include "view/TreeModel.h" -#include "view/TutorialCustomCodeWidget.h" -#include "view/TutorialInformationWidget.h" #include "view/TutorialTreeItem.h" #include "view/TutorialTreeSelectionManager.h" //public: KTutorialEditor::KTutorialEditor(): KXmlGuiWindow(0), - mTutorial(0), - mCurrentStep(0), - mCurrentReaction(0) { + mTutorial(0) { mTreeView = new AutoExpandableTreeView(); mTreeView->setObjectName("centralTreeView"); setCentralWidget(mTreeView); - mUndoStack = new KUndoStack(this); - connect(mUndoStack, SIGNAL(cleanChanged(bool)), + setupDocks(); + + setupActions(); + + connect(mEditActions, SIGNAL(cleanChanged(bool)), this, SIGNAL(cleanChanged(bool))); connect(this, SIGNAL(cleanChanged(bool)), this, SLOT(handleUndoStackCleanChanged(bool))); - setupDocks(); + //The actions can not be added in setupDocks because setupActions() needs + //the docks to be created (to get their toggleAction), so it can be called + //before setupDocks(). + setupActionListWidgets(); - setupActions(); - mFileActions->newTutorial(); setupGUI(); @@ -77,7 +68,7 @@ } void KTutorialEditor::setClean() { - mUndoStack->setClean(); + mEditActions->setClean(); //Force clean state, as setting an empty stack as clean would not emit //cleanChanged() @@ -137,11 +128,11 @@ new TutorialTreeSelectionManager(mTreeView->selectionModel(), mTreeView->selectionModel()); connect(selectionManager, SIGNAL(stepSelected(Step*)), - this, SLOT(selectStep(Step*))); + mEditActions, SLOT(selectStep(Step*))); connect(selectionManager, SIGNAL(reactionSelected(Reaction*)), - this, SLOT(selectReaction(Reaction*))); + mEditActions, SLOT(selectReaction(Reaction*))); - mUndoStack->clear(); + mEditActions->clearCommands(); delete mTutorial; mTutorial = tutorial; @@ -168,144 +159,63 @@ KStandardAction::quit(this, SLOT(close()), actionCollection()); - mUndoStack->createUndoAction(actionCollection()); + mEditActions = new EditActions(this); - mUndoStack->createRedoAction(actionCollection()); + actionCollection()->addAction("showEditTutorialDock", + mTutorialActionDock->toggleViewAction()); + actionCollection()->addAction("showEditStepDock", + mStepActionDock->toggleViewAction()); + actionCollection()->addAction("showEditReactionDock", + mReactionActionDock->toggleViewAction()); +} +void KTutorialEditor::setupActionListWidgets() { ActionListWidget* actionListWidget = new ActionListWidget(mTutorialActionDock); - KAction* action = new KAction(this); - action->setText(i18nc("@action", "Set information...")); - action->setStatusTip(i18nc("@info:status", "Set the name and description " -"of the tutorial.")); - action->setIcon(KIcon("documentinfo")); - actionCollection()->addAction("setTutorialInformation", action); - connect(action, SIGNAL(triggered(bool)), - this, SLOT(setTutorialInformation())); + QAction* action = actionCollection()->action("setTutorialInformation"); actionListWidget->addAction(action); - action = new KAction(this); - action->setText(i18nc("@action", "Set license...")); - action->setStatusTip(i18nc("@info:status", "Set the license text of the " -"tutorial.")); - action->setIcon(KIcon("document-edit")); - actionCollection()->addAction("setTutorialLicense", action); - connect(action, SIGNAL(triggered(bool)), this, SLOT(setTutorialLicense())); + action = actionCollection()->action("setTutorialLicense"); actionListWidget->addAction(action); - action = new KAction(this); - action->setText(i18nc("@action", "Set setup code...")); - action->setStatusTip(i18nc("@info:status", "Set the custom code to be " -"executed when the tutorial starts.")); - action->setIcon(KIcon("code-function")); - actionCollection()->addAction("setTutorialSetup", action); - connect(action, SIGNAL(triggered(bool)), this, SLOT(setTutorialSetup())); + action = actionCollection()->action("setTutorialSetup"); actionListWidget->addAction(action); - action = new KAction(this); - action->setText(i18nc("@action", "Set tear down code...")); - action->setStatusTip(i18nc("@info:status", "Set the custom code to be " -"executed when the tutorial finishes.")); - action->setIcon(KIcon("code-function")); - actionCollection()->addAction("setTutorialTearDown", action); - connect(action, SIGNAL(triggered(bool)), this, SLOT(setTutorialTearDown())); + action = actionCollection()->action("setTutorialTearDown"); actionListWidget->addAction(action); mTutorialActionDock->setWidget(actionListWidget); actionListWidget = new ActionListWidget(mStepActionDock); - action = new KAction(this); - action->setText(i18nc("@action", "Add step...")); - action->setStatusTip(i18nc("@info:status", "Add a new step to the " -"tutorial.")); - action->setIcon(KIcon("list-add")); - actionCollection()->addAction("addStep", action); - connect(action, SIGNAL(triggered(bool)), this, SLOT(addStep())); + action = actionCollection()->action("addStep"); actionListWidget->addAction(action); - action = new KAction(this); - action->setText(i18nc("@action", "Set data...")); - action->setStatusTip(i18nc("@info:status", "Set the name and text of the " -"currently selected step.")); - action->setIcon(KIcon("document-edit")); - action->setEnabled(false); - actionCollection()->addAction("setStepData", action); - connect(action, SIGNAL(triggered(bool)), this, SLOT(setStepData())); + action = actionCollection()->action("setStepData"); actionListWidget->addAction(action); - action = new KAction(this); - action->setText(i18nc("@action", "Set setup code...")); - action->setStatusTip(i18nc("@info:status", "Set the custom code to be " -"executed when the tutorial passes to the currently selected step.")); - action->setIcon(KIcon("code-function")); - action->setEnabled(false); - actionCollection()->addAction("setStepSetup", action); - connect(action, SIGNAL(triggered(bool)), this, SLOT(setStepSetup())); + action = actionCollection()->action("setStepSetup"); actionListWidget->addAction(action); - action = new KAction(this); - action->setText(i18nc("@action", "Set tear down code...")); - action->setStatusTip(i18nc("@info:status", "Set the custom code to be " -"executed when the tutorial changes from the currently selected step to " -"another step.")); - action->setIcon(KIcon("code-function")); - action->setEnabled(false); - actionCollection()->addAction("setStepTearDown", action); - connect(action, SIGNAL(triggered(bool)), this, SLOT(setStepTearDown())); + action = actionCollection()->action("setStepTearDown"); actionListWidget->addAction(action); - action = new KAction(this); - action->setText(i18nc("@action", "Remove step")); - action->setStatusTip(i18nc("@info:status", "Removes the currently selected " -"step from the tutorial.")); - action->setIcon(KIcon("list-remove")); - action->setEnabled(false); - actionCollection()->addAction("removeStep", action); - connect(action, SIGNAL(triggered(bool)), this, SLOT(removeStep())); + action = actionCollection()->action("removeStep"); actionListWidget->addAction(action); mStepActionDock->setWidget(actionListWidget); actionListWidget = new ActionListWidget(mReactionActionDock); - action = new KAction(this); - action->setText(i18nc("@action", "Add reaction...")); - action->setStatusTip(i18nc("@info:status", "Add a new reaction to the " -"selected step.")); - action->setIcon(KIcon("list-add")); - action->setEnabled(false); - actionCollection()->addAction("addReaction", action); - connect(action, SIGNAL(triggered(bool)), this, SLOT(addReaction())); + action = actionCollection()->action("addReaction"); actionListWidget->addAction(action); - action = new KAction(this); - action->setText(i18nc("@action", "Set data...")); - action->setStatusTip(i18nc("@info:status", "Set the trigger and the " -"response of the currently selected reaction.")); - action->setIcon(KIcon("document-edit")); - action->setEnabled(false); - actionCollection()->addAction("setReactionData", action); - connect(action, SIGNAL(triggered(bool)), this, SLOT(setReactionData())); + action = actionCollection()->action("setReactionData"); actionListWidget->addAction(action); - action = new KAction(this); - action->setText(i18nc("@action", "Remove reaction")); - action->setStatusTip(i18nc("@info:status", "Removes the currently selected " -"reaction from its step.")); - action->setIcon(KIcon("list-remove")); - action->setEnabled(false); - actionCollection()->addAction("removeReaction", action); - connect(action, SIGNAL(triggered(bool)), this, SLOT(removeReaction())); + action = actionCollection()->action("removeReaction"); actionListWidget->addAction(action); mReactionActionDock->setWidget(actionListWidget); - - actionCollection()->addAction("showEditTutorialDock", - mTutorialActionDock->toggleViewAction()); - actionCollection()->addAction("showEditStepDock", - mStepActionDock->toggleViewAction()); - actionCollection()->addAction("showEditReactionDock", - mReactionActionDock->toggleViewAction()); } QString KTutorialEditor::captionFromTutorialUrl() { @@ -322,49 +232,8 @@ return caption; } -int KTutorialEditor::showEditionDialog(CommandWidget* commandWidget) { - commandWidget->setUndoStack(mUndoStack); - - EditionDialog* dialog = new EditionDialog(commandWidget, this); - dialog->setObjectName("editionDialog"); - int dialogCode = dialog->exec(); - dialog->deleteLater(); - - return dialogCode; -} - //private slots: -void KTutorialEditor::selectStep(Step* step) { - mCurrentStep = step; - - if (mCurrentStep) { - actionCollection()->action("setStepData")->setEnabled(true); - actionCollection()->action("setStepSetup")->setEnabled(true); - actionCollection()->action("setStepTearDown")->setEnabled(true); - actionCollection()->action("removeStep")->setEnabled(true); - actionCollection()->action("addReaction")->setEnabled(true); - } else { - actionCollection()->action("setStepData")->setEnabled(false); - actionCollection()->action("setStepSetup")->setEnabled(false); - actionCollection()->action("setStepTearDown")->setEnabled(false); - actionCollection()->action("removeStep")->setEnabled(false); - actionCollection()->action("addReaction")->setEnabled(false); - } -} - -void KTutorialEditor::selectReaction(Reaction* reaction) { - mCurrentReaction = reaction; - - if (mCurrentReaction) { - actionCollection()->action("setReactionData")->setEnabled(true); - actionCollection()->action("removeReaction")->setEnabled(true); - } else { - actionCollection()->action("setReactionData")->setEnabled(false); - actionCollection()->action("removeReaction")->setEnabled(false); - } -} - void KTutorialEditor::handleUndoStackCleanChanged(bool clean) { QString caption = captionFromTutorialUrl(); if (clean) { @@ -374,86 +243,3 @@ tutorial was modified but not saved yet", "%1 [not saved]", caption)); } } - -void KTutorialEditor::setTutorialInformation() { - showEditionDialog(new TutorialInformationWidget(mTutorial)); -} - -void KTutorialEditor::setTutorialLicense() { - showEditionDialog(new LicenseWidget(mTutorial)); -} - -void KTutorialEditor::setTutorialSetup() { - showEditionDialog(new TutorialCustomCodeWidget(mTutorial, - TutorialCustomCodeWidget::Setup)); -} - -void KTutorialEditor::setTutorialTearDown() { - showEditionDialog(new TutorialCustomCodeWidget(mTutorial, - TutorialCustomCodeWidget::TearDown)); -} - -void KTutorialEditor::addStep() { - Step* step = new Step(); - - QUndoCommand* parentCommand = new QUndoCommand(); - parentCommand->setText(i18nc("@action", "Add step")); - TutorialCommands(mTutorial).addStep(step, parentCommand); - - CommandWidget* widget = new StepDataWidget(step); - widget->setParentUndoCommand(parentCommand); - if (showEditionDialog(widget) == QDialog::Rejected) { - delete parentCommand; - } -} - -void KTutorialEditor::setStepData() { - Q_ASSERT(mCurrentStep); - - showEditionDialog(new StepDataWidget(mCurrentStep)); -} - -void KTutorialEditor::setStepSetup() { - showEditionDialog(new StepCustomCodeWidget(mCurrentStep, - StepCustomCodeWidget::Setup)); -} - -void KTutorialEditor::setStepTearDown() { - showEditionDialog(new StepCustomCodeWidget(mCurrentStep, - StepCustomCodeWidget::TearDown)); -} - -void KTutorialEditor::removeStep() { - Q_ASSERT(mCurrentStep); - - mUndoStack->push(TutorialCommands(mTutorial).removeStep(mCurrentStep)); -} - -void KTutorialEditor::addReaction() { - Q_ASSERT(mCurrentStep); - - Reaction* reaction = new Reaction(); - - QUndoCommand* parentCommand = new QUndoCommand(); - parentCommand->setText(i18nc("@action", "Add reaction")); - StepCommands(mCurrentStep).addReaction(reaction, parentCommand); - - CommandWidget* widget = new ReactionWidget(reaction); - widget->setParentUndoCommand(parentCommand); - if (showEditionDialog(widget) == QDialog::Rejected) { - delete parentCommand; - } -} - -void KTutorialEditor::setReactionData() { - Q_ASSERT(mCurrentReaction); - - showEditionDialog(new ReactionWidget(mCurrentReaction)); -} - -void KTutorialEditor::removeReaction() { - Q_ASSERT(mCurrentStep); - - mUndoStack->push(StepCommands(mCurrentStep).removeReaction( - mCurrentReaction)); -} Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-31 06:58:14 UTC (rev 224) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-31 16:21:39 UTC (rev 225) @@ -22,13 +22,9 @@ #include <KXmlGuiWindow> #include <KUrl> -class CommandWidget; -class EditionWidget; +class EditActions; class FileActions; -class KUndoStack; class QTreeView; -class Reaction; -class Step; class Tutorial; /** @@ -146,9 +142,9 @@ FileActions* mFileActions; /** - * The stack of undoable commands. + * The edit related actions and data. */ - KUndoStack* mUndoStack; + EditActions* mEditActions; /** * The tutorial being edited. @@ -156,16 +152,6 @@ Tutorial* mTutorial; /** - * The currently selected step. - */ - Step* mCurrentStep; - - /** - * The currently selected reaction. - */ - Reaction* mCurrentReaction; - - /** * Sets up the dock widgets. */ void setupDocks(); @@ -176,6 +162,11 @@ void setupActions(); /** + * Sets up the widgets to show the actions in the docks. + */ + void setupActionListWidgets(); + + /** * Returns a caption (window title) string based on the tutorial URL. * The caption contains the URL, which is truncated if it is too lengthy. If * the URL is empty, "New file" is returned. @@ -184,36 +175,9 @@ */ QString captionFromTutorialUrl(); - /** - * Shows an EditionDialog for the given CommandWidget. - * The undo stack used in the CommandWidget is mUndoStack. - * - * @param commandWidget The CommandWidget to wrap. - * @return QDialog::Accepted if the dialog was accepted, or - * QDialog::Rejected if the dialog was rejected. - */ - int showEditionDialog(CommandWidget* commandWidget); - private Q_SLOTS: /** - * Sets the current step and enables or disables the actions that depend on - * a step as needed. - * - * @param step The step to select, or null to deselect the current one. - */ - void selectStep(Step* step); - - /** - * Sets the current reaction and enables or disables the actions that depend - * on a reaction as needed. - * - * @param reaction The reaction to select, or null to deselect the current - * one. - */ - void selectReaction(Reaction* reaction); - - /** * Modifies the caption based on the clean state of the stack. * When the stack is not clean, "[not saved]" is added after the caption * (the URL or "New file", depending on the case). Otherwise, the caption is @@ -223,69 +187,6 @@ */ void handleUndoStackCleanChanged(bool clean); - /** - * Shows a TutorialInformationWidget for the tutorial. - */ - void setTutorialInformation(); - - /** - * Shows a LicenseWidget for the tutorial. - */ - void setTutorialLicense(); - - /** - * Shows a TutorialCustomCodeWidget for the setup code of the tutorial. - */ - void setTutorialSetup(); - - /** - * Shows a TutorialCustomCodeWidget for the tear down code of the tutorial. - */ - void setTutorialTearDown(); - - /** - * Adds a new step to the tutorial after showing a StepDataWidget for it. - * The step isn't added if the dialog is cancelled. - */ - void addStep(); - - /** - * Shows a StepDataWidget for the current step. - */ - void setStepData(); - - /** - * Shows a StepCustomCodeWidget for the setup code of the current step. - */ - void setStepSetup(); - - /** - * Shows a StepCustomCodeWidget for the tear down code of the current step. - */ - void setStepTearDown(); - - /** - * Removes the current step from the tutorial. - */ - void removeStep(); - - /** - * Adds a new reaction to the current step after showing a ReactionWidget - * for it. - * The reaction isn't added if the dialog is cancelled. - */ - void addReaction(); - - /** - * Shows a ReactionWidget for the current reaction. - */ - void setReactionData(); - - /** - * Removes the current reaction from its step. - */ - void removeReaction(); - }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-04-25 23:15:19
|
Revision: 235 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=235&view=rev Author: danxuliu Date: 2010-04-25 23:15:13 +0000 (Sun, 25 Apr 2010) Log Message: ----------- Make destructors virtual. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/FileActions.h trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObjectMapper.h Modified: trunk/ktutorial/ktutorial-editor/src/FileActions.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/FileActions.h 2010-04-25 23:10:44 UTC (rev 234) +++ trunk/ktutorial/ktutorial-editor/src/FileActions.h 2010-04-25 23:15:13 UTC (rev 235) @@ -63,7 +63,7 @@ * Destroys this FileActions. * The entries in the recent files action are saved in the configuration. */ - ~FileActions(); + virtual ~FileActions(); /** * Returns the tutorial URL. Modified: trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObjectMapper.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObjectMapper.h 2010-04-25 23:10:44 UTC (rev 234) +++ trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObjectMapper.h 2010-04-25 23:15:13 UTC (rev 235) @@ -48,7 +48,7 @@ * Destroys this RemoteObjectMapper. * All the mapped RemoteObjects and RemoteClasses are also destroyed. */ - ~RemoteObjectMapper(); + virtual ~RemoteObjectMapper(); /** * Returns the RemoteObject associated with the given object id. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2010-09-25 03:40:22
|
Revision: 255 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=255&view=rev Author: danxuliu Date: 2010-09-25 03:40:16 +0000 (Sat, 25 Sep 2010) Log Message: ----------- Use KTutorial library in KTutorial editor to be able to provide tutorials for the editor itself. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc Modified: trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-09-25 03:33:38 UTC (rev 254) +++ trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-09-25 03:40:16 UTC (rev 255) @@ -10,6 +10,22 @@ add_subdirectory(util) add_subdirectory(view) +# When KTutorial is built, the library isn't installed yet when the editor is +# built. In that case, use the headers and libraries in the build directory +# of the library. +if(ktutorial-library_BINARY_DIR) + set(KTUTORIAL_FOUND TRUE) + include_directories(${ktutorial-library_BINARY_DIR}/includes) + set(KTUTORIAL_LIBRARIES ktutorial) +endif(ktutorial-library_BINARY_DIR) + +# If ktutorial-test-app is built in standalone mode, look for an installed +# KTutorial library. +if(NOT KTUTORIAL_FOUND) + find_package(KTutorial REQUIRED) + include_directories(${KTUTORIAL_INCLUDE_DIRS}) +endif(NOT KTUTORIAL_FOUND) + if (QT_QTDBUS_FOUND) add_definitions(-DQT_QTDBUS_FOUND) add_subdirectory(targetapplication) @@ -39,6 +55,7 @@ ktutorial_editor_serialization ktutorial_editor_util ktutorial_editor_view + ${KTUTORIAL_LIBRARIES} ) if (QT_QTDBUS_FOUND) Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-09-25 03:33:38 UTC (rev 254) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-09-25 03:40:16 UTC (rev 255) @@ -26,6 +26,8 @@ #include <KConfigGroup> #include <KLocalizedString> +#include <ktutorial/KTutorial.h> + #include "EditActions.h" #include "FileActions.h" #include "data/Tutorial.h" @@ -64,6 +66,8 @@ mFileActions->newTutorial(); + KTutorial::self()->setup(this); + setupGUI(); } Modified: trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc =================================================================== --- trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-09-25 03:33:38 UTC (rev 254) +++ trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-09-25 03:40:16 UTC (rev 255) @@ -38,6 +38,9 @@ <Action name="showEditReactionDock"/> </Menu> </Menu> + <Menu name="help"> + <DefineGroup name="ktutorial"/> + </Menu> </MenuBar> <ToolBar name="mainToolBar"> <Text context="@title:menu">Main Toolbar</Text> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |