Jump to content

Snippet holder for SciTE


BigDaddyO
 Share

Recommended Posts

Snippet Holder for SciTE

This script will allow you to easily store and retrieve commonly used code.

This Script will only work properly if you have SciTE installed in the standard location. If you installed SciTE into a custom location you will have to modify the code to show that location.

Versions

v 2.1 Fixed / added the following

- <Added> file, exit

- <Added> the Help, About with a hyperlink to the Forum thread for more info

- <fixed> the Add New Snippet problem if no catagories exist (Thanks JdeB)

- <Fixed> The Category CMDtmp was showing on the main screen

- <Fixed> Overwrite of Snippet checking was preventing the Modifications of current Snippets

v 2.0 Much better handling of the Right Click in SciTE, modification made to the ini structure to handle this... "Thanks again JdeB"

Also put in checking so you don't accidently overwrite an old snippet when you name a new one, "can't imagine how I found this bug. :">

v1.9 Allow new Snippet creation via, Right Click in SciTE

v1.8 Used gafrost code to automatically update the stored x,y coords when ever they change, Also added the hotkey of Ctrl+Alt+s to automatically add any selected text in scite into a new Snippet.

v1.7 Modified the already launched function to show msgbox. & modified the way it attempts to find the SciTE directory to launch SciTE.

v1.6 modified the GUI so it is a MDICHILD of SCITE so it will minimize with SciTE and is only on top of SciTE

v1.5 Added ability to modify code before adding into ini

- Added ability to modify a snippet that is currently stored

- added the abiltiy to move a snippet from one category to another

- modified ini structure slightly

- The code is too long now to paste directly into this so I have attached the file below

v1.4 Added ability to rename and delete Categories and snippets

v1.3 no longer replaces the clipboard contents when retrieving a snippet

v1.2 Improved the Paste into SciTE, Added a Right click, Preview Snippet option.

v1.1 fixed an issue with unable to paste code back into SciTE

Instructions for Use

Upon the initial launch of Snippet you will only see a blank white box with a menu option of Commands.

You must first add some categories to the Snippet holder by clicking Commands, Create a new Category.

You must then specify a name for that Category; an example could be COM Objects or GUI Stuff

Once you have your Categories setup you can then add snippets of code into those Categories.

There are several ways to now add code into those Categories. You may select the category then right click and choose Add new Snippet here.

Or you can Select the Category then click Commands, Add SciTE code as Snippet

Or you can not select any Category and just click Commands, Add SciTE code as Snippet

Or you can Highlight a section of Text in SciTE and right click then choose Add as Snippet. (Only available if you have modified your au3.properties file, See below for more info)

Once the Snippet Code window opens you must specify the Snippet Name you want to use. You must also select a Snippet Category. This will automatically be filled in if a Category was selected before opening this window.

In the large edit box you must now type in or paste in the Code you wish to store.

Click on Save Snippet once finished.

You will now have that snippet name listed under the Category you just selected.

You now have more options when you select a Snippet and right click.

You may perform any of the following

- Send to SciTE

o This will copy and paste this code directly into the SciTE editor where your cursor is

- Preview Snippet

o This will display the snippet in a message box so you can verify it is the one you were looking for

- Modify this Snippet

o This will open the snippet in the Add Snippet window so you can modify the Name, Category, or code

- Rename Selection

o This will allow you to rename the Snippet or Category that is selected

- Delete Selection

o This will allow you to delete the Snippet or Category that is selected

How to Integrate with SciTE

Below are some steps that I have done to make my life easier.

(Warning, perform these options at your own risk)

I created a folder off the SciTE directory called Snippets where I have saved the Snippet.exe

I then modified my SciTE shortcut to point to the new Snippet.exe file since it auto-launches SciTE if its not already open. That way I only have one shortcut to launch SciTE and the Snippet holder.

I have also added a Ctrl+Alt+s command to launch the Snippet.exe once I am in SciTE if I accidentially closed it. Modify SciTEs au3.Properties file by adding the following lines "For me it starts at line 140". Once added, close and re-open SciTE to initialize the changes.

Thanks to JdeB's info I now have added the ability to create a new Snippet by Highlighting text, Right click, click on Add as Snippet. The new version 1.9 supports this feature.

# 16 MikeOsdx Snippet holder

command.16.$(file.patterns.au3)="$(SciteDefaultHome)\Snippets\Snippet.exe" $(CurrentSelection)

command.name.16.$(file.patterns.au3)=Snippet Holder

command.shortcut.16.$(file.patterns.au3)=Ctrl+Alt+s

command.subsystem.16.$(file.patterns.au3)=2

command.save.before.16.$(file.patterns.au3)=2

command.replace.selection.16.$(file.patterns.au3)=0

command.quiet.16.$(file.patterns.au3)=1

#Modify Context Menu to add Right Click, Add as Snippet

user.context.menu=||Add as Snippet|1116|

Snippet.au3

Edited by BigDaddyO
re-added the snippet.au3
Link to comment
Share on other sites

hi mike

at the risk of sounding stupid, what is a "snippet" ? before i run anything i like to have some idea what it does. i googled snippet and got everything under the sun!

thank you...phil

Phil,

A snippet is a section of code. It could be anything from an often used function to a few lines. Storing snippets in a library that is easy to access and insert into source is one thing I miss using SciTE, so I'm looking forward to trying Mike's solution here.

HTH,

billmez

Link to comment
Share on other sites

Hi,

I think I followed your instructions, but I am having a problem.

I made the changes to au3.properties Scite continues to work fine, I also made the shortcut to start snippet.exe and put it (snippet.exe) in the snippets folder under the Scite folder.

Snippet wouldn't run.

I made the following changes to the script: Note it is not in code tags because it loses the bold and color...

Begin Code Snippet

;Snippet holder for SCITE

;Must find a way to have the Snippet.exe only be on top of SCITE not ontop of everything...

$g_szVersion = "Snippet"

;If WinExists($g_szVersion) Then ; {Third change}

; Exit ; It's already running ; {Third change}

;EndIf ; {Third change}

AutoItWinSetTitle($g_szVersion)

;#NoTrayIcon ; {First Change}

#include <GuiConstants.au3> ;Inclusion file for the GUI interface controls

#include <file.au3>

#include <array.au3>

#include <GuiTreeView.au3>

Opt("WinTitleMatchMode", 2)

If Not ProcessExists("SciTe.exe") Then

;Run(@ProgramFilesDir & "\AutoIt3\SciTe\SciTe.exe", @ScriptDir)

Run("K:\Local\Prog\AutoIt3\SciTe\SciTe.exe", @ScriptDir) ; {Second change}

EndIf

End Code Snippet

  • After I made the first change I could see the tray icon popup and disappear,
  • After the second change I could see the tray icon popup and disappear and Scite didn't start.
  • After the third change the # 1 & 2 behavior occurred followed by this error message. "AutoIt3.exe has generated errors and will be closed by Windows. You will need to restart the program.

    An error log is being created.

    " I looked for an error log in the AutoIt, Beta, Scite, and Snippet folders but didn't find one. Before making the third change I had checked repeatedly the Task Manager Applications and Processes to see a previos iteration was running. Some where in the process of trying to find the problem a reboot occured.
I'm running Win2K, SP4, 256MB RAM several GB of free space on HD. IE 6.x

I hope you have some ideas.

Gene

Edits typos & forgotten thoughts.

Snippet Holder for SciTE

# 16 MikeOsdx Snippet holder

command.16.$(file.patterns.au3)="$(SciteDefaultHome)\Snippets\Snippet.exe"

command.name.16.$(file.patterns.au3)=Snippet Holder

command.shortcut.16.$(file.patterns.au3)=Ctrl+Alt+s

command.subsystem.16.$(file.patterns.au3)=2

command.save.before.16.$(file.patterns.au3)=2

command.replace.selection.16.$(file.patterns.au3)=0

command.quiet.16.$(file.patterns.au3)=1

Edited by Gene

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Link to comment
Share on other sites

Gene,

Thanks for taking a look at it.

I made some changes and uploaded v1.7 in the first post. I tested it on a Win2K with SciTE installed in a non-standard directory and it worked fine.

I Compiled it using the most current Beta version .103 for my tests.

Let me know if this version works for you.

Mike

Link to comment
Share on other sites

Hi MikeOsdx,

Thanks for the updates, it works now. There is one curious anomally, I have Scite set to open 25 pixels from the left of the screen and be 825 (p)ixels wide. The right edge of Scite would 850 p from the left. I moved Snippet to the right of the Scite window with a 5 or 6 p gap, closed Scite and Snippet, then reopened them via Snippet. Scite opened in its normal place and Snippet opened at x= 884 p with the right edge off the screen. I closed them both, opened Snippet.INI and set x=855, and closed w/ save. I reopened S & S via Snippet again Snippet opened at x=884 p with the right edge off the screen. I reopened the Snippet.INI to make sure I had saved it, x was still = 855. When I closed S & S the INI was reset to x-884. Go figure?

I used AutoIt Window Information to determine the locations of Scite and Snippet. Snippet also comes up in different vertical locations too. :lmao: I haven't tried its reasons for being yet, but I will.

Gene

Gene,

Thanks for taking a look at it.

I made some changes and uploaded v1.7 in the first post. I tested it on a Win2K with SciTE installed in a non-standard directory and it worked fine.

I Compiled it using the most current Beta version .103 for my tests.

Let me know if this version works for you.

Mike

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Link to comment
Share on other sites

Gene,

The saving of the location was working great until I made the Snippet holder a child of SciTE, after that the save never seemed to work as well as it used to. I have even seen on my system when I was trying to save the Snippet window so it was just below all the tool bars but above the status bar and it would not keep it no matter what I tried... I finally moved it so it was over the top tool bar and it save that...

I don't quite understand it but I know it has something to do with being a Child of SciTE

Mike

Link to comment
Share on other sites

Mike,

This is a very useful little piece of code, and having to position the snippet window is a small price to pay.

I tried the first version you posted and havn't had time to get back to it, but the insert into selection didn't work for me. It now works fine, and the additional right click selections are also a plus.

thanks,

billmez

Gene,

The saving of the location was working great until I made the Snippet holder a child of SciTE, after that the save never seemed to work as well as it used to. I have even seen on my system when I was trying to save the Snippet window so it was just below all the tool bars but above the status bar and it would not keep it no matter what I tried... I finally moved it so it was over the top tool bar and it save that...

I don't quite understand it but I know it has something to do with being a Child of SciTE

Mike

Link to comment
Share on other sites

Hi Mike,

  • Could you try saving the new location when it is moved instead of on exit and
  • Assume the opening position will be off and move it to the INI position? Or
  • Read the Scite Global properties to see where Scite will open, open Snippet invisible behind Scite move it to the INI location and make it visible.
That may be a kludge programmatically, but it would be nice for the user.

Gene

Edit: I went back and reread your reasons for making it a child of Scite. Couldn't you do all of that in a UDF that would watch Scite an react accordingly? It could run from Case Else in your main Select...Case tree.

Gene,

The saving of the location was working great until I made the Snippet holder a child of SciTE, after that the save never seemed to work as well as it used to. I have even seen on my system when I was trying to save the Snippet window so it was just below all the tool bars but above the status bar and it would not keep it no matter what I tried... I finally moved it so it was over the top tool bar and it save that...

I don't quite understand it but I know it has something to do with being a Child of SciTE

Mike

Edited by Gene

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Link to comment
Share on other sites

decided to take a look at this, see if i could make a more to my liking here's what i came up with so far.

1st: Changed from treeview to listview

2nd: added the edit window for source code viewing editing, didn't change the way new snippets are added

3rd: added filter to category

4th: no global variables

5th: ini x, y info updated as window is moved.

6th: When Snippet window is not the active window it minimizes

Edit: forgot to add a check on exit to see if the code in the edit box has changed. (added) and fixed modify code.

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

This looks good too. I like the edit view. In the Add Snippet window the Snippet Category dropdown does not show any categories. The listview is OK, but I liked the treeview better.

Gene :lol:

Edit: If you Minimize Scite then restore Snippet and then try to restore Scite, it won't restore. It remains Minimized, but Snippet restores, then each time you click Scite on the Task bar, Snippet Minimizes and then immediately restores. If you right-click Scite on the Task bar and select Restore, Scite will restore. :king:;):):lmao:

Hmmmn.... Whats up Doc? o:)

decided to take a look at this, see if i could make a more to my liking here's what i came up with so far.

1st: Changed from treeview to listview

2nd: added the edit window for source code viewing editing, didn't change the way new snippets are added

3rd: added filter to category

4th: no global variables

5th: ini x, y info updated as window is moved.

6th: When Snippet window is not the active window it minimizes

Edit: forgot to add a check on exit to see if the code in the edit box has changed. (added) and fixed modify code.

http://www.autoitscript.com/fileman/users/gafrost/Snippet.GIF

Edited by Gene

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Link to comment
Share on other sites

change the height of the combo to 100 or more, then it should work

Try the following its at the top of the while loop, looks like it works for what you described

While 1
        If Not ProcessExists("SciTE.exe") Then Exit
        If Not WinActive($g_szVersion) Then
            GUISetState(@SW_MINIMIZE)
        ElseIf BitAND(WinGetState($g_szVersion), 16) And (BitAND(WinGetState("SciTE", "Source"),8) Or BitAND(WinGetState("SciTE", "Source"),32) Or BitAND(WinGetState("SciTE", "Source"),4)) Then
            GUISetState(@SW_RESTORE)
            WinActivate($g_szVersion)
        EndIf
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

made the above changes

v1.9

Maybe tomorrow i'll change the rename process, should be able to do that inline in the listview

Updated, still a few glitches to work out

Edit: Removed Source, Some things to work out and some ideas to ponder/impliment.

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Thanks, I should have remembered that.

Gene

change the height of the combo to 100 or more, then it should work

Try the following its at the top of the while loop, looks like it works for what you described

While 1
        If Not ProcessExists("SciTE.exe") Then Exit
        If Not WinActive($g_szVersion) Then
            GUISetState(@SW_MINIMIZE)
        ElseIf BitAND(WinGetState($g_szVersion), 16) And (BitAND(WinGetState("SciTE", "Source"),8) Or BitAND(WinGetState("SciTE", "Source"),32) Or BitAND(WinGetState("SciTE", "Source"),4)) Then
            GUISetState(@SW_RESTORE)
            WinActivate($g_szVersion)
        EndIf

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Link to comment
Share on other sites

made the above changes

v1.9

Maybe tomorrow i'll change the rename process, should be able to do that inline in the listview

Updated, still a few glitches to work out

I took a look at this version which I must say I grabbed the update x,y on move. But it is WAY to big. I made this Snippet holder so I can leave it open all the time on the right side of my SciTE screen that gives me very quick access.

Also,

A friend of mine uses another application for vb scripting and he says that he just highlights the code in his editor window, Right clicks, then clicks add as Snippet. I don't know if this is possible but I think I will look into adding an item into SciTE's Right click menu.

For now, I added a HotKey of Ctrl+Alt+s "Which is what I use to Launch Snippet" to grab the selected text in SciTE and automatically open the Snippet editor window and insert the text. If anyone knows how to modify the SciTE right click menu that would be really cool :lmao:

I updated the au3 file in the first post with this version

Mike

Link to comment
Share on other sites

OK,

So if I add the following lines to the au3.properties file I will get the Add as Snippet on the Right click but I can't seem to get it to do anything...

Anybody have any ideas?

#Modify Context Menu to add Right Click, Add as Snippet

user.context.menu=||Add as Snippet|Ctrl+Alt+s|

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...