# Path: operators/tools/get_base_strip.py
# def get_base_strip(strip, base_strips):
#     """Get the strip's base strip"""
#     for i in range(len(base_strips)):
#         if base_strips[i].frame_start <= strip.frame_start:
#             if base_strips[i].frame_final_end >= strip.frame_final_end:
#                 return base_strips[i]
# 
# Path: operators/tools/get_text_strips.py
# def get_text_strips(scene, channel=None):
#     """Get all the text strips in the edit channel"""
# 
#     if channel == None:
#         channel = scene.subtitle_edit_channel
# 
#     all_strips = list(sorted(scene.sequence_editor.sequences,
#             key=lambda x: x.frame_start))
# 
#     text_strips = []
#     for strip in all_strips:
#         if (strip.channel == channel and
#                 strip.type == 'TEXT'):
#             text_strips.append(strip)
# 
#     return text_strips


import bpy
from .tools.get_base_strip import get_base_strip
from .tools.get_text_strips import get_text_strips

class SEQUENCER_OT_shift_frame_start(bpy.types.Operator):
    bl_idname = "sequencerextra.shift_frame_start"
    bl_label = "Shift Frame Start of Next Text Strip"
    bl_description = "Shifts frame start of text strip to the current frame"

    def execute(self, context):
        scene = context.scene

        try:
            text_strips = get_text_strips(scene)

            if len(text_strips) == 0:
                return {"FINISHED"}
        except AttributeError:
            return {"FINISHED"}

        current_frame = scene.frame_current
        base_channel = text_strips[0].channel - 1

# Path: operators/tools/get_base_strip.py
# def get_base_strip(strip, base_strips):
#     """Get the strip's base strip"""
#     for i in range(len(base_strips)):
#         if base_strips[i].frame_start <= strip.frame_start:
#             if base_strips[i].frame_final_end >= strip.frame_final_end:
#                 return base_strips[i]
# 
# Path: operators/tools/get_text_strips.py
# def get_text_strips(scene, channel=None):
#     """Get all the text strips in the edit channel"""
# 
#     if channel == None:
#         channel = scene.subtitle_edit_channel
# 
#     all_strips = list(sorted(scene.sequence_editor.sequences,
#             key=lambda x: x.frame_start))
# 
#     text_strips = []
#     for strip in all_strips:
#         if (strip.channel == channel and
#                 strip.type == 'TEXT'):
#             text_strips.append(strip)
# 
#     return text_strips


# Path: operators/shortcuts.py
import bpy
from .tools.get_base_strip import get_base_strip
from .tools.get_text_strips import get_text_strips


class SEQUENCER_OT_shift_frame_start(bpy.types.Operator):
    bl_idname = "sequencerextra.shift_frame_start"
    bl_label = "Shift Frame Start of Next Text Strip"
    bl_description = "Shifts frame start of text strip to the current frame"

    def execute(self, context):
        scene = context.scene

        try:
            text_strips = get_text_strips(scene)

            if len(text_strips) == 0:
                return {"FINISHED"}
        except AttributeError:
            return {"FINISHED"}

        current_frame = scene.frame_current
        base_channel = text_strips[0].channel - 1

        base_strips = get_text_strips(scene, channel=base_channel)