Last active
February 3, 2020 15:35
-
-
Save tin2tin/339e2e9ade530d34bc82e03d9c2a39a9 to your computer and use it in GitHub Desktop.
Find & Replace Popup for Blender Text Editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
class PopupFindReplace(bpy.types.Operator): | |
bl_idname = 'text.popup_find_replace' | |
bl_label = 'Find & Replace' | |
bl_description = 'Pop-up with Find and Replace' | |
bl_options = {'REGISTER', 'UNDO'} | |
@classmethod | |
def poll(cls, context): | |
return context.area.type == 'TEXT_EDITOR' | |
def draw(self, context): | |
layout = self.layout | |
st = context.space_data | |
# find | |
col = layout.column(align=True) | |
row = col.row(align=True) | |
row.operator("text.find_set_selected", text="", icon='EYEDROPPER') | |
subrow = row.split(align=True) | |
subrow.scale_x = 1.6 | |
subrow.prop(st, "find_text", text="") | |
subrow.activate_init = True | |
row.operator("text.find", text="Find Next", icon='VIEWZOOM') | |
# replace | |
col = layout.column(align=True) | |
row = col.row(align=True) | |
row.operator("text.replace_set_selected", text="", icon='EYEDROPPER') | |
subrow = row.split(align=True) | |
subrow.scale_x = 1.6 | |
subrow.prop(st, "replace_text", text="") | |
row.operator("text.replace", text="Replace ", icon='FILE_REFRESH') | |
# settings | |
row = layout.row(align=True) | |
row.prop(st, "use_match_case", text="Match Case", icon="SMALL_CAPS") | |
row.prop(st, "use_find_wrap", text="Wrap Around", icon="INDIRECT_ONLY_OFF") | |
row.prop(st, "use_find_all", text="All Texts", icon="DECORATE_DRIVER") | |
def execute(self, context): | |
return {'FINISHED'} | |
def invoke(self, context, event): | |
return context.window_manager.invoke_props_dialog(self, width=400) | |
def register_keymaps(): | |
kc = bpy.context.window_manager.keyconfigs | |
if kc.addon: | |
km = kc.addon.keymaps.new(name='Text', space_type='TEXT_EDITOR') | |
km.keymap_items.new('text.popup_find_replace', | |
'F', 'PRESS', ctrl=True, shift=True) | |
def unregister_keymaps(): | |
kc = bpy.context.window_manager.keyconfigs | |
if kc.addon: | |
km = kc.addon.keymaps['Text'] | |
kmi = km.keymap_items['text.popup_find_replace'] | |
km.keymap_items.remove(kmi) | |
def register(): | |
bpy.utils.register_class(PopupFindReplace) | |
register_keymaps() | |
def unregister(): | |
bpy.utils.unregister_class(PopupFindReplace) | |
unregister_keymaps() | |
if __name__ == '__main__': | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment