示例#1
0
    def _addDirectory(self):
        '''
        Add directory to settings
        '''
        panel = NSOpenPanel.openPanel()
        panel.setCanChooseFiles_(False)
        panel.setCanChooseDirectories_(True)
        panel.setAllowsMultipleSelection_(True)
        if panel.runModal() == NSModalResponseOK:
            for url in panel.URLs():
                pred = NSPredicate.predicateWithFormat_(
                    "path == %@", url.path())
                if self.data['paths'].filteredArrayUsingPredicate_(
                        pred).count() > 0:
                    continue

                directory = Directory.alloc().init()
                directory.path = url.path()
                directory.enable = True
                directory.depth = 1

                self.tableView.beginUpdates()
                self.data['paths'].addObject_(directory)
                index = NSIndexSet.indexSetWithIndex_(
                    self.data['paths'].count() - 1)
                self.tableView.insertRowsAtIndexes_withAnimation_(
                    index, NSTableViewAnimationSlideUp)
                self.tableView.endUpdates()

                # Save to file
                self.saveSettings()
示例#2
0
 def load(cls):
     '''
     Load the all paths from setting file
     :return An array which contain all the directory model
     '''
     settingPath = cls.settingPath()
     fm = NSFileManager.defaultManager()
     paths = NSMutableArray.array()
     settings = NSMutableDictionary.dictionary()
     if fm.fileExistsAtPath_isDirectory_(settingPath, None)[0]:
         settingFile = NSData.dataWithContentsOfFile_(settingPath)
         jsonData = NSJSONSerialization.JSONObjectWithData_options_error_(
             settingFile, 0, None)[0]
         settings['startup'] = jsonData['startup']
         settings['api_key'] = jsonData['api_key']
         for item in jsonData['paths']:
             directory = Directory.alloc().initWithDict_(item)
             paths.addObject_(directory)
         settings['paths'] = paths
     else:
         settings['startup'] = True
         settings['api_key'] = ''
         settings['paths'] = paths
     return settings