public override string RunSingle(MultiboxFunctionParam args) { string rval = "Search engine not found"; int ind = args.MultiboxText.IndexOf(" "); string k; string t; if (ind > 1) { k = args.MultiboxText.Substring(1, ind - 1); try { t = args.MultiboxText.Substring(ind + 1); } catch { t = ""; } } else { k = args.MultiboxText.Substring(1); t = ""; } foreach (SearchItem i in SearchList.Items) { if (!i.Keyword.Equals(k)) continue; rval = "Search " + i.Name + " for \"" + t + "\""; break; } return rval; }
public static void KeyDown(IMainClass mc, KeyEventArgs e) { try { MultiboxFunctionParam p = new MultiboxFunctionParam(e.KeyCode, e.Control, e.Alt, e.Shift, mc); IMultiboxFunction af = GetActivatedFunction(p); if (af == null) return; if (af.IsMulti(p) && (p.Key == Keys.Up || p.Key == Keys.Down)) { switch (p.Key) { case Keys.Up: p.MC.LabelManager.SelectPrev(); break; case Keys.Down: p.MC.LabelManager.SelectNext(); break; } } if (af.HasKeyDownAction(p)) af.RunKeyDownAction(p); if (af.SupressKeyPress(p)) e.SuppressKeyPress = true; } catch {} }
public static void KeyDown(IMainClass mc, KeyEventArgs e) { try { MultiboxFunctionParam p = new MultiboxFunctionParam(e.KeyCode, e.Control, e.Alt, e.Shift, mc); IMultiboxFunction af = GetActivatedFunction(p); if (af == null) { return; } if (af.IsMulti(p) && (p.Key == Keys.Up || p.Key == Keys.Down)) { switch (p.Key) { case Keys.Up: p.MC.LabelManager.SelectPrev(); break; case Keys.Down: p.MC.LabelManager.SelectNext(); break; } } if (af.HasKeyDownAction(p)) { af.RunKeyDownAction(p); } if (af.SupressKeyPress(p)) { e.SuppressKeyPress = true; } } catch {} }
public override void RunActionKeyEvent(MultiboxFunctionParam args) { int ind = args.MultiboxText.IndexOf(" "); string k; string t; if (ind > 1) { k = args.MultiboxText.Substring(1, ind - 1); try { t = args.MultiboxText.Substring(ind + 1); } catch { t = ""; } } else { k = args.MultiboxText.Substring(1); t = ""; } t = HttpUtility.UrlEncode(t); foreach (SearchItem i in SearchList.Items) { if (!i.Keyword.Equals(k)) continue; Process.Start(i.SearchPath.Replace("%s", t)); break; } }
public override List<ResultItem> RunMulti(MultiboxFunctionParam args) { if (args.MultiboxText.Trim().Length == 1 && !(args.Key == Keys.Up || args.Key == Keys.Down || args.Key == Keys.Tab || args.Key == Keys.Enter || args.Key == Keys.Back)) return args.MC.HelpDialog.GetAutocompleteOptions(""); if (args.Key == Keys.Tab) { ResultItem tmp = args.MC.LabelManager.CurrentSelection; if (tmp != null) { args.MC.InputFieldText = "?" + tmp.FullText; return args.MC.HelpDialog.GetAutocompleteOptions(tmp.FullText); } } else if (args.Key == Keys.Back) { if (args.MultiboxText.Length <= 1) { args.MC.InputFieldText = ""; return null; } int ind = args.MultiboxText.LastIndexOf(">", args.MultiboxText.Length - 2); if (ind > 1) { args.MC.InputFieldText = args.MultiboxText.Remove(ind + 1); return args.MC.HelpDialog.GetAutocompleteOptions(args.MultiboxText.Substring(1)); } args.MC.InputFieldText = "?"; return args.MC.HelpDialog.GetAutocompleteOptions(""); } return null; }
public static void SelectionChanged(IMainClass mc) { try { MultiboxFunctionParam p = new MultiboxFunctionParam(Keys.None, false, false, false, mc); IMultiboxFunction af = GetActivatedFunction(p); if (!af.IsMulti(p) || !af.HasDetails(p)) { p.MC.DetailsLabelText = ""; p.MC.UpdateSize(); return; } bool ibs = af.IsBackgroundDetailsStream(p); if (ibs) { new RunBgS(af.GetBackgroundDetailsStream).BeginInvoke(p, null, null); } else { p.MC.DetailsLabelText = af.GetDetails(p); p.MC.UpdateSize(); } } catch {} }
public override string GetDetails(MultiboxFunctionParam args) { string pth = AddHDIfNeeded(args, args.MC.LabelManager.CurrentSelection.FullText); long sz = GetFileSize(pth); string sizestr = FormatSizestr(sz); string typ = GetTypeString(pth, sz); if(sz <= 0 && IsDrive(pth)) { try { foreach (Drive di in Filesystem.GetDrives()) { if (!di.Name.Equals(pth)) continue; sizestr = FormatSizestr(di.TotalSize - di.TotalFreeSpace) + " / " + FormatSizestr(di.TotalSize); break; } } catch { } } string lmd = ""; try { DateTime lmddt = Filesystem.GetFileLastWriteTime(pth); lmd = lmddt.ToShortDateString() + " " + lmddt.ToLongTimeString(); } catch { } return "Name: " + args.MC.LabelManager.CurrentSelection.DisplayText + "\nType: " + typ + "\nSize: " + sizestr + "\nLast Modified: " + lmd; }
public override string GetDetails(MultiboxFunctionParam args) { try { ResultItem tmp2 = args.MC.LabelManager.CurrentSelection; if (tmp2 != null) return "Path: " + (!string.IsNullOrEmpty(tmp2.FullText) ? tmp2.FullText : "--") + "\nSection #: " + (!string.IsNullOrEmpty(tmp2.EvalText) ? tmp2.EvalText : "--"); } catch { } return ""; }
private static IMultiboxFunction GetActivatedFunction(MultiboxFunctionParam args) { try { foreach (IMultiboxFunction f in functions) { if (f.Triggers(args)) { return(f); } } } catch {} return(null); }
public override string RunSingle(MultiboxFunctionParam args) { try { string rval; Expression tmp = new Expression(intToDec.Replace(prefixDec.Replace(args.MultiboxText, PrefixDecHelper), IntToDecHelper), EvaluateOptions.IgnoreCase); if (tmp.HasErrors()) rval = tmp.Error; else { try { rval = ((int)tmp.Evaluate()).ToString("#,##0.#########"); } catch { try { rval = ((float)tmp.Evaluate()).ToString("#,##0.#########"); } catch { try { rval = ((double)tmp.Evaluate()).ToString("#,##0.#########"); } catch { rval = double.Parse("" + tmp.Evaluate()).ToString("#,##0.#########"); } } } } return rval; //return intToDec.Replace(prefixDec.Replace(args.MultiboxText, PrefixDecHelper), IntToDecHelper); } catch { } return ""; }
public override string RunSpecialDisplayCopyHandling(MultiboxFunctionParam args) { return args.MC.LabelManager.CurrentSelection != null ? AddHDIfNeeded(args, args.MC.LabelManager.CurrentSelection.FullText) : null; }
private static List<ResultItem> GetSearchResultItems(MultiboxFunctionParam args, bool ht, List<string> rlts) { List<ResultItem> tmp = new List<ResultItem>(0); tmp.AddRange(rlts.Select(tpth => new ResultItem(tpth.Substring(tpth.LastIndexOf("\\") + 1), tpth, ht ? tpth.Replace(Filesystem.UserProfile, "~") : tpth))); return tmp; }
private static string GetEnding(MultiboxFunctionParam args, int ind) { try { return args.MultiboxText.Substring(ind + 3).ToLower(); } catch {} return sizeEndings[sizeEndings.Length - 1].ToLower(); }
private static string GetBookmarkString(MultiboxFunctionParam args, int ind2) { string pth2 = args.MultiboxText.Substring(1, ind2 - 1).Substring(0, args.MultiboxText.Substring(1, ind2 - 1).LastIndexOf("\\") + 1); string name = ""; try { name = args.MultiboxText.Substring(ind2 + 2); } catch {} return "Bookmark " + pth2 + " as \"" + name + "\""; }
private static List<ResultItem> BackspaceIfNeededAndGetFileResultItems(MultiboxFunctionParam args, string pth) { if (args.Key == Keys.Back && args.Control) { if (string.IsNullOrEmpty(pth)) { args.MC.InputFieldText = ""; return null; } args.MC.InputFieldText = ":"; pth = ""; } return GetFileResultItems(pth); }
public static bool KeyUp(IMainClass mc, KeyEventArgs e) { try { MultiboxFunctionParam p = new MultiboxFunctionParam(e.KeyCode, e.Control, e.Alt, e.Shift, mc); IMultiboxFunction af = GetActivatedFunction(p); if (af == null) { mc.OutputLabelText = ""; mc.LabelManager.ResultItems = null; return false; } if (p.Key == Keys.Enter && !p.Control && !p.Shift && !p.Alt && p.MultiboxText.Trim().Length > 0) { if (af.HasActionKeyEvent(p)) af.RunActionKeyEvent(p); } else if (p.Key == Keys.Enter && p.Control && !p.Shift && !p.Alt) { string tc = p.DisplayText; if(af.IsMulti(p)) tc = p.MC.LabelManager.CurrentSelection != null ? p.MC.LabelManager.CurrentSelection.FullText : null; if (af.HasSpecialDisplayCopyHandling(p)) tc = af.RunSpecialDisplayCopyHandling(p); if (!string.IsNullOrEmpty(tc)) Clipboard.SetText(tc); } else if (p.Key == Keys.Enter && p.Shift && !p.Control && !p.Alt && p.MultiboxText.Trim().Length > 0) { string tc = p.MultiboxText; if (af.HasSpecialInputCopyHandling(p)) tc = af.RunSpecialInputCopyHandling(p); if (!string.IsNullOrEmpty(tc)) Clipboard.SetText(tc); } else { bool sr = af.ShouldRun(p); bool ibs = af.IsBackgroundStream(p); if (af.IsMulti(p)) { if (sr && !(p.Key == Keys.Up || p.Key == Keys.Down || p.Key == Keys.ControlKey || p.Key == Keys.ShiftKey)) { if (ibs) new RunBgS(af.RunMultiBackgroundStream).BeginInvoke(p, null, null); else p.MC.LabelManager.ResultItems = af.RunMulti(p); } if (af.SupressKeyPress(p) || p.Key == Keys.Up || p.Key == Keys.Down) e.SuppressKeyPress = true; return true; } if (sr) { if (ibs) new RunBgS(af.RunSingleBackgroundStream).BeginInvoke(p, null, null); else p.MC.OutputLabelText = af.RunSingle(p); } } if (af.SupressKeyPress(p)) e.SuppressKeyPress = true; } catch {} return false; }
public override void RunActionKeyEvent(MultiboxFunctionParam args) { if (args.MultiboxText.IndexOf(">>>") > 1) throw new InvalidOperationException(); int ind2 = args.MultiboxText.IndexOf("<<"); if (ind2 <= 1) { ResultItem tmp2 = args.MC.LabelManager.CurrentSelection; if (tmp2 != null) Process.Start(AddHDIfNeeded(args, tmp2.FullText)); return; } string pth = args.MultiboxText.Substring(1, ind2 - 1); string name = ""; try { name = args.MultiboxText.Substring(ind2 + 2); } catch { } if (name.Length > 0) BookmarkList.Add(new BookmarkItem(name, pth)); }
public override List<ResultItem> RunMulti(MultiboxFunctionParam args) { if ((args.MultiboxText.IndexOf(">>>") > 1) || (args.MultiboxText.IndexOf("<<") > 1)) throw new InvalidOperationException(); AutocompleteIfNeeded(args); int ind = args.MultiboxText.IndexOf(">> "); if (args.Key != Keys.Up && args.Key != Keys.Down) { if (ind <= 1) { string pth = args.MultiboxText.Substring(1); if (!pth.Contains("\\")) return BackspaceIfNeededAndGetFileResultItems(args, pth); pth = BackspaceIfNeeded(args, pth); string pth2 = pth.Substring(0, pth.LastIndexOf("\\") + 1); string pth3 = AddHDIfNeeded(args, pth2); string pth4 = AddHDIfNeeded(args, pth); string[] pths = DirList(pth3, pth4); if (pths != null) { List<ResultItem> tmp = new List<ResultItem>(0); tmp.AddRange(pths.Select(tpth => new ResultItem(tpth, pth3 + tpth, pth2 + tpth))); return tmp; } } else { string pth = args.MultiboxText.Substring(1, ind - 1); string pth2 = pth.Substring(0, pth.LastIndexOf("\\") + 1); string pth3 = AddHDIfNeeded(args, pth2); string fnd = args.MultiboxText.Substring(ind + 3); if (fnd.Length > 0 && fnd[0] == '/') fnd = @"^" + fnd.Substring(1) + @"$"; List<string> rlts = new List<string>(0); DirSearch(pth3, fnd, rlts); if (rlts.Count > 0) return GetSearchResultItems(args, pth2.Length > 0 && pth2[0] == '~', rlts); } } return null; }
public override bool HasActionKeyEvent(MultiboxFunctionParam args) { return (args.MultiboxText.IndexOf(">>>") <= 1); }
public override void RunSingleBackgroundStream(MultiboxFunctionParam args) { int ind = args.MultiboxText.IndexOf(">>>"); if (ind <= 1) return; string pth = AddHDIfNeeded(args, args.MultiboxText.Substring(1, ind - 1)); currentEnding = GetEnding(args, ind); if (args.Key != Keys.Tab && lastSizePath != null && lastSizePath.Equals(pth) && isCalculating) return; cancelCalc = true; Thread.Sleep(10); cancelCalc = false; if (args.Key == Keys.Tab || lastSizeValue <= 0 || lastSizePath == null || !lastSizePath.Equals(pth) || (DateTime.Now - lastSizeTime).TotalMinutes >= 5) { lastSizePath = pth; args.MC.OutputLabelText = "Calculating size, please wait..."; args.MC.UpdateSize(); DateTime ld = DateTime.Now; SetLastSizeValues(0); isCalculating = true; if (!GetFolderSize(pth, args.MC, ref lastSizeValue, ref lastSizeFiles, ref lastSizeFolders, ref ld, 500)) SetLastSizeValues(-1); isCalculating = false; if (cancelCalc) return; lastSizeTime = DateTime.Now; } if (lastSizeValue <= 0) { args.MC.OutputLabelText = "Invalid selection"; return; } SetMCOutputLabelText(args.MC, lastSizeValue, lastSizeFiles, lastSizeFolders, currentEnding); args.MC.UpdateSize(); }
public override string RunSingle(MultiboxFunctionParam args) { if (args.MultiboxText.IndexOf(">>>") <= 1 && args.MultiboxText.IndexOf("<<") > 1) return GetBookmarkString(args, args.MultiboxText.IndexOf("<<")); throw new InvalidOperationException(); }
public override bool HasDetails(MultiboxFunctionParam args) { return true; }
public override bool IsMulti(MultiboxFunctionParam args) { return ((args.MultiboxText.IndexOf(">>>") <= 1) && (args.MultiboxText.IndexOf("<<") <= 1)); }
public override bool SupressKeyPress(MultiboxFunctionParam args) { return (args.Key == Keys.Tab || (args.Key == Keys.Back && args.Control)); }
private static IMultiboxFunction GetActivatedFunction(MultiboxFunctionParam args) { try { foreach (IMultiboxFunction f in functions) { if (f.Triggers(args)) return f; } } catch {} return null; }
public static void SelectionChanged(IMainClass mc) { try { MultiboxFunctionParam p = new MultiboxFunctionParam(Keys.None, false, false, false, mc); IMultiboxFunction af = GetActivatedFunction(p); if (!af.IsMulti(p) || !af.HasDetails(p)) { p.MC.DetailsLabelText = ""; p.MC.UpdateSize(); return; } bool ibs = af.IsBackgroundDetailsStream(p); if (ibs) new RunBgS(af.GetBackgroundDetailsStream).BeginInvoke(p, null, null); else { p.MC.DetailsLabelText = af.GetDetails(p); p.MC.UpdateSize(); } } catch {} }
private static string AddHDIfNeeded(MultiboxFunctionParam args, string pth) { return pth.Length > 0 && pth[0] == '~' ? Filesystem.UserProfile + pth.Substring(1) : pth; }
private static void AutocompleteIfNeeded(MultiboxFunctionParam args) { if (args.Key != Keys.Tab) return; ResultItem tmp2 = args.MC.LabelManager.CurrentSelection; if (tmp2 == null) return; args.MC.InputFieldText = ":" + tmp2.EvalText; }
private static string BackspaceIfNeeded(MultiboxFunctionParam args, string pth) { if (args.Key == Keys.Back && args.Control) { pth = pth.EndsWith("\\") ? pth.Remove(pth.LastIndexOf("\\", pth.Length - 2) + 1) : pth.Remove(pth.LastIndexOf("\\") + 1); args.MC.InputFieldText = ":" + pth; } return pth; }
public override bool HasActionKeyEvent(MultiboxFunctionParam args) { return true; }
public override bool HasSpecialDisplayCopyHandling(MultiboxFunctionParam args) { return IsMulti(args); }
public virtual bool SupressKeyPress(MultiboxFunctionParam args) { return(false); }
public virtual void RunAction(MultiboxFunctionParam args) { throw new InvalidOperationException(); }
public static bool KeyUp(IMainClass mc, KeyEventArgs e) { try { MultiboxFunctionParam p = new MultiboxFunctionParam(e.KeyCode, e.Control, e.Alt, e.Shift, mc); IMultiboxFunction af = GetActivatedFunction(p); if (af == null) { mc.OutputLabelText = ""; mc.LabelManager.ResultItems = null; return(false); } if (p.Key == Keys.Enter && !p.Control && !p.Shift && !p.Alt && p.MultiboxText.Trim().Length > 0) { if (af.HasActionKeyEvent(p)) { af.RunActionKeyEvent(p); } } else if (p.Key == Keys.Enter && p.Control && !p.Shift && !p.Alt) { string tc = p.DisplayText; if (af.IsMulti(p)) { tc = p.MC.LabelManager.CurrentSelection != null ? p.MC.LabelManager.CurrentSelection.FullText : null; } if (af.HasSpecialDisplayCopyHandling(p)) { tc = af.RunSpecialDisplayCopyHandling(p); } if (!string.IsNullOrEmpty(tc)) { Clipboard.SetText(tc); } } else if (p.Key == Keys.Enter && p.Shift && !p.Control && !p.Alt && p.MultiboxText.Trim().Length > 0) { string tc = p.MultiboxText; if (af.HasSpecialInputCopyHandling(p)) { tc = af.RunSpecialInputCopyHandling(p); } if (!string.IsNullOrEmpty(tc)) { Clipboard.SetText(tc); } } else { bool sr = af.ShouldRun(p); bool ibs = af.IsBackgroundStream(p); if (af.IsMulti(p)) { if (sr && !(p.Key == Keys.Up || p.Key == Keys.Down || p.Key == Keys.ControlKey || p.Key == Keys.ShiftKey)) { if (ibs) { new RunBgS(af.RunMultiBackgroundStream).BeginInvoke(p, null, null); } else { p.MC.LabelManager.ResultItems = af.RunMulti(p); } } if (af.SupressKeyPress(p) || p.Key == Keys.Up || p.Key == Keys.Down) { e.SuppressKeyPress = true; } return(true); } if (sr) { if (ibs) { new RunBgS(af.RunSingleBackgroundStream).BeginInvoke(p, null, null); } else { p.MC.OutputLabelText = af.RunSingle(p); } } } if (af.SupressKeyPress(p)) { e.SuppressKeyPress = true; } } catch {} return(false); }
public virtual bool HasAction(MultiboxFunctionParam args) { return(false); }
public abstract bool Triggers(MultiboxFunctionParam args);
public virtual List <ResultItem> GetActions(MultiboxFunctionParam args) { throw new InvalidOperationException(); }
public virtual void GetBackgroundActionsStream(MultiboxFunctionParam args) { throw new InvalidOperationException(); }
public virtual string GetDetails(MultiboxFunctionParam args) { throw new InvalidOperationException(); }
public virtual bool IsBackgroundActionsStream(MultiboxFunctionParam args) { return(false); }
public virtual string RunSingle(MultiboxFunctionParam args) { throw new InvalidOperationException(); }
public virtual void RunSingleBackgroundStream(MultiboxFunctionParam args) { throw new InvalidOperationException(); }
public virtual bool ShouldRun(MultiboxFunctionParam args) { return(true); }
public virtual string RunSpecialInputCopyHandling(MultiboxFunctionParam args) { throw new InvalidOperationException(); }
public virtual bool HasSpecialInputCopyHandling(MultiboxFunctionParam args) { return(false); }
public override bool Triggers(MultiboxFunctionParam args) { return (!string.IsNullOrEmpty(args.MultiboxText) && args.MultiboxText[0] == '@'); }
public override bool IsBackgroundStream(MultiboxFunctionParam args) { return (args.MultiboxText.IndexOf(">>>") > 1); }