bookmarkSubfolderWindow.py (6222B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\bookmarks\bookmarkSubfolderWindow.py 2 import eveicon 3 from carbonui import uiconst 4 from carbonui.control.combo import Combo 5 from carbonui.control.singlelineedits.singleLineEditText import SingleLineEditText 6 from carbonui.control.window import Window 7 from carbonui.primitives.container import Container 8 from carbonui.primitives.sprite import Sprite 9 from carbonui.util.sortUtil import SortListOfTuples 10 from carbonui.button.group import ButtonGroup 11 from eve.client.script.ui.control.eveLabel import EveLabelMedium 12 from eve.common.lib.appConst import MAX_FOLDER_NAME_LENGTH 13 from eveexceptions import UserError 14 from localization import GetByLabel 15 from player_messaging.client.ui_message import prompt_player_fsd_dialog 16 ROW_PADDING = (2, 2, 2, 2) 17 18 class BookmarkSubfolderWindow(Window): 19 default_windowID = 'bookmarkSubfolderWindow' 20 __notifyevents__ = ['OnRefreshBookmarks'] 21 22 def ApplyAttributes(self, attributes): 23 Window.ApplyAttributes(self, attributes) 24 self.subfolder = attributes.get('subfolder', None) 25 self.folderID = attributes.folderID 26 if self.subfolder is None: 27 self.SetCaption(GetByLabel('UI/AclBookmarks/NewSubfolder')) 28 self.isNew = True 29 if self.folderID is None: 30 self.folderID = settings.char.ui.Get('bookmarkSubfolderDefaultFolder', None) 31 else: 32 self.SetCaption(GetByLabel('UI/AclBookmarks/EditSubfolder')) 33 self.isNew = False 34 self.folderID = self.subfolder.folderID 35 if self.folderID: 36 try: 37 self.folder = sm.GetService('bookmarkSvc').GetBookmarkFolder(self.folderID) 38 except KeyError: 39 if self.isNew: 40 self.folder = None 41 self.folderID = None 42 else: 43 raise UserError('FolderAccessDenied') 44 45 else: 46 self.folder = None 47 self.SetMinSize(size=(400, 180)) 48 main = Container(name='main', parent=self.sr.main, align=uiconst.TOALL, left=4, width=4) 49 labelContainer = Container(name='labelContainer', parent=main, align=uiconst.TOTOP, top=8, height=20, padding=ROW_PADDING) 50 EveLabelMedium(text=GetByLabel('UI/PeopleAndPlaces/Name'), parent=labelContainer, align=uiconst.TOLEFT, width=60) 51 self.nameEdit = SingleLineEditText(name='nameEdit', setvalue=self.subfolder.subfolderName if self.subfolder else '', parent=labelContainer, align=uiconst.TOALL, maxLength=MAX_FOLDER_NAME_LENGTH, width=0, OnReturn=self.Confirm) 52 sectionContainer = Container(name='sectionContainer', parent=main, align=uiconst.TOTOP, top=8, height=20, padding=ROW_PADDING) 53 EveLabelMedium(text=GetByLabel('UI/PeopleAndPlaces/Folder'), parent=sectionContainer, align=uiconst.TOLEFT, width=60) 54 if self.isNew: 55 options = self.GetFolderOptions() 56 self.sectionCombo = Combo(name='sectionCombo', parent=sectionContainer, align=uiconst.TOALL, width=0, select=self.folderID, options=options) 57 else: 58 sectionName = self.folder.folderName 59 if self.folder.isPersonal: 60 texturePath = eveicon.folder 61 hint = GetByLabel('UI/AclBookmarks/PersonalFolderType') 62 else: 63 texturePath = eveicon.shared_folder 64 hint = GetByLabel('UI/AclBookmarks/SharedFolderType') 65 Sprite(parent=sectionContainer, align=uiconst.CENTERLEFT, pos=(60, 0, 16, 16), texturePath=texturePath, hint=hint) 66 EveLabelMedium(text=sectionName, parent=sectionContainer, align=uiconst.TOALL, width=60, left=20) 67 buttonGroup = ButtonGroup(name='buttonGroup', parent=main) 68 submitButton = buttonGroup.AddButton(GetByLabel('UI/Common/Submit'), self.Confirm) 69 buttonGroup.AddButton(GetByLabel('UI/Common/Cancel'), self.Cancel) 70 submitButton.OnSetFocus() 71 72 def GetFolderOptions(self): 73 folders = sm.GetService('bookmarkSvc').GetFilteredFolders() 74 options = [] 75 for folder in folders: 76 label = folder.folderName 77 if folder.isPersonal: 78 texturePath = eveicon.folder 79 hint = GetByLabel('UI/AclBookmarks/PersonalFolderType') 80 else: 81 texturePath = eveicon.shared_folder 82 hint = GetByLabel('UI/AclBookmarks/SharedFolderType') 83 entry = (label, 84 folder.folderID, 85 hint, 86 texturePath) 87 sortKey = (-folder.isPersonal, label.lower()) 88 options.append((sortKey, entry)) 89 90 options = SortListOfTuples(options) 91 return options 92 93 def OnRefreshBookmarks(self): 94 if self.isNew: 95 options = self.GetFolderOptions() 96 if options: 97 self.sectionCombo.entries = self.GetFolderOptions() 98 else: 99 prompt_player_fsd_dialog('CustomNotify', {'notify': GetByLabel('UI/AclBookmarks/NoValidFolder')}) 100 self.Close() 101 102 def Confirm(self, *args): 103 name = self.nameEdit.GetValue() 104 name = name.strip() 105 if not name: 106 raise UserError('CustomInfo', {'info': GetByLabel('UI/Map/MapPallet/msgPleaseTypeSomething')}) 107 if self.isNew: 108 self.folderID = self.sectionCombo.GetValue() 109 bookmarkSvc = sm.GetService('bookmarkSvc') 110 subfolders = bookmarkSvc.GetSubfolders() 111 currentSubfolderID = self.subfolder.subfolderID if self.subfolder else None 112 existingSubfolderNames = {x.subfolderName for x in subfolders.itervalues() if x.subfolderID != currentSubfolderID and x.folderID == self.folderID} 113 if name in existingSubfolderNames: 114 raise UserError('CustomInfo', {'info': GetByLabel('UI/Notepad/FolderAlreadyExists')}) 115 if self.isNew: 116 bookmarkSvc.CreateSubfolder(self.folderID, name) 117 else: 118 bookmarkSvc.UpdateSubfolder(self.folderID, self.subfolder.subfolderID, name) 119 settings.char.ui.Set('bookmarkSubfolderDefaultFolder', self.folderID) 120 self.Close() 121 122 def Cancel(self, *args): 123 self.Close()