def create_or_link_account(): agent = None account = sublime.ok_cancel_dialog( 'You need a Floobits account!\n\n' 'Click "Open browser" if you have one or click "cancel" and we\'ll make it for you.', 'Open browser') if account: token = binascii.b2a_hex(uuid.uuid4().bytes).decode('utf-8') agent = RequestCredentialsConnection(token) elif not utils.get_persistent_data().get('disable_account_creation'): agent = CreateAccountConnection() if not agent: sublime.error_message( 'A configuration error occured earlier. Please go to floobits.com and sign up to use this plugin.\n\nWe\'re really sorry. This should never happen.' ) return try: Listener.reset() G.AGENT = agent agent.connect() except Exception as e: print(e) tb = traceback.format_exc() print(tb)
def run_agent(owner, workspace, host, port, secure): global on_room_info_waterfall if G.AGENT: msg.debug('Stopping agent.') G.AGENT.stop() G.AGENT = None on_room_info_waterfall.add(update_recent_workspaces, {'url': workspace_url}) try: msg.debug("agent_conn_kwargs: %s" % str(agent_conn_kwargs)) G.AGENT = AgentConnection( owner=owner, workspace=workspace, host=host, port=port, secure=secure, on_room_info=on_room_info_waterfall.call, **agent_conn_kwargs) on_room_info_waterfall = utils.Waterfall() Listener.reset() G.AGENT.connect() except Exception as e: print(e) tb = traceback.format_exc() print(tb)
def run(self, paths, current_file=False): if not self.is_enabled(): return if paths is None and current_file: paths = [self.window.active_view().file_name()] for path in paths: Listener.create_buf(path)
def run(self, paths, current_file=False): if not self.is_enabled(): return confirm = bool(sublime.ok_cancel_dialog('This will delete your local copy as well. Are you sure you want do do this?', 'Delete')) if not confirm: return if paths is None and current_file: paths = [self.window.active_view().file_name()] for path in paths: Listener.delete_buf(path)
def run(self, paths, current_file=False): if not self.is_enabled(): return confirm = bool( sublime.ok_cancel_dialog( 'This will delete your local copy as well. Are you sure you want do do this?' )) if not confirm: return if paths is None and current_file: paths = [self.window.active_view().file_name()] for path in paths: Listener.delete_buf(path)
def run_agent(owner, room, host, port, secure): global agent if agent: agent.stop() agent = None try: agent = AgentConnection(owner, room, host=host, port=port, secure=secure, on_connect=ON_CONNECT) # owner and room name are slugfields so this should be safe Listener.set_agent(agent) agent.connect() except Exception as e: print(e) tb = traceback.format_exc() print(tb) else: joined_room = {'url': room_url} update_recent_rooms(joined_room)
def run_agent(owner, workspace, host, port, secure): global on_room_info_waterfall if G.AGENT: msg.debug('Stopping agent.') G.AGENT.stop() G.AGENT = None on_room_info_waterfall.add(update_recent_workspaces, {'url': workspace_url}) try: G.AGENT = AgentConnection(owner=owner, workspace=workspace, host=host, port=port, secure=secure, on_room_info=on_room_info_waterfall.call) on_room_info_waterfall = utils.Waterfall() Listener.reset() G.AGENT.connect() except Exception as e: print(e) tb = traceback.format_exc() print(tb)
def create_or_link_account(): agent = None account = sublime.ok_cancel_dialog('You need a Floobits account!\n\n' 'Click "Open browser" if you have one or click "cancel" and we\'ll make it for you.', 'Open browser') if account: token = binascii.b2a_hex(uuid.uuid4().bytes).decode('utf-8') agent = RequestCredentialsConnection(token) elif not utils.get_persistent_data().get('disable_account_creation'): agent = CreateAccountConnection() if not agent: sublime.error_message('A configuration error occured earlier. Please go to floobits.com and sign up to use this plugin.\n\nWe\'re really sorry. This should never happen.') return try: Listener.reset() G.AGENT = agent agent.connect() except Exception as e: print(e) tb = traceback.format_exc() print(tb)
def run_agent(owner, room, host, port, secure): global agent if agent: msg.debug('Stopping agent.') agent.stop() agent = None try: agent = AgentConnection(owner, room, host=host, port=port, secure=secure, on_connect=ON_CONNECT) # owner and room name are slugfields so this should be safe Listener.set_agent(agent) agent.connect() except Exception as e: print(e) tb = traceback.format_exc() print(tb) else: joined_room = {'url': room_url} update_recent_rooms(joined_room)
def global_tick(): Listener.push() if G.AGENT and G.AGENT.sock: G.AGENT.select() utils.set_timeout(global_tick, G.TICK_TIME)
def run(self): Listener.summon(self.window.active_view())
def run(self): Listener.clear_highlights(self.window.active_view())
def run(self): Listener.ping(self.window.active_view())
def on_input(self, dir_to_share): global ON_CONNECT dir_to_share = os.path.expanduser(dir_to_share) dir_to_share = utils.unfuck_path(dir_to_share) room_name = os.path.basename(dir_to_share) floo_room_dir = os.path.join(G.COLAB_DIR, G.USERNAME, room_name) print(G.COLAB_DIR, G.USERNAME, room_name, floo_room_dir) if os.path.isfile(dir_to_share): return sublime.error_message('give me a directory please') try: utils.mkdir(dir_to_share) except Exception: return sublime.error_message("The directory %s doesn't exist and I can't make it." % dir_to_share) floo_file = os.path.join(dir_to_share, '.floo') info = {} try: floo_info = open(floo_file, 'rb').read().decode('utf-8') info = json.loads(floo_info) except (IOError, OSError): pass except Exception: print("couldn't read the floo_info file: %s" % floo_file) room_url = info.get('url') if room_url: try: result = utils.parse_url(room_url) except Exception as e: sublime.error_message(str(e)) else: room_name = result['room'] floo_room_dir = os.path.join(G.COLAB_DIR, result['owner'], result['room']) if os.path.realpath(floo_room_dir) == os.path.realpath(dir_to_share): if result['owner'] == G.USERNAME: try: api.create_room(room_name) print('Created room %s' % room_url) except Exception as e: print('Tried to create room' + str(e)) # they wanted to share teh dir, so always share it return self.window.run_command('floobits_join_room', {'room_url': room_url}) # go make sym link try: utils.mkdir(os.path.dirname(floo_room_dir)) os.symlink(dir_to_share, floo_room_dir) except OSError as e: if e.errno != 17: raise except Exception as e: return sublime.error_message("Couldn't create symlink from %s to %s: %s" % (dir_to_share, floo_room_dir, str(e))) # make & join room ON_CONNECT = lambda x: Listener.create_buf(dir_to_share) self.window.run_command('floobits_create_room', { 'room_name': room_name, 'ln_path': floo_room_dir, })
def is_enabled(self): return bool(agent and agent.is_ready() and not G.FOLLOW_MODE) class FloobitsDisableFollowModeCommand(FloobitsBaseCommand): def run(self): G.FOLLOW_MODE = False def is_visible(self): return bool(self.is_enabled()) def is_enabled(self): return bool(agent and agent.is_ready() and G.FOLLOW_MODE) class FloobitsNotACommand(sublime_plugin.WindowCommand): def run(self, *args, **kwargs): pass def is_visible(self): return True def is_enabled(self): return False def description(self): return Listener.push()
# TODO: this scrolling is lame and centers text :/ self.view.show(size) def is_visible(self): return False def is_enabled(self): return True def description(self): return # The new ST3 plugin API sucks class FlooViewReplaceRegion(sublime_plugin.TextCommand): def run(self, edit, r, data, *args, **kwargs): region = sublime.Region(int(r[0]), int(r[1])) self.view.replace(edit, region, data) def is_visible(self): return False def is_enabled(self): return True def description(self): return Listener.push()
def on_input(self, dir_to_share): global ON_CONNECT dir_to_share = os.path.expanduser(dir_to_share) dir_to_share = utils.unfuck_path(dir_to_share) room_name = os.path.basename(dir_to_share) floo_room_dir = os.path.join(G.COLAB_DIR, G.USERNAME, room_name) print(G.COLAB_DIR, G.USERNAME, room_name, floo_room_dir) if os.path.isfile(dir_to_share): return sublime.error_message('Give me a directory please') try: utils.mkdir(dir_to_share) except Exception: return sublime.error_message( "The directory %s doesn't exist and I can't make it." % dir_to_share) floo_file = os.path.join(dir_to_share, '.floo') info = {} try: floo_info = open(floo_file, 'rb').read().decode('utf-8') info = json.loads(floo_info) except (IOError, OSError): pass except Exception: print("Couldn't read the floo_info file: %s" % floo_file) room_url = info.get('url') if room_url: try: result = utils.parse_url(room_url) except Exception as e: sublime.error_message(str(e)) else: room_name = result['room'] floo_room_dir = os.path.join(G.COLAB_DIR, result['owner'], result['room']) if os.path.realpath(floo_room_dir) == os.path.realpath( dir_to_share): if result['owner'] == G.USERNAME: try: api.create_room(room_name) print('Created room %s' % room_url) except Exception as e: print('Tried to create room' + str(e)) # they wanted to share teh dir, so always share it return self.window.run_command('floobits_join_room', {'room_url': room_url}) # go make sym link try: utils.mkdir(os.path.dirname(floo_room_dir)) os.symlink(dir_to_share, floo_room_dir) except OSError as e: if e.errno != 17: raise except Exception as e: return sublime.error_message( "Couldn't create symlink from %s to %s: %s" % (dir_to_share, floo_room_dir, str(e))) # make & join room ON_CONNECT = lambda x: Listener.create_buf(dir_to_share) self.window.run_command('floobits_create_room', { 'room_name': room_name, 'ln_path': floo_room_dir, })