Robot Framework Integrated Development Environment (RIDE)
editorcreator.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 
17 from .. import robotapi
18 from .. import controller
19 # from ..controller import Project
20 from ..controller.dataloader import TestDataDirectoryWithExcludes
21 from ..controller import filecontrollers
22 # import ExcludedDirectoryController
23 from ..controller.settingcontrollers import VariableController
24 from .editors import (InitFileEditor, TestCaseFileEditor, WelcomePage, ResourceFileEditor)
25 from .macroeditors import TestCaseEditor, UserKeywordEditor
26 
27 
28 def VariableEditorChooser(plugin, parent, _controller, tree):
29 
32  _controller = _controller.datafile_controller
33  editor_class = plugin.get_editor(_controller.data.__class__)
34  return editor_class(plugin, parent, _controller, tree)
35 
36 
37 class EditorCreator():
38  # TODO: Should not use robot.model classes here
39 
42  _EDITORS = ((robotapi.TestDataDirectory, InitFileEditor),
43  (robotapi.ResourceFile, ResourceFileEditor),
44  (robotapi.TestCase, TestCaseEditor),
45  (robotapi.TestCaseFile, TestCaseFileEditor),
46  (robotapi.UserKeyword, UserKeywordEditor),
47  (robotapi.Variable, VariableEditorChooser),
48  (TestDataDirectoryWithExcludes, InitFileEditor))
49 
50  def __init__(self, editor_registerer):
51  self._editor_registerer_editor_registerer = editor_registerer
52  self._editor_editor = None
53 
54  def register_editors(self):
55  for item, editorclass in self._EDITORS_EDITORS:
56  self._editor_registerer_editor_registerer(item, editorclass)
57 
58  def editor_for(self, plugin, editor_panel, tree):
59  self._editor_editor = self._create_editor_create_editor(editor_panel, plugin, tree)
60  return self._editor_editor
61 
62  def _create_editor(self, editor_panel, plugin, tree):
63 
66  _controller = plugin.get_selected_item()
67  if self._invalid_invalid(_controller):
68  # http://code.google.com/p/robotframework-ride/issues/detail?id=1092
69  if self._editor_editor and tree and (not tree._datafile_nodes or
70  self._only_resource_files_only_resource_files(tree)):
71  self._editor_editor.destroy()
72  self._editor_editor = None
73  return None
74  if self._editor_editor:
75  return self._editor_editor
76  return WelcomePage(editor_panel)
77  if self._should_use_old_editor_should_use_old_editor(_controller):
78  return self._editor_editor
79  return self._create_new_editor_create_new_editor(_controller, editor_panel, plugin, tree)
80 
81  @staticmethod
82  def _invalid(_controller):
83  return not _controller or _controller.data is None or \
84  isinstance(_controller, controller.Project) or \
85  isinstance(_controller, filecontrollers.ExcludedDirectoryController)
86 
87  def _should_use_old_editor(self, _controller):
88  return self._editor_editor and \
89  isinstance(_controller, VariableController) and \
90  _controller.datafile_controller is self._editor_editor.controller
91 
92  def _create_new_editor(self, _controller, editor_panel, plugin, tree):
93  editor_class = plugin.get_editor(_controller.data.__class__)
94  if self._editor_editor:
95  self._editor_editor.destroy()
96  editor_panel.Show(False)
97  return editor_class(plugin, editor_panel, _controller, tree)
98 
99  @staticmethod
101  return all([tree.node_is_resource_file(node)
102  for node in tree._datafile_nodes])
def _should_use_old_editor(self, _controller)
def editor_for(self, plugin, editor_panel, tree)
def __init__(self, editor_registerer)
def _create_editor(self, editor_panel, plugin, tree)
def _create_new_editor(self, _controller, editor_panel, plugin, tree)
The parsed resource file object.
Definition: model.py:254
The parsed test case file object.
Definition: model.py:216
The parsed test data directory object.
Definition: model.py:296
def VariableEditorChooser(plugin, parent, _controller, tree)