• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kig

  • sources
  • kde-4.12
  • kdeedu
  • kig
  • modes
  • popup
scriptactionsprovider.cc
Go to the documentation of this file.
1 
20 #include "scriptactionsprovider.h"
21 
22 #ifdef KIG_ENABLE_PYTHON_SCRIPTING
23 
24 #include "popup.h"
25 
26 #include "../../kig/kig_part.h"
27 #include "../../modes/normal.h"
28 #include "../../objects/text_type.h"
29 
30 #include <KIconLoader>
31 
36 static ObjectTypeCalcer* getPythonExecuteTypeFromCalcer( ObjectCalcer* o )
37 {
38  ObjectTypeCalcer* oc = dynamic_cast<ObjectTypeCalcer *>( o );
39  if ( !oc ) return 0;
40  const PythonExecuteType* pythonexec = dynamic_cast<const PythonExecuteType*>( oc->type() );
41  if ( pythonexec ) return oc;
42 
43  const GenericTextType* text = dynamic_cast<const GenericTextType*>( oc->type() );
44  if ( !text ) return 0;
45  std::vector<ObjectCalcer*> parents = oc->parents();
46 
47  for (uint i = 3; i < parents.size(); i++)
48  {
49  oc = dynamic_cast<ObjectTypeCalcer *>( parents[i] );
50  if ( oc )
51  {
52  pythonexec = dynamic_cast<const PythonExecuteType*>( oc->type() );
53  if ( pythonexec ) return oc;
54  }
55  }
56  return 0;
57 }
58 
59 void ScriptActionsProvider::fillUpMenu( NormalModePopupObjects& popup, int menu, int& nextfree )
60 {
61  if ( menu == NormalModePopupObjects::StartMenu )
62  {
63  KIconLoader* l = popup.part().iconLoader();
64  popup.addInternalAction( menu, KIcon( ScriptType::icon( ScriptType::Python ), l ), i18n( "Python Script" ), nextfree++ );
65  mns++;
66  }
67  else if ( menu == NormalModePopupObjects::ToplevelMenu )
68  {
69  if ( !popup.objects().empty() &&
70  getPythonExecuteTypeFromCalcer( popup.objects().front()->calcer() ) )
71  {
72  popup.addInternalAction( menu, "Edit Script...", nextfree );
73  }
74  nextfree++;
75  }
76 }
77 
78 bool ScriptActionsProvider::executeAction(
79  int menu, int& id, const std::vector<ObjectHolder*>& os,
80  NormalModePopupObjects&, KigPart& doc, KigWidget& w, NormalMode& mode )
81 {
82  if ( menu == NormalModePopupObjects::StartMenu )
83  {
84  if ( id == 0 )
85  {
86  ScriptCreationMode m( doc );
87  m.setScriptType( ScriptType::Python );
88  if ( os.size() > 0 )
89  {
90  mode.clearSelection();
91  m.addArgs( os, w );
92  m.goToCodePage();
93  }
94  doc.runMode( &m );
95  return true;
96  }
97  else
98  {
99  id -= mns;
100  }
101  }
102  else if ( menu == NormalModePopupObjects::ToplevelMenu )
103  {
104  if ( id == 0 )
105  {
106  ObjectTypeCalcer* oc = getPythonExecuteTypeFromCalcer( os.front()->calcer() );
107  if ( oc )
108  {
109  ScriptEditMode m( oc, doc );
110  m.setScriptType( ScriptType::Python );
111  doc.runMode( &m );
112  }
113  return true;
114  }
115  else
116  {
117  id -= 1;
118  }
119  }
120 
121  return false;
122 }
123 #endif
popup.h
NormalModePopupObjects::part
KigPart & part()
Definition: popup.h:70
NormalModePopupObjects::addInternalAction
QAction * addInternalAction(int menu, const QString &name, int id)
Definition: popup.cc:276
GenericTextType
Definition: text_type.h:23
ScriptType::icon
static const char * icon(ScriptType::Type type)
Returns the icon's name for a script language.
Definition: script-common.cc:107
NormalModePopupObjects::ToplevelMenu
Definition: popup.h:60
NormalModePopupObjects::StartMenu
Definition: popup.h:59
ObjectTypeCalcer
This is an ObjectCalcer that uses one of the various ObjectType's to calculate its ObjectImp...
Definition: object_calcer.h:183
ScriptType::Python
Definition: script-common.h:36
NormalModePopupObjects
This is the popup menu that appears when you click on selected objects in NormalMode.
Definition: popup.h:46
ObjectCalcer
An ObjectCalcer is an object that represents an algorithm for calculating an ObjectImp from other Obj...
Definition: object_calcer.h:66
KigPart::runMode
void runMode(KigMode *)
Definition: kig_part.cpp:735
KigWidget
This class is the real widget showing the document.
Definition: kig_view.h:50
NormalModePopupObjects::objects
std::vector< ObjectHolder * > objects() const
Definition: popup.h:69
ObjectTypeCalcer::type
const ObjectType * type() const
Definition: object_calcer.cc:132
NormalMode::clearSelection
void clearSelection()
Definition: normal.cc:88
PythonExecuteType
Definition: python_type.h:41
ObjectTypeCalcer::parents
std::vector< ObjectCalcer * > parents() const
Returns the parent ObjectCalcer's of this ObjectCalcer.
Definition: object_calcer.cc:105
ScriptEditMode
Script mode to edit an already-built script.
Definition: script_mode.h:104
KigPart
This is a "Part".
Definition: kig_part.h:68
scriptactionsprovider.h
NormalMode
Definition: normal.h:26
uint
unsigned int uint
Definition: object_imp.h:87
ScriptCreationMode
Script mode to create a script.
Definition: script_mode.h:90
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kig

Skip menu "kig"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal