Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

TDL: Protocol for .dan.g.'s ToDoList, Useful for SVN Users

, 25 Apr 2008 CPOL
Register a fake protocol of TDL: to make tdl:///filename.tdl?tid available
tdl-app_exe.zip
TdlApp.exe
tdl-app_src.zip
MainFormUnit.dfm
res
tdl.ico
TdlApp.bdsproj
TdlApp.res
tdl_scr.zip
ToDoList.wsf
// ToDoList Protocol (TDL) Script Edition, Version 1.0 Beta2

function TdlShell() {
    this.regProtocolKey = "HKCR\\TDL";
    this.regUrlProtocol = this.regProtocolKey + "\\URL Protocol"
    this.regCommandKey = "HKCR\\TDL\\shell\\open\\command";
   
    this.fso = new ActiveXObject("Scripting.FileSystemObject");
    this.shell = new ActiveXObject("WScript.Shell");
    this.todolist = null
    this.folder = null;
    this.ini = null;
    this.html = null;
    this.wsf = null;
}

TdlShell.prototype.init = function() {
    TdlShell.prototype.InstallError = new Error("install error");
    TdlShell.prototype.UninstallError = new Error("uninstall error");
    TdlShell.prototype.FileNotExistsError = new Error("file not exists error");
}

TdlShell.prototype.installProtocol = function() {
    try {
        this.shell.RegWrite(this.regProtocolKey + "\\",
            "\"URL: ToDoList protocol\"");
        this.shell.RegWrite(this.regUrlProtocol, "");
        this.shell.RegWrite(this.regCommandKey + "\\",
            "wscript \"" + this.getWsfFile() + "\" \"%1\"");
    } catch (err) {
        throw this.InstallError;
    }
}

TdlShell.prototype.uninstallProtocol = function() {
    var r = this.shell.Run("reg delete HKCR\\TDL /f", 0, true);
    if (r == 0) {
        return;
    }
    
    throw this.UninstallError;
}

TdlShell.prototype.getExecutable = function() {
    if (this.todolist == null) {
        this.getTodolist();
    }
    
    return this.todolist;
}

TdlShell.prototype.writeExecutable = function(filepath) {
    this.todolist = filepath;
    var ini = this.getIniFile();
    
    var ts = this.fso.CreateTextFile(ini, true);
    ts.WriteLine("todolist=" + filepath);
    ts.Close();
}

TdlShell.prototype.getTodolist = function() {
    var ini = this.getIniFile();
    if (!this.fso.FileExists(ini)) {
        return;
    }

    var ts = this.fso.OpenTextFile(ini);
    var line;
    while (!ts.AtEndOfStream) {
        line = ts.ReadLine();
        if (line.match(/^\s*todolist\s*=/i) != null) {
            this.todolist = line.replace(/^\s*todolist\s*=\s*(.*)/i, "$1");
        }
    }
    ts.Close();
}

TdlShell.prototype.getWsfFile = function() {
    if (this.wsf == null) {
        var folder = this.getInstallFolder();
        this.ini = this.fso.BuildPath(folder, "todolist.wsf");
    }
    return this.wsf;
}

TdlShell.prototype.getIniFile = function() {
    if (this.ini == null) {
        var folder = this.getInstallFolder();
        this.ini = this.fso.BuildPath(folder, "tdl.ini");
    }
    return this.ini;
}

TdlShell.prototype.getHtmlSetting = function() {
    if (this.html == null) {
        var folder = this.getInstallFolder();
        this.html = this.fso.BuildPath(folder, "tdl.html");
    }
    return this.html;
}

TdlShell.prototype.getInstallFolder = function() {
    if (this.folder == null) {
        var script = this.fso.GetFile(WScript.ScriptFullName);
        this.folder = script.ParentFolder;
    }
    return this.folder;
}

TdlShell.prototype.configure = function() {
    var html = this.getHtmlSetting();
    if (!this.fso.FileExists(html)) {
        return false;
    }
    
    try {
        this.shell.Run(html);
    } catch (err) {
        // Do nothing
    }
}

TdlShell.prototype.confirm = function(message) {
    var r = this.shell.Popup(message, 0, "TDL Protocol", 4 | 48);
    return r == 6;
}

TdlShell.prototype.openTodolist = function(todolist, tid) {
    if (this.todolist == null) {
        return;
    }
    cmd = "\"" + this.todolist + "\" \"" + todolist + "\"";
    if (tid != null) {
        cmd += " -tid " + tid;
    }

    this.shell.Run(cmd);
}

TdlShell.prototype.init();

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

jamesfancy

China China
James Fancy, is a software engineer from China. He enjoys and familiar with Java, C++ and some script languages.
 
If you can read Chinese word, here is one of James Fancy's BLOG:
http://hi.baidu.com/jamesfancy

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411023.1 | Last Updated 25 Apr 2008
Article Copyright 2007 by jamesfancy
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid