AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Scriptlet Library v4
Goto page 1, 2, 3, 4, 5  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Rajat



Joined: 28 Mar 2004
Posts: 1717

PostPosted: Thu Feb 24, 2005 1:49 pm    Post subject: Scriptlet Library v4 Reply with quote

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:



Download
_________________


Last edited by Rajat on Sun Aug 27, 2006 8:01 pm; edited 3 times in total
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Thu Feb 24, 2005 3:33 pm    Post subject: Reply with quote

Very nice script. Thanks for sharing it.
Back to top
View user's profile Send private message Send e-mail
Titan



Joined: 11 Aug 2004
Posts: 5009
Location: imaginationland

PostPosted: Thu Feb 24, 2005 4:53 pm    Post subject: Reply with quote

I got to try it out, it's fantastic!
Thanks for sharing. Smile
Back to top
View user's profile Send private message Visit poster's website
Rajat



Joined: 28 Mar 2004
Posts: 1717

PostPosted: Sat Apr 23, 2005 12:25 pm    Post subject: Reply with quote

a li'l change: added TAB key support to editor window.
_________________
Back to top
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2381

PostPosted: Sat Apr 23, 2005 5:30 pm    Post subject: Reply with quote

Very handy. Thanks for sharing Smile.
Back to top
View user's profile Send private message Visit poster's website
Rajat



Joined: 28 Mar 2004
Posts: 1717

PostPosted: Sat Apr 23, 2005 7:42 pm    Post subject: Reply with quote

this will come in even more handy with the new function feature! call it Function Library if u like!
_________________
Back to top
View user's profile Send private message
tester
Guest





PostPosted: Sat Jul 16, 2005 12:44 pm    Post subject: bug Reply with quote

if 2 item have name:
abc abc
abcabc

this 2 item above will have the same content.
Back to top
tester
Guest





PostPosted: Sat Jul 16, 2005 12:46 pm    Post subject: to fix the bug above Reply with quote

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
Back to top
Rajat



Joined: 28 Mar 2004
Posts: 1717

PostPosted: Sat Jul 16, 2005 4:16 pm    Post subject: Reply with quote

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.
_________________
Back to top
View user's profile Send private message
Guest






PostPosted: Sun Jul 17, 2005 9:14 pm    Post subject: Reply with quote

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....
Back to top
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Fri Jul 22, 2005 10:00 am    Post subject: Reply with quote

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


Last edited by toralf on Mon Jul 25, 2005 6:40 pm; edited 7 times in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Rajat



Joined: 28 Mar 2004
Posts: 1717

PostPosted: Fri Jul 22, 2005 3:56 pm    Post subject: Reply with quote

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!
_________________
Back to top
View user's profile Send private message
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Fri Jul 22, 2005 4:25 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Rajat



Joined: 28 Mar 2004
Posts: 1717

PostPosted: Fri Jul 22, 2005 4:44 pm    Post subject: Reply with quote

i should have clarified... i meant auto-sorting after adding a new item.
_________________
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 3942
Location: Pittsburgh

PostPosted: Sat Jul 23, 2005 2:29 am    Post subject: Reply with quote

Beaut!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2, 3, 4, 5  Next
Page 1 of 5

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group