[Ktutorial-commits] SF.net SVN: ktutorial:[225] trunk/ktutorial/ktutorial-editor/src
Status: Alpha
Brought to you by:
danxuliu
|
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.
|