38 |
37 |
39 class DotDesktopWizard(QObject): |
38 class DotDesktopWizard(QObject): |
40 """ |
39 """ |
41 Class implementing the .desktop wizard plug-in. |
40 Class implementing the .desktop wizard plug-in. |
42 """ |
41 """ |
|
42 |
43 def __init__(self, ui): |
43 def __init__(self, ui): |
44 """ |
44 """ |
45 Constructor |
45 Constructor |
46 |
46 |
47 @param ui reference to the user interface object (UI.UserInterface) |
47 @param ui reference to the user interface object (UI.UserInterface) |
48 """ |
48 """ |
49 super().__init__(ui) |
49 super().__init__(ui) |
50 self.__ui = ui |
50 self.__ui = ui |
51 self.__action = None |
51 self.__action = None |
52 |
52 |
53 def __initialize(self): |
53 def __initialize(self): |
54 """ |
54 """ |
55 Private slot to (re)initialize the plug-in. |
55 Private slot to (re)initialize the plug-in. |
56 """ |
56 """ |
57 self.__act = None |
57 self.__act = None |
58 |
58 |
59 def activate(self): |
59 def activate(self): |
60 """ |
60 """ |
61 Public method to activate this plug-in. |
61 Public method to activate this plug-in. |
62 |
62 |
63 @return tuple of None and activation status (boolean) |
63 @return tuple of None and activation status (boolean) |
64 """ |
64 """ |
65 self.__initAction() |
65 self.__initAction() |
66 self.__initMenu() |
66 self.__initMenu() |
67 |
67 |
68 return None, True |
68 return None, True |
69 |
69 |
70 def deactivate(self): |
70 def deactivate(self): |
71 """ |
71 """ |
72 Public method to deactivate this plug-in. |
72 Public method to deactivate this plug-in. |
73 """ |
73 """ |
74 menu = self.__ui.getMenu("wizards") |
74 menu = self.__ui.getMenu("wizards") |
75 if menu: |
75 if menu: |
76 menu.removeAction(self.__action) |
76 menu.removeAction(self.__action) |
77 self.__ui.removeEricActions([self.__action], 'wizards') |
77 self.__ui.removeEricActions([self.__action], "wizards") |
78 |
78 |
79 def __initAction(self): |
79 def __initAction(self): |
80 """ |
80 """ |
81 Private method to initialize the action. |
81 Private method to initialize the action. |
82 """ |
82 """ |
83 self.__action = EricAction( |
83 self.__action = EricAction( |
84 self.tr('.desktop Wizard'), |
84 self.tr(".desktop Wizard"), |
85 self.tr('.desktop Wizard...'), |
85 self.tr(".desktop Wizard..."), |
86 0, 0, self, |
86 0, |
87 'wizards_dotdesktop') |
87 0, |
88 self.__action.setStatusTip(self.tr('.desktop Wizard')) |
88 self, |
89 self.__action.setWhatsThis(self.tr( |
89 "wizards_dotdesktop", |
90 """<b>.desktop Wizard</b>""" |
90 ) |
91 """<p>This wizard opens a dialog for entering all the parameters""" |
91 self.__action.setStatusTip(self.tr(".desktop Wizard")) |
92 """ needed to create the contents of a .desktop file. The""" |
92 self.__action.setWhatsThis( |
93 """ generated code replaces the text of the current editor.""" |
93 self.tr( |
94 """ Alternatively a new editor is opened.</p>""" |
94 """<b>.desktop Wizard</b>""" |
95 )) |
95 """<p>This wizard opens a dialog for entering all the parameters""" |
|
96 """ needed to create the contents of a .desktop file. The""" |
|
97 """ generated code replaces the text of the current editor.""" |
|
98 """ Alternatively a new editor is opened.</p>""" |
|
99 ) |
|
100 ) |
96 self.__action.triggered.connect(self.__handle) |
101 self.__action.triggered.connect(self.__handle) |
97 |
102 |
98 self.__ui.addEricActions([self.__action], 'wizards') |
103 self.__ui.addEricActions([self.__action], "wizards") |
99 |
104 |
100 def __initMenu(self): |
105 def __initMenu(self): |
101 """ |
106 """ |
102 Private method to add the actions to the right menu. |
107 Private method to add the actions to the right menu. |
103 """ |
108 """ |
104 menu = self.__ui.getMenu("wizards") |
109 menu = self.__ui.getMenu("wizards") |
105 if menu: |
110 if menu: |
106 menu.addAction(self.__action) |
111 menu.addAction(self.__action) |
107 |
112 |
108 def __handle(self): |
113 def __handle(self): |
109 """ |
114 """ |
110 Private method to handle the wizards action. |
115 Private method to handle the wizards action. |
111 """ |
116 """ |
112 editor = ericApp().getObject("ViewManager").activeWindow() |
117 editor = ericApp().getObject("ViewManager").activeWindow() |
113 |
118 |
114 if editor is None: |
119 if editor is None: |
115 EricMessageBox.critical( |
120 EricMessageBox.critical( |
116 self.__ui, |
121 self.__ui, |
117 self.tr('No current editor'), |
122 self.tr("No current editor"), |
118 self.tr('Please open or create a file first.')) |
123 self.tr("Please open or create a file first."), |
|
124 ) |
119 else: |
125 else: |
120 if editor.text(): |
126 if editor.text(): |
121 ok = EricMessageBox.yesNo( |
127 ok = EricMessageBox.yesNo( |
122 self.__ui, |
128 self.__ui, |
123 self.tr(".desktop Wizard"), |
129 self.tr(".desktop Wizard"), |
124 self.tr("""The current editor contains text.""" |
130 self.tr( |
125 """ Shall this be replaced?"""), |
131 """The current editor contains text.""" |
126 icon=EricMessageBox.Critical) |
132 """ Shall this be replaced?""" |
|
133 ), |
|
134 icon=EricMessageBox.Critical, |
|
135 ) |
127 if not ok: |
136 if not ok: |
128 ericApp().getObject("ViewManager").newEditor() |
137 ericApp().getObject("ViewManager").newEditor() |
129 editor = ericApp().getObject("ViewManager").activeWindow() |
138 editor = ericApp().getObject("ViewManager").activeWindow() |
130 |
139 |
131 from WizardPlugins.DotDesktopWizard.DotDesktopWizardDialog import ( |
140 from WizardPlugins.DotDesktopWizard.DotDesktopWizardDialog import ( |
132 DotDesktopWizardDialog |
141 DotDesktopWizardDialog, |
133 ) |
142 ) |
|
143 |
134 dlg = DotDesktopWizardDialog(None) |
144 dlg = DotDesktopWizardDialog(None) |
135 if dlg.exec() == QDialog.DialogCode.Accepted: |
145 if dlg.exec() == QDialog.DialogCode.Accepted: |
136 code = dlg.getCode() |
146 code = dlg.getCode() |
137 if code: |
147 if code: |
138 editor.selectAll() |
148 editor.selectAll() |
139 # It should be done on this way to allow undo |
149 # It should be done on this way to allow undo |
140 editor.beginUndoAction() |
150 editor.beginUndoAction() |
141 editor.replaceSelectedText(code) |
151 editor.replaceSelectedText(code) |
142 editor.endUndoAction() |
152 editor.endUndoAction() |
143 |
153 |
144 editor.setLanguage("dummy.desktop") |
154 editor.setLanguage("dummy.desktop") |
|
155 |
145 |
156 |
146 # |
157 # |
147 # eflag: noqa = M801 |
158 # eflag: noqa = M801 |