K-Meleon


KMeleonWiki > Resources > MacroLibrary > KmmGrpMSearch

Submitted by: JamesD



Notes:

Groups MultiSearch allows user to maintain more than one group of search engines for MultiSearch and swap between them easily.




Open your User Macro Folder (Edit > Configuration > User-Defined Macros) or your Macro Folder (Edit > Configuration > Macros) and create the following text file:

Grp_M_Search.kmm

#  K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
#
# ---------- Grp_M_Search.kmm
# ---------- Setup groups of search URLs for use with multisearch ---------------
# ---------- Allow setup, deletion and choice of group
#
# Dependencies        : main.kmm
# Resources              : 
# Preferences          : k-meleon_search_group.<name><0,1,..>
#                                : k-meleon_search_group.names  
#                                  : kmeleon.plugins.macros.search.meta<0,1,..>.url
# Version                   : 2.0  2010-08-19
# Author                     : JamesD  
# --------------------------------------------------------------------------------
#####  ADDITIONS
_Grp_M_Search_Add {
macroinfo = _("Save the current multisearch engines as a group.");
$_Grp_M_Search_m1 = "kmeleon.plugins.macros.search.meta";
$_Grp_M_Search_m3 = ".url";
$_Grp_M_Search_CUrls = "";
$_Grp_M_Search_cnt = 0;
while($_Grp_M_Search_cnt != -1) {
        $_Grp_M_Search_URL = getpref(STRING, $_Grp_M_Search_m1.$_Grp_M_Search_cnt.$_Grp_M_Search_m3);
        if (length($_Grp_M_Search_URL) != 0) {
                $_Grp_M_Search_CUrls = $_Grp_M_Search_CUrls ."\n".$_Grp_M_Search_URL ;        
                $_Grp_M_Search_cnt = $_Grp_M_Search_cnt +1 ;
                } else { 
                $_Grp_M_Search_cnt = -1; 
        }
}
$_Grp_M_Search_Text =               _("\n\nThe search URLs listed above are your current")."\n";
$_Grp_M_Search_Text=$_Grp_M_Search_Text._("multisearch engines.  To make them a named group")."\n";
$_Grp_M_Search_Text=$_Grp_M_Search_Text._("of engines, provide a unique name for them at")."\n";
$_Grp_M_Search_Text=$_Grp_M_Search_Text._("the prompt which follows.  ( click for prompt )");
alert($_Grp_M_Search_CUrls.$_Grp_M_Search_Text, _("Current multisearch engine URLs"), INFO);
macros(_Grp_M_Search_Add1);
}

_Grp_M_Search_Add1 {
$_Grp_M_Search_PNewName = prompt(_("Name cannot contain the % character"),_("Assign a name for this group"));
## catch cancel
$_Grp_M_Search_PNewName == "" ? &_Grp_M_Search_CancelA : &_Grp_M_Search_Add1a ;
}

_Grp_M_Search_Add1a {
## catch % delimiter in name
index($_Grp_M_Search_PNewName,"%") > 0 ? &_Grp_M_Search_percent : &_Grp_M_Search_Add1b ;
}

_Grp_M_Search_Add1b {
## catch duplicate name
macros(_Grp_M_Search_AddV);
$_Grp_M_Search_Dup == true ? &_Grp_M_Search_Duplicate : &_Grp_M_Search_Add2 ;

}

_Grp_M_Search_CancelA {
$_Grp_M_Search_Can = confirm(_("Did you mean to cancel?"), _("Prompt was cancelled"),YESNO,QUESTION);
$_Grp_M_Search_Can == "YES" ? 0 : &_Grp_M_Search_Add1 ;
}

_Grp_M_Search_percent {
$_Grp_M_Search_Pct = confirm(_("The name  ").$_Grp_M_Search_PNewName._("  contains a %."), _("% character not allowed."),RETRYCANCEL,QUESTION);
$_Grp_M_Search_Pct == 0 ? 0 : &_Grp_M_Search_Add1 ;
}

_Grp_M_Search_Duplicate {
$_Grp_M_Search_Dv = confirm(_("The name  ").$_Grp_M_Search_PNewName._("  is currently used."), _("Duplicate name"),RETRYCANCEL,QUESTION);
$_Grp_M_Search_Dv == 0 ? 0 : &_Grp_M_Search_Add1 ;
}

_Grp_M_Search_Add2 {
$_Grp_M_Search_cnt = 0;
while($_Grp_M_Search_cnt != -1) {
        $_Grp_M_Search_URL = getpref(STRING, $_Grp_M_Search_m1.$_Grp_M_Search_cnt.$_Grp_M_Search_m3);
        if (length($_Grp_M_Search_URL) != 0) {
                setpref(STRING,"k-meleon_search_group.".$_Grp_M_Search_PNewName.$_Grp_M_Search_cnt,$_Grp_M_Search_URL);        
                $_Grp_M_Search_cnt = $_Grp_M_Search_cnt +1 ;
                } else { 
                $_Grp_M_Search_cnt = -1; 
        }
}
setpref(STRING,"k-meleon_search_group.names", getpref(STRING,"k-meleon_search_group.names").$_Grp_M_Search_PNewName . "%");
# add group to inline menu
macros(_Grp_M_Search_BuildMenuGrp);
}

_Grp_M_Search_AddV {
$_Grp_M_Search_Names = getpref(STRING,"k-meleon_search_group.names");
$_Grp_M_Search_NBreak = 0;
$_Grp_M_Search_Dup = false ;
while( $_Grp_M_Search_NBreak != -1) { 
        $_Grp_M_Search_NBreak = index($_Grp_M_Search_Names, "%");
        $_Grp_M_Search_Name = substr($_Grp_M_Search_Names,0,$_Grp_M_Search_NBreak);
        if ($_Grp_M_Search_Name == $_Grp_M_Search_PNewName) {
                $_Grp_M_Search_Dup = true ;
                $_Grp_M_Search_NBreak = -1;
        } else {
        $_Grp_M_Search_Names = substr($_Grp_M_Search_Names, $_Grp_M_Search_NBreak +1);
        }
}
}

_Grp_M_Search_UseGrp {
## first remove existing multisearch prefs
$_Grp_M_Search_m1 = "kmeleon.plugins.macros.search.meta";
$_Grp_M_Search_m3 = ".url";
$_Grp_M_Search_cnt = 0;
while($_Grp_M_Search_cnt != -1) {
        $_Grp_M_Search_URL = getpref(STRING,$_Grp_M_Search_m1.$_Grp_M_Search_cnt.$_Grp_M_Search_m3);
        if ($_Grp_M_Search_URL != "") {
                delpref($_Grp_M_Search_m1.$_Grp_M_Search_cnt.$_Grp_M_Search_m3);
                $_Grp_M_Search_cnt = $_Grp_M_Search_cnt +1 ;
                } else { $_Grp_M_Search_cnt = -1;
        }
}
## read group urls and write them to multisearch prefs
$_Grp_M_Search_m2 = "k-meleon_search_group." ;
$_Grp_M_Search_m1 = "kmeleon.plugins.macros.search.meta";
$_Grp_M_Search_m4 = ".url";
$_Grp_M_Search_cnt = 0;
while($_Grp_M_Search_cnt != -1) {
        $_Grp_M_Search_URL = getpref(STRING,$_Grp_M_Search_m2.$ARG.$_Grp_M_Search_cnt);
        if ($_Grp_M_Search_URL != "") {
                setpref(STRING,$_Grp_M_Search_m1.$_Grp_M_Search_cnt.$_Grp_M_Search_m4,$_Grp_M_Search_URL);
                $_Grp_M_Search_cnt = $_Grp_M_Search_cnt +1 ;
                } else {
                ## if URL missing check cnt < 3 then output missing
                if ( $_Grp_M_Search_cnt < 3 ) {
                setpref(STRING,$_Grp_M_Search_m1.$_Grp_M_Search_cnt.$_Grp_M_Search_m4,"");
                $_Grp_M_Search_cnt = $_Grp_M_Search_cnt +1 ;
                } else {
                $_Grp_M_Search_cnt = -1;
                }
        }
}
}

##########  DELETES

_Grp_M_Search_Del {
macroinfo = _("Delete an existing multisearch group.");
$_Grp_M_Search_Names =  getpref(STRING,"k-meleon_search_group.names");
##  only 62 character display in prompt - display other name in statusbar
if (length($_Grp_M_Search_Names) > 62 ) {
        macros(_Grp_M_Search_LongList);
        $_Grp_M_Search_Na62 = substr($_Grp_M_Search_Names, 0 , $_Grp_M_Search_pcp);
        $_Grp_M_Search_Na63 = substr($_Grp_M_Search_Names, $_Grp_M_Search_pcp +1 );
        statusbar("Additional Names >> ".$_Grp_M_Search_Na63);
        $_Grp_M_Search_Delete = prompt($_Grp_M_Search_Na62, _("For delete, enter name without the %"));
        statusbar("");
        } else {
        $_Grp_M_Search_Delete = prompt($_Grp_M_Search_Names, _("For delete, enter name without the %"));
        statusbar("");
        }
## catch cancel
$_Grp_M_Search_Delete == "" ? &_Grp_M_Search_CancelD : &_Grp_M_Search_Missing ;
}

_Grp_M_Search_LongList {
##  compute position last delimiter in first 62 string
$_Grp_M_Search_pos = 61 ;
while($_Grp_M_Search_pos != -1 ) {
        if (substr(        $_Grp_M_Search_Names, $_Grp_M_Search_pos, 1 ) == "%") {
                $_Grp_M_Search_pcp = $_Grp_M_Search_pos;
                $_Grp_M_Search_pos = -1 ;
                } else {  $_Grp_M_Search_pos = $_Grp_M_Search_pos -1 ; }
}
}

_Grp_M_Search_Missing {
## catch missing
macros(_Grp_M_Search_DelV);
$_Grp_M_Search_Mis == true ? &_Grp_M_Search_misx : &_Grp_M_Search_Del2  ;
}

_Grp_M_Search_CancelD {
$_Grp_M_Search_Can = confirm(_("Did you mean to cancel?"), _("Prompt was cancelled"),YESNO,QUESTION);
$_Grp_M_Search_Can == "YES" ? 0 : &_Grp_M_Search_Del ;
}

_Grp_M_Search_misx {
$_Grp_M_Search_mis = confirm(_("The name  ").$_Grp_M_Search_Delete._("  is not found."), _("Not in list"),RETRYCANCEL,QUESTION);
$_Grp_M_Search_mis == 0 ? 0 : &_Grp_M_Search_Del ;
}

_Grp_M_Search_Del2 {
$_Grp_M_Search_Names = getpref(STRING,"k-meleon_search_group.names");
$_Grp_M_Search_NewNames = gsub($_Grp_M_Search_Delete."%", "", $_Grp_M_Search_Names );
setpref(STRING,"k-meleon_search_group.names",$_Grp_M_Search_NewNames);
$_Grp_M_Search_m2 = "k-meleon_search_group." ;
$_Grp_M_Search_cnt = 0;
while($_Grp_M_Search_cnt != -1) {
        $_Grp_M_Search_URL = getpref(STRING,$_Grp_M_Search_m2.$_Grp_M_Search_Delete.$_Grp_M_Search_cnt);
        if ($_Grp_M_Search_URL != "") {
                delpref($_Grp_M_Search_m2.$_Grp_M_Search_Delete.$_Grp_M_Search_cnt);
                $_Grp_M_Search_cnt = $_Grp_M_Search_cnt +1 ;
                } else {
                $_Grp_M_Search_cnt = -1;
        }
}
# delete group from inline menu
macros(_Grp_M_Search_BuildMenuGrp);
}

_Grp_M_Search_DelV {
$_Grp_M_Search_Names = getpref(STRING,"k-meleon_search_group.names");
$_Grp_M_Search_Mis = true ;
$_Grp_M_Search_NBreak = 0;
while( $_Grp_M_Search_NBreak != -1) { 
        $_Grp_M_Search_NBreak = index($_Grp_M_Search_Names, "%");
        $_Grp_M_Search_Name = substr($_Grp_M_Search_Names,0,$_Grp_M_Search_NBreak);
        $_Grp_M_Search_Name == $_Grp_M_Search_Delete ? $_Grp_M_Search_Mis = false :0 ;
        $_Grp_M_Search_Names = substr($_Grp_M_Search_Names, $_Grp_M_Search_NBreak +1);
}
}

######  INSTRUCTIONS

_Grp_M_Search_Help {
macroinfo = _("Present help on saving multisearch groups.");
$_GMS1 =      _("First")."\n";
$_GMS1=$_GMS1._("Use the dialog in 'Tools - Web Search - Configure' to set multisearch")." \n";
$_GMS1=$_GMS1._("to have the search engines that you require for a group.")." \n";
$_GMS1a =     _("If you have installed Search+, the the dialog may be reach by")." \n";
$_GMS1a=$_GMS1a._("'Tools - Web Search - Search Options - Configure Search Engines'.")." \n\n";
$_GMS2 =      _("Second")." \n";
$_GMS2=$_GMS2._("Use the 'Add Group' item  in 'Group Multisearch' to give the search engines")." \n";
$_GMS2=$_GMS2._("in multisearch a name and store them as a group.")." \n\n";
$_GMS3 =      _("Third")." \n";
$_GMS3=$_GMS3._("Repeat the first and second steps using search engines required for")." \n";
$_GMS3=$_GMS3._("other groups.")." \n\n\n";
$_GMS4 =      _("To insert one of your groups to be the current multisearch list of engines,")." \n";
$_GMS4=$_GMS4._("just click on the group name in the inline menu.  You may then search as")." \n";
$_GMS4=$_GMS4._("you are accustomed.");
alert($_GMS1.$_GMS1a.$_GMS2.$_GMS3.$_GMS4, _("Instructions"), INFO);
}

_Grp_M_Search_BuildMenu {
        $_g = _("Group Multisearch");
        setmenu("WebServices",popup,$_g,1);
        setmenu($_g,macro,_("Add Group"),_Grp_M_Search_Add,0);
        setmenu($_g,macro,_("Delete Group"),_Grp_M_Search_Del,1);
        setmenu($_g,macro,_("Help"),_Grp_M_Search_Help,2);
        setmenu($_g,separator,3);
        macros(_Grp_M_Search_BuildMenuGrp);
}

_Grp_M_Search_BuildMenuGrp {
        $_g = _("Group Multisearch");
        $_m = "_MSGrps";
        setmenu($_g, inline, $_m);
        $_Grp_M_Search_ExistCnt = getpref(INT,"k-meleon_search_group.count");
        $_Grp_M_Search_Names = getpref(STRING,"k-meleon_search_group.names");
        $__incr = 0;
        $_Grp_M_Search_NBreak = 0;
        while( $_Grp_M_Search_NBreak != -1) { 
                $_Grp_M_Search_NBreak = index($_Grp_M_Search_Names, "%");
                $_Grp_M_Search_Name = substr($_Grp_M_Search_Names,0,$_Grp_M_Search_NBreak);
                if (length($_Grp_M_Search_Name) != 0) {
                setmenu($_m, macro, $_Grp_M_Search_Name, "_Grp_M_Search_UseGrp(" . $_Grp_M_Search_Name . ")");
                $_Grp_M_Search_Names = substr($_Grp_M_Search_Names, $_Grp_M_Search_NBreak +1);
                }
                $__incr = $__incr +1 ;
                $_Grp_M_Search_Delete != "" ? setmenu($_m, macro, $_Grp_M_Search_Delete, "") : 0;
        }
rebuildmenu($_g);
rebuildmenu($_m);
$_Grp_M_Search_Delete="";        
}

_Grp_M_Search_Initial {
$_Grp_M_Search_Delete="";
}

## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$OnInit=$OnInit."_Grp_M_Search_Initial;_Grp_M_Search_BuildMenu;";
$macroModules=$macroModules."Grp_M_Search;";


Comments & Questions

K-Meleon

(c) 2000-2010 kmeleonbrowser.org. All rights reserved.
design by splif.