1919"""
2020import json
2121import os
22+ from copy import deepcopy
2223
2324from PySide6 import QtGui , QtWidgets
25+
26+ from mapclient .core .managers .pluginmanager import CONST_DEFAULT_PROFILE
2427from mapclient .tools .pluginmanager .ui .ui_pluginmanagerdialog import Ui_PluginManagerDialog
2528
2629
@@ -34,8 +37,12 @@ def __init__(self, plugin_manager, parent=None):
3437 self ._ui = Ui_PluginManagerDialog ()
3538 self ._ui .setupUi (self )
3639 self ._ui .removeButton .setEnabled (False )
40+ self ._ui .advancedButton .setVisible (False )
3741
3842 self ._plugin_manager = plugin_manager
43+ self ._profile_directories = deepcopy (plugin_manager .profile_directories ())
44+ self ._initialise_ui ()
45+ self ._update_ui ()
3946
4047 self ._make_connections ()
4148
@@ -61,16 +68,28 @@ def _show_advanced_dialog(self):
6168 self ._updaterSettings = dlg ._updaterSettings
6269 self .reload_plugins ()
6370
64- def _profile_changed (self , previous_text , current_text ):
65- print ("Update directory listing for profile:" , self ._ui .profileComboBox .currentText ())
66- print (previous_text , current_text )
67- self ._plugin_manager .set_profile_directories (previous_text , self .directories ())
71+ def _initialise_ui (self ):
72+ self ._ui .profileComboBox .clear ()
6873 self ._ui .directoryListing .clear ()
69- profile_name = self ._ui .profileComboBox .currentText ()
70- if profile_name :
71- directories = self ._plugin_manager .profile_directories (profile_name )
72- if directories :
73- self ._set_directories (directories )
74+
75+ # Add profiles to the combo box.
76+ current_profile = self ._plugin_manager .current_profile ()
77+ for profile in self ._profile_directories :
78+ self ._ui .profileComboBox .addItem (profile )
79+ if profile == current_profile :
80+ self ._ui .profileComboBox .setCurrentText (profile )
81+
82+ self ._set_directories (self ._profile_directories .get (current_profile , []))
83+
84+ def _update_ui (self ):
85+ editable_profile = self ._ui .profileComboBox .currentText () != CONST_DEFAULT_PROFILE
86+ self ._ui .profileEditButton .setEnabled (editable_profile )
87+ self ._ui .profileDeleteButton .setEnabled (editable_profile )
88+
89+ def _profile_changed (self , current_index ):
90+ current_profile = self ._ui .profileComboBox .currentText ()
91+ self ._set_directories (self ._profile_directories .get (current_profile , []))
92+ self ._update_ui ()
7493
7594 def _directory_selection_changed (self ):
7695 self ._ui .removeButton .setEnabled (len (self ._ui .directoryListing .selectedItems ()) > 0 )
@@ -85,7 +104,7 @@ def _create_new_profile(self):
85104 self ._ui .profileComboBox .addItem (new_profile )
86105 self ._ui .profileComboBox .setCurrentText (new_profile )
87106 self ._ui .directoryListing .clear ()
88- self ._plugin_manager . add_profile ( new_profile )
107+ self ._profile_directories [ new_profile ] = []
89108
90109 def _edit_current_profile (self ):
91110 from mapclient .tools .pluginmanager .editprofiledialog import EditProfileDialog
@@ -94,22 +113,27 @@ def _edit_current_profile(self):
94113 if dlg .exec ():
95114 current_profile = self ._ui .profileComboBox .currentText ()
96115 edited_profile = dlg .getProfileName ()
97- if edited_profile :
116+ if edited_profile and edited_profile != current_profile and edited_profile not in self . _profile_directories . keys () :
98117 current_index = self ._ui .profileComboBox .currentIndex ()
99118 self ._ui .profileComboBox .setItemText (current_index , edited_profile )
100- self ._plugin_manager .rename_profile (current_profile , edited_profile )
119+ self ._profile_directories [edited_profile ] = self ._profile_directories [current_profile ]
120+ del self ._profile_directories [current_profile ]
101121
102122 def _delete_current_profile (self ):
123+ current_profile = self ._ui .profileComboBox .currentText ()
103124 self ._ui .profileComboBox .removeItem (self ._ui .profileComboBox .currentIndex ())
104- self ._plugin_manager .remove_profile (self ._ui .profileComboBox .currentText ())
125+ self ._profile_directories .pop (current_profile )
126+ self ._update_ui ()
105127
106128 def _remove_button_clicked (self ):
107129 for item in self ._ui .directoryListing .selectedItems ():
108- self ._ui .directoryListing .takeItem (self ._ui .directoryListing .row (item ))
130+ row = self ._ui .directoryListing .row (item )
131+ current_profile = self ._ui .profileComboBox .currentText ()
132+ del self ._profile_directories [current_profile ][row ]
133+ self ._ui .directoryListing .takeItem (row )
109134
110135 def _add_directory_clicked (self ):
111136 selected_items = self ._ui .directoryListing .selectedItems ()
112- last = ''
113137 if selected_items :
114138 last_selected_item = selected_items [- 1 ]
115139 last = last_selected_item
@@ -121,6 +145,8 @@ def _add_directory_clicked(self):
121145
122146 directory = QtWidgets .QFileDialog .getExistingDirectory (self , caption = 'Select External Plugin Directory' , dir = last , options = QtWidgets .QFileDialog .ShowDirsOnly | QtWidgets .QFileDialog .DontResolveSymlinks | QtWidgets .QFileDialog .ReadOnly )
123147 if len (directory ) > 0 :
148+ current_profile = self ._ui .profileComboBox .currentText ()
149+ self ._profile_directories [current_profile ].append (directory )
124150 self ._ui .directoryListing .addItem (directory )
125151
126152 def _get_profile_directories (self , profile_name ):
@@ -161,6 +187,7 @@ def profile(self):
161187 return self ._ui .profileComboBox .currentText ()
162188
163189 def _set_directories (self , directories ):
190+ self ._ui .directoryListing .clear ()
164191 self ._ui .directoryListing .addItems ([directory for directory in directories if os .path .exists (directory )])
165192
166193 def directories (self ):
@@ -170,6 +197,10 @@ def directories(self):
170197
171198 return directories
172199
200+ def save_profile_data (self ):
201+ self ._plugin_manager .set_current_profile (self ._ui .profileComboBox .currentText ())
202+ self ._plugin_manager .set_profile_directories (self ._profile_directories )
203+
173204# import sys
174205# import json
175206# import os
0 commit comments