Skip to content

Commit

Permalink
create command for uploading current selected text as file
Browse files Browse the repository at this point in the history
  • Loading branch information
eremeevdev committed May 23, 2015
1 parent c6f516b commit ca347a7
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion Slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ def send_messages(self, index):
})
loading.done = True


def init_message_send(self):
# check is channels are cached in memory
receivers = []
Expand Down Expand Up @@ -314,6 +313,46 @@ def friendly_filename(self):
return filename


class UploadSelectionAsFileCommand(UploadCurrentFileCommand):
""" Uploads current selected text as file """

def run(self, view):
super(UploadCurrentFileCommand, self).run(view)

self.file = self.view.file_name()
if not self.file:
return sublime.error_message('SLACK: No file open')

# get all selected regions
for region in self.view.sel():
text = self.view.substr(region)

if not text:
sublime.error_message("SLACK Error: No text selected")
return
self.messages.append(text)

threading.Thread(target=self.init_message_send).start()

def upload_file(self, receiver_index):

receiver = self.receivers[receiver_index]
loading = Loader('Uploading file ...', False)

for content in self.messages:

self._api_call(API_UPLOAD_FILES, {
'token': receiver.get('token'),
'channels': receiver.get('id'),
'filename': self.friendly_filename(),
'content': content
}, loading=loading)

loading.done = True
sublime.status_message('Selection uploaded successfully!')
self.file = None


class UploadFromPathCommand(UploadCurrentFileCommand):
def run(self, view):
self.settings = sublime.load_settings("Slack.sublime-settings")
Expand Down

0 comments on commit ca347a7

Please sign in to comment.