Home Download Buy Blog Forum Support

Editing source in multiple instances

Editing source in multiple instances

Postby estarshono on Tue Nov 12, 2013 4:33 am

I'm used to edit my sources in 2 instances and every time I save changes in one instance the others in which the same source is opened offer me to reload source from the disk and delete all changes I've made in that instances. I wonder is there a way to make sublime 'add' changes from disk if the source changed (like scm git do).
Thank you!
estarshono
 
Posts: 1
Joined: Tue Nov 12, 2013 4:25 am

Re: Editing source in multiple instances

Postby tito on Thu Nov 14, 2013 5:40 pm

I've the same problem, not sure if a package exists to avoid fakes "clones". Would be nice to have a package that automatically clones the view, when opening the same file twice. I'll take a look :P
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 706
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: Editing source in multiple instances

Postby tito on Fri Nov 15, 2013 1:28 am

tito wrote:I've the same problem, not sure if a package exists to avoid fakes "clones". Would be nice to have a package that automatically clones the view, when opening the same file twice. I'll take a look :P


I remember now, why I did not solved this before, cloned views can't be moved from own window. Then, if you open the same file in another window, is not possible to clone the other, and move it to replace the current one.

I got stuck here:
Code: Select all
import sublime_plugin, sublime

class Pref():
   def load(self):
      Pref.run = True

Pref = Pref()
Pref.load();

class Dolly(sublime_plugin.EventListener):

   def on_load(self, view):
      sublime.set_timeout(lambda: self.find_fake_clones(view), 1000)
      sublime.set_timeout(lambda: self.find_fake_clones_run(view), 3000)

   def on_post_save(self, view):
      sublime.set_timeout(lambda: self.find_fake_clones(view), 1000)
      sublime.set_timeout(lambda: self.find_fake_clones_run(view), 3000)

   def find_fake_clones_run(self, view):
      Pref.run = True

   def find_fake_clones(self, view):
      if Pref.run: # on save will run for each cloned view?
         Pref.run = False
         clones = []
         for window in sublime.windows():
            for _view in window.views():
               if _view.file_name() and _view.file_name() == view.file_name() and _view.buffer_id() != view.buffer_id():

                  # the view to clone
                  original_window = _view.window()
                  original_window.focus_view(_view)
                  original_window.run_command('clone_file');

                  good_clone = original_window.active_view();

                  # the view to close, and then append the clone to

                  fake_window = view.window()
                  fake_window.focus_view(view)

                  fake_group, fake_index = fake_window.get_view_index(view)

                  original_window.set_view_index(good_clone, fake_group, fake_index);

                  fake_window.focus_view(view)

                  # fake_window.run_command('close')
                  return

                  # window.run_command('close')sss

                  # print(clones);
                  # active_group()   int   Returns the index of the currently selected group.
                  #    None   Makes the given group active.
                  # focus_view(view)   None   Switches to the given view.
                  # get_view_index(view)   (group, index)   Returns the group, and index within the group of the view. Returns -1 if not found.
                  # set_view_index(view, group, index)   None   Moves the view to the given group and index.
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 706
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay


Return to General Discussion

Who is online

Users browsing this forum: pete340 and 23 guests