Search code examples
phpmacrosdreamweavernotepad++gettext

How to create macros/shortcuts in Dreamweaver or Notepad++


I've never made "macros" or anything like that with any program.

I'm moving my php code to use "gettext", so I have to look for all my static text and change it up.

For example, I need to change page title to <?php echo _('page title'); ?>.

I don't think there is a way to change it all up in one shot, as it involves looking to see if it looks like static text, but I'm sure it's possible in one of those editors to maybe, select a text, press some keyboard shortcut, and it would do the replacement for me.

Is that possible? How?

I have both Dreamweaver and Notepad++ handy. I'm open to using some other tool.

Thanks!


Solution

  • Download and install PSPad.

    Then save the following script into a VBS file in <PSPadFolder>\Script\VBScript and re-open PSPad.

    'Enclose It! by Lukman
    const module_name  = "Enclose It!"
    const module_ver   = "0.1"
    const enclose_token = "_SRC_"
    const enclose_hotkey = "CTRL+Q"
    
    enclose_last = enclose_token
    
    sub Init
        addMenuItem "Enclose It!","", "EncloseIt", enclose_hotkey
    end sub
    
    sub EncloseIt
        encloser = InputBox("Enclose content", module_name, enclose_last)
        If encloser = False Then Exit Sub
    
        Set editor = newEditor()
        editor.assignActiveEditor
        editor.selText Replace(encloser, enclose_token, editor.selText)        
        enclose_last = encloser
    end sub
    

    Then open your document.

    Highlight some text in the documentand press Ctrl + Q hotkey (customizable in the script itself) to open a input dialog with _SRC_ predefault in it. Just change the keyword to <?php echo _('_SRC_'); ?> and press enter. Repeat. (The script remembers the last keyword used so you don't have to type it all again).