Jump to content

Allowing user to customize a gui?


Chimaera
 Share

Recommended Posts

I was thinking about creating a gui in which i need for the user to create a category and then add subsets of text to that category which are saved on a txt file 

he needs to be able to click one of the lower category's so it can be added to the clipboard for work with another document.

Im not sure which bit of AutoIt to use for the category either

I can of course create the main category's for the user but i wondered if it was possible to add the flexibility so that they can create further sections and add lower category's as they need.

Or is it easier to add a create new category button? with separate code that does that process?

Can anyone point me in the right direction as i cant seem to find relevant stuff through search

Many thanks

Link to comment
Share on other sites

  • Moderators

Chimaera,

Does this thread which uses an ini file to create menu items offer any solutions? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Ok interesting and complex

I dont actually need menu items but it seems a lot of work redimmming the array etc everytime a change is made, but i see what you getting at.

I think for mine i will have to create 5 buttons which in turn has a seperate listview (maybe) so they can add text into it

and i will just have to workout how to change the listviews as each button is clicked

Bear in mind im just therozing here

Im assuming all elements in a listview are accessible by an array..

Anyway back to the drawing board, im a little further on than the initial idea so thx for the prompt

Link to comment
Share on other sites

Perhaps if you provide some code that will give us a clearer picture, as I for one, are not exactly sure of what you are asking/wanting. For instance, are you wanting to do something that will require you to resize your GUI or add a TAB etc etc?

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Im really only at the idea stage atm, it was just something that popped into my head this morning

post-60350-0-92432900-1378122617_thumb.p

Here is a rough mock-up of where im heading

Button 1 has an accompanying listview so if you press Button1 you can see that listview etc with only the currently selected visible

When that list view is selected it will have 10 pieces of text that the user has typed and it will save it

Its probably going to need to separate each bit of text maybe 10 slots in total (not sure if listview is the right way or maybe read txt into array or something)

When he clicks on a piece of text (one of the 10) it adds it to the clipboard for easy use

Sort of like a quick jump for text you have to use over and over again but you can choose different bits of text.

and im thinking about shortcut keys for each of the 10 segments

And different buttons give you different category's

So it will hold 50 different txt inserts in total

Hopefully that explains it a little better

Edited by Chimaera
Link to comment
Share on other sites

  • Moderators

Chimaera,

Something like this perhaps?

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Global $aButton[5]
Global $sIni = @ScriptDir & "\Chim.ini"

$hGUI = GUICreate("Test", 500, 250)

For $i = 0 To 4
    $aButton[$i] = GUICtrlCreateButton("Button " & $i, 10, 10 + ($i * 50), 80, 30)
Next

$cLV = GUICtrlCreateListView("Texts", 100, 10, 390, 230)
_GUICtrlListView_SetColumnWidth($cLV, 0, 370)

GUISetState()

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $aButton[0] To $aButton[4]
            $iIndex = $iMsg - $aButton[0]
            $aItems = IniReadSection($sIni, $iIndex)
            _GUICtrlListView_DeleteAllItems($cLV)
            For $i = 1 To $aItems[0][0]
                GUICtrlCreateListViewItem($aItems[$i][1], $cLV)
            Next
    EndSwitch
WEnd
The data is stored like this:

[0]
1=Text 0.1
2=Text 0.2
3=Text 0.3
4=Text 0.4
5=Text 0.5
6=Text 0.6
7=Text 0.7
8=Text 0.8
9=Text 0.9
10=Text 0.10
[1]
1=Text 1.1
2=Text 1.2
3=Text 1.3
4=Text 1.4
5=Text 1.5
6=Text 1.6
7=Text 1.7
8=Text 1.8
9=Text 1.9
10=Text 1.10
[2]
1=Text 2.1
2=Text 2.2
3=Text 2.3
4=Text 2.4
5=Text 2.5
6=Text 2.6
7=Text 2.7
8=Text 2.8
9=Text 2.9
10=Text 2.10
[3]
1=Text 3.1
2=Text 3.2
3=Text 3.3
4=Text 3.4
5=Text 3.5
6=Text 3.6
7=Text 3.7
8=Text 3.8
9=Text 3.9
10=Text 3.10
[4]
1=Text 4.1
2=Text 4.2
3=Text 4.3
4=Text 4.4
5=Text 4.5
6=Text 4.6
7=Text 4.7
8=Text 4.8
9=Text 4.9
10=Text 4.10
And is in ini format so very easy to change. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

that is great and pretty much what i was after

Ill have a play with the text and stuff and get used to how you created the parts

More later

Link to comment
Share on other sites

Whilst the idea is where im heading it seems the limitation is the .ini file

It would be nice to be able to hold any kind of data in the file text / numbers / unicode / code / html

But is there a way that can be achieved?

I tried a number of filetypes .doc would be the best i guess as its got good support but it seems not easy to work with.

I suppose you could call this a snippet holder ;) that would be the easiest description i guess.

Link to comment
Share on other sites

What limitation are you referring to, as you can code around duplicate Section and Key names quite easily ... or go the XML or SQL route.

A simple solution I've used on a few occasions, to great effect, is to use multiple INI files, but you don't have to even do that.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Sorry about the late reply

Its more a formatting issue rather than anything

The limitation im referring to is the fact that a txt or ini cannot use tab and needs to be able to understand multi line pieces of texts paragraphs etc

I want the box to ther right to be able to hold anything text related really so that when you reuse it it will be formatted properly

Ill have to look at xml etc to see if that offers new solutions

Thx

edit i just realised you can paste full paragraphs into a txt file with tabs but not add the tabs whilst typing

Link to comment
Share on other sites

  • Moderators

Chimaera,

You can store tabs and newlines in plain text using the t and n shortcuts - you just need to translate them back and forth as required. Here are the 2 functions that do the job in the SciTEConfig Abbreviation Manager:

Func _Abbrev2Code($sFull_Abbrev)

    Local $sCode = ""
    ; Remove name
    Local $sAbbrev = StringRegExpReplace($sFull_Abbrev, "(?U)^(.*=)", "")
    ; Split into lines
    Local $aSplit = StringSplit($sAbbrev, "\n", 1)
    For $i = 1 To UBound($aSplit) - 1
        If StringInStr($aSplit[$i], "\t", 1) Then $aSplit[$i] = StringReplace($aSplit[$i], "\t", @TAB)
        If $i = UBound($aSplit) - 1 Then
            $sCode &= $aSplit[$i]
        Else
            $sCode &= $aSplit[$i] & @CRLF
        EndIf
    Next
    Return $sCode
EndFunc   ;==>_Abbrev2Code

Func _Code2Abbrev($sAbbrev_Text)

    Local $sAbbr = "", $sLine
    ; Split text
    Local $aLines = StringSplit($sAbbrev_Text, @CRLF, 1)
    For $i = 1 To $aLines[0]
        $sLine = $aLines[$i]
        If StringInStr($sLine, @TAB, 1) Then $sLine = StringReplace($sLine, @TAB, "\t")
        If $i = $aLines[0] Then
            $sAbbr &= $sLine
        Else
            $sAbbr &= $sLine & "\n"
        EndIf
    Next

    Return $sAbbr

EndFunc   ;==>_Code2Abbrev
Any use? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I assume you mean store from scite?

The end user wont have anything except the program and the txt file

I think this is rapidly getting beyond my abilities.

All im trying to do is not store just a single line but bits like this in plain text

 

SELECT column_name(s)

FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;
Or

 

Func _Code2Abbrev($sAbbrev_Text)

 
    Local $sAbbr = "", $sLine
    ; Split text
    Local $aLines = StringSplit($sAbbrev_Text, @CRLF, 1)
    For $i = 1 To $aLines[0]
        $sLine = $aLines[$i]
        If StringInStr($sLine, @TAB, 1) Then $sLine = StringReplace($sLine, @TAB, "t")
        If $i = $aLines[0] Then
            $sAbbr &= $sLine
        Else
            $sAbbr &= $sLine & "n"
        EndIf
    Next
 
    Return $sAbbr
 
EndFunc   ;==>_Code2Abbrev

 

pretty much as they are for repeated use

is it possible to make the text file use multiple lines like the above eg?

Edited by Chimaera
Link to comment
Share on other sites

  • Moderators

Chimaera,

If you use the nt tip I gave you above, you do not have to use multiple lines. You can put it all in one line as is done with the SciTE abbreviations. ;)

Those 2 chunks of text would become:

SELECT column_name(s)\nFROM table1\nINNER JOIN table2\nON table1.column_name=table2.column_name;

; And 

Func _Code2Abbrev($sAbbrev_Text)\n\n\tLocal $sAbbr = "", $sLine\n\t; Split text\n\tLocal $aLines = StringSplit($sAbbrev_Text, @CRLF, 1)\n\tFor $i = 1 To $aLines[0]\n\t\t$sLine = $aLines[$i]\n\t\tIf StringInStr($sLine, @TAB, 1) Then $sLine = StringReplace($sLine, @TAB, "\t")\n\t\tIf $i = $aLines[0] Then\n\t\t\t$sAbbr &= $sLine\n\t\tElse\n\t\t\t$sAbbr &= $sLine & "\n"\n\t\tEndIf\n\tNext\n\tReturn $sAbbr\nEndFunc   ;==>_Code2Abbrev
Actually the second one would be a problem given that you are using the nt codes within the text, but I am sure you can see what I mean. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@Melba23 thx but its beyond my abilities to keep up with that. And im trying to just keep it simple so a user can add the text themselves or edit it.

@kylomas thx for that its a shame that they have gone too involved with Scite in a way, ill have to study them when i get the time and see what i can do with them.

Link to comment
Share on other sites

Chimaera,

Check this out.  Just drag and drop text files onto the edit control.  The script will create an SQL DB in whatever dir you run this from.

#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <sqlite.au3>
#include <array.au3>
#include <GuiTreeView.au3>
#include <GuiToolbar.au3>

#AutoIt3Wrapper_Add_Constants=n

;---------------------------------------------------------------------------------------
; initialize SQLite and open DB - create table if it does not exist
;---------------------------------------------------------------------------------------

Local $sn_DB = @ScriptDir & '\snippets.DB3'

_SQLite_Startup()

If @error Then
    ConsoleWrite('error loading sqlite.dll' & @LF)
    Exit
EndIf

Local $hDB = _SQLite_Open($sn_DB)

If @error Then
    ConsoleWrite('Unable to open DB' & @LF)
    _exit()
EndIf

OnAutoItExitRegister("_DbClose")

;  uncomment the following to re-initialize t5he DB

;~ If _SQLite_Exec($hDB, "drop table if exists Categories; drop table if exists Snippets;") <> $sqlite_ok Then
;~  MsgBox($mb_ok, '***** SQL Error *****', 'Drop table error' & @LF & _SQLite_ErrCode() & @LF & _SQLite_ErrMsg())
;~  Exit
;~ EndIf

If _SQLite_Exec($hDB, "create table if not exists Categories (id integer primary key, catname);") <> $sqlite_ok Then
    MsgBox($mb_ok, '***** SQL Error *****', 'Category table create error' & @LF & _SQLite_ErrCode() & @LF & _SQLite_ErrMsg())
    Exit
EndIf

If _SQLite_Exec($hDB, "create table if not exists Snippets (category_id, title, text);") <> $sqlite_ok Then
    MsgBox($mb_ok, '***** SQL Error *****', 'Snippets table create error' & @LF & _SQLite_ErrCode() & @LF & _SQLite_ErrMsg())
    Exit
EndIf

;---------------------------------------------------------------------------------------
; setup gui
;---------------------------------------------------------------------------------------

Local $gui010   =   GUICreate('Snippet Manager', 1100, 800, default, default, default, $ws_ex_acceptfiles)
local $hToolBar =   _guictrltoolbar_create($gui010)
local $aSize    =   _GUICtrlToolbar_GetMaxSize($hToolbar)

Local $iStyle   =   BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
Local $hTV      =    _GUICtrlTreeView_Create($gui010, 20, $aSize[1]+80, 200, 680, $iStyle, $WS_EX_CLIENTEDGE)
                    _GUICtrlTreeView_SetTextColor($hTV, 0x0000ff)
                    _GUICtrlTreeView_SetLineColor($hTV, 0xaa0000)
local $hImage   =   _GUIImageList_Create(16, 16, 5, 3)
                    _GUIImageList_AddIcon($hImage, "shell32.dll", 3)
                    _GUIImageList_AddIcon($hImage, "shell32.dll", 19)
                    _GUIImageList_AddIcon($hImage, "shell32.dll", 70)
                    _GUIImageList_AddIcon($hImage, "shell32.dll", 55)
                    _GUICtrlTreeView_SetNormalImageList($hTV, $hImage)

                    guictrlcreatelabel('Category',20,58,80,15)
                    guictrlsetfont(-1,8,800,default,'lucinda console')
local $catin    =   guictrlcreateinput('',20,75,200,20)
                    guictrlsetfont(-1,10,600)
                    guictrlcreatelabel('Title',250,58,40,15)
                    guictrlsetfont(-1,8,800,default,'lucinda console')
local $titin    =   guictrlcreateinput('',250,75,400,20)
                    guictrlsetfont(-1,10,600)
local $editok   =   guictrlcreatecheckbox('Allow Edit',950,$aSize[1]+50,100,20)
                    guictrlsetfont(-1,10,800,default,'lucinda console')
Local $edt010   =   GUICtrlCreateEdit('', 250, $aSize[1]+80, 830, 680, bitor($es_readonly,$ss_sunken,$ws_vscroll,$ws_hscroll))
                    guictrlsetstate($edt010,$GUI_DROPACCEPTED)
                    GUICtrlSetFont($edt010, 8.5, 800, -1, 'courier new')
                    guictrlcreatelabel('Status',400,15,50,20)
                    guictrlsetfont(-1,10,800,default,'lucinda console')
local $status   =   guictrlcreatelabel('',450,15,600,20,$ss_sunken)
                    guictrlsetfont(-1,10,800,default,'lucinda console')
                    guictrlsetcolor($status,0xaa0000)


Local $aStrings[4]
local Enum $cDEL = 1000, $sADD, $sDEL, $sSAV
_GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR)

$aStrings[0] = _GUICtrlToolbar_AddString($hToolbar, "Del Category")
$aStrings[1] = _GUICtrlToolbar_AddString($hToolbar, "Add Snippet")
$aStrings[2] = _GUICtrlToolbar_AddString($hToolbar, "Del Snippet")
$aStrings[3] = _GUICtrlToolbar_AddString($hToolbar, "Save Snippet")
_GUICtrlToolbar_AddButton($hToolbar, $cDEL, $STD_DELETE, $aStrings[0])
_GUICtrlToolbar_AddButtonSep($hToolbar)
_GUICtrlToolbar_AddButtonSep($hToolbar)
_GUICtrlToolbar_AddButtonSep($hToolbar)
_GUICtrlToolbar_AddButton($hToolbar, $sADD, $STD_FILENEW, $aStrings[1])
_GUICtrlToolbar_AddButton($hToolbar, $sDEL, $STD_DELETE, $aStrings[2])
_GUICtrlToolbar_AddButton($hToolbar, $sSAV, $STD_FILESAVE, $aStrings[3])

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

_populate_treeview()

Func _populate_treeview()

    Local $crows, $cnbrows, $cnbcols, $cret, $srows, $snbrows, $snbcols, $sret, $hItem, $hT

    $cret = _SQLite_GetTable2d(-1, "select * from Categories;", $crows, $cnbrows, $cnbcols)
    If @error Then
        MsgBox($mb_ok, '***** ERROR *****', 'Error getting categories' & @LF & _SQLite_ErrCode() & @LF & _SQLite_ErrMsg())
        Exit
    EndIf

    _GUICtrlTreeView_BeginUpdate($hTV)

    For $1 = 1 To $cnbrows

        ;$hItem = _GUICtrlTreeView_Add($hTV, 0, $crows[$1][1], $1)
        $hItem = _GUICtrlTreeView_Add($hTV, 0, $crows[$1][1], 0,1)
        _GUICtrlTreeView_SetBold($hTV, $hItem)

        $sret = _SQLite_GetTable2d(-1, "select * from snippets where category_id = " & $crows[$1][0] & ';', $srows, $snbrows, $snbcols)

        ;_arraydisplay($srows)

        For $2 = 1 To $snbrows
            $hT = _GUICtrlTreeView_AddChild($hTV, $hItem, $srows[$2][1],2,3)
        Next

    Next

    _guictrltreeview_sort($hTV)

    _GUICtrlTreeView_EndUpdate($hTV)

EndFunc   ;==>_populate_treeview

local $dropped_files

While 1
    Switch GUIGetMsg()
        Case $gui_event_close
            Exit
        Case $editok
            if guictrlread($editok) <> $gui_checked then
                guictrlsetstyle($edt010,$es_readonly)
            else
                guictrlsetstyle($edt010,bitor($ES_MULTILINE, $WS_TABSTOP, $es_wantreturn, not $es_readonly))
            endif
        Case $GUI_EVENT_DROPPED
            guictrlsetdata($catin,'')
            guictrlsetdata($titin,'')
            Switch @GUI_DropId
                Case $edt010
                    guictrlsetdata($edt010,'')
                    guictrlsetdata($edt010,fileread(stringreplace(@gui_dragfile,@crlf,'')),1)
            endswitch
   EndSwitch

WEnd

Func _add_snippet()

    local $trows, $tret

    if guictrlread($edt010) = '' then
        guictrlsetdata($status,'  No snippet to add...')
        Return 1
    EndIf

    if guictrlread($catin) = '' or guictrlread($titin) = '' then
        guictrlsetdata($status,'  Enter Category and Title...')
        return 1
    endif

    local $cat = _SQLite_FastEscape(guictrlread($catin))
    local $tit = _SQLite_FastEscape(guictrlread($titin))

    ;  add cat if it does not exist

    $tret = _SQLite_QuerySingleRow( $hDB, 'select id from categories where catname = ' & $cat & ';',$trows)
    if $tret <> $sqlite_ok then
        _sqlite_exec($hDB,'insert into categories (catname) values(' & $cat & ');')
        $tret = _SQLite_QuerySingleRow( $hDB, 'select id from categories where catname = ' & $cat & ';',$trows)
        if $tret <> $sqlite_ok then
            MsgBox($mb_ok, '***** ERROR *****', 'Error inserting category name' & @LF & _SQLite_ErrCode() & @LF & _SQLite_ErrMsg())
            Exit
        EndIf
    EndIf

    local $tcat = $trows[0]

    ;  determine if cat/title exists

    $tret = _SQLite_QuerySingleRow( $hDB, _
                                'select title,category_id from snippets where title = ' & $tit & ' and category_id = ' & $tcat & ';',$trows)

    if $tret = $sqlite_ok then

        guictrlsetdata($status,'  Snippet already exists...specify another name...')
        guictrlsetstate($titin,$gui_focus)
        return 1

    EndIf

    ; insert snippet record

    if _sqlite_exec($hDB,'insert into snippets (category_id,title,text) values(' & $tcat & ',' & $tit & ',' & _
        _SQLite_FastEscape(guictrlread($edt010)) & ');') <> $sqlite_ok then
            MsgBox($mb_ok, '***** ERROR *****', 'Insert error for snippet add' & @LF & _SQLite_ErrCode() & @LF & _SQLite_ErrMsg())
            Exit
    EndIf

    guictrlsetdata($status,guictrlread($catin) & '\' & guictrlread($titin) & ' added...')

    ; update treeview control

    local $tHND = _GUICtrlTreeView_FindItem($hTV,guictrlread($catin))

;~  ConsoleWrite(stringformat('%-30s = %-30s\n%-30s = %-30s', _
;~                              'value from gettext', _
;~                              _guictrltreeview_gettext($hTV,$tHND), _
;~                              'value from guictrlread', _
;~                              guictrlread($catin)) & @LF)

;~  if _guictrltreeview_gettext($hTV,$tHND) == guictrlread($catin) then
;~  Else
;~      $tHND = 0
;~  endif

    if $tHND <> 0 then
        _GUICtrlTreeView_AddChild($hTV, $tHND, guictrlread($titin),2,3)
    Else
        local $tH = _GUICtrlTreeView_Add($hTV,0,guictrlread($catin),0,1)
        _GUICtrlTreeView_AddChild($hTV,$tH,guictrlread($titin),2,3)
        _guictrltreeview_expand($hTV,$tH)
    endif

    _guictrltreeview_sort($hTV)

EndFunc

Func _del_snippet()

    local $trows, $tret

    if guictrlread($catin) = '' or guictrlread($titin) = '' then
        guictrlsetdata($status,'  Enter Category and Title...')
        return 1
    endif

    local $cat = _SQLite_FastEscape(guictrlread($catin))
    local $tit = _SQLite_FastEscape(guictrlread($titin))

    ;  get category

    $tret = _SQLite_QuerySingleRow( $hDB, 'select id from categories where catname = ' & $cat & ';',$trows)
    if $tret <> $sqlite_ok then
        guictrlsetdata($status,'Category does NOT exist...respecify...')
        guictrlsetstate($catin,$gui_focus)
        return 1
    EndIf

    local $tcat = $trows[0]

    ;  determine if cat/title exists

    $tret = _SQLite_QuerySingleRow( $hDB, 'select title,category_id from snippets where title = ' & $tit & ' and category_id = ' & $tcat & ';',$trows)

    if $tret <> $sqlite_ok then
        guictrlsetdata($status,'  Snippet does NOT exist...respecify...')
        guictrlsetstate($titin,$gui_focus)
        return
    EndIf

    ; delete snippet record

    if _sqlite_exec($hDB,'delete from snippets where category_id = ' & $tcat & ' and title = ' & $tit & ';') <> $sqlite_ok then
            MsgBox($mb_ok, '***** ERROR *****', 'Delete Error' & @LF & _SQLite_ErrCode() & @LF & _SQLite_ErrMsg())
            Exit
    EndIf

    guictrlsetdata($status,guictrlread($catin) & '\' & guictrlread($titin) & ' deleted...')

    ; update treeview control

    local $tHND = _GUICtrlTreeView_FindItemEx($hTV, guictrlread($catin) & '|' & guictrlread($titin))

    if $tHND <> 0 then
        $tret = _GUICtrlTreeView_Delete($hTV, $tHND)
    endif

EndFunc

Func _del_cat()

    local $trows, $tret

    if _GUICtrlTreeView_GetSelection($hTV) = 0 or _GUICtrlTreeView_Level($hTV, _GUICtrlTreeView_GetSelection($hTV)) <> 0 then
        guictrlsetdata($status,'No category selected...')
        return
    Else
        local $cat = _sqlite_escape(_GUICtrlTreeView_GetText($hTV, _GUICtrlTreeView_GetSelection($hTV)))
    endif

    $tret = _SQLite_QuerySingleRow( $hDB, 'select id from categories where catname = ' & $cat & ';',$trows)
    if $tret <> $sqlite_ok then
        guictrlsetdata($status,'Category does NOT exist...respecify...')
        return 1
    EndIf

    local $tcat = $trows[0]

    ; delete snippet and category records

    if _sqlite_exec($hDB,'delete from snippets where category_id = ' & $tcat & ';') <> $sqlite_ok then
            MsgBox($mb_ok, '***** ERROR *****', 'Delete Error for snippets on category delete' & @LF & _SQLite_ErrCode() & @LF & _SQLite_ErrMsg())
            Exit
    EndIf

    if _sqlite_exec($hDB,'delete from categories where id = ' & $tcat & ';') <> $sqlite_ok then
            MsgBox($mb_ok, '***** ERROR *****', 'Delete Error for category on category delete' & @LF & _SQLite_ErrCode() & @LF & _SQLite_ErrMsg())
            Exit
    EndIf

    guictrlsetdata($status,'  Category = ' & $cat & ' deleted...')

    ; update treeview control

    local $tHND = _GUICtrlTreeView_FindItem($hTV, stringreplace($cat,"'",''))

    if $tHND <> 0 then
        $tret = _GUICtrlTreeView_Delete($hTV, $tHND)
    endif

    ;_guictrltreeview_sort($hTV)

EndFunc

Func _sav_snippet()

    local $trows, $tret

    if guictrlread($edt010) = '' then
        guictrlsetdata($status,'  No snippet to save...')
        Return 1
    EndIf

    if guictrlread($catin) = '' or guictrlread($titin) = '' then
        guictrlsetdata($status,'  Enter Category and Title...')
        return 1
    endif

    local $cat = _SQLite_FastEscape(guictrlread($catin))
    local $tit = _SQLite_FastEscape(guictrlread($titin))

    ;  if category does not exist then call _add_snippet() routine

    $tret = _SQLite_QuerySingleRow( $hDB, 'select id from categories where catname = ' & $cat & ';',$trows)
    if $tret <> $sqlite_ok then
        _add_snippet()
        return
    else
        local $tcat = $trows[0]
    EndIf

    ;  if cat\title does not exist then call _add_snippet() routine

    $tret = _SQLite_QuerySingleRow( $hDB, _
                                'select title,category_id from snippets where title = ' & $tit & ' and category_id = ' & $tcat & ';',$trows)

    if $tret <> $sqlite_ok then
        _add_snippet()
        return
    EndIf

    ; update snippet record

    if _sqlite_exec($hDB,'update snippets set text = ' & _
        _SQLite_FastEscape(guictrlread($edt010)) & ' where category_id = ' & $tcat & ' and title = ' & $tit & ';') <> $sqlite_ok then
            MsgBox($mb_ok, '***** ERROR *****', 'Insert error for category add' & @LF & _SQLite_ErrCode() & @LF & _SQLite_ErrMsg())
            Exit
    Else
        guictrlsetdata($status,guictrlread($catin) & '\' & guictrlread($titin) & ' updated...')
    EndIf

EndFunc

Func _DbClose()
    _SQLite_Close($hDB)
EndFunc   ;==>_DbClose

Func _exit()
    _SQLite_Close()
    _SQLite_Shutdown()
    Exit
EndFunc   ;==>_exit

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview, $arow
    $hWndTreeview = $hTV
    If Not IsHWnd($hTV) Then $hWndTreeview = GUICtrlGetHandle($hTV)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTreeview
            Switch $iCode
                Case $NM_DBLCLK, $TVN_SELCHANGEDW

                    guictrlsetdata($edt010,'')

                    Local $tname = _GUICtrlTreeView_GetText($hTV, _GUICtrlTreeView_GetSelection($hTV))

                    if _GUICtrlTreeView_Level($hTV, _GUICtrlTreeView_GetSelection($hTV)) = 0 then
                        guictrlsetdata($catin,$tname)
                        guictrlsetdata($titin,'')
                    else
                        _SQLite_QuerySingleRow(-1, "SELECT text from snippets where title = " & _SQLite_FastEscape($tname) & ";", $arow)
                        GUICtrlSetData($edt010, $arow[0])
                        guictrlsetdata($titin,$tname)
                        guictrlsetdata($catin, _GUICtrlTreeView_GetText($htv,_GUICtrlTreeView_GetParentHandle($hTV)))
                    endif

                    Return
            EndSwitch

        Case $hToolbar
            Switch $icode
                Case $NM_LDOWN
                    local $tNMMOUSE
                    $tNMMOUSE = dllstructcreate($tagNMMOUSE,$ilparam)
                    local $cID = dllstructgetdata($tNMMOUSE,'ItemSpec')
                    Switch $cID
                        Case $cDEL
                            _del_cat()
                        Case $sADD
                            _add_snippet()
                        Case $sSAV
                            _sav_snippet()
                        Case $sDEL
                            _del_snippet()
                    EndSwitch
            EndSwitch

    EndSwitch

EndFunc   ;==>WM_NOTIFY

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Thx for that kylomas

Im positive i would not have got to that result

Ive been making a few changes adding a copy button etc but im not sure how to phrase the copy function

ive added this to the WMNotify section

Case $sCOP
    _copy_snippet()

and created the button on the toolbar with the correct icon with some trial and error

But i dont understand how to phrase the function

I tried this

Func _copy_snippet()

        If guictrlread($edt010) = '' then
            guictrlsetdata($status,'  No snippet to copy...')
            Return 1
        Else
            ClipPut($edt010)
        EndIf

EndFunc ; <==  _copy_snippet()

All i want it to do is copy the text in the right hand box to the clipboard ?

does it need a sqlite instruction to do it?

Also i have a few compile errors tried with normal version and beta

 

-### Obfuscation Error: Found Call() statement using unsolvable Func, which will/could lead to problems running your obfuscated script.

>### current Func: _SQLite_Startup
C:Program Files (x86)AutoIt3includeSQLite.au3(216,1) Warning for line:Local $vInlineVersion = Call('__SQLite_Inline_Version') 
 
-### Obfuscation Error: Found Call() statement using unsolvable Func, which will/could lead to problems running your obfuscated script.
>### current Func: _SQLite_GetTable2d
C:Program Files (x86)AutoIt3includeSQLite.au3(707,1) Warning for line:$iCbRval = Call($sCallBack, $aDataRow) 
 
-### Obfuscation Error: Found Call() statement using unsolvable Func, which will/could lead to problems running your obfuscated script.
>### current Func: _SQLite_GetTable2d
C:Program Files (x86)AutoIt3includeSQLite.au3(723,1) Warning for line:$iCbRval = Call($sCallBack, $aDataRow) 
 
-### Obfuscation Error: Found Call() statement using unsolvable Func, which will/could lead to problems running your obfuscated script.
>### current Func: __SQLite_Print
C:Program Files (x86)AutoIt3includeSQLite.au3(1352,1) Warning for line:Call($g_sPrintCallback_SQLite, DllStructGetData($tStr8, 1)) 
 
-### Obfuscation Error: Found Call() statement using unsolvable Func, which will/could lead to problems running your obfuscated script.
>### current Func: __SQLite_Print
C:Program Files (x86)AutoIt3includeSQLite.au3(1354,1) Warning for line:Call($g_sPrintCallback_SQLite, $sText) 
Edited by Chimaera
Link to comment
Share on other sites

Chimaera,

Try the copy like this...

Func _copy_snippet()

        If guictrlread($edt010) = '' then
            guictrlsetdata($status,'  No snippet to copy...')
            Return 1
        Else
            ClipPut(guictrlread($edt010))  ; <----- change to this 
        EndIf

EndFunc ; <==  _copy_snippet()

I don't know why the SQLite functions are returning the error messages...

kylomas

P.S. - can you post your code? (I completely forgot about the copy to clipboard do-hicky..)

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Aaah so i had to read it before the send to clipboard..

I added this but im not sure if it was needed as it seemed to find the icon anyway

_GUIImageList_AddIcon($hImage, "shell32.dll", 165) 

which i believe is the copy one

Code yeah sure

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Run_Obfuscator=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <SQLite.au3>
#include <array.au3>
#include <GuiTreeView.au3>
#include <GuiToolbar.au3>
FileInstall(".\compile\sqlite3.def", @ScriptDir & "\", 1)
FileInstall(".\compile\sqlite3.dll", @ScriptDir & "\", 1)
;---------------------------------------------------------------------------------------
; initialize SQLite and open DB - create table if it does not exist
;---------------------------------------------------------------------------------------
Local $sn_DB = @ScriptDir & '\snippets_datastore.DB3'
_SQLite_Startup()
If @error Then
    ConsoleWrite('error loading sqlite.dll' & @LF)
    Exit
EndIf
Local $hDB = _SQLite_Open($sn_DB)
If @error Then
    ConsoleWrite('Unable to open DB' & @LF)
    _exit()
EndIf
OnAutoItExitRegister("_DbClose")
;  uncomment the following to re-initialize t5he DB

;~ If _SQLite_Exec($hDB, "drop table if exists Categories; drop table if exists Snippets;") <> $sqlite_ok Then
;~  MsgBox($mb_ok, '***** SQL Error *****', 'Drop table error' & @LF & _SQLite_ErrCode() & @LF & _SQLite_ErrMsg())
;~  Exit
;~ EndIf

If _SQLite_Exec($hDB, "create table if not exists Categories (id integer primary key, catname);") <> $sqlite_ok Then
    MsgBox($mb_ok, '***** SQL Error *****', 'Category table create error' & @LF & _SQLite_ErrCode() & @LF & _SQLite_ErrMsg())
    Exit
EndIf

If _SQLite_Exec($hDB, "create table if not exists Snippets (category_id, title, text);") <> $sqlite_ok Then
    MsgBox($mb_ok, '***** SQL Error *****', 'Snippets table create error' & @LF & _SQLite_ErrCode() & @LF & _SQLite_ErrMsg())
    Exit
EndIf

;---------------------------------------------------------------------------------------
; setup gui
;---------------------------------------------------------------------------------------

Local $gui010   =   GUICreate('Snippet Manager', 900, 700, default, default, default, $ws_ex_acceptfiles)
local $hToolBar =   _guictrltoolbar_create($gui010)
local $aSize    =   _GUICtrlToolbar_GetMaxSize($hToolbar)

Local $iStyle   =   BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
Local $hTV      =   _GUICtrlTreeView_Create($gui010, 20, $aSize[1]+80, 200, 580, $iStyle, $WS_EX_CLIENTEDGE)
                    _GUICtrlTreeView_SetTextColor($hTV, 0x0000ff)
                    _GUICtrlTreeView_SetLineColor($hTV, 0xaa0000)
local $hImage   =   _GUIImageList_Create(16, 16, 5, 3)
                    _GUIImageList_AddIcon($hImage, "shell32.dll", 3)
                    _GUIImageList_AddIcon($hImage, "shell32.dll", 19)
                    _GUIImageList_AddIcon($hImage, "shell32.dll", 70)
                    _GUIImageList_AddIcon($hImage, "shell32.dll", 55)
                    _GUIImageList_AddIcon($hImage, "shell32.dll", 165)
                    _GUICtrlTreeView_SetNormalImageList($hTV, $hImage)

                    guictrlcreatelabel('Category',20,58,80,15)
                    guictrlsetfont(-1,8,800,default,'Tahoma')
local $catin    =   guictrlcreateinput('',20,75,200,20)
                    guictrlsetfont(-1,10,600)
                    guictrlcreatelabel('Title',250,58,40,15)
                    guictrlsetfont(-1,8,800,default,'Tahoma')
local $titin    =   guictrlcreateinput('',250,75,400,20)
                    guictrlsetfont(-1,10,600)
local $editok   =   guictrlcreatecheckbox('Allow Edit',750,$aSize[1]+50,100,20)
                    guictrlsetfont(-1,10,800,default,'Tahoma')
Local $edt010   =   GUICtrlCreateEdit('', 250, $aSize[1]+80, 630, 580, bitor($es_readonly,$ss_sunken,$ws_vscroll,$ws_hscroll))
                    guictrlsetstate($edt010,$GUI_DROPACCEPTED)
                    GUICtrlSetFont($edt010, 8.5, 800, -1, 'Tahoma')
                    guictrlcreatelabel('Status',500,15,50,20)
                    guictrlsetfont(-1,10,800,default,'Tahoma')
local $status   =   guictrlcreatelabel('',550,15,330,20,$ss_sunken)
                    guictrlsetfont(-1,10,800,default,'Tahoma')
                    guictrlsetcolor($status,0xaa0000)

Local $aStrings[5]
local Enum $cDEL = 1000, $sADD, $sDEL, $sSAV, $sCOP
_GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR)

$aStrings[0] = _GUICtrlToolbar_AddString($hToolbar, "Delete Category")
$aStrings[1] = _GUICtrlToolbar_AddString($hToolbar, "Add Snippet")
$aStrings[2] = _GUICtrlToolbar_AddString($hToolbar, "Delete Snippet")
$aStrings[3] = _GUICtrlToolbar_AddString($hToolbar, "Update Snippet")
$aStrings[4] = _GUICtrlToolbar_AddString($hToolbar, "Copy Snippet")
_GUICtrlToolbar_AddButton($hToolbar, $sCOP, $STD_COPY, $aStrings[4]) ; Copy
_GUICtrlToolbar_AddButtonSep($hToolbar)
_GUICtrlToolbar_AddButton($hToolbar, $sADD, $STD_FILENEW, $aStrings[1]) ; Add
_GUICtrlToolbar_AddButtonSep($hToolbar)
_GUICtrlToolbar_AddButton($hToolbar, $sSAV, $STD_FILESAVE, $aStrings[3]) ; Save / Update
_GUICtrlToolbar_AddButtonSep($hToolbar)
_GUICtrlToolbar_AddButton($hToolbar, $sDEL, $STD_DELETE, $aStrings[2]) ; Delete Snippet
_GUICtrlToolbar_AddButtonSep($hToolbar)
_GUICtrlToolbar_AddButton($hToolbar, $cDEL, $STD_DELETE, $aStrings[0]) ; Delete Category
_GUICtrlToolbar_AddButtonSep($hToolbar)
GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

_populate_treeview()

Func _populate_treeview()

    Local $crows, $cnbrows, $cnbcols, $cret, $srows, $snbrows, $snbcols, $sret, $hItem, $hT

    $cret = _SQLite_GetTable2d(-1, "select * from Categories;", $crows, $cnbrows, $cnbcols)
    If @error Then
        MsgBox($mb_ok, '***** ERROR *****', 'Error getting categories' & @LF & _SQLite_ErrCode() & @LF & _SQLite_ErrMsg())
        Exit
    EndIf

    _GUICtrlTreeView_BeginUpdate($hTV)

    For $1 = 1 To $cnbrows

        ;$hItem = _GUICtrlTreeView_Add($hTV, 0, $crows[$1][1], $1)
        $hItem = _GUICtrlTreeView_Add($hTV, 0, $crows[$1][1], 0,1)
        _GUICtrlTreeView_SetBold($hTV, $hItem)

        $sret = _SQLite_GetTable2d(-1, "select * from snippets where category_id = " & $crows[$1][0] & ';', $srows, $snbrows, $snbcols)

        ;_arraydisplay($srows)

        For $2 = 1 To $snbrows
            $hT = _GUICtrlTreeView_AddChild($hTV, $hItem, $srows[$2][1],2,3)
        Next

    Next

    _guictrltreeview_sort($hTV)

    _GUICtrlTreeView_EndUpdate($hTV)

EndFunc   ;==>_populate_treeview

local $dropped_files

While 1
    Switch GUIGetMsg()
        Case $gui_event_close
            Exit
        Case $editok
            if guictrlread($editok) <> $gui_checked then
                guictrlsetstyle($edt010,$es_readonly)
            else
                guictrlsetstyle($edt010,bitor($ES_MULTILINE, $WS_TABSTOP, $es_wantreturn, not $es_readonly))
            endif
        Case $GUI_EVENT_DROPPED
            guictrlsetdata($catin,'')
            guictrlsetdata($titin,'')
            Switch @GUI_DropId
                Case $edt010
                    guictrlsetdata($edt010,'')
                    guictrlsetdata($edt010,fileread(stringreplace(@gui_dragfile,@crlf,'')),1)
            endswitch
   EndSwitch
WEnd

Func _add_snippet()

    local $trows, $tret

    if guictrlread($edt010) = '' then
        guictrlsetdata($status,'  No snippet to add...')
        Return 1
    EndIf

    if guictrlread($catin) = '' or guictrlread($titin) = '' then
        guictrlsetdata($status,'  Enter Category and Title...')
        return 1
    endif

    local $cat = _SQLite_FastEscape(guictrlread($catin))
    local $tit = _SQLite_FastEscape(guictrlread($titin))

    ;  add cat if it does not exist

    $tret = _SQLite_QuerySingleRow( $hDB, 'select id from categories where catname = ' & $cat & ';',$trows)
    if $tret <> $sqlite_ok then
        _sqlite_exec($hDB,'insert into categories (catname) values(' & $cat & ');')
        $tret = _SQLite_QuerySingleRow( $hDB, 'select id from categories where catname = ' & $cat & ';',$trows)
        if $tret <> $sqlite_ok then
            MsgBox($mb_ok, '***** ERROR *****', 'Error inserting category name' & @LF & _SQLite_ErrCode() & @LF & _SQLite_ErrMsg())
            Exit
        EndIf
    EndIf

    local $tcat = $trows[0]

    ;  determine if cat/title exists

    $tret = _SQLite_QuerySingleRow( $hDB, _
                                'select title,category_id from snippets where title = ' & $tit & ' and category_id = ' & $tcat & ';',$trows)

    if $tret = $sqlite_ok then

        guictrlsetdata($status,'  Snippet already exists...specify another name...')
        guictrlsetstate($titin,$gui_focus)
        return 1

    EndIf

    ; insert snippet record

    if _sqlite_exec($hDB,'insert into snippets (category_id,title,text) values(' & $tcat & ',' & $tit & ',' & _
        _SQLite_FastEscape(guictrlread($edt010)) & ');') <> $sqlite_ok then
            MsgBox($mb_ok, '***** ERROR *****', 'Insert error for snippet add' & @LF & _SQLite_ErrCode() & @LF & _SQLite_ErrMsg())
            Exit
    EndIf

    guictrlsetdata($status,guictrlread($catin) & '\' & guictrlread($titin) & ' added...')

    ; update treeview control

    local $tHND = _GUICtrlTreeView_FindItem($hTV,guictrlread($catin))

;~  ConsoleWrite(stringformat('%-30s = %-30s\n%-30s = %-30s', _
;~                              'value from gettext', _
;~                              _guictrltreeview_gettext($hTV,$tHND), _
;~                              'value from guictrlread', _
;~                              guictrlread($catin)) & @LF)

;~  if _guictrltreeview_gettext($hTV,$tHND) == guictrlread($catin) then
;~  Else
;~      $tHND = 0
;~  endif

    if $tHND <> 0 then
        _GUICtrlTreeView_AddChild($hTV, $tHND, guictrlread($titin),2,3)
    Else
        local $tH = _GUICtrlTreeView_Add($hTV,0,guictrlread($catin),0,1)
        _GUICtrlTreeView_AddChild($hTV,$tH,guictrlread($titin),2,3)
        _guictrltreeview_expand($hTV,$tH)
    endif

    _guictrltreeview_sort($hTV)

EndFunc

Func _del_snippet()

    local $trows, $tret

    if guictrlread($catin) = '' or guictrlread($titin) = '' then
        guictrlsetdata($status,'  Enter Category and Title...')
        return 1
    endif

    local $cat = _SQLite_FastEscape(guictrlread($catin))
    local $tit = _SQLite_FastEscape(guictrlread($titin))

    ;  get category

    $tret = _SQLite_QuerySingleRow( $hDB, 'select id from categories where catname = ' & $cat & ';',$trows)
    if $tret <> $sqlite_ok then
        guictrlsetdata($status,'Category does NOT exist...respecify...')
        guictrlsetstate($catin,$gui_focus)
        return 1
    EndIf

    local $tcat = $trows[0]

    ;  determine if cat/title exists

    $tret = _SQLite_QuerySingleRow( $hDB, 'select title,category_id from snippets where title = ' & $tit & ' and category_id = ' & $tcat & ';',$trows)

    if $tret <> $sqlite_ok then
        guictrlsetdata($status,'  Snippet does NOT exist...respecify...')
        guictrlsetstate($titin,$gui_focus)
        return
    EndIf

    ; delete snippet record

    if _sqlite_exec($hDB,'delete from snippets where category_id = ' & $tcat & ' and title = ' & $tit & ';') <> $sqlite_ok then
            MsgBox($mb_ok, '***** ERROR *****', 'Delete Error' & @LF & _SQLite_ErrCode() & @LF & _SQLite_ErrMsg())
            Exit
    EndIf

    guictrlsetdata($status,guictrlread($catin) & '\' & guictrlread($titin) & ' deleted...')

    ; update treeview control

    local $tHND = _GUICtrlTreeView_FindItemEx($hTV, guictrlread($catin) & '|' & guictrlread($titin))

    if $tHND <> 0 then
        $tret = _GUICtrlTreeView_Delete($hTV, $tHND)
    endif

EndFunc

Func _del_cat()

    local $trows, $tret

    if _GUICtrlTreeView_GetSelection($hTV) = 0 or _GUICtrlTreeView_Level($hTV, _GUICtrlTreeView_GetSelection($hTV)) <> 0 then
        guictrlsetdata($status,'No category selected...')
        return
    Else
        local $cat = _sqlite_escape(_GUICtrlTreeView_GetText($hTV, _GUICtrlTreeView_GetSelection($hTV)))
    endif

    $tret = _SQLite_QuerySingleRow( $hDB, 'select id from categories where catname = ' & $cat & ';',$trows)
    if $tret <> $sqlite_ok then
        guictrlsetdata($status,'Category does NOT exist...respecify...')
        return 1
    EndIf

    local $tcat = $trows[0]

    ; delete snippet and category records

    if _sqlite_exec($hDB,'delete from snippets where category_id = ' & $tcat & ';') <> $sqlite_ok then
            MsgBox($mb_ok, '***** ERROR *****', 'Delete Error for snippets on category delete' & @LF & _SQLite_ErrCode() & @LF & _SQLite_ErrMsg())
            Exit
    EndIf

    if _sqlite_exec($hDB,'delete from categories where id = ' & $tcat & ';') <> $sqlite_ok then
            MsgBox($mb_ok, '***** ERROR *****', 'Delete Error for category on category delete' & @LF & _SQLite_ErrCode() & @LF & _SQLite_ErrMsg())
            Exit
    EndIf

    guictrlsetdata($status,'  Category = ' & $cat & ' deleted...')

    ; update treeview control

    local $tHND = _GUICtrlTreeView_FindItem($hTV, stringreplace($cat,"'",''))

    if $tHND <> 0 then
        $tret = _GUICtrlTreeView_Delete($hTV, $tHND)
    endif

    ;_guictrltreeview_sort($hTV)

EndFunc

Func _sav_snippet()

    local $trows, $tret

    if guictrlread($edt010) = '' then
        guictrlsetdata($status,'  No snippet to save...')
        Return 1
    EndIf

    if guictrlread($catin) = '' or guictrlread($titin) = '' then
        guictrlsetdata($status,'  Enter Category and Title...')
        return 1
    endif

    local $cat = _SQLite_FastEscape(guictrlread($catin))
    local $tit = _SQLite_FastEscape(guictrlread($titin))

    ;  if category does not exist then call _add_snippet() routine

    $tret = _SQLite_QuerySingleRow( $hDB, 'select id from categories where catname = ' & $cat & ';',$trows)
    if $tret <> $sqlite_ok then
        _add_snippet()
        return
    else
        local $tcat = $trows[0]
    EndIf

    ;  if cat\title does not exist then call _add_snippet() routine

    $tret = _SQLite_QuerySingleRow( $hDB, _
                                'select title,category_id from snippets where title = ' & $tit & ' and category_id = ' & $tcat & ';',$trows)

    if $tret <> $sqlite_ok then
        _add_snippet()
        return
    EndIf

    ; update snippet record

    if _sqlite_exec($hDB,'update snippets set text = ' & _
        _SQLite_FastEscape(guictrlread($edt010)) & ' where category_id = ' & $tcat & ' and title = ' & $tit & ';') <> $sqlite_ok then
            MsgBox($mb_ok, '***** ERROR *****', 'Insert error for category add' & @LF & _SQLite_ErrCode() & @LF & _SQLite_ErrMsg())
            Exit
    Else
        guictrlsetdata($status,guictrlread($catin) & '\' & guictrlread($titin) & ' updated...')
    EndIf

EndFunc

Func _copy_snippet()

        If guictrlread($edt010) = '' then
            guictrlsetdata($status,'  No snippet to copy...')
            Return 1
        Else
            ClipPut(guictrlread($edt010))
        EndIf

EndFunc ; <==  _copy_snippet()


Func _DbClose()
    _SQLite_Close($hDB)
EndFunc   ;==>_DbClose

Func _exit()
    _SQLite_Close()
    _SQLite_Shutdown()
    Exit
EndFunc   ;==>_exit

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview, $arow
    $hWndTreeview = $hTV
    If Not IsHWnd($hTV) Then $hWndTreeview = GUICtrlGetHandle($hTV)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTreeview
            Switch $iCode
                Case $NM_DBLCLK, $TVN_SELCHANGEDW

                    guictrlsetdata($edt010,'')

                    Local $tname = _GUICtrlTreeView_GetText($hTV, _GUICtrlTreeView_GetSelection($hTV))

                    if _GUICtrlTreeView_Level($hTV, _GUICtrlTreeView_GetSelection($hTV)) = 0 then
                        guictrlsetdata($catin,$tname)
                        guictrlsetdata($titin,'')
                    else
                        _SQLite_QuerySingleRow(-1, "SELECT text from snippets where title = " & _SQLite_FastEscape($tname) & ";", $arow)
                        GUICtrlSetData($edt010, $arow[0])
                        guictrlsetdata($titin,$tname)
                        guictrlsetdata($catin, _GUICtrlTreeView_GetText($htv,_GUICtrlTreeView_GetParentHandle($hTV)))
                    endif

                    Return
            EndSwitch

        Case $hToolbar
            Switch $icode
                Case $NM_LDOWN
                    local $tNMMOUSE
                    $tNMMOUSE = dllstructcreate($tagNMMOUSE,$ilparam)
                    local $cID = dllstructgetdata($tNMMOUSE,'ItemSpec')
                    Switch $cID
                        Case $cDEL
                            _del_cat()
                        Case $sADD
                            _add_snippet()
                        Case $sSAV
                            _sav_snippet()
                        Case $sDEL
                            _del_snippet()
            Case $sCOP
                 _copy_snippet()
                    EndSwitch
            EndSwitch

    EndSwitch

EndFunc   ;==>WM_NOTIFY
Edited by Chimaera
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...