Jump to content
Sign in to follow this  
tonyatcodeleakers

Reading from a snippet file

Recommended Posts

tonyatcodeleakers

Im making a simple notepad program with highlighting, and i want to add snippet support.

It already had simple things like add init, or for in the menu but what im looking to do is be able to save my snippets in a ini file and be able to add them as menu items at anytime.

i know how i want to go about doing it but i can't seem to get it to work

I have the ini file set up like so,

[hello]
snip =hello

[wassup]
snip =wassup

[multiline]
snip=hi
there
bob

i wanted to then have the program do this,

$Snip = IniReadSectionNames ( "[snippets].ini" )
For i=0 To $Snip[0] +1
   $menu4item[$i] = GUICtrlCreateMenuItem("Dvar", $menu4)
   GUICtrlSetOnEvent($menu4item[$i], "readinisec")
Next

but i realised this would not work unless i added parameters to setonevent which i dont believe i can.

(readinisec, would then read snip fromt the section given in the parameter and add it to the richedit)

So does anyone know of a better way to go about this, or if it is possible

Share this post


Link to post
Share on other sites
BrewManNH

The ini functions don't handle multiline key/values so that won't work. I'd need to see a working example script of what you're trying to do that might make it clearer, at least to me. :)


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
guinness

With highlight? You have my attention. How you doing that?


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
tonyatcodeleakers

With highlight? You have my attention. How you doing that?

 

I took an example script i found a while back if you want ill try and find the link

The ini functions don't handle multiline key/values so that won't work. I'd need to see a working example script of what you're trying to do that might make it clearer, at least to me. :)

 

Ok, it may show up black since i cant send the settings file, also this is a simplified version because i didnt feel like uploading the udfs i used. 

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIRichEdit.au3>
#include <GUIEdit.au3>
#include <GuiMenu.au3>
#include <GuiListBox.au3>
#include <math.au3>
#include <Array.au3>

Opt("GUIOnEventMode", 1) 
Global $background, $fontsize, $fontname, $background2
Global $aMarquee[8], $isitsame, $isitsame1
Global $_Words2[4]=['thread','level','self']
LoadCFG( )
$Snip = IniReadSectionNames ( "[snippets].ini" )
_ArrayDisplay($Snip)
$main = GUICreate( "Tonys Script Editor", 800, 600, Default, Default, BitOR( $GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP ) )
GUISetBkColor($background2)
$menu1 = GUICtrlCreateMenu("File")
$menu1item1 = GUICtrlCreateMenuItem("Save", $menu1)
$menu1item3 = GUICtrlCreateMenuItem("Open", $menu1)
$menu1item2 = GUICtrlCreateMenuItem("Exit", $menu1)
$menu2 = GUICtrlCreateMenu("Edit")
$menu2item1 = GUICtrlCreateMenuItem("Undo", $menu2)
$menu2item2 = GUICtrlCreateMenuItem("Redo", $menu2)
$menu2item3 = GUICtrlCreateMenuItem("Select All", $menu2)
$menu2item4 = GUICtrlCreateMenuItem("Copy", $menu2)
$menu2item5 = GUICtrlCreateMenuItem("Cut", $menu2)
$menu2item6 = GUICtrlCreateMenuItem("Paste", $menu2)
$menu3 = GUICtrlCreateMenu("Options")
$ftp3 = GUICtrlCreateMenuItem("Upload to FTP", $menu3)
$menu4 = GUICtrlCreateMenu("Snipps")
$edit = _GUICtrlRichEdit_Create( $main, "", 5, 5, 790, 450, BitOR( $ES_AUTOHSCROLL, $ES_AUTOVSCROLL, $WS_HSCROLL, $WS_VSCROLL, $ES_MULTILINE) )
_WinAPI_SetFont( $edit, _WinAPI_CreateFont( 16, 0, 0, 0, 500, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "Courier New" ) )
_GUICtrlRichEdit_SetBkColor( $edit, $background )
_GUICtrlRichEdit_SetLimitOnText($edit, 100000)

$console = _GUICtrlEdit_Create( $main, "", 5, 460, 790, 90, BitOR( $ES_AUTOVSCROLL, $WS_VSCROLL, $ES_MULTILINE) )
_WinAPI_SetFont( $console, _WinAPI_CreateFont( 15, 0, 0, 0, 500, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "Courier New" ) )

$bar = _GUICtrlStatusBar_Create( $main, Default, " Lines = 1 | Functions = 0" )
_WinAPI_SetFont( $bar, _WinAPI_CreateFont( 16, 0, 0, 0, 100, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "Courier New Bold" ) )


$mnu = GUICtrlCreateContextMenu( GUICtrlCreateDummy( ) )
$mnuUndo = GUICtrlCreateMenuItem( "Undo", $mnu )
$mnuRedo = GUICtrlCreateMenuItem( "Redo", $mnu )
GUICtrlCreateMenuItem( "", $mnu )
$mnuCut = GUICtrlCreateMenuItem( "Cut", $mnu )
$mnuCopy = GUICtrlCreateMenuItem( "Copy", $mnu )
$mnuPaste = GUICtrlCreateMenuItem( "Paste", $mnu )
GUICtrlCreateMenuItem( "", $mnu )
$mnuSelectAll = GUICtrlCreateMenuItem( "Select All", $mnu )
_GUICtrlRichEdit_SetEventMask( $edit, $ENM_MOUSEEVENTS )

GUISetState( @SW_SHOW )

GUIRegisterMsg( $WM_SIZE, "WM_SIZE" )
GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" )

Global $pos, $line, $column, $x, $y, $special = 0, $save

Global Const $COLOR_RED     = 2037680
Global Const $COLOR_GREEN   = 32768
Global Const $COLOR_BLACK   = 0
Global Const $COLOR_BLUE    = 16711680
Global Const $COLOR_PUR     = 220208255

Global $list = 0

While True
    $action = GUIGetMsg()
    If $action == $gui_event_close Then
        $save = MsgBox(3, "Tonys Script Editor V4", "Do you want to save before close?")
        If $save == 6 Then
            Local $bloop = 1
            While $bloop = 1
                Local FileSaveDialog( "Save File", @SCRIPTDIR, "All (*.*)" )
                If @error = 1 Or $text = "" Then
                    $bloop = 0
                    MsgBox(64, "Tonys Script Editor V4", "Error")
                Else
                    FileWrite($text, _guictrlrichedit_gettext($edit))
                    FileWrite($text & "-com.txt", _guictrledit_gettext($console))
                    $bloop = 0
                    MsgBox(64, "Tonys Script Editor V4", "File saved successfuly")
                EndIf
            WEnd
            _guictrlrichedit_destroy($edit)
            Exit 
        ElseIf $save == 7 Then
            _guictrlrichedit_destroy($edit)
            Exit 
        Else
            ContinueLoop 
        EndIf
     EndIf
    If $action == $menu1item1 Then
        Local $bloop = 1
        While $bloop = 1
            $textt = FileSaveDialog( "Save File", @SCRIPTDIR, "All (*.*)", 2 )
            If @error = 1 Or $textt = "" Then
                $bloop = 0
                MsgBox(64, "Tonys Script Editor V4", "Error")
             Else
                FileWrite($textt, _guictrlrichedit_gettext($edit))
                FileWrite($textt & "-com.txt", _guictrledit_gettext($console))
                $bloop = 0
                MsgBox(64, "Tonys Script Editor V4", "File saved successfuly")
            EndIf
        WEnd
    ElseIf $action == $menu1item2 Then
        _guictrlrichedit_destroy($edit)
        Exit 
    EndIf
    If $action == $menu2item1 Then
        _guictrlrichedit_undo($edit)
      ElseIf $action == $ftp3 Then
         Run("TonysFTP.exe")
         $sMsg  = "This tool was coded and compiled" & @CRLF & @CRLF
         $sMsg &= "By Tony@codeleakers" & @CRLF & "Version: 1.0"
         $aRet = _Toast_Show(0, "Upload to FTP", $sMsg, 0.75)
         _Toast_Hide()
    ElseIf $action == $menu2item2 Then
        _guictrlrichedit_redo($edit)
    ElseIf $action == $menu1item3 Then
        $tonvar = FileOpenDialog("Choose File to Open", "C:\Windows\", "Files (*.gsc;*.txt*;.cpp;*.au3)", 1 + 4)
        $openvt = FileRead($tonvar)
        $openvt2 = FileRead($tonvar & "-com.txt")
        _GUICtrlEdit_SetText($console, $openvt2)
        _guictrlrichedit_settext($edit, $openvt)
    ElseIf $action == $menu2item5 Then
        _guictrlrichedit_cut($edit)
    ElseIf $action == $menu2item4 Then
        _guictrlrichedit_copy($edit)
    ElseIf $action == $menu2item6 Then
        _guictrlrichedit_paste($edit)
    ElseIf $action == $menu2item3 Then
        _guictrlrichedit_setsel($edit, 0, -1)
    EndIf
WEnd

Func WM_SIZE( $hWnd, $iMsg, $wParam, $lParam )
    Local $iWidth = _WinAPI_LoWord( $lParam )
    Local $iHeight = _WinAPI_HiWord( $lParam )
    _WinAPI_MoveWindow( $edit, 5, 5, $iWidth - 10, $iHeight - 130 )
    _WinAPI_MoveWindow( $bar, 0, 0, 0, 0 )
    _WinAPI_MoveWindow( $console, 5, $iHeight - 120, $iWidth - 10, 90 )    
    Return 0
EndFunc
 
 Func LoadCFG( )
    $file = FileRead( "Settings.cfg" )
    ;Sleep( 200 )
    $file = StringSplit( $file, "=" & @CRLF )
    ;Sleep( 200 )
    For $i = 1 To UBound( $file ) - 1
        If $file[$i] == "editor.background" Then
            $background = $file[$i+1]
            If $background == 0 Then
                $background = 16777215
            EndIf
            ;Sleep( 300 )
        ElseIf $file[$i] == "editor.background2" Then
            $background2 = $file[$i+1]
            If $background2 == 0 Then
                $background2 = 16777215
            EndIf
            ;Sleep( 300 )
        EndIf
    Next
    ;Sleep( 500 )
EndFunc

Share this post


Link to post
Share on other sites
BrewManNH

What exactly was the point of posting that script? It doesn't use anything from the ini files except when you read the section names and displays them in _ArrayDisplay. This doesn't show me what you're doing with the information.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
tonyatcodeleakers

What exactly was the point of posting that script? It doesn't use anything from the ini files except when you read the section names and displays them in _ArrayDisplay. This doesn't show me what you're doing with the information.

As i said in my first post, i showed how i tried to go about doing it but it did not work so i removed it from the source.

Share this post


Link to post
Share on other sites
tonyatcodeleakers

Bump- is there another way to go about this or is it impossible

Share this post


Link to post
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
Sign in to follow this  

×