Skip to content

Instantly share code, notes, and snippets.

@sqlstunts
Created September 29, 2015 10:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sqlstunts/2c8050efd7fdb371f133 to your computer and use it in GitHub Desktop.
Save sqlstunts/2c8050efd7fdb371f133 to your computer and use it in GitHub Desktop.
Refactor plugin for MySQL Workbench.
# import the wb module
from wb import *
# import the grt module
import grt
# import the mforms module for GUI stuff
import mforms
# define this Python module as a GRT module
ModuleInfo = DefineModule(name="Refactor", author="mjlmo", version="0.1")
@ModuleInfo.plugin("wb.text.refactor", caption = "Refactor Selection", input=[wbinputs.currentQueryBuffer()], pluginMenu= "SQL/Utilities")
@ModuleInfo.export(grt.INT, grt.classes.db_query_QueryBuffer)
def refactorText(editor):
fulltext=editor.script
text = editor.selectedText
if not text:
mforms.Utilities.show_warning("No selection","No text selected for refactoring.","OK","","")
else:
ret, new_text=mforms.Utilities.request_input("New Text","Enter the text to replace with","")
editor.replaceContents(fulltext.replace(text,new_text))
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment