├── common.pyc ├── media.pyc ├── plugin.pyc ├── posts.pyc ├── terms.pyc ├── __init__.pyc ├── command.pyc ├── settings.pyc ├── wordpress.pyc ├── wordpress_xmlrpc ├── base.pyc ├── compat.pyc ├── __init__.pyc ├── fieldmaps.pyc ├── wordpress.pyc ├── exceptions.pyc └── methods │ ├── media.pyc │ ├── posts.pyc │ ├── users.pyc │ ├── __init__.pyc │ ├── options.pyc │ └── taxonomies.pyc ├── common.py ├── package-metadata.json ├── Default Wordpress.sublime-settings ├── plugin.py ├── wordpress.py └── terms.py /common.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/common.pyc -------------------------------------------------------------------------------- /media.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/media.pyc -------------------------------------------------------------------------------- /plugin.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/plugin.pyc -------------------------------------------------------------------------------- /posts.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/posts.pyc -------------------------------------------------------------------------------- /terms.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/terms.pyc -------------------------------------------------------------------------------- /__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/__init__.pyc -------------------------------------------------------------------------------- /command.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/command.pyc -------------------------------------------------------------------------------- /settings.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/settings.pyc -------------------------------------------------------------------------------- /wordpress.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/wordpress.pyc -------------------------------------------------------------------------------- /wordpress_xmlrpc/base.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/wordpress_xmlrpc/base.pyc -------------------------------------------------------------------------------- /wordpress_xmlrpc/compat.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/wordpress_xmlrpc/compat.pyc -------------------------------------------------------------------------------- /wordpress_xmlrpc/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/wordpress_xmlrpc/__init__.pyc -------------------------------------------------------------------------------- /wordpress_xmlrpc/fieldmaps.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/wordpress_xmlrpc/fieldmaps.pyc -------------------------------------------------------------------------------- /wordpress_xmlrpc/wordpress.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/wordpress_xmlrpc/wordpress.pyc -------------------------------------------------------------------------------- /wordpress_xmlrpc/exceptions.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/wordpress_xmlrpc/exceptions.pyc -------------------------------------------------------------------------------- /wordpress_xmlrpc/methods/media.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/wordpress_xmlrpc/methods/media.pyc -------------------------------------------------------------------------------- /wordpress_xmlrpc/methods/posts.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/wordpress_xmlrpc/methods/posts.pyc -------------------------------------------------------------------------------- /wordpress_xmlrpc/methods/users.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/wordpress_xmlrpc/methods/users.pyc -------------------------------------------------------------------------------- /wordpress_xmlrpc/methods/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/wordpress_xmlrpc/methods/__init__.pyc -------------------------------------------------------------------------------- /wordpress_xmlrpc/methods/options.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/wordpress_xmlrpc/methods/options.pyc -------------------------------------------------------------------------------- /wordpress_xmlrpc/methods/taxonomies.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brzrkr/Sublpress/HEAD/wordpress_xmlrpc/methods/taxonomies.pyc -------------------------------------------------------------------------------- /common.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import sublime, sublime_plugin 3 | 4 | sp_wp = None 5 | sp_settings = None 6 | sp_started = False 7 | -------------------------------------------------------------------------------- /package-metadata.json: -------------------------------------------------------------------------------- 1 | {"version": "2013.03.25.10.18.55", "url": "https://github.com/dnstbr/Sublpress", "description": "A Sublime Text 2/3 Plugin to manage WordPress websites. Still under heavy construction."} -------------------------------------------------------------------------------- /Default Wordpress.sublime-settings: -------------------------------------------------------------------------------- 1 | { 2 | "upload_on_save": true, // Unused 3 | "scratch_directory": "~/.sublime/wordpress", // Unused 4 | "sites": 5 | { 6 | /* 7 | "Site Label": 8 | { 9 | "host": "website.com", 10 | "salt": "unused", 11 | "username": "username", 12 | "password": "password", 13 | } 14 | */ 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /plugin.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import sublime, sublime_plugin 3 | import os, sys, threading, shutil 4 | if sys.version_info[0] == 3: 5 | from .wordpress_xmlrpc import * 6 | from .wordpress_xmlrpc.methods.posts import * 7 | from .wordpress_xmlrpc.methods.taxonomies import * 8 | from .wordpress_xmlrpc.methods.users import * 9 | from . import common 10 | else: 11 | from wordpress_xmlrpc import * 12 | from wordpress_xmlrpc.methods.posts import * 13 | from wordpress_xmlrpc.methods.taxonomies import * 14 | from wordpress_xmlrpc.methods.users import * 15 | import common 16 | 17 | class CreateDefaultWordpressSettingsCommand(sublime_plugin.TextCommand): 18 | def run(self, edit): 19 | if os.path.exists(sublime.packages_path() + "/User/Wordpress.sublime-settings"): 20 | return 21 | 22 | n = sublime.active_window().open_file(sublime.packages_path() + "/User/Wordpress.sublime-settings") 23 | n.insert(edit, 0, """ 24 | { 25 | "upload_on_save": true, // Unused 26 | "scratch_directory": "~/.sublime/wordpress", // Unused 27 | "sites": 28 | { 29 | /* 30 | "Site Label": 31 | { 32 | "host": "website.com", 33 | "salt": "unused", 34 | "username": "username", 35 | "password": "password", 36 | } 37 | */ 38 | } 39 | } 40 | """) 41 | 42 | """ Called by Sublime after Sublime has loaded and is ready to load Sublpress """ 43 | def plugin_loaded(): 44 | # log commands for debugging 45 | #sublime.log_commands(True) 46 | 47 | # show console for debugging 48 | #sublime.active_window().run_command("show_panel", { "panel": "console", "toggle": True }) 49 | 50 | if not os.path.exists(sublime.packages_path() + "/User/Wordpress.sublime-settings"): 51 | sublime.active_window().run_command('create_default_wordpress_settings') 52 | 53 | # initialize some default values 54 | common.sp_wp = None 55 | common.sp_settings = sublime.load_settings('Wordpress.sublime-settings') 56 | common.sp_started = True 57 | 58 | print("Sublpress loaded.") 59 | 60 | if not common.sp_started: 61 | sublime.set_timeout(plugin_loaded, 300) 62 | 63 | class WordpressManageSites(sublime_plugin.WindowCommand): 64 | def is_enabled(self): 65 | return True 66 | 67 | def run(self, *args, **kwargs): 68 | if not os.path.exists(sublime.packages_path() + "/User/Wordpress.sublime-settings"): 69 | sublime.active_window().run_command('create_default_wordpress_settings') 70 | 71 | class WordpressConnectCall(threading.Thread): 72 | """ Used to connect Sublime's Wordpress Connect command to wordpress_xmlrpc via theads """ 73 | def __init__(self, url, username, password): 74 | # initialize some stuff 75 | self.url = url 76 | self.username = username 77 | self.password = password 78 | self.result = None 79 | 80 | # make sure to initialize the thread 81 | threading.Thread.__init__(self) 82 | 83 | """ Called by the threading module after being started """ 84 | def run(self): 85 | # make sure we have a valid wordpress client object 86 | if common.sp_wp == None: 87 | common.sp_wp = Client(self.url, self.username, self.password) 88 | self.result = common.sp_wp 89 | return 90 | 91 | # display an error message 92 | sublime.error_message('Already connected.') 93 | 94 | # and make sure the result gets set again 95 | self.result = common.sp_wp 96 | 97 | class WordpressApiCall(threading.Thread): 98 | """ Used to connect Sublime's Wordpress API commands to wordpress_xmlrpc via theads """ 99 | def __init__(self, method): 100 | # initialize some stuff 101 | self.method = method 102 | self.result = None 103 | 104 | # make sure to initialize the thread 105 | threading.Thread.__init__(self) 106 | 107 | """ Called by the threading module after being started """ 108 | def run(self): 109 | # make sure we have a valid wordpress client object 110 | if common.sp_wp != None: 111 | self.result = common.sp_wp.call(self.method) 112 | return 113 | 114 | # display an error message 115 | sublime.error_message('Not connected') 116 | 117 | # make sure we don't execute the callback 118 | self.result = False -------------------------------------------------------------------------------- /wordpress.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import sublime, sublime_plugin 3 | import os, sys, threading, zipfile, re, pprint, subprocess 4 | if sys.version_info[0] == 3: 5 | from .wordpress_xmlrpc import * 6 | from .wordpress_xmlrpc.methods.posts import * 7 | from .wordpress_xmlrpc.methods.taxonomies import * 8 | from .wordpress_xmlrpc.methods.users import * 9 | from . import * 10 | else: 11 | from wordpress_xmlrpc import * 12 | from wordpress_xmlrpc.methods.posts import * 13 | from wordpress_xmlrpc.methods.taxonomies import * 14 | from wordpress_xmlrpc.methods.users import * 15 | import common, plugin, command 16 | 17 | class WordpressInsertCommand(sublime_plugin.TextCommand): 18 | """ Sublime Text Command to insert content into the active view """ 19 | def __init__(self, *args, **kwargs): 20 | super(WordpressInsertCommand, self).__init__(*args, **kwargs) 21 | self.wc = command.WordpressTextCommand() 22 | 23 | """ Called to determine if the command should be enabled """ 24 | def is_enabled(self): 25 | return self.wc.is_enabled() 26 | 27 | """ Called when the command is ran """ 28 | def run(self, edit, *args, **kwargs): 29 | # grab the status keys and view data from the passed args 30 | title = kwargs.get('title', 'Unknown') 31 | content = kwargs.get('content', 'No Content') 32 | status = kwargs.get('status', {}) 33 | syntax = kwargs.get('syntax', 'Packages/HTML/HTML.tmLanguage') 34 | 35 | # create a new file 36 | self.file = sublime.active_window().new_file() 37 | 38 | # set some initial data 39 | self.file.set_name(title) 40 | self.file.set_syntax_file(syntax) # HTML syntax 41 | self.file.set_scratch(True) 42 | 43 | # loop through the and set the status keys 44 | for k, v in status.items(): 45 | self.file.set_status(k, v) 46 | 47 | # insert the content into the new view 48 | self.file.insert(edit, 0, content) 49 | 50 | class WordpressActionsCommand(sublime_plugin.WindowCommand): 51 | """ Sublime command to display the initial WordPress control panel """ 52 | def __init__(self, *args, **kwargs): 53 | super(WordpressActionsCommand, self).__init__(*args, **kwargs) 54 | self.wc = command.WordpressCommand() 55 | 56 | """ Called to determine if the command should be enabled """ 57 | def is_enabled(self): 58 | return self.wc.is_enabled() 59 | 60 | """ Called when the command is ran """ 61 | def run(self, *args, **kwargs): 62 | # initialize anything we need for this command 63 | self.setup_command(*args, **kwargs) 64 | 65 | """ Called right before the rest of the command runs """ 66 | def setup_command(self, *args, **kwargs): 67 | self.options = ['Edit Settings', 'Manage all Pages', 'Manage all Posts', 'Manage all Taxonomies', 'Manage a Custom Post Type'] 68 | self.wc.show_quick_panel(self.options, self.panel_callback) 69 | 70 | """ Called when the quick panel has finished """ 71 | def panel_callback(self, index): 72 | 73 | # the user cancelled the panel 74 | if index == -1: 75 | return 76 | 77 | # settings 78 | if index == 0: 79 | self.window.run_command('wordpress_edit_settings') 80 | 81 | # manage Pages 82 | if index == 1: 83 | self.window.run_command('wordpress_manage_posts', {'post_type': 'page'}) 84 | return 85 | 86 | # manage Posts 87 | if index == 2: 88 | self.window.run_command('wordpress_manage_posts', {'post_type': 'post'}) 89 | 90 | # manage Taxonomies 91 | if index == 3: 92 | self.window.run_command('wordpress_manage_taxes') 93 | 94 | # manage a Custom Post Type 95 | if index == 4: 96 | self.window.run_command('wordpress_manage_custom_posts') 97 | 98 | class WordpressConnectCommand(sublime_plugin.WindowCommand): 99 | """ Sublime command to display the list of sites we can connect to """ 100 | def __init__(self, *args, **kwargs): 101 | super(WordpressConnectCommand, self).__init__(*args, **kwargs) 102 | self.wc = command.WordpressCommand() 103 | 104 | """ Called to determine if the command should be enabled """ 105 | def is_enabled(self): 106 | if common.sp_wp == None: 107 | return True 108 | 109 | return False 110 | 111 | """ Called when the command is ran """ 112 | def run(self, *args, **kwargs): 113 | # initialize anything we need for this command 114 | self.setup_command(*args, **kwargs) 115 | 116 | """ Called right before the rest of the command runs """ 117 | def setup_command(self, *args, **kwargs): 118 | self.sites = [] 119 | self.options = [] 120 | 121 | # check if we have valid sublpress settings, reload if not 122 | if common.sp_settings == None: 123 | common.sp_settings = sublime.load_settings('Wordpress.sublime-settings') 124 | 125 | if not common.sp_settings.has('sites') or len(common.sp_settings.get('sites')) <= 0: 126 | sublime.error_message('No sites configured.') 127 | return 128 | 129 | # loop through all the sites 130 | for name, site in common.sp_settings.get('sites').items(): 131 | 132 | # and add them to the quick panel options and our sites container 133 | self.options.append([name, site['username'] + '@' + site['host']], ) 134 | self.sites.append(site) 135 | 136 | # show the quick panel 137 | self.wc.show_quick_panel(self.options, self.panel_callback) 138 | 139 | 140 | """ Called when the quick panel has finished """ 141 | def panel_callback(self, index): 142 | 143 | # the user cancelled the panel 144 | if index == -1: 145 | return 146 | site = self.sites[index] 147 | 148 | url = 'http://' + site['host'] + '/xmlrpc.php' 149 | 150 | # create threaded API call because the http connections could take awhile 151 | thread = plugin.WordpressConnectCall(url, site['username'], site['password']) 152 | 153 | # add the thread to the list 154 | self.wc.add_thread(thread) 155 | 156 | # initiate any threads we have 157 | self.wc.init_threads(self.thread_callback) 158 | 159 | """ Called when the thread has finished executing """ 160 | def thread_callback(self, result): 161 | #pprint.pprint(vars(result)) 162 | # display a status message 163 | sublime.status_message('Connected to ' + common.sp_wp.url + ' successfully.') 164 | 165 | # show the wordpress actions panel 166 | self.window.run_command('wordpress_actions') 167 | 168 | class WordpressDisconnectCommand(sublime_plugin.WindowCommand): 169 | def is_enabled(self): 170 | if common.sp_wp == None: 171 | return False 172 | 173 | return True 174 | 175 | def run(self, *args, **kwargs): 176 | common.sp_wp = None 177 | common.sp_settings = sublime.load_settings('Wordpress.sublime-settings') 178 | -------------------------------------------------------------------------------- /terms.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import sublime, sublime_plugin 3 | import os, sys, threading, zipfile, re, pprint, subprocess 4 | if sys.version_info[0] == 3: 5 | from .wordpress_xmlrpc import * 6 | from .wordpress_xmlrpc.methods.posts import * 7 | from .wordpress_xmlrpc.methods.taxonomies import * 8 | from .wordpress_xmlrpc.methods.users import * 9 | from . import * 10 | else: 11 | from wordpress_xmlrpc import * 12 | from wordpress_xmlrpc.methods.posts import * 13 | from wordpress_xmlrpc.methods.taxonomies import * 14 | from wordpress_xmlrpc.methods.users import * 15 | import common, plugin, command 16 | 17 | 18 | class WordpressManageTaxesCommand(sublime_plugin.WindowCommand): 19 | """ Sublime Command that shows the user a list of WordPress taxonomies, or for a specific post type""" 20 | def __init__(self, *args, **kwargs): 21 | super(WordpressManageTaxesCommand, self).__init__(*args, **kwargs) 22 | self.wc = command.WordpressCommand() 23 | 24 | """ Called to determine if the command should be enabled """ 25 | def is_enabled(self): 26 | return self.wc.is_enabled() 27 | 28 | """ Called when the command is ran """ 29 | def run(self, *args, **kwargs): 30 | # initialize anything we need for this command 31 | self.setup_command(*args, **kwargs) 32 | 33 | # initiate any threads we have 34 | self.wc.init_threads(self.thread_callback) 35 | 36 | """ Called right before the rest of the command runs """ 37 | def setup_command(self, *args, **kwargs): 38 | # create threaded API call because the http connections could take awhile 39 | thread = plugin.WordpressApiCall(GetTaxonomies()) 40 | 41 | # add the thread to the list 42 | self.wc.add_thread(thread) 43 | 44 | """ Called when a thread is finished executing """ 45 | def thread_callback(self, result, *args, **kwargs): 46 | self.taxes = result 47 | #self.options = ['New Taxonomy'] 48 | self.options = [] 49 | 50 | for tax in self.taxes: 51 | self.options.append(tax.name) 52 | 53 | self.wc.show_quick_panel(self.options, self.panel_callback) 54 | 55 | """ Called when the quick panel is closed """ 56 | def panel_callback(self, index): 57 | # the user cancelled the panel 58 | if index == -1: 59 | return 60 | 61 | #if index == 0: 62 | #self.window.run_command('wordpress_new_term') 63 | #return 64 | 65 | # loop through all of the retreived taxonomies 66 | for tax in self.taxes: 67 | 68 | # check for a matching title for the selected quick panel option 69 | if tax.name == self.options[index]: 70 | # show the user actions for this taxonomy 71 | self.window.run_command('wordpress_manage_terms', { 'taxonomy': tax.name }) 72 | 73 | class WordpressManageTermsCommand(sublime_plugin.WindowCommand): 74 | """ Sublime Command that shows the user a list of WordPress terms for a specific taxonomy""" 75 | def __init__(self, *args, **kwargs): 76 | super(WordpressManageTermsCommand, self).__init__(*args, **kwargs) 77 | self.wc = command.WordpressCommand() 78 | 79 | """ Called to determine if the command should be enabled """ 80 | def is_enabled(self): 81 | return self.wc.is_enabled() 82 | 83 | """ Called when the command is ran """ 84 | def run(self, *args, **kwargs): 85 | # initialize anything we need for this command 86 | self.setup_command(*args, **kwargs) 87 | 88 | # initiate any threads we have 89 | self.wc.init_threads(self.thread_callback) 90 | 91 | """ Called right before the rest of the command runs """ 92 | def setup_command(self, *args, **kwargs): 93 | self.taxonomy = kwargs.get('taxonomy', None) 94 | 95 | # create threaded API call because the http connections could take awhile 96 | thread = plugin.WordpressApiCall(GetTerms(self.taxonomy)) 97 | 98 | # add the thread to the list 99 | self.wc.add_thread(thread) 100 | 101 | """ Called when a thread is finished executing """ 102 | def thread_callback(self, result, *args, **kwargs): 103 | self.terms = result 104 | self.options = ['New Term'] 105 | 106 | for term in self.terms: 107 | self.options.append(term.name) 108 | 109 | self.wc.show_quick_panel(self.options, self.panel_callback) 110 | 111 | """ Called when the quick panel is closed """ 112 | def panel_callback(self, index): 113 | # the user cancelled the panel 114 | if index == -1: 115 | return 116 | 117 | # create new term 118 | if index == 0: 119 | self.window.run_command('wordpress_new_term') 120 | return 121 | 122 | # loop through all terms 123 | for term in self.terms: 124 | if term.name == self.options[index]: 125 | self.window.run_command('wordpress_term_action', {'id': term.id, 'name': term.name, 'taxonomy': self.taxonomy}) 126 | 127 | class WordpressRenameTermCommand(sublime_plugin.WindowCommand): 128 | """ Sublime Command that shows allows the user to rename a taxonomy term """ 129 | def __init__(self, *args, **kwargs): 130 | super(WordpressRenameTermCommand, self).__init__(*args, **kwargs) 131 | self.wc = command.WordpressCommand() 132 | 133 | """ Called when the input panel has received input """ 134 | def doDone(self, name): 135 | # save the old name 136 | self.old_name = self.term.name 137 | 138 | # assign the new name to this term 139 | self.term.name = name 140 | 141 | # create threaded API call because the http connections could take awhile 142 | thread = plugin.WordpressApiCall(EditTerm(self.term.id, self.term)) 143 | 144 | # add the thread to the list 145 | self.wc.add_thread(thread) 146 | 147 | # initiate any threads we have 148 | self.wc.init_threads(self.thread_callback) 149 | 150 | """ Called to determine if the command should be enabled """ 151 | def is_enabled(self): 152 | return self.wc.is_enabled() 153 | 154 | """ Called when the command is ran """ 155 | def run(self, *args, **kwargs): 156 | # initialize anything we need for this command 157 | self.setup_command(*args, **kwargs) 158 | 159 | """ Called right before the rest of the command runs """ 160 | def setup_command(self, *args, **kwargs): 161 | # initialize an empty WordPress term 162 | self.term = WordPressTerm() 163 | 164 | # grab the id, name, and taxonomy from the commands arguments 165 | self.term.id = kwargs.get('id', None) 166 | self.term.name = kwargs.get('name', None) 167 | self.term.taxonomy = kwargs.get('taxonomy', None) 168 | 169 | # make sure we have a valid term 170 | if self.term.id == None or self.term.name == None: 171 | sublime.status_message('No term id or name specified.') 172 | else: 173 | self.window.show_input_panel('Rename Term', self.term.name, self.doDone, None, None) 174 | 175 | """ Called when the thread is finished executing """ 176 | def thread_callback(self, result, *args, **kwargs): 177 | # Display a successful status message 178 | sublime.status_message('Successfully renamed ' + self.old_name + ' to ' + self.term.name + '.') 179 | 180 | class WordpressNewTermCommand(sublime_plugin.WindowCommand): 181 | """ Sublime Command that shows allows the user to create a new taxonomy term """ 182 | def __init__(self, *args, **kwargs): 183 | super(WordpressNewTermCommand, self).__init__(*args, **kwargs) 184 | self.wc = command.WordpressCommand() 185 | 186 | """ Called when the input panel has received input """ 187 | def doDone(self, name): 188 | # initialize an empty WordPress term 189 | self.term = WordPressTerm() 190 | self.term.taxonomy = 'category' 191 | #new_term.parent = parent_cat.id 192 | self.term.name = name 193 | 194 | # create threaded API call because the http connections could take awhile 195 | thread = plugin.WordpressApiCall(NewTerm(self.term)) 196 | 197 | # add the thread to the list 198 | self.wc.add_thread(thread) 199 | 200 | # initiate any threads we have 201 | self.wc.init_threads(self.thread_callback) 202 | 203 | """ Called to determine if the command should be enabled """ 204 | def is_enabled(self): 205 | return self.wc.is_enabled() 206 | 207 | """ Called when the command is ran """ 208 | def run(self, *args, **kwargs): 209 | # initialize anything we need for this command 210 | self.setup_command(*args, **kwargs) 211 | 212 | """ Called right before the rest of the command runs """ 213 | def setup_command(self, *args, **kwargs): 214 | self.window.show_input_panel('New Term Name', '', self.doDone, None, None) 215 | 216 | """ Called when the thread is finished executing """ 217 | def thread_callback(self, result, *args, **kwargs): 218 | self.term.id = result 219 | 220 | # Display a successful status message 221 | sublime.status_message('Successfully created ' + self.term.name + ' with id of ' + self.term.id + '.') 222 | 223 | class WordpressDeleteTermCommand(sublime_plugin.WindowCommand): 224 | """ Sublime Command that shows allows the user to delete a new taxonomy term """ 225 | def __init__(self, *args, **kwargs): 226 | super(WordpressDeleteTermCommand, self).__init__(*args, **kwargs) 227 | self.wc = command.WordpressCommand() 228 | 229 | """ Called to determine if the command should be enabled """ 230 | def is_enabled(self): 231 | return self.wc.is_enabled() 232 | 233 | """ Called when the command is ran """ 234 | def run(self, *args, **kwargs): 235 | # initialize anything we need for this command 236 | self.setup_command(*args, **kwargs) 237 | 238 | # initiate any threads we have 239 | self.wc.init_threads(self.thread_callback) 240 | 241 | """ Called right before the rest of the command runs """ 242 | def setup_command(self, *args, **kwargs): 243 | # create threaded API call because the http connections could take awhile 244 | thread = plugin.WordpressApiCall(DeleteTerm(kwargs.get('taxonomy', None), kwargs.get('id'))) 245 | 246 | # add the thread to the list 247 | self.wc.add_thread(thread) 248 | 249 | 250 | """ Called when the thread is finished executing """ 251 | def thread_callback(self, result, *args, **kwargs): 252 | sublime.status_message(' Successfully deleted term.') 253 | 254 | class WordpressTermActionCommand(sublime_plugin.WindowCommand): 255 | """ Sublime Command that displays a list of actions for a WordPress term """ 256 | def __init__(self, *args, **kwargs): 257 | super(WordpressTermActionCommand, self).__init__(*args, **kwargs) 258 | self.wc = command.WordpressCommand() 259 | 260 | """ Called to determine if the command should be enabled """ 261 | def is_enabled(self): 262 | return self.wc.is_enabled() 263 | 264 | """ Called when the command is ran """ 265 | def run(self, *args, **kwargs): 266 | # initialize anything we need for this command 267 | self.setup_command(*args, **kwargs) 268 | 269 | """ Called right before the rest of the command runs """ 270 | def setup_command(self, *args, **kwargs): 271 | self.taxonomy = kwargs.get('taxonomy', None) 272 | self.id = kwargs.get('id', None) 273 | self.name = kwargs.get('name', None) 274 | 275 | self.options = ['Rename Term', 'Delete Term'] 276 | 277 | self.wc.show_quick_panel(self.options, self.panel_callback) 278 | 279 | """ Called when the quick panel is closed """ 280 | def panel_callback(self, index): 281 | # the user cancelled the panel 282 | if index == -1: 283 | return 284 | 285 | # rename term 286 | if index == 0: 287 | self.window.run_command('wordpress_rename_term', { 'id': self.id, 'name': self.name, 'taxonomy': self.taxonomy }) 288 | 289 | # delete term 290 | if index == 1: 291 | self.window.run_command('wordpress_delete_term', { 'id': self.id, 'name': self.name, 'taxonomy': self.taxonomy }) 292 | 293 | """ Called when the thread is finished executing """ 294 | def thread_callback(self, result, *args, **kwargs): 295 | pass 296 | 297 | class WordpressModifyPostTermsCommand(sublime_plugin.WindowCommand): 298 | """ Sublime Command called when the user selects the option to modify the terms and taxes of a post from the quick panel """ 299 | def __init__(self, *args, **kwargs): 300 | super(WordpressModifyPostTermsCommand, self).__init__(*args, **kwargs) 301 | self.wc = command.WordpressCommand() 302 | 303 | """ Called to determine if the command should be enabled """ 304 | def is_enabled(self): 305 | return self.wc.is_enabled() 306 | 307 | """ Called when the command is ran """ 308 | def run(self, *args, **kwargs): 309 | # initialize anything we need for this command 310 | self.setup_command(*args, **kwargs) 311 | 312 | # initiate any threads we have 313 | self.wc.init_threads(self.thread_callback) 314 | 315 | """ Called right before the rest of the command runs """ 316 | def setup_command(self, *args, **kwargs): 317 | # grab the passed in post id 318 | self.post_id = kwargs.get('id', None) 319 | self.selected_terms = [] 320 | 321 | # create threaded API calls because the http connections could take awhile 322 | thread = plugin.WordpressApiCall(GetPost(self.post_id)) 323 | thread2 = plugin.WordpressApiCall(GetTaxonomies()) 324 | 325 | # save a copy of the current view when ran 326 | self.view = self.window.active_view() 327 | 328 | # add the thread to the list 329 | self.wc.add_thread(thread) 330 | self.wc.add_thread(thread2) 331 | 332 | """ Called when the thread has returned a list of taxonomies and we need the user to choose one """ 333 | def choose_taxonomy(self, taxes): 334 | self.taxes = taxes 335 | self.taxonomy_options = ["Choose a Taxonomy", ] 336 | 337 | for tax in self.taxes: 338 | self.taxonomy_options.append(tax.name) 339 | 340 | self.wc.show_quick_panel(self.taxonomy_options, self.choose_taxonomy_callback) 341 | 342 | """ Called when the user has chosen a taxonomy """ 343 | def choose_taxonomy_callback(self, index): 344 | # the user cancelled the panel 345 | if index == -1: 346 | return 347 | 348 | # Do Nothing 349 | if index == 0: 350 | self.choose_taxonomy(self.taxes) 351 | return 352 | 353 | # loop through all of the retreived taxonomies 354 | for tax in self.taxes: 355 | # check for a matching title for the selected quick panel option 356 | if tax.name == self.taxonomy_options[index]: 357 | self.cur_tax = tax 358 | thread = plugin.WordpressApiCall(GetTerms(tax.name)) 359 | self.wc.add_thread(thread) 360 | self.wc.init_threads(self.thread_callback) 361 | 362 | """ Called when the thread has returned a list of terms and we need the user to choose one """ 363 | def choose_term(self, terms): 364 | self.terms = terms 365 | self.term_options = [["Save Post", "with the terms marked below"], ] 366 | 367 | for term in self.terms: 368 | term_description = term.description 369 | if not term.description: 370 | term_description = "No Description" 371 | 372 | if term.id in self.selected_terms: 373 | self.term_options.append([self.wc.prefix.decode('utf8') + term.name, "ID " + term.id + ": " + term_description]) 374 | else: 375 | self.term_options.append([term.name, "ID " + term.id + ": " + term_description]) 376 | 377 | self.wc.show_quick_panel(self.term_options, self.choose_term_callback) 378 | 379 | """ Called when the user has chosen a term """ 380 | def choose_term_callback(self, index): 381 | # the user cancelled 0he panel 382 | if index == -1: 383 | return 384 | 385 | # save the new terms 386 | if index == 0: 387 | self.update_post() 388 | return 389 | 390 | # loop through all of the retreived terms 391 | for term in self.terms: 392 | 393 | # split up the second line by the colon 394 | parts = self.term_options[index][1].partition(':') 395 | 396 | # check for a matching id for the selected quick panel option 397 | if term.id == parts[0][3:]: 398 | if term.id not in self.selected_terms: 399 | self.selected_terms.append(term.id) 400 | else: 401 | self.selected_terms.remove(term.id) 402 | self.choose_term(self.terms) 403 | 404 | """ Called when the thread is finished executing """ 405 | def thread_callback(self, result, *args, **kwargs): 406 | if type(result) is WordPressPost: 407 | self.post = result 408 | 409 | for term in self.post.terms: 410 | self.selected_terms.append(term.id) 411 | elif type(result) is list: 412 | if type(result[0]) is WordPressTerm: 413 | self.choose_term(result) 414 | if type(result[0]) is WordPressTaxonomy: 415 | self.choose_taxonomy(result) 416 | elif type(result) is bool and result == True: 417 | sublime.status_message('Post updated with new terms and taxes') 418 | 419 | """ Called when the user wants to save the post with the new taxes and terms """ 420 | def update_post(self): 421 | 422 | self.post.terms = [term for term in self.terms if term.id in self.selected_terms] 423 | #pprint.pprint(self.post.terms) 424 | 425 | thread = plugin.WordpressApiCall(EditPost(self.post.id, self.post)) 426 | self.wc.add_thread(thread) 427 | self.wc.init_threads(self.thread_callback) 428 | --------------------------------------------------------------------------------