Coverage for src/robotide/ui/resourcedialogs.py: 26%

75 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 

16import wx 1ab

17 

18from ..controller.ctrlcommands import DeleteResourceAndImports, DeleteFile, DeleteFolder, DeleteFolderAndImports 1ab

19from ..usages.commands import FindResourceUsages, FindTestFolderUsages 1ab

20from ..usages.usagesdialog import ResourceImportListModel, RecursiveResourceImportListModel 1ab

21from ..widgets import RIDEDialog, VirtualList, VerticalSizer, Label 1ab

22 

23 

24class _UsageDialog(RIDEDialog): 1ab

25 _width = 650 1ab

26 _height = 250 1ab

27 

28 def __init__(self, usages, title, checkbox_label, model=ResourceImportListModel): 1ab

29 RIDEDialog.__init__(self, title, size=(self._width, self._height)) 

30 # set Left to Right direction (while we don't have localization) 

31 self.SetLayoutDirection(wx.Layout_LeftToRight) 

32 self._sizer = VerticalSizer() 

33 self._create_controls(usages, checkbox_label, model) 

34 self._create_horizontal_line(self._sizer) 

35 self._create_buttons(self._sizer) 

36 self.SetSizer(self._sizer) 

37 

38 def _create_controls(self, usages, checkbox_label, model): 1ab

39 self._sizer.add_with_padding(Label(self, label="Usages:")) 

40 model = model(usages) 

41 self._sizer.add_expanding(VirtualList(self, model.headers, model)) 

42 self._add_usages_modifying_help(usages) 

43 self._checkbox = wx.CheckBox(self, label=checkbox_label) 

44 self._checkbox.SetValue(True) 

45 self._sizer.add_with_padding(self._checkbox) 

46 

47 def _add_usages_modifying_help(self, usages): 1ab

48 if any(u for u in usages if not u.can_be_renamed): 

49 hhelp = Label(self, 

50 label='Highlighted imports are not modified because they contain variables in resource file' 

51 ' name.') 

52 hhelp.Wrap(self._width) 

53 hhelp.SetForegroundColour('red') 

54 self._sizer.add_with_padding(hhelp) 

55 

56 def show(self): 1ab

57 confirmed = self.ShowModal() == wx.ID_OK 

58 return confirmed, self._checkbox.IsChecked() 

59 

60 

61class _FolderUsageDialog(_UsageDialog): 1ab

62 

63 def __init__(self, usages, title, checkbox_label): 1ab

64 _UsageDialog.__init__(self, usages, title, checkbox_label) 

65 

66 

67class ResourceRenameDialog(object): 1ab

68 def __init__(self, controller): 1ab

69 self._rename_confirmed = True 

70 self._rename_usage = False 

71 title = 'Rename resource' 

72 checkbox_label = 'Also update resource imports' 

73 

74 usages = list(controller.execute(FindResourceUsages())) 

75 if usages: 

76 self._rename_confirmed, self._rename_usage = _UsageDialog(usages, title, checkbox_label).show() 

77 

78 def execute(self): 1ab

79 return self._rename_confirmed and self._rename_usage 

80 

81 

82class ResourceDeleteDialog(object): 1ab

83 def __init__(self, controller): 1ab

84 self._delete_confirmed = False 

85 self._delete_usage = False 

86 self._controller = controller 

87 title = 'Delete resource' 

88 checkbox_label = 'Also delete resource imports' 

89 

90 usages = list(controller.execute(FindResourceUsages())) 

91 self._delete_confirmed, self._delete_usage = _UsageDialog(usages, title, checkbox_label).show() 

92 

93 def execute(self): 1ab

94 if self._delete_confirmed: 

95 if self._delete_usage: 

96 self._controller.execute(DeleteResourceAndImports()) 

97 else: 

98 self._controller.execute(DeleteFile()) 

99 

100 

101class FolderDeleteDialog(object): 1ab

102 def __init__(self, controller): 1ab

103 self._delete_confirmed = False 

104 self._delete_usage = False 

105 self._controller = controller 

106 title = 'Delete test data folder' 

107 checkbox_label = 'Also delete resource imports' 

108 

109 usages = list(controller.execute(FindTestFolderUsages())) 

110 self._delete_confirmed, self._delete_usage = _UsageDialog(usages, title, checkbox_label, 

111 RecursiveResourceImportListModel).show() 

112 

113 def execute(self): 1ab

114 if self._delete_confirmed: 

115 if self._delete_usage: 

116 self._controller.execute(DeleteFolderAndImports()) 

117 else: 

118 self._controller.execute(DeleteFolder())