Home Download Buy Blog Forum Support

What happened to "clone_file" in Sublime text 3?

What happened to "clone_file" in Sublime text 3?

Postby imsangha on Fri Sep 27, 2013 6:16 pm

This command used to work fine in Sublime Text 2:

Code: Select all
self.window.run_command('clone_file')


Somehow it doesn't work anymore. Is there a way to make it work or an alternative?

Thank you.
imsangha
 
Posts: 3
Joined: Fri Sep 27, 2013 6:09 pm

Re: What happened to "clone_file" in Sublime text 3?

Postby robertcollier4 on Fri Sep 27, 2013 11:29 pm

Update: The below code is for a different functionality of creating a duplicate of the current file and opening it for you. I believe the command "clone_file" still exists in ST3 but now with the more clear menu caption "File->New view into File".
Use the below code only if you would like "Duplicate File" functionality.

Create a file SublimeDataDir\Packages\User\Main.sublime-menu:
Code: Select all
[
   {
      "caption": "File",
      "mnemonic": "F",
      "id": "file",
      "children":
      [
         { "command": "duplicate_file", "caption": "Duplicate File"},
      ]
   }
]

Create a file SublimeDataDir\Packages\User\DuplicateFile.py:
Code: Select all
import sublime, sublime_plugin
import os
import shutil

class DuplicateFile(sublime_plugin.WindowCommand):
   def run(self):
      self.window.run_command("save")
      self.window.show_input_panel("Duplicate File Name:", "", self.on_done, None, None)
      pass

   def on_done(self, userinput):
      file1 = self.window.active_view().file_name()
      file2 = os.path.dirname(file1) + "\\" + userinput
      shutil.copy2(file1, file2)
      self.window.open_file(file2)
      sublime.status_message("Created Duplicate File: " + file2)
Last edited by robertcollier4 on Sat Sep 28, 2013 12:53 am, edited 3 times in total.
robertcollier4
 
Posts: 154
Joined: Sun Feb 24, 2013 5:37 pm

Re: What happened to "clone_file" in Sublime text 3?

Postby tito on Fri Sep 27, 2013 11:38 pm

Submit clone view works fine.

sublime.active_window().run_command('clone_file')

@robertcollier4, clone is not duplicate. Clone will open the same file in another view. so you can have many tabs with the same content. Useful for multi monitor set-ups and people that use different layouts.

If you can paste the code maybe we can catch why window is not set in self.
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 851
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: What happened to "clone_file" in Sublime text 3?

Postby imsangha on Sun Sep 29, 2013 4:16 pm

tito wrote:sublime.active_window().run_command('clone_file')


Hm... This doesn't work for me. Here is the full code:

Code: Select all
class clone_tab_in_new_window(sublime_plugin.WindowCommand):
    def run(self):

        if self.window.num_groups() == 1:
            self.window.run_command('set_layout',
                            {
                                "cols": [0.0, 0.5, 1.0],
                                "rows": [0.0, 1.0],
                                "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
                            })

            sublime.active_window().run_command('clone_file')           
            sublime.active_window().run_command('move_to_group', {"group": 1})


Any idea why it doesn't work?
imsangha
 
Posts: 3
Joined: Fri Sep 27, 2013 6:09 pm

Re: What happened to "clone_file" in Sublime text 3?

Postby bizoo on Mon Sep 30, 2013 7:03 am

I think set_layout command change the active group, so after this command you are on the group 1.
You need to focus the group 0 before the move_to_group command.
This can be done using the api or using a command:
Code: Select all
class ExampleCommand(sublime_plugin.WindowCommand):
    def run(self):
        if self.window.num_groups() == 1:
            self.window.run_command('clone_file')
            self.window.run_command('set_layout',
                            {
                                "cols": [0.0, 0.5, 1.0],
                                "rows": [0.0, 1.0],
                                "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
                            })
            self.window.run_command('focus_group', {"group": 0})
            self.window.run_command('move_to_group', {"group": 1})
bizoo
 
Posts: 873
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: What happened to "clone_file" in Sublime text 3?

Postby FichteFoll on Sun Oct 06, 2013 8:50 pm

FichteFoll
 
Posts: 377
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany


Return to General Discussion

Who is online

Users browsing this forum: Google [Bot] and 15 guests