stroke lib

function getWindows(name) {
    let wnds = sp.AllApplications();
    const proName = name;
    let result = new Array();
    for(let i =0;i< wnds.Length;++i) {
        let cur = wnds[i];
        //sp.MessageBox(cur.Process.ProcessName, "Result");
        if(cur.Process.ProcessName == proName) {
            result.push(cur);
        }
    }
    return result;
}


function sortWindowByTitle(windArray){
    if(!!!windArray || windArray.length<1) return;

    windArray.sort(function(a,b){return a.Title.localeCompare(b.Title)});
}

function ArrangeWindow(windArray) {
    if(!!!windArray || windArray.length<1) return;

    const total = windArray.length;
    const curScreen = windArray[0].Screen;
    const sWidth = curScreen.WorkingArea.Width;
    const sHeight = curScreen.WorkingArea.Height;

    const cellW = Math.floor(sWidth/2);
    const cellH = Math.floor(sHeight/Math.floor((total+1)/2));


    for(let i =0; i<total;++i) {
        sp.Sleep(1);

        var position = windArray[i].Position;
        position.Left = (i%2)*cellW;
        position.Top = Math.floor((i)/2.0)*cellH;

        position.Right = position.Left + cellW;
        position.Bottom = position.Top + cellH;

        windArray[i].Position = position;

         
        //sp.MessageBox("", windArray[i].Title);
    }
}

function showWindw(windArray) {
    if(!!!windArray || windArray.length<1) return;

    const total = windArray.length;
    for(let i =0; i<total;++i) {
        sp.Sleep(50);
        windArray[i].BringToFront();
        windArray[i].Activate();
    }
}

function see(name){
    let windArray = getWindows(name);
    if(!!!windArray || windArray.length<1){
       //sp.MessageBox("", " no window:" + name);
    }
    else {
        //sp.MessageBox("", windArray.length);
        sortWindowByTitle(windArray);
        ArrangeWindow(windArray);
        showWindw(windArray);
    }
}

see("Code");
function getExplorerWindows() {
    let wnds = sp.AllApplications();
    const proName = "explorer";
    let result = new Array();
    for(let i =0;i< wnds.Length;++i) {
        let cur = wnds[i];
        //sp.MessageBox(cur.Process.ProcessName, "Result");
        if(cur.Process.ProcessName == proName) {
            result.push(cur);
        }
    }

    return result;
}

function sortExplorer(windArray) {
    if(!!!windArray || windArray.length<1) return;
    const total = windArray.length;
    const curScreen = windArray[0].Screen;
    const sWidth = curScreen.WorkingArea.Width;
    const sHeight = curScreen.WorkingArea.Height;

    const cellW = Math.floor(sWidth/2);
    const cellH = Math.floor(sHeight/Math.floor((total+1)/2));


    let result = "";
    for(let i =0; i<total;++i) {
        let rect =   windArray[i].Rectangle;
        windArray[i].BringToFront()
        rect.Width =cellW;
        rect.Height = cellH;
        rect.X = (i%2)*cellW;
        rect.Y = Math.floor((i)/2.0)*cellH;
        windArray[i].Rectangle = rect;
    }
}


function showExplorer(){
    let windArray = getExplorerWindows();
    if(!!!windArray || windArray.length<1){
        sp.RunProgram(sp.ExpandEnvironmentVariables("%SystemRoot%")+"\\explorer.exe", "", "", "", false, false, false);
    }
    else {
        sortExplorer(getExplorerWindows());
    }
}

showExplorer();
function getExplorerWindows() {
    let wnds = sp.AllApplications();
    const proName = "explorer";
    let result = new Array();
    for(let i =0;i< wnds.Length;++i) {
        let cur = wnds[i];
        //sp.MessageBox(cur.Process.ProcessName, "Result");
        if(cur.Process.ProcessName == proName) {
            result.push(cur);
        }
    }

    return result;
}

function closeExporer() {
    let todo = getExplorerWindows();
    for(let i =0;i< todo.length;++i) {
        todo[i].SendClose()
    }
}

closeExporer();
function searchCode(){
    let ipAddr = "127.0.0.1";
    let project = "TheProjectName";
    let fullTarget = clip.GetText();

    let browserProgram = "firefox";

    let browserOption = "--new-tab "

    let url = "http://" + ipAddr + ":8080/source/search?"+"project=" + project + "&full="+ fullTarget +"&defs=&refs=&path=&type=&xrd=&nn=1&si=full&si=full"
    let cmd =  browserOption + url;
    sp.RunProgram(browserProgram, cmd, '', '', false, false, false);
}

searchCode();

function getWindowByTitle(winTitle){
    let wnds = sp.AllWindows();
    let result = new Array();
    for(let i =0;i< wnds.Length;++i) {
        let cur = wnds[i];
        if(cur.Title == winTitle) {
            //sp.MessageBox(cur.Title, "Result");
            result.push(cur);
        }
    }

    return result;
}
function findWindowUntil(title, maxWaitSec, retryWaitSec){
    const winTitle = title;
    let result = new Array();
    let curWaitSec = 0;
    while(true) {
        let wnds = sp.AllWindows();
        for(let i =0;i< wnds.Length;++i) {
            let cur = wnds[i];
            if(cur.Title == winTitle) {
                result.push(cur);
            }
        }

        if(result.length > 0) {
            break;
        }
        else {
            sp.Sleep(retryWaitSec*1000);
            curWaitSec = curWaitSec + retryWaitSec;
            if(curWaitSec > maxWaitSec) {
                break;
            }
        }
    }

    if(result.length<1) {
        //sp.MessageBox("Time out, Not Found, target Window with title:" + title, "Failed");
    }

    return result;
}

function activateWindow(wind){
    if(!!!wind)  return;
    wind.BringToFront();
    wind.Activate();
}

function setEnterToWindow(wind) {
    if(!!!wind)  return;
    sp.SendKeys("{ENTER}");
}

function sendKey(k){
    sp.SendVKeyDown(vk.VK_1);
    sp.Sleep(2);
    sp.SendVKeyUp(vk.VK_1);
}

    let info = "hello"
    sp.SendKeys(info);
    sp.Sleep(10);
    sp.SendKeys("{ENTER}")
// return text if found, otherwise ""
function isWindowContainText(wind, text) {
    if(!!!wind) return "";

    if(wind.Text.includes(text)) {
        return wind.Text;
    }
    else {
        let child = wind.AllChildWindows;
        for(let i =0;i< child.Length;++i) {
            let cur = child[i];
            let res = isWindowContainText(cur,text);
            if(res.length >0) {
                return res;
            }
        }
        return "";
    }
}
function click(){
    sp.ConsumePhysicalInput(true);
    sp.Sleep(10);
    sp.MouseClick(new Point(11, 11), MouseButtons.Left, true, false);
    sp.Sleep(10);
    sp.MouseClick(new Point(11, 11), MouseButtons.Left, false, true);
    sp.Sleep(10);

    sp.ConsumePhysicalInput(false);
    sp.ConsumePhysicalInput(false);
}
function showMessage(msg, sec){
    var info = new DisplayTextInfo();
    info.Title = '';
    info.TitleAlignment = 'Center';
    info.Message = msg;
    info.MessageAlignment = 'Left';
    info.Duration = 1000*sec;
    //The transparency of the popup, valid ranges: 0.05 - 1.0  (1.0 is no transparency)
    info.Opacity = 0.7;
    //Location supports location as well, use this format to specify a type: '100,200'
    //types: topleft, top, topright, right, bottomright, bottom, bottomleft, left
    info.Location = 'top'; 
    info.TitleFont = new Font('Segoe UI', 12, host.flags(FontStyle.Bold));
    info.MessageFont = new Font('Segoe UI Semibold', 18);
    info.BackColor = 'black';//'56,169,255'; //Also supports RGB
    info.ForeColor = 'yellow';
    info.Padding = 15;
    info.FadeSteps = 18;
    //If true, always displays on primary screen (unless Location is a point type), 
    //otherwise displays on the screen where the gesture started
    info.UsePrimaryScreen = true; 
    sp.DisplayText(info);
}
posted @ 2023-04-27 16:52  fndefbwefsowpvqfx  阅读(16)  评论(0编辑  收藏  举报