Jump to content
Sign in to follow this  
steveR

AutoClipIt

Recommended Posts

steveR

Hello, I made this small program today. It holds 50 non-duplicated text items from the Clipboard.

It minimizes to tray or you can select stay on top. You can also edit the clip or add a new one.

It has a few glitches. I might add some more functions to it if I find time.

EDIT: v1.1 Added Save as option in Edit dialog, lets you save the clip as a text file. Added a explode clip into fragments function which allows you break up a clip with any delimit character. Fixed some stuff. I might add an Options dialog so settings can be saved in an .ini file .

This might need the latest beta to work.

AutoClipIt v1.1

AutoClipIt_v1.1.zip

;
; AutoClipIt v1.1
; Steve Renolds
;
#region includes
#include <GUIConstants.au3>
#include <Constants.au3>
#include <Array.au3>
#endregion includes
;
#region Constants
$FALSE = 0
$ERR = $FALSE
$TRUE = Not $FALSE
$OK = $TRUE
#endregion Constants
;
#region Globals
Global $AutoClipItXPos = @DesktopWidth - 230
Global $AutoClipItYPos = @DesktopHeight - 250
Global $MaxListArray = 50
Global $ListArray[$MaxListArray]
Global $CurClip
Global $AppState = 1
Global $focused = $TRUE
Global $TRAY_UP = 1
Global $TRAY_DOWN = 0
Global $delimiters = ",.;:-"
#endregion Globals
;
Opt ("WinTitleMatchMode", 2)
Opt ("TrayAutoPause", 0)
Opt ("TrayMenuMode", 1)
Opt ("GuiCloseOnEsc", 1)
Opt ("GuiCoordMode", 0)
;
Dim $AutoClipIt = GUICreate("AutoClipIt v.1.1", 198, 180, $AutoClipItXPos, $AutoClipItYPos, -1, $WS_EX_TOOLWINDOW)
Dim $inpCurClip = GUICtrlCreateInput("", 5, 5, 190, 20, $ES_READONLY, -1)
Dim $listHistory = GUICtrlCreateList("", 0, 25, 190, 135, $WS_VSCROLL + $LBS_NOTIFY, -1)
Dim $chkOnTop = GUICtrlCreateCheckbox("On Top", 5, 123)
Dim $btnOptions = GUICtrlCreateButton("Opt", 55, 0, 25, 25)
GUICtrlSetState($btnOptions, $GUI_HIDE)
Dim $btnClear = GUICtrlCreateButton("Clear", 30, 0, 50, -1)
Dim $btnEdit = GUICtrlCreateButton("Edit", 50, 0, 50, -1)
;
Dim $trayShowHide = TrayCreateItem ("Hide")
Dim $trayEdit = TrayCreateItem ("Edit")
TrayCreateItem ("")
Dim $trayExit = TrayCreateItem ("Exit")
TraySetClick (40); 64
;
GUISetState()
;
_InitListArray()
;
Do
    Dim $GuiMsg = GUIGetMsg()
    Dim $trayMsg = TrayGetMsg ()
;
    Select
        Case $trayMsg = -7 Or $trayMsg = -13 Or $focused = $FALSE Or $trayMsg = $trayShowHide
            _ToggleAppState()
        Case $GuiMsg = $chkOnTop
            _ToggleOnTop()
        Case $GuiMsg = $btnOptions
            _dlgOptions()
        Case $GuiMsg = $listHistory
            _HistoryClicked()
        Case $GuiMsg = $btnEdit Or $trayMsg = $trayEdit
            _EditClip()
        Case $GuiMsg = $btnClear And _InitListArray() = $OK And _AddClip() = $OK
            _PopList()
        Case _IsClipChanged() = $TRUE And _IsClipNew() = $TRUE And _AddClip() = $OK
            _PopList()
        Case Not WinActive("AutoClipIt") And $AppState = $TRAY_UP And GUICtrlRead($chkOnTop) = $GUI_UNCHECKED And $focused = $TRUE And Not $trayMsg
            $focused = $FALSE
    EndSelect
;
Until $GuiMsg = $GUI_EVENT_CLOSE Or $trayMsg = $trayExit
;
;
Func _InitListArray()
    Local $i = 0, $e
    For $e in $ListArray
        $ListArray[$i] = ""
        $i = $i + 1
    Next
    Return $OK
EndFunc  ;==>_InitListArray
;
;
Func _IsClipChanged()
    Local $clp = ClipGet()
    If @error = 1 Then Return $ERR
    If $clp = "" Or $clp = $CurClip Then Return $FALSE
    $CurClip = StringStripWS($clp, 3)
    ClipPut($CurClip)
    GUICtrlSetData($inpCurClip, $CurClip)
    Return $TRUE
EndFunc  ;==>_IsClipChanged
;
;
Func _IsClipNew()
    Local $i = 0, $e
    For $e in $ListArray
        If $CurClip = $e Then Return $FALSE
        $i = $i + 1
    Next
    Return $TRUE
EndFunc  ;==>_IsClipNew
;
;
Func _AddClip()
    If _ArrayInsert($ListArray, 0, $CurClip) = 1 Then
        ReDim $ListArray[$MaxListArray]
        Return $OK
    EndIf
    Return $ERR
EndFunc  ;==>_AddClip
;
;
Func _PopList()
    Local $arrToStr = _ArrayToString($ListArray, "|", 0, $MaxListArray - 1)
    GUICtrlSetData($listHistory, "")
    GUICtrlSetData($listHistory, $arrToStr)
EndFunc  ;==>_PopList
;
;
Func _HistoryClicked()
    ClipPut(GUICtrlRead($listHistory))
EndFunc  ;==>_HistoryClicked
;
;
Func _ToggleOnTop()
    If GUICtrlRead($chkOnTop) = $GUI_CHECKED Then
        WinSetOnTop("AutoClipIt", "", 1)
        Return 0
    EndIf
    WinSetOnTop("AutoClipIt", "", 0)
EndFunc  ;==>_ToggleOnTop
;
;
Func _ToggleAppState()
    If $focused = $FALSE Then
        $focused = $TRUE
        $AppState = $TRAY_UP
    EndIf
    If $AppState = $TRAY_DOWN Then
        $AppState = $TRAY_UP
        TraySetItemText ($trayShowHide, "Hide")
        GUISetState(@SW_SHOW, $AutoClipIt)
        Return
    EndIf
    $AppState = $TRAY_DOWN
    TraySetItemText ($trayShowHide, "Show")
    GUISetState(@SW_HIDE, $AutoClipIt)
EndFunc  ;==>_ToggleAppState
;
;
Func _EditClip()
    Local $DlgMsg
;
    GUISetState(@SW_DISABLE, $AutoClipIt)
;
    Local $dlgEdit = GUICreate("AutoClipIt Edit Clip", 500, 300, -1, -1, -1)
    Local $editBox = GUICtrlCreateEdit($CurClip, 5, 5, 495, 250)
    Global $editText
    Global $inpDelimit = GUICtrlCreateInput($delimiters, 5, 260, 50, 20)
    Local $btnExplode = GUICtrlCreateButton("Explode", 60, 0, 50)
    Local $btnSave = GUICtrlCreateButton("Save", 100, 0, 50)
    Local $btnApply = GUICtrlCreateButton("Apply", 100, 0, 50)
    Local $btnExit = GUICtrlCreateButton("Exit", 100, 0, 50)
    GUISetState()
    WinSetOnTop("AutoClipIt Edit Clip", "", 1)
;
    While WinExists("AutoClipIt Edit Clip")
        $DlgMsg = GUIGetMsg()
        Select
            Case $DlgMsg = $GUI_EVENT_CLOSE Or $DlgMsg = $btnExit
                GUIDelete($dlgEdit)
            Case $DlgMsg = $btnApply
                ClipPut(GUICtrlRead($editBox))
                If _IsClipChanged() = $TRUE And _IsClipNew() = $TRUE And _AddClip() = $OK Then _PopList()
            Case $DlgMsg = $btnExplode
                $editText = GUICtrlRead($editBox)
                _Explode($editText)
            Case $DlgMsg = $btnSave
                $editText = GUICtrlRead($editBox)
                _Save($editText)
        EndSelect
    WEnd
;
    GUISetState(@SW_ENABLE, $AutoClipIt)
    WinActivate("AutoClipIt")
EndFunc  ;==>_EditClip
;
;
Func _Explode($editText)
    Local $arrExplode, $arrDelimit, $arrToClip, $d, $e
    $delimiters = GUICtrlRead($inpDelimit)
;
    $arrDelimit = StringSplit($delimiters, "")
    _ArrayDelete($arrDelimit, 0)
;
    For $d in $arrDelimit
        $arrExplode = StringSplit($editText, $d)
        _ArrayDelete($arrExplode, 0)
        _ArrayReverse($arrExplode)
        $editText = _ArrayToString($arrExplode, Chr(248), -1, -1)
    Next
;
    $arrToClip = StringSplit($editText, Chr(248))
    _ArrayDelete($arrToClip, 0)
    For $e in $arrToClip
        ClipPut($e)
        If _IsClipChanged() = $TRUE And _IsClipNew() = $TRUE And _AddClip() = $OK Then _PopList()
    Next
EndFunc  ;==>_Explode
;
;
Func _Save($editText)
    Local $fileName, $fileHandle
;
    WinSetOnTop("AutoClipIt Edit Clip", "", 0)
;
    $fileName = FileSaveDialog("Save As...", @MyDocumentsDir, "(*.*; *.txt; *.au3; *.vbs; *.bat; *.bas)", 26)
;
    If @error = 1 Then
        Return
    EndIf
;
    $fileHandle = FileOpen($fileName, 2)
    If $fileHandle = -1 Then
        FileClose($fileHandle)
        _ErrBox("File could not be opened!")
        Return
    EndIf
;
    If FileWrite($fileHandle, $editText) = 0 Then
        FileClose($fileHandle)
        _ErrBox("Could not write file!")
        Return
    EndIf
    FileClose($fileHandle)
    WinSetOnTop("AutoClipIt Edit Clip", "", 1)
EndFunc  ;==>_Save
;
;
Func _ErrBox($errMsg)
    MsgBox(262144 + 64, "Error!", $errMsg)
    WinSetOnTop("AutoClipIt Edit Clip", "", 1)
EndFunc  ;==>_ErrBox
;
;
Func _dlgOptions()
    GUISetState(@SW_DISABLE, $AutoClipIt)
;
    $dlgOptions = GUICreate("AutoClipIt Options", 400, 400)
    GUISetState()
    WinSetOnTop("AutoClipIt Options", "", 1)
;
    While WinExists("AutoClipIt Options")
        $DlgMsg = GUIGetMsg()
        Select
            Case $DlgMsg = $GUI_EVENT_CLOSE; Or $dlgOptions = $btnExit
                GUIDelete($dlgOptions)
        EndSelect
    WEnd
;
    GUISetState(@SW_ENABLE, $AutoClipIt)
    WinActivate("AutoClipIt")
    
EndFunc  ;==>_dlgOptions
Edited by steveR

AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass.

Share this post


Link to post
Share on other sites
AutoElectric

Great work, this has very practical uses. I usually have the notepad opened shuffling data between the clip board and the notepad because I have more pieces of information that I need to temporarily store, then there are clip boards (1).

How did you manage to implement scroll bars into your code tag?


From the book of AutoElectric"Do not accuse another man, without proof, or you too will be accused", Morals 4:21The book of AutoElectric is MY book of morals, and follows biblical teachings.

Share this post


Link to post
Share on other sites
AutoElectric

CODE

test test test test test test test test test

test test test test test test test test test

test test test test test test test test test

test test test test test test test test test

test test test test test test test test test

test test test test test test test test test

test test test test test test test test test

test test test test test test test test test

test test test test test test test test test

test test test test test test test test test

test test test test test test test test test

test test test test test test test test test

test test test test test test test test test

test test test test test test test test test

test test test test test test test test test

test test test test test test test test test

test test test test test test test test test

test test test test test test test test test

test test test test test test test test test

test test test test test test test test test

Ah, now I see. Thanx.


From the book of AutoElectric"Do not accuse another man, without proof, or you too will be accused", Morals 4:21The book of AutoElectric is MY book of morals, and follows biblical teachings.

Share this post


Link to post
Share on other sites
zcoacoaz

i recommend not using the

CODE

tags because they make it so when you copy it you get one really long line Edited by Xenogis

[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Share this post


Link to post
Share on other sites
zcoacoaz

yeah, i learned not to use them when i made SearchBar and no one could use it


[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

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  

×