コード例 #1
0
ファイル: makePDF.py プロジェクト: r-stein/LaTeXTools
	def run(self, select=False):
		select = False if select not in (True, False) else select
		view = self.view = self.window.active_view()
		if not select:
			window_settings = self.WINDOWS.get(self.window.id(), {})
			build_system = window_settings.get('build_system')

			if build_system:
				build_variant = window_settings.get('build_variant', '')
				self.run_build(build_system, build_variant)
				return

		# no previously selected build system or select is True
		# find all .sublime-build files
		if _ST3:
			sublime_build_files = sublime.find_resources('*.sublime-build')
			project_settings = self.window.project_data()
		else:
			sublime_build_files = glob.glob(os.path.join(
				sublime.packages_path(), '*', '*.sublime-build'
			))
			project_file_name = get_project_file_name(view)
			if project_file_name is not None:
				try:
					project_settings = \
						parse_json_with_comments(project_file_name)
				except:
					print('Error parsing project file')
					traceback.print_exc()
					project_settings = {}
			else:
				project_settings = {}

		builders = []
		for i, build_system in enumerate(
			project_settings.get('build_systems', [])
		):
			if (
				'selector' not in build_system or
				view.score_selector(0, project_settings['selector']) > 0
			):
				try:
					build_system['name']
				except:
					print('Could not determine name for build system {0}'.format(
						build_system
					))
					continue

				build_system['index'] = i
				builders.append(build_system)

		for filename in sublime_build_files:
			try:
				sublime_build = parse_json_with_comments(filename)
			except:
				print(u'Error parsing file {0}'.format(filename))
				continue

			if (
				'selector' not in sublime_build or
				view.score_selector(0, sublime_build['selector']) > 0
			):
				sublime_build['file'] = filename.replace(
					sublime.packages_path(), 'Packages', 1
				).replace(os.path.sep, '/')

				sublime_build['name'] = os.path.splitext(
					os.path.basename(sublime_build['file'])
				)[0]

				builders.append(sublime_build)

		formatted_entries = []
		build_system_variants = []
		for builder in builders:
			build_system_name = builder['name']
			build_system_internal_name = builder.get(
				'index', builder.get('file')
			)

			formatted_entries.append(build_system_name)
			build_system_variants.append((build_system_internal_name, ''))

			for variant in builder.get('variants', []):
				try:
					formatted_entries.append(
						"{0} - {1}".format(
							build_system_name,
							variant['name']
						)
					)
				except KeyError:
					continue

				build_system_variants.append(
					(build_system_internal_name, variant['name'])
				)

		entries = len(formatted_entries)
		if entries == 0:
			self.window.run_command('build')
		elif entries == 1:
			build_system, build_variant = build_system_variants[0]
			self.WINDOWS[self.window.id()] = {
				'build_system': build_system,
				'build_variant': build_variant
			}
			self.run_build(build_system, build_variant)
		else:
			def on_done(index):
				# cancel
				if index == -1:
					return

				build_system, build_variant = build_system_variants[index]
				self.WINDOWS[self.window.id()] = {
					'build_system': build_system,
					'build_variant': build_variant
				}
				self.run_build(build_system, build_variant)

			self.window.show_quick_panel(formatted_entries, on_done)
コード例 #2
0
    def run(self, select=False):
        select = False if select not in (True, False) else select
        view = self.view = self.window.active_view()
        if not select:
            window_settings = self.WINDOWS.get(self.window.id(), {})
            build_system = window_settings.get('build_system')

            if build_system:
                build_variant = window_settings.get('build_variant', '')
                self.run_build(build_system, build_variant)
                return

        # no previously selected build system or select is True
        # find all .sublime-build files
        if _ST3:
            sublime_build_files = sublime.find_resources('*.sublime-build')
            project_settings = self.window.project_data() or {}
        else:
            sublime_build_files = glob.glob(
                os.path.join(sublime.packages_path(), '*', '*.sublime-build'))
            project_file_name = get_project_file_name(view)
            if project_file_name is not None:
                try:
                    project_settings = \
                     parse_json_with_comments(project_file_name)
                except:
                    print('Error parsing project file')
                    traceback.print_exc()
                    project_settings = {}
            else:
                project_settings = {}

        builders = []
        for i, build_system in enumerate(
                project_settings.get('build_systems', [])):
            if ('selector' not in build_system or view.score_selector(
                    0, project_settings.get('selector', 'text.tex.latex')) >
                    0):
                try:
                    build_system['name']
                except:
                    print(
                        'Could not determine name for build system {0}'.format(
                            build_system))
                    continue

                build_system['index'] = i
                builders.append(build_system)

        for filename in sublime_build_files:
            try:
                sublime_build = parse_json_with_comments(filename)
            except:
                print(u'Error parsing file {0}'.format(filename))
                continue

            if ('selector' not in sublime_build
                    or view.score_selector(0, sublime_build['selector']) > 0):
                sublime_build['file'] = filename.replace(
                    sublime.packages_path(), 'Packages',
                    1).replace(os.path.sep, '/')

                sublime_build['name'] = os.path.splitext(
                    os.path.basename(sublime_build['file']))[0]

                builders.append(sublime_build)

        formatted_entries = []
        build_system_variants = []
        for builder in builders:
            build_system_name = builder['name']
            build_system_internal_name = builder.get('index',
                                                     builder.get('file'))

            formatted_entries.append(build_system_name)
            build_system_variants.append((build_system_internal_name, ''))

            for variant in builder.get('variants', []):
                try:
                    formatted_entries.append("{0} - {1}".format(
                        build_system_name, variant['name']))
                except KeyError:
                    continue

                build_system_variants.append(
                    (build_system_internal_name, variant['name']))

        entries = len(formatted_entries)
        if entries == 0:
            self.window.run_command('build')
        elif entries == 1:
            build_system, build_variant = build_system_variants[0]
            self.WINDOWS[self.window.id()] = {
                'build_system': build_system,
                'build_variant': build_variant
            }
            self.run_build(build_system, build_variant)
        else:

            def on_done(index):
                # cancel
                if index == -1:
                    return

                build_system, build_variant = build_system_variants[index]
                self.WINDOWS[self.window.id()] = {
                    'build_system': build_system,
                    'build_variant': build_variant
                }
                self.run_build(build_system, build_variant)

            self.window.show_quick_panel(formatted_entries, on_done)