static void _ShowRegexOrKeysWindow(bool regex) { bool retry = false; g1: if (!CodeInfo.GetDocumentAndFindNode(out var cd, out var node)) { return; } var pos16 = cd.pos16; if (!CiUtil.IsInString(ref node, pos16)) { if (regex || retry) { ADialog.ShowInfo("The text cursor must be in a string."); return; } InsertCode.Statements("AKeys.Key(\"%\");", goToPercent: true); retry = true; goto g1; } var doc = cd.sciDoc; var stringSpan = node.Span; var t = CodeInfo._tools; if (regex) { t.RegexWindowShow(doc, cd.code, pos16, stringSpan, replace: false); } else { t.KeysWindowShow(doc, cd.code, pos16, stringSpan); } }
unsafe void _Drop(POINT xy, int effect) { _GetDropPos(ref xy, out int pos8); var z = new Sci_DragDropData { x = xy.x, y = xy.y }; string s = null; var b = new StringBuilder(); int what = 0, index = 0; if (_justText) { s = _data.text; } else { _sci.Call(SCI_DRAGDROP, 2, &z); //just hides the drag indicator and sets caret position if (_sci._fn.IsCodeFile) { string mi = _data.scripts ? "1 string s = name;|2 string s = path;|3 script.run(path);|4 t[name] = o => script.run(path);" : "11 string s = path;|12 run.it(path);|13 t[name] = o => run.it(path);"; what = popupMenu.showSimple(mi); if (what == 0) { return; } } if (_data.scripts) { var a = Panels.Files.TreeControl.DragDropFiles; if (a != null) { foreach (var f in a) { _AppendScriptOrLink(f.ItemPath, f.Name, f); } } } else if (_data.files != null) { foreach (var path in _data.files) { _AppendFileOrShell(path); } } else if (_data.shell != null) { _GetShell(_data.shell, out var shells, out var names); if (shells != null) { for (int i = 0; i < shells.Length; i++) { _AppendFileOrShell(shells[i], names[i]); } } } else if (_data.linkName != null) { _AppendScriptOrLink(_data.text, _GetLinkName(_data.linkName)); } s = b.ToString(); } if (!s.NE()) { if (_justText) //a simple drag-drop inside scintilla or text-only from outside { var s8 = Encoding.UTF8.GetBytes(s); fixed(byte *p8 = s8) { z.text = p8; z.len = s8.Length; if (0 == ((DragDropEffects)effect & DragDropEffects.Move)) { z.copy = 1; } CodeInfo.Pasting(_sci); _sci.Call(SCI_DRAGDROP, 2, &z); } } else //file, script or URL { InsertCode.Statements(s, ICSFlags.NoFocus); } if (!_sci.IsFocused && _sci.Hwnd.Window.IsActive) //note: don't activate window; let the drag source do it, eg Explorer activates on drag-enter. { _sci._noModelEnsureCurrentSelected = true; //don't scroll treeview to currentfile _sci.Focus(); _sci._noModelEnsureCurrentSelected = false; } } else { _sci.Call(SCI_DRAGDROP, 3); } void _AppendFileOrShell(string path, string name = null) { if (b.Length > 0) { b.AppendLine(); } var pi = new TUtil.PathInfo(path, name); b.Append(pi.FormatCode(what - 11, ++index)); } void _AppendScriptOrLink(string path, string name, FileNode fn = null) { if (b.Length > 0) { b.AppendLine(); } if (what == 0) { b.Append(path); } else { if (what == 4) { name = name.RemoveSuffix(".cs"); } name = name.Escape(); if (what is 4 or 13) { var t = InsertCodeUtil.GetNearestLocalVariableOfType("Au.toolbar", "Au.popupMenu"); b.Append($"{t?.Name ?? "t"}[\"{name}\"] = o => "); }
public void Debug_AddDebuggerBreakCode() { InsertCode.UsingDirective("System.Diagnostics"); InsertCode.Statements("if(Debugger.IsAttached) Debugger.Break(); else Debugger.Launch();"); }
DIcons(bool expandFileIcon, bool randomizeColors) { Title = "Icons"; Owner = App.Wmain; ShowInTaskbar = false; var b = new wpfBuilder(this).WinSize(600, 600); b.Columns(-1, 0); //left - edit control and tree view b.Row(-1).StartDock(); b.Add(out _tName).Tooltip(@"Search. Part of icon name, or wildcard expression. Examples: part, Part (match case), start*, *end, **rc regex case-sensitive. Can be Pack.Icon, like Modern.List.") .Dock(Dock.Top).Focus(); //b.Focus(); //currently cannot use this because of WPF tooltip bugs b.xAddInBorder(out KTreeView tv); //tv.SingleClickActivate = true; b.End(); //right - color picker, buttons, etc b.StartGrid().Columns(-1); b.Add(out KColorPicker colors); colors.ColorChanged += color => { _random = null; _color = _ColorToString(color); tv.Redraw(); }; b.StartStack(); TextBox randFromTo = null, iconSizes = null; b.AddButton("Randomize colors", _ => _RandomizeColors()); b.Add("L %", out randFromTo, "30-70").Width(50); b.End(); b.AddSeparator().Margin("B20"); //rejected: double-clicking an icon clicks the last clicked button. Unclear and not so useful. //_Action lastAction = 0; tv.ItemActivated += (o, e) => { // switch (lastAction) { // case 0: break; // case _Action.FileIcon: _SetIcon(tv); break; // default: _InsertCodeOrExport(tv, lastAction); break; // } _InsertCodeOrExport(tv, _Action.MenuIcon); }; b.StartStack <Expander>(out var exp1, "Set icon of selected files"); b.AddButton(out var bThis, "This", _ => { _SetIcon(tv); /*lastAction = _Action.FileIcon;*/ }).Width(70).Disabled(); b.AddButton("Default", _ => _SetIcon(null)).Width(70); //b.AddButton("Random", null).Width(70); //idea: set random icons for multiple selected files. Probably too crazy. b.AddButton("Show current", _ => _tName.Text = FilesModel.TreeControl.SelectedItems.FirstOrDefault()?.CustomIconName).Margin("L20"); b.End(); if (expandFileIcon) { exp1.IsExpanded = true; } b.StartGrid <Expander>("Insert code for menu/toolbar/etc icon"); b.R.Add <Label>("Set icon of: "); b.StartStack(); b.AddButton(out var bMenuItem, "Menu or toolbar item", _ => _InsertCodeOrExport(tv, _Action.MenuIcon)).Disabled() .Tooltip("To assign the selected icon to a toolbar button or menu item,\nin the code editor click its line (anywhere except action code)\nand then click this button. Or double-click an icon."); b.End(); b.R.Add <Label>("Insert line: "); b.StartStack(); b.AddButton(out var bCodeVar, "Variable = XAML", _ => _InsertCodeOrExport(tv, _Action.InsertXamlVar)).Disabled(); b.AddButton(out var bCodeField, "Field = XAML", _ => _InsertCodeOrExport(tv, _Action.InsertXamlField)).Disabled(); b.End(); b.R.Add <Label>("Copy text: "); b.StartStack(); b.AddButton(out var bCodeName, "Name", _ => _InsertCodeOrExport(tv, _Action.CopyName)).Width(70).Disabled() .Tooltip("Shorter string than XAML.\nCan be used with custom menus and toolbars,\neditor menus and toolbars (edit Commands.xml),\nscript.editor.GetIcon, IconImageCache, ImageUtil,\noutput tag <image>."); b.AddButton(out var bCodeXaml, "XAML", _ => _InsertCodeOrExport(tv, _Action.CopyXaml)).Width(70).Disabled(); b.End(); //b.Add<Label>("Tip: double-clicking an icon clicks the same button."); b.End(); b.StartStack <Expander>("Export to current workspace folder"); b.AddButton(out var bExportXaml, ".xaml", _ => _InsertCodeOrExport(tv, _Action.ExportXaml)).Width(70).Disabled(); b.AddButton(out var bExportIco, ".ico", _ => _InsertCodeOrExport(tv, _Action.ExportIcon)).Width(70).Disabled(); b.Add("sizes", out iconSizes, "16,24,32,48,64").Width(100); b.End(); b.StartStack <Expander>("Other actions"); b.AddButton("Clear program's icon cache", _ => IconImageCache.Common.Clear(redrawWindows: true)); //SHOULDDO: clear when app version changes. b.End(); //b.StartGrid<Expander>("List display options"); ////b.Add("Background", out ComboBox cBackground).Items("Default|Control|White|Black)"); ////cBackground.SelectionChanged += (o, e) => _ChangeBackground(); //b.Add(out KCheckBox cCollection, "Collection"); //cCollection.CheckChanged += (_, _) => { // _withCollection = cCollection.IsChecked == true; // tv.Redraw(); //}; //b.End(); b.Row(-1); b.R.Add <TextBlock>().Align("R").Text("Thanks to ", "<a>MahApps.Metro.IconPacks", new Action(() => run.it("https://github.com/MahApps/MahApps.Metro.IconPacks"))); b.End(); b.End(); b.Loaded += () => { _dpi = Dpi.OfWindow(this); _OpenDB(); _a = new(30000); foreach (var(table, _) in s_tables) { using var stat = s_db.Statement("SELECT name FROM " + table); while (stat.Step()) { var k = new _Item(table, stat.GetText(0)); //var s = _ColorName(k); if (s.Length < 20 || s.Length > 60) print.it(s.Length, s); _a.Add(k); } } _a.Sort((a, b) => string.Compare(a._name, b._name, StringComparison.OrdinalIgnoreCase)); if (randomizeColors) { _RandomizeColors(); } tv.SetItems(_a); }; _tName.TextChanged += (_, _) => { string name = _tName.Text, table = null; Func <_Item, bool> f = null; bool select = false; if (!name.NE()) { if (select = name.RxMatch(@"^\*(\w+)\.(\w+) #(\w+)$", out var m)) //full name with * and #color { table = m[1].Value; name = m[2].Value; f = o => o._name == name && o._table == table; colors.Color = m[3].Value.ToInt(0, STIFlags.IsHexWithout0x); } else { if (name.RxMatch(@"^(\w+)\.(.+)", out m)) { table = m[1].Value; name = m[2].Value; } wildex wild = null; StringComparison comp = StringComparison.OrdinalIgnoreCase; bool matchCase = name.RxIsMatch("[A-Z]"); if (wildex.hasWildcardChars(name)) { try { wild = new wildex(name, matchCase && !name.Starts("**")); } catch { name = null; } } else if (matchCase) { comp = StringComparison.Ordinal; } if (name != null) { f = o => (table == null || o._table.Eqi(table)) && (wild?.Match(o._name) ?? o._name.Contains(name, comp)); } } } var e = f == null ? _a : _a.Where(f); tv.SetItems(e); if (select && (select = e.Count() == 1)) { tv.Select(0); } _EnableControls(select); }; tv.SelectedSingle += (o, i) => { _EnableControls(true); //var k = _a[i]; //if(GetIconFromBigDB(k._table, k._name, _ItemColor(k), out var xaml)) { // print.it(xaml); //} }; b.WinSaved(App.Settings.wndpos.icons, o => App.Settings.wndpos.icons = o); void _EnableControls(bool enable) { bThis.IsEnabled = enable; bMenuItem.IsEnabled = enable; bCodeVar.IsEnabled = enable; bCodeField.IsEnabled = enable; bCodeXaml.IsEnabled = enable; bCodeName.IsEnabled = enable; bExportXaml.IsEnabled = enable; bExportIco.IsEnabled = enable; } void _SetIcon(KTreeView tv) { string icon = tv?.SelectedItem is _Item k?_ColorName(k) : null; foreach (var v in FilesModel.TreeControl.SelectedItems) { v.CustomIconName = icon; } } void _InsertCodeOrExport(KTreeView tv, _Action what) { //lastAction = what; if (tv.SelectedItem is not _Item k) { return; } string code = null; if (what == _Action.MenuIcon) { InsertCode.SetMenuToolbarItemIcon(_ColorName(k)); } else if (what == _Action.CopyName) { code = _ColorName(k); } else if (GetIconFromBigDB(k._table, k._name, _ItemColor(k), out var xaml)) { xaml = xaml.Replace('\"', '\'').RxReplace(@"\R\s*", ""); switch (what) { case _Action.InsertXamlVar: code = $"string icon{k._name} = \"{xaml}\";"; break; case _Action.InsertXamlField: code = $"public const string {k._name} = \"{xaml}\";"; break; case _Action.CopyXaml: code = xaml; break; case _Action.ExportXaml: _Export(false); break; case _Action.ExportIcon: _Export(true); break; } void _Export(bool ico) { //App.Model.New var cf = App.Model.CurrentFile.Parent; if (cf == null) { return; } var path = $"{cf.FilePath}\\{k._name}{(ico ? ".ico" : ".xaml")}"; //CONSIDER: if path exists, show dialog if (ico) { var sizes = iconSizes.Text.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).Select(o => o.ToInt()).ToArray(); KImageUtil.XamlImageToIconFile(path, xaml, sizes); } else { filesystem.saveText(path, xaml); } var fn = App.Model.ImportFromWorkspaceFolder(path, cf, FNPosition.Inside); if (fn == null) { print.it("failed"); } else { print.it($"<>Icon exported to <open>{fn.ItemPath}<>"); } } } if (code != null) { if (what is _Action.CopyName or _Action.CopyXaml) { clipboard.text = code; } else if (what is _Action.InsertXamlVar or _Action.InsertXamlField) { InsertCode.Statements(code); }
public static void Debug_launch() { InsertCode.Statements("Debugger.Launch();"); }
public static void Debug_break() { InsertCode.Statements("Debugger.Break();"); }
public static void Debug_attach() { InsertCode.Statements("script.debug();\r\nDebugger.Break();"); }