Coverage for src/robotide/application/editorprovider.py: 100%

34 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-05-06 10:40 +0100

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 

16class EditorProvider(object): 1ab

17 

18 def __init__(self): 1ab

19 self._editors = {} 

20 

21 def register_editor(self, key, editor, default=True): 1ab

22 if key not in self._editors: 1adfgiche

23 self._editors[key] = _EditorList() 

24 self._editors[key].add(editor, default) 1adfgiche

25 

26 def unregister_editor(self, key, editor): 1ab

27 self._editors[key].remove(editor) 1jce

28 

29 def set_active_editor(self, key, editor): 1ab

30 self._editors[key].set_default(editor) 1d

31 

32 def get_editor(self, key): 1ab

33 return self._editors[key].get() 1djghe

34 

35 def get_editors(self, key): 1ab

36 return self._editors[key].get_all() 1fic

37 

38 

39class _EditorList(object): 1ab

40 

41 def __init__(self): 1ab

42 self._editors = [] 

43 

44 def add(self, editor, default=True): 1ab

45 if editor in self._editors: 1adfgiche

46 return 1ic

47 if default: 1adfgche

48 self._editors.append(editor) 1afge

49 else: 

50 self._editors.insert(0, editor) 1dch

51 

52 def set_default(self, editor): 1ab

53 if self._editors.index(editor) != len(self._editors) - 1: 1dc

54 self._editors.remove(editor) 1d

55 self._editors.append(editor) 1d

56 

57 def remove(self, editor): 1ab

58 self._editors.remove(editor) 1jce

59 

60 def get(self): 1ab

61 return self._editors[-1] 1djgche

62 

63 def get_all(self): 1ab

64 return self._editors 1fic