AutoHotkey Community

It is currently May 26th, 2012, 6:43 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 77 posts ]  Go to page 1, 2, 3, 4, 5, 6  Next
Author Message
 Post subject: Scriptlet Library v4
PostPosted: February 24th, 2005, 1:49 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
Another script whose mommy is Mrs Necessity.

This is to store all those li'l functions or snips (or Scriptlets as i like to call 'em) that you use often in other scripts.
I've never really been a fan of #Include because most of the times u've to modify the scriptlets a li'l to adapt it to current use. This is the way to go!

Revision: toralf made many changes to my original script and his version is much more feature-rich. So i've updated this post to direct to his script instead:

Image

Download

_________________
Image


Last edited by Rajat on August 27th, 2006, 8:01 pm, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2005, 3:33 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Very nice script. Thanks for sharing it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2005, 4:53 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
I got to try it out, it's fantastic!
Thanks for sharing. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 23rd, 2005, 12:25 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
a li'l change: added TAB key support to editor window.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 23rd, 2005, 5:30 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2542
Very handy. Thanks for sharing :).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 23rd, 2005, 7:42 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
this will come in even more handy with the new function feature! call it Function Library if u like!

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject: bug
PostPosted: July 16th, 2005, 12:44 pm 
if 2 item have name:
abc abc
abcabc

this 2 item above will have the same content.


Report this post
Top
  
Reply with quote  
 Post subject: to fix the bug above
PostPosted: July 16th, 2005, 12:46 pm 
Code:
WinName = Scriptlet Library

SetWorkingDir, %A_ScriptDir%

;loading settings
IniRead, PosX, Library.ini, Settings, PosX, 100
IniRead, PosY, Library.ini, Settings, PosY, 100
IniRead, SizeW, Library.ini, Settings, SizeW, 600
IniRead, SizeH, Library.ini, Settings, SizeH, 405
IniRead, LastUsed, Library.ini, Settings, LastUsed, --


;reading scriptlets
FileRead, ScriptFile, Library.ini

Loop, Parse, ScriptFile, `n
{
   IfInString, A_LoopField, <---Start_
      StartFile = 1
   
   IfNotEqual, StartFile, 1, Continue
   
   ;from here the lines which contain scripts are parsed one by one
   
   ;scriptlet started
   IfInString, A_LoopField, <---Start_
   {
      StringReplace, ItemName, A_LoopField, <---Start_,
      StringReplace, ItemName, ItemName, --->,
      StringReplace, ItemName, ItemName, `n,, A
      StringReplace, ItemName, ItemName, `r,, A
      ItemList = %ItemList%|%ItemName%
      ItemRunning = 1
      Continue
   }
   
   ;the current scriptlet ends here
   IfInString, A_LoopField, <---End_
   {
      ItemRunning = 0
      Continue
   }

   ;the current scriptlet is getting parsed
   IfEqual, ItemRunning, 1
   {
      StringReplace, NoSpaceName, ItemName, %A_Space%,_Space_, A
      StringTrimRight, CurrScriptlet, %NoSpaceName%_Script, 0
      %NoSpaceName%_Script = %CurrScriptlet%`n%A_LoopField%
   }
}

StringTrimLeft, ItemList, ItemList, 1
Sort, ItemList, D|


;removing extra carriage returns from scriptlets
Loop, parse, ItemList, |
{
   StringReplace, NoSpaceName, A_LoopField, %A_Space%,_Space_, A
   StringTrimLeft, %NoSpaceName%_Script, %NoSpaceName%_Script, 1
   StringRight, Test, %NoSpaceName%_Script, 2
   
   IfEqual, Test, `r`n   
      StringTrimRight, %NoSpaceName%_Script, %NoSpaceName%_Script, 2
}
   
   


;creating window and controls

Gui, +Resize
Gui, Color,, 0xE9F5F0
Gui, Add, ListBox, x2 y37 w130 h342 vSelItem gSelector, %ItemList%
Gui, Add, Button, x196 y7 w50 h20, &Save
Gui, Add, Button, x136 y7 w50 h20, &Copy
Gui, Add, Button, x26 y7 w20 h20, +
Gui, Add, Button, x66 y7 w20 h20, --

Gui, Font, , Courier
Gui, Add, Edit, x132 y37 w460 h342 Multi vEditData,

Gui, Show, x%PosX% y%PosY% h0 w0, %WinName%
WinMove, %WinName%,,,, %SizeW%, %SizeH%

;last selection
Control, ChooseString, %LastUsed%, ListBox1, %WinName%

;resize settings
WinGetPos,,, WinW, WinH, %WinName%
ControlGetPos,,, C1W, C1H, ListBox1, %WinName%
ControlGetPos,,, C2W, C2H, Edit1, %WinName%

Diff2W := WinW - C2W


Return



Selector:
   Gui, Submit, NoHide
   StringReplace, NoSpaceName, SelItem, %A_Space%,_Space_, A
   CurrData := %NoSpaceName%_Script
   GuiControl,, Edit1, %CurrData%
Return
   


Button+:
   InputBox, ItemName, Enter Scriptlet Name:,,, 200, 90
   IfNotEqual, ErrorLevel, 0, Return
   IfEqual, ItemName,, Return
   ControlGetText, CurrData, Edit1, %WinName%
   FileAppend, <---Start_%ItemName%--->`n%CurrData%`n<---End_%ItemName%--->`n, Library.ini
   
   StringReplace, NoSpaceName, ItemName, %A_Space%,_Space_, A
   %NoSpaceName%_Script = %CurrData%
   ItemList = %ItemList%|%ItemName%
   Sort, ItemList, D|
   GuiControl,, ListBox1, |%ItemList%
Return



Button--:
   MsgBox, 4, Delete Scriptlet?, Please confirm deletion of current scriptlet.
   IfMsgBox, Yes
   {
      Gui, Submit, NoHide
      ItemList = |%ItemList%|
      StringReplace, ItemList, ItemList, |%SelItem%|,|, A
      StringTrimLeft, ItemList, ItemList, 1
      StringTrimRight, ItemList, ItemList, 1
   }
   
   GuiControl,, ListBox1, |%ItemList%
Return


ButtonSave:
   Gui, Submit, NoHide
   ControlGetText, CurrData, Edit1, %WinName%
   StringReplace, NoSpaceName, SelItem, %A_Space%,_Space_, A
   %NoSpaceName%_Script = %CurrData%
Return


ButtonCopy:
   ControlGetText, Clipboard, Edit1, %WinName%
Return   
   

~Esc::
   IfWinNotActive, %WinName%,, Return
GuiClose:
   FileDelete, Library.ini
   WinGetPos, PosX, PosY, SizeW, SizeH, %WinName%
   IniWrite, %PosX%, Library.ini, Settings, PosX
   IniWrite, %PosY%, Library.ini, Settings, PosY
   IniWrite, %SizeW%, Library.ini, Settings, SizeW
   IniWrite, %SizeH%, Library.ini, Settings, SizeH
   IniWrite, %SelItem%, Library.ini, Settings, LastUsed
   
   FileAppend, `r`n, Library.ini
   
   ControlGet, ItemList, List,, ListBox1, %WinName%
      
   Loop, Parse, ItemList, `n
   {
      IfEqual, A_LoopField,, Continue
      StringReplace, NoSpaceName, A_LoopField, %A_Space%,_Space_, A
      
      StringTrimRight, CurrScriptlet, %NoSpaceName%_Script, 0
      FileAppend, `r`n<---Start_%A_LoopField%--->`r`n%CurrScriptlet%`r`n<---End_%A_LoopField%--->`r`n, Library.ini
   }
   
   ExitApp
Return


GuiSize:
   ;function adapted from jonny's clip.ahk. thanx jonny!
   new_w := (A_GuiWidth - 5)
   new_h := (A_GuiHeight - 39)
   field_y := (A_GuiHeight - 40)
   new_w := (new_w / 4)
   guicontrol,move,SelItem,w%new_w% h%field_y%
   new_x := (new_w + 5)
   new_w := (new_w * 3)
   guicontrol,move,EditData,w%new_w% h%field_y% x%new_x%
Return

   
Tab::
   WinGetTitle, ATitle, A
   ControlGetFocus, ACtrl, A
   
   OtherWin = 1
   IfEqual, ATitle, %WinName%
      IfEqual, ACtrl, Edit1
      {
         Send, ^{Tab}
         OtherWin = 0
      }
   
   IfEqual, OtherWin, 1
      Send, {Tab}
Return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 16th, 2005, 4:16 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
that's true because the data of an item is saved in the var 'itemname_Script' and a varname doesn't allow a space in it. i know a way to fix that, but as this is a very little problem it might be a while till i get to it.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 17th, 2005, 9:14 pm 
Rajat, your imagination amazes me sometimes. You have posted some awesome scripts here that I have come to depend on and use daily.

Thank you....


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2005, 10:00 am 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Dear Rajat,

I have had a closer look at the script, I like the way the scriplets are stored in the INI.
I decided to make a mod.
1) ListBox is replaced with ListView
2) Names of scriplets can be any string without any limit
3) Names like "1 2" and "12" are regarded different
4) I was able t o reduce the number of lines to 102 (coming from 188)[Ok, I also removed some comments and empty lines]

Would you allow me to incorporate this script in a larger software I plan to code?

Edit 05-07-25:
- I changed some var names
- added sort after add, new item gets selected
- right mouse click rolls the window up
- add some shortcuts
- it now has 139 lines :(

Code:
WinNameGui1 = Scriptlet Library v2
;requires AHK 1.0.37

Gui, 1:+Resize
Gui, 1:Add, Button, Section gBtnAdd, &Add
Gui, 1:Add, Button, ys vBtnDelete gBtnDelete Disabled, &Del
Gui, 1:Add, Button, x+100 ys vBtnSave gBtnSave Disabled, &Save changes
Gui, 1:Add, Button, ys gBtnCopy, Copy to &Clipboard
Gui, 1:Add, ListView, xs Section w100 h200 -Multi AltSubmit vLsbNames gLsbNames, Scriptlet Name|Internal ID
Internal_ID = 0
Loop, Read, %A_ScriptName%.ini
    {
        If A_LoopReadLine Contains <---Start_
            {
                Internal_ID++
                StringReplace, Name, A_LoopReadLine, <---Start_,
                LV_Add("",Name,Internal_ID)
                ItemInProcess := True
                Script%Internal_ID% =
            }
        Else If A_LoopReadLine Contains <---End_,
            {
                ItemInProcess := False
                StringTrimRight, Script%Internal_ID%, Script%Internal_ID%, 1
            }
        Else If ItemInProcess
                Script%Internal_ID% := Script%Internal_ID% . A_LoopReadLine . "`n"
    }
Gui, 1:Font, , Courier
Gui, 1:Add, Edit, ys w200 h200 Multi T8 vEditData,
IniRead, GuiSize1, %A_ScriptName%.ini, Settings, GuiSize1, %A_Space%
Gui, 1:Show, %GuiSize1%, %WinNameGui1%
WinGet, Gui1UniqueID, ID, %WinNameGui1%
GuiRolledUp := False
Return

$Rbutton::
  MouseGetPos, , , GuiID
  If ( Gui1UniqueID = GuiID )
    {
      If GuiRolledUp
        {
          GuiControl, 1:Move, LsbNames, h%LsbNamesH%
          Gui, 1:Show, AutoSize
        }
      Else
        {
          GuiControlGet, LsbNames, Pos, LsbNames
          WinMove, ahk_id %Gui1UniqueID%,,,,, 30
        }
      GuiRolledUp := not GuiRolledUp
    }
  Else
      Send, {Rbutton}
return

LsbNames:
    LV_GetText(ID, LV_GetNext(), 2)
    If ( ID <> "Internal ID" )
      {
        GuiControl,1:, EditData, % Script%ID%  ;%
        GuiControl,1: Enable, BtnDelete
        GuiControl,1: Enable, BtnSave
      }
    Else
      {
        GuiControl,1:, EditData
        GuiControl,1: Disable, BtnDelete
        GuiControl,1: Disable, BtnSave
      }
Return

BtnAdd:
    Gui, 1:+OwnDialogs
    Gui, 1:Submit, NoHide
    InputBox, Name, Enter Scriptlet Name:,,, 200, 90
    IfNotEqual, ErrorLevel, 0, Return
    IfEqual, Name,, Return
    Gui, 1:Submit, NoHide
    Internal_ID++
    LV_Add("Select",Name,Internal_ID)
    LV_ModifyCol(1, "Sort")
    Script%Internal_ID% = %EditData%
Return

BtnDelete:
    RowNumber := LV_GetNext()
    LV_GetText(Name, RowNumber, 1)
    MsgBox, 4, Delete Scriptlet?, Please confirm deletion`nof current scriptlet:`n%Name%
    IfMsgBox, Yes
        {
            LV_GetText(ID, RowNumber, 2)
            Script%ID% =
            LV_Delete(RowNumber)
        }
Return

BtnSave:
    Gui, 1:Submit, NoHide
    LV_GetText(ID, LV_GetNext(), 2)
    Script%ID% = %EditData%
Return

BtnCopy:
    Gui, 1:Submit, NoHide
    Clipboard = %EditData%
Return

GuiEscape:
GuiClose:
    If GuiRolledUp
        {
          GuiControl, 1:Move, LsbNames, h%LsbNamesH%
          Gui, 1:Show, AutoSize
        }
    FileDelete, %A_ScriptName%.ini
    WinGetPos, PosX, PosY, SizeW, SizeH, %WinNameGui1%
    IniWrite, x%PosX% y%PosY% w%SizeW% h%SizeH%, %A_ScriptName%.ini, Settings, GuiSize1
    FileAppend, `n`n, %A_ScriptName%.ini
    Loop, % LV_GetCount()  ;%
        {
            LV_GetText(Name, A_Index, 1)
            LV_GetText(ID, A_Index, 2)
            Script := Script%ID%
            FileAppend, <---Start_%Name%`n%Script%`n<---End_%Name%`n`n`n, %A_ScriptName%.ini
        }
    ExitApp
Return

GuiSize:
    new_w := (A_GuiWidth - 30 ) / 3
    new_h := A_GuiHeight - 41
    GuiControl, 1:Move, LsbNames, w%new_w% h%new_h%
    LV_ModifyCol(1, new_w)
    LV_ModifyCol(2, 0)
    new_x := new_w + 20
    new_w := new_w * 2
    GuiControl, 1:Move, EditData, w%new_w% h%new_h% x%new_x%
Return

_________________
Ciao
toralf
Image


Last edited by toralf on July 25th, 2005, 6:40 pm, edited 7 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2005, 3:56 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
that's nice work toralf! may i suggest incorporating sorting to your script.. that'd be nice i guess.

Quote:
Would you allow me to incorporate this script in a larger software I plan to code?

sure... please go ahead with that!

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2005, 4:25 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
What kind of sort do you want?
If you click on the column header of the listview it sorts the names ascending or descending. When you then close the gui, it will be saved in that order.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2005, 4:44 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
i should have clarified... i meant auto-sorting after adding a new item.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 23rd, 2005, 2:29 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Beaut!


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 77 posts ]  Go to page 1, 2, 3, 4, 5, 6  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: fusion1920, Ragnar, Retro Gamer and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group