<commit_before>import sublime
import sublime_plugin
import threading 
import os.path
from pickle import dump, load, UnpicklingError, PicklingError
from copy import deepcopy

def Log(string):
	if False:
		print (string)

REGION_BASE_TAG = int(11001001000011111101)
SETTINGS_NAME = "SublimeBookmarks.sublime-settings"
#if someone names their project this, we're boned
NO_PROJECT = "___NO_PROJECT_PRESENT____"

BOOKMARKS = []
UID = None

#list of bookmarks that have ben deleted. 
#This is used to remove bookmarks' buffer highlights. Without this, if a bookmark is removed,
#when a file is revisited, the buffer will still be marked. This will keep track of bookmarks
#that have been removed.
ERASED_BOOKMARKS = []
   
#whether all bookmarks (even unrelated) should be shown
SHOW_ALL_BOOKMARKS = True

class OptionsSelector:
	def __init__(self, window, panelItems, onDone, onHighlight):
		self.window = window
		self.panelItems = panelItems
		self.onDone = onDone
		self.onHighlight = onHighlight

		
	def start(self):
		view = self.window.active_view()
		startIndex = 0
		
		self.window.show_quick_panel(self.panelItems, self.onDone, 0, startIndex, self.onHighlight)

class OptionsInput:
	def __init__(self, window, caption, initalText, onDone, onCancel):
		self.window = window
		self.caption = caption
		self.initalText = initalText
		self.onDone = onDone
		self.onCancel = onCancel

		
	def start(self):
		view = self.window.active_view()
		inputPanelView = self.window.show_input_panel(self.caption, self.initalText, self.onDone, None, self.onCancel)

		#select the text in the view so that when the user types a new name, the old name
		#is overwritten
		assert (len(inputPanelView.sel()) > 0)
		selectionRegion = inputPanelView.full_line(inputPanelView.sel()[0])
		print ("DATA: " + inputPanelView.substr(selectionRegion))
		inputPanelView.sel().add(selectionRegion)
	
#helper functions--------------------------------
#Region manipulation-----------------------------
def getCurrentLineRegion(view):
	assert (len(view.sel()) > 0)
	selectedRegion = view.sel()[0]
	region =  view.line(selectedRegion)

	return region 

#Bookmark manipulation---------------------
def gotoBookmark(bookmark, window):
	filePath = bookmark.getFilePath()
	lineNumber = bookmark.getLineNumber()

	#Okay, so there's a bug in sublime text.
	#if you open a file *before* opening the options menu,
	#the options menu gets created where the file is opened
	#Yes, this is stupid.

	#This happens in this plugin, since the _AutoMove() callback
	#seems to be called before the options menu is shown
	#So, if I open the file in another group, the options menu
	#opens in the *other* group, and not the current group.
	#I don't know if it's my bug or sublime text's but I have
	#a feeling it's sublime text's bug. Will have to report
	#this. This is a pain...
	
	hilightedGroup = window.active_group()
	
	view = window.open_file(filePath)
		
	#get the group and index of the view
	(viewGroup, viewIndex) = window.get_view_index(view) 

	
	#the needed view is in the highlighted (current)group,
	#so we don't need to do anything.
	if hilightedGroup == viewGroup:
		pass
	else:
		#if there are 0 views, then the moved view will have index 0
		#similarly, if there are n views, the last view will have index (n-1), and
		#so the new view will have index n  
		newIndex = len (window.views_in_group(hilightedGroup))
		#move the view to the highlighted group and assign a
		#correct index
		window.set_view_index(view, hilightedGroup, newIndex)

	view.show_at_center(bookmark.getRegion())
	
	return
	#view.show_at_center(bookmark.getRegion())
	#window.focus_group(hilightedGroup)
	#return


	activeGroup = window.active_group()
	view = window.open_file(filePath)

	#open the view in the active group.
	window.set_view_index(view, activeGroup, 0)
	view.show_at_center(bookmark.getRegion())

	#move cursor to the middle of the bookmark's region
	bookmarkRegionMid = 0.5 * (bookmark.getRegion().begin() +  bookmark.getRegion().end())
	moveRegion = sublime.Region(bookmarkRegionMid, bookmarkRegionMid)
	view.sel().clear()
	view.sel().add(moveRegion)



def shouldShowBookmark(bookmark, window, showAllBookmarks):
	currentProjectPath = window.project_file_name()
	
	#free bookmarks can be shown. We don't need a criteria
	if showAllBookmarks:
		return True
	#there is no current project now. Show all bookmarks
	elif currentProjectPath == None or currentProjectPath == "":
		return True

	#return if the bookmark belongs to current project or not.
	else:
		return bookmark.getProjectPath() == currentProjectPath


#Menu generation-----------------------------------

def createBookmarkPanelItems(window, bookmarks, shouldShowAllBookmarks):	<commit_msg>moved view-group relationship code to new fn<commit_after>import sublime
import sublime_plugin
import threading 
import os.path
from pickle import dump, load, UnpicklingError, PicklingError
from copy import deepcopy

def Log(string):
	if False:
		print (string)

REGION_BASE_TAG = int(11001001000011111101)
SETTINGS_NAME = "SublimeBookmarks.sublime-settings"
#if someone names their project this, we're boned
NO_PROJECT = "___NO_PROJECT_PRESENT____"

BOOKMARKS = []
UID = None

#list of bookmarks that have ben deleted. 
#This is used to remove bookmarks' buffer highlights. Without this, if a bookmark is removed,
#when a file is revisited, the buffer will still be marked. This will keep track of bookmarks
#that have been removed.
ERASED_BOOKMARKS = []
   
#whether all bookmarks (even unrelated) should be shown
SHOW_ALL_BOOKMARKS = True

class OptionsSelector:
	def __init__(self, window, panelItems, onDone, onHighlight):
		self.window = window
		self.panelItems = panelItems
		self.onDone = onDone
		self.onHighlight = onHighlight

		
	def start(self):
		view = self.window.active_view()
		startIndex = 0
		
		self.window.show_quick_panel(self.panelItems, self.onDone, 0, startIndex, self.onHighlight)

class OptionsInput:
	def __init__(self, window, caption, initalText, onDone, onCancel):
		self.window = window
		self.caption = caption
		self.initalText = initalText
		self.onDone = onDone
		self.onCancel = onCancel

		
	def start(self):
		view = self.window.active_view()
		inputPanelView = self.window.show_input_panel(self.caption, self.initalText, self.onDone, None, self.onCancel)

		#select the text in the view so that when the user types a new name, the old name
		#is overwritten
		assert (len(inputPanelView.sel()) > 0)
		selectionRegion = inputPanelView.full_line(inputPanelView.sel()[0])
		print ("DATA: " + inputPanelView.substr(selectionRegion))
		inputPanelView.sel().add(selectionRegion)
	
#helper functions--------------------------------
#Region manipulation-----------------------------
def getCurrentLineRegion(view):
	assert (len(view.sel()) > 0)
	selectedRegion = view.sel()[0]
	region =  view.line(selectedRegion)

	return region 

#Bookmark manipulation---------------------

def moveViewToGroup(window, view, group):
	(viewGroup, viewIndex) = window.get_view_index(view) 

	#the view is in the required group,
	#so we don't need to do anything.
	if group == viewGroup:
		pass
	#we have to move the view to the other group and give it a new index
	else:
		print("DIFFERENT")
		#if there are 0 views, then the moved view will have index 0
		#similarly, if there are n views, the last view will have index (n-1), and
		#so the new view will have index n  
		newIndex = len (window.views_in_group(group))
		#move the view to the highlighted group and assign a
		#correct index
		window.set_view_index(view, group, newIndex)


def gotoBookmark(bookmark, window):
	filePath = bookmark.getFilePath()
	lineNumber = bookmark.getLineNumber()

	#Okay, so there's a bug in sublime text.
	#if you open a file *before* opening the options menu,
	#the options menu gets created where the file is opened
	#Yes, this is stupid.

	#This happens in this plugin, since the _AutoMove() callback
	#seems to be called before the options menu is shown
	#So, if I open the file in another group, the options menu
	#opens in the *other* group, and not the current group.
	#I don't know if it's my bug or sublime text's but I have
	#a feeling it's sublime text's bug. Will have to report
	#this. This is a pain...

	#this line's order is important. This needs to be done first
	#since opening a file will cause the active group to change
	activeGroup = window.active_group()
	

	view = window.open_file(filePath)
	#move the view to the currently active group
	moveViewToGroup(window, view, activeGroup)

	#focus on the active group to avoid the panel problem as described
	window.focus_group(activeGroup)	
	window.focus_view(view)
	#show bookmark :)
	view.show_at_center(bookmark.getRegion())
		
	#move cursor to the middle of the bookmark's region
	bookmarkRegionMid = 0.5 * (bookmark.getRegion().begin() +  bookmark.getRegion().end())
	moveRegion = sublime.Region(bookmarkRegionMid, bookmarkRegionMid)
	view.sel().clear()
	view.sel().add(moveRegion)


def shouldShowBookmark(bookmark, window, showAllBookmarks):
	currentProjectPath = window.project_file_name()
	
	#free bookmarks can be shown. We don't need a criteria
	if showAllBookmarks:
		return True
	#there is no current project now. Show all bookmarks
	elif currentProjectPath == None or currentProjectPath == "":
		return True

	#return if the bookmark belongs to current project or not.
	else:
		return bookmark.getProjectPath() == currentProjectPath


#Menu generation-----------------------------------

def createBookmarkPanelItems(window, bookmarks, shouldShowAllBookmarks):	
{'fraction_non_alphanumeric': 0.10687022900763359, 'fraction_numerical': 0.006587890829237687, 'mean_word_length': 4.128150134048258, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2597145', 'n_tokens_mistral': 3117, 'n_tokens_neox': 2877, 'n_words': 1024}