use open folder as current project when not using revision control

This commit is contained in:
Alan Hamlett 2015-04-02 16:41:55 -07:00
parent 2371daac1b
commit 00a1193bd3

View file

@ -142,22 +142,40 @@ def enough_time_passed(now, last_time):
return False return False
def find_project_name_from_folders(folders): def find_folder_containing_file(folders, current_file):
try: """Returns absolute path to folder containing the file.
"""
parent_folder = None
current_folder = current_file
while True:
for folder in folders: for folder in folders:
for file_name in os.listdir(folder): if os.path.realpath(os.path.dirname(current_folder)) == os.path.realpath(folder):
if file_name.endswith('.sublime-project'): parent_folder = folder
return file_name.replace('.sublime-project', '', 1) break
except: if parent_folder is not None:
pass break
return None if not current_folder or os.path.dirname(current_folder) == current_folder:
break
current_folder = os.path.dirname(current_folder)
return parent_folder
def find_project_from_folders(folders, current_file):
"""Find project name from open folders.
"""
folder = find_folder_containing_file(folders, current_file)
return os.path.basename(folder)
def handle_action(view, is_write=False): def handle_action(view, is_write=False):
window = view.window() window = view.window()
if window is not None: if window is not None:
target_file = view.file_name() target_file = view.file_name()
project = window.project_file_name() if hasattr(window, 'project_file_name') else None project = window.project_data() if hasattr(window, 'project_data') else None
folders = window.folders() folders = window.folders()
thread = SendActionThread(target_file, view, is_write=is_write, project=project, folders=folders) thread = SendActionThread(target_file, view, is_write=is_write, project=project, folders=folders)
thread.start() thread.start()
@ -200,12 +218,10 @@ class SendActionThread(threading.Thread):
] ]
if self.is_write: if self.is_write:
cmd.append('--write') cmd.append('--write')
if self.project: if self.project and self.project.get('name'):
self.project = os.path.basename(self.project).replace('.sublime-project', '', 1) cmd.extend(['--project', self.project.get('name')])
if self.project:
cmd.extend(['--project', self.project])
elif self.folders: elif self.folders:
project_name = find_project_name_from_folders(self.folders) project_name = find_project_from_folders(self.folders, self.target_file)
if project_name: if project_name:
cmd.extend(['--project', project_name]) cmd.extend(['--project', project_name])
for pattern in self.ignore: for pattern in self.ignore: