~joten/cubit


Stable release 0.1.0 / 18.06.2011
Status Inactive development / not supported
Written in AutoHotkey script
Runtime environment AutoHotkey
Available in English
Type Application Launcher
License GNU General Public License
Distribution AutoHotkey script source
Download from AutoHotkey.net (AHK, 8 KB)

Description

cubit is an application launcher or link lister, which is configured by using LNK files. It lists the content of the LNK files in a given directory with a prepending alphanumeric character, which is used as a hotkey to run or open the associated application or file.

Source view

/**
 *    cubit - link lister
 *    Copyright (c) 2011 joten
 *
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 *    @version 0.1.0.02 (18.06.2011)
 */


/**
 *  quick help
 *  
 *  cubit is a link lister or launcher, which reads all links in a given 
 *  directory and lists them in a new window, where you can select an entry
 *  for which the associated application is run.
 *  The directory, which should be recursively searched for links can be 
 *  given as an argument, when running the script, or will be set to the 
 *  script directory. If not given an absolute path, the sript will asume, 
 *  that the path is relative to the script directory.
 *  The window shows the following information in columns:
 *    + Alphanumeric sign (for selection purposes)
 *    + Name (The filename relative to the given link directory)
 *    + Target
 *    + Arguments
 *    + Working Directory
 *    + Run State (minimized or maximized)
 *  
 *  The first two columns are always shown with a width adjusted to fit 
 *  their content (AutoHdr). For the other four colums you may set the 
 *  width with the configuration variables at the beginning of the script 
 *  ("Config_columnWidth<header name>") to either "AutoHdr", a fixed size 
 *  in pixel or 0, if the column should be hidden. You may also set the 
 *  window width by means of the configuration variable 
 *  "Config_listViewWidth".
 *  
 *  You may select an entry either by mouse or by keyboard; selecting it by
 *  keyboard can be done with the "Up" and "Down" arrow keys, or by 
 *  pressing the key given by the alphanumeric sign in the first column. 
 *  If you set the configuration variable "Config_runOnSelection" to True 
 *  the associated application is immediatly run and the script closes the 
 *  window and exits. If you set "Config_runOnSelection" to False you also 
 *  need to press the "Enter" key to run the application. If you did not 
 *  select any entry and hit "Enter", all listed applications are run. If 
 *  you do not want to run any application press the "Escape" key and the 
 *  script will only close the window and exit.
 *  
 *  You may also set the variable "Config_removeSortingFromLinkName" to 
 *  True, if you put numbers in front of the link names to sort them in a 
 *  non-alphabetic order and do not want them to appear in the name shown 
 *  in the second column of the script window.
 *  You may set the variable "Config_useLinkNameInitial" to True, if you 
 *  want the script to not choose the next number or letter in line for the
 *  first column of an entry, but the first letter of the link name, if 
 *  available (not already used for a prior entry).
 */

NAME    := "cubit"
VERSION := "0.1.0"

; Configuration
Config_columnWidthArguments        := "AutoHdr"
Config_columnWidthRunState         := 0
Config_columnWidthTarget           := 0
Config_columnWidthWorkingDirectory := "AutoHdr"
Config_listViewWidth               := 700
Config_runOnSelection              := True         ; else run on Enter
Config_removeSortingFromLinkName   := True
Config_useLinkNameInitial          := True         ; else each list entry gets a sequential initial for selection purposes

; script settings
SetBatchLines, -1
SetTitleMatchMode, 3
SetTitleMatchMode, fast
#NoEnv
#NoTrayIcon
#SingleInstance force

; pseudo main function
    Suspend, On
    
    ; Define the link directory
    If 0 > 0
    {
        Config_linkDirectory = %1%
        If Not InStr(Config_linkDirectory, ":")
            Config_linkDirectory := A_WorkingDir "\" Config_linkDirectory
    } Else
        Config_linkDirectory := A_WorkingDir
    
    ; Create the GUI
    IfExist %A_ScriptDir%\images\%NAME%.ico
        Menu, Tray, Icon, %A_ScriptDir%\images\%NAME%.ico
    Gui, 1: Default
    IfWinExist, %NAME%
        Gui, Destroy
    Gui, +LastFound +0xCF0000
    
    Config_listViewRows := 0
    Loop, %Config_linkDirectory%\*.lnk, 0, 1
        Config_listViewRows += 1
    Gui, Add, ListView, AltSubmit Count36 -Multi R%Config_listViewRows% W%Config_listViewWidth% gGui_listViewEvent vGui_listView, #|Name|Target|Arguments|Working Directory|Run State
    Gui, Add, Button, Hidden Default gGui_listViewEnter, 
    GuiControl, -Redraw, Gui_listView
    Gui_#String := "1;2;3;4;5;6;7;8;9;0;A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y;Z;"
    
    ; Get the shortcut information and fill the GUI ListView
    Loop, %Config_linkDirectory%\*.lnk, 0, 1
    {
        FileGetShortcut, %A_LoopFileLongPath%, Gui_linkTarget, Gui_linkDir, Gui_linkArgs, , , , Gui_linkRunState
        
        Gui_linkName := A_LoopFileLongPath
        StringReplace, Gui_linkName, Gui_linkName, %Config_linkDirectory%\, 
        StringTrimRight, Gui_linkName, Gui_linkName, 4
        
        StringReplace, Gui_linkTarget, Gui_linkTarget, `%WinDir`%, %A_WinDir%
        StringReplace, Gui_linkDir, Gui_linkDir, `%WinDir`%, %A_WinDir%
        
        If Gui_linkRunState = 7
            Gui_linkRunState := "Min"
        Else If Gui_linkRunState = 3
            Gui_linkRunState := "Max"
        Else
            Gui_linkRunState := ""
        
        If Config_useLinkNameInitial {
            Gui_i := InStr(Gui_linkName, "\", False, 0)
            Gui_# := SubStr(Gui_linkName, Gui_i + 1, 1)
            StringUpper, Gui_#, Gui_#
        }
        If Not InStr(Gui_#String, Gui_# ";") Or (Gui_# = "")
            StringLeft, Gui_#, Gui_#String, 1
        StringReplace, Gui_#String, Gui_#String, %Gui_#%`;, 
        
        If Config_removeSortingFromLinkName And RegExMatch(Gui_linkName, "^[0-9]+ ")
            Gui_linkName := RegExReplace(Gui_linkName, "^[0-9]+ ")
        
        LV_Add("", Gui_#%i%, Gui_linkName, Gui_linkTarget, Gui_linkArgs, Gui_linkDir, Gui_linkRunState)
    }
    
    LV_ModifyCol(1, "AutoHdr")
    LV_ModifyCol(2, "AutoHdr")
    LV_ModifyCol(3, Config_columnWidthTarget)
    LV_ModifyCol(4, Config_columnWidthArguments)
    LV_ModifyCol(5, Config_columnWidthWorkingDirectory)
    LV_ModifyCol(6, Config_columnWidthRunState)
    GuiControl, +Redraw, Gui_listView
    Gui, Show, AutoSize, %NAME%
    
    Suspend, Off
Return                 ; end of the auto-execute section


/**
 *    function & label definitions
 */
GuiClose:
    ExitApp
Return

GuiEscape:
    ExitApp
Return

GuiSize:
    Config_listViewWidth := A_GuiWidth - 0
    Gui_listViewHeight := A_GuiHeight - 12
    GuiControl, Move, Gui_listView, X0 Y0 W%Config_listViewWidth% H%Gui_listViewHeight%
Return

Gui_listViewEvent:
    GuiControlGet, Gui_focusedControl, FocusV
    If (Gui_focusedControl = "Gui_listView") And (A_GuiEvent = "DoubleClick" Or (A_GuiEvent = "I" And Config_runOnSelection))
        Gui_processSelection()
return

Gui_listViewEnter:
    GuiControlGet, Gui_focusedControl, FocusV
    If (Gui_focusedControl = "Gui_listView")
        Gui_processSelection()
return

Gui_processSelection() {
    If LV_GetNext(0, "Focused") {
        LV_GetText(selectedTarget, LV_GetNext(0, "Focused"), 3)
        LV_GetText(selectedDir, LV_GetNext(0, "Focused"), 5)
        LV_GetText(selectedArgs, LV_GetNext(0, "Focused"), 4)
        LV_GetText(selectedRunState, LV_GetNext(0, "Focused"), 6)
        If selectedArgs
            selectedTarget .= " " selectedArgs
        Run, %selectedTarget%, %selectedDir%, %selectedRunState%
    } Else
        Loop, % LV_GetCount() {
            LV_GetText(selectedTarget, A_Index, 3)
            LV_GetText(selectedDir, A_Index, 5)
            LV_GetText(selectedArgs, A_Index, 4)
            LV_GetText(selectedRunState, A_Index, 6)
            If selectedArgs
                selectedTarget .= " " selectedArgs
            Run, %selectedTarget%, %selectedDir%, %selectedRunState%
        }
    ExitApp
}


© 2010-2012 joten, last modified 08.01.2012