Example #1
0
    /// <summary>
    /// Creates dialog with a list of toolbars of this thread. Just creates, does not show. Can be used to find lost toolbars.
    /// </summary>
    /// <param name="show">Show the dialog now, non-modal. If a dialog shown by this function already exists in this thread - activate.</param>
    public static Window toolbarsDialog(bool show = false)
    {
        if (show && s_dialog != null)
        {
            s_dialog.Hwnd().ActivateL(true);
            return(s_dialog);
        }

        var b = new wpfBuilder("Active toolbars").WinSize(330, 300).Columns(-1, 0);

        b.Row(-1).Add(out ListBox lb).Focus();
        //b.StartStack(vertical: true);
        //b.AddButton(out var bMove, "X", e => _Click(2));
        //b.End();
        b.End();

        var window = b.Window;

        var osdr = new osdRect {
            Color = 0xff0000, Thickness = 12
        };
        osdText osdt = null;
        var     atb  = _Manager._atb;

        (toolbar tb, bool sat)[] patb = atb.Select(o => (o, o.Satellite?.IsOpen ?? false)).ToArray();
Example #2
0
        public DNewWorkspace(string name, string location)
        {
            _name     = name;
            _location = location;

            Title = "New Workspace";

            var     b = new wpfBuilder(this).WinSize(600);
            TextBox tName, tLocation = null;

            b.R.Add("Folder name", out tName, _name).Validation(_Validate);
            b.R.Add("Parent folder", out tLocation, _location).Validation(_Validate);
            b.R.AddButton("Browse...", _Browse).Width(70).Align("L");
            b.R.AddOkCancel();
            b.End();

            void _Browse(WBButtonClickArgs e)
            {
                var d = new FileOpenSaveDialog("{4D1F3AFB-DA1A-45AC-8C12-41DDA5C51CDA}")
                {
                    InitFolderNow = filesystem.exists(tLocation.Text).Directory ? tLocation.Text : folders.ThisAppDocuments,
                };

                if (d.ShowOpen(out string s, this, selectFolder: true))
                {
                    tLocation.Text = s;
                }
            }

            string _Validate(FrameworkElement e)
            {
                var s = (e as TextBox).Text;

                if (e == tLocation)
                {
                    if (!filesystem.exists(s).Directory)
                    {
                        return("Folder does not exist");
                    }
                }
                else
                {
                    if (pathname.isInvalidName(s))
                    {
                        return("Invalid filename");
                    }
                    ResultPath = pathname.combine(tLocation.Text, s);                     //validation is when OK clicked
                    if (filesystem.exists(ResultPath))
                    {
                        return(s + " already exists");
                    }
                }
                return(null);
            }

            //b.OkApply += e => {
            //	print.it(ResultPath); e.Cancel = true;
            //};
        }
Example #3
0
    public DWinapi(string name = null)
    {
        Title = "Find Windows API";
        var doc = Panels.Editor.ZActiveDoc;

        Owner = GetWindow(doc);

        if (name == null)
        {
            name = doc.zSelectedText();
            if (!name.NE())
            {
                name = name.RxReplace(@"\W+", " ");
            }
        }

        var b = new wpfBuilder(this).WinSize(800, 500);

        b.WinProperties(WindowStartupLocation.CenterOwner, showInTaskbar: false);
        b.R.Add("Name", out tName, name);
        b.Row(-1).Add(out code); code.ZInitBorder = true;
        b.R.AddButton("?", _ => _Help());
        b.AddOkCancel("OK, copy to clipboard");
        b.End();

        b.OkApply += o => {
            string s = code.zText;
            if (s.NE())
            {
                return;
            }
            Clipboard.SetText(s);
        };

        tName.TextChanged += (_, _) => _TextChanged();

        void _Help()
        {
            var s = @"/**
Here you can find Windows API declarations: function, struct, enum, interface, delegate, constant, GUID.
Enter API name in the above field. Case-sensitive. Wildcard examples: Start*, *End, *Part*.
Or multiple full names, like Name1 Name2 Name3.
You can in editor select text with one or more names and open this window. Or use error tooltips.
If script is without a class, create new class (or convert script to class) and paste declarations there.

Also try snippet nativeApiSnippet (select it from the completion list when text cursor is where classes can be,
for example at the end of script). It adds a special class. Then anywhere in script just type class name, dot,
and select from the list. It adds the declaration to the class, and more declarations if need.

The database contains ~51000 declarations. They are not perfect. You can edit.
If some really useful API are missing, tell about it: https://www.quickmacros.com/forum or [email protected].
*/";

            code.ZSetText(s);
        }
    }
Example #4
0
 ///
 public DialogWithTabs()
 {
     Title = "Dialog";
     _b    = new wpfBuilder(this).WinSize(400);
     _b.Row(-1).Add(out _tc).Height(300..);
     _b.R.AddOkCancel(apply: "_Apply");
     _Page1();
     _Page2();
     // ...
     _b.End();
     //_tc.SelectedIndex = 1;
 }
Example #5
0
    //CONSIDER: add mouse xy like in Delm.
    //CONSIDER: add wnd Activate if pixels from screen.

    public Duiimage()
    {
        Title = "Find image or color in window";

        _noeventValueChanged = true;
        var b = new wpfBuilder(this).WinSize((410, 400..), (380, 330..)).Columns(160, -1);

        b.R.Add(out _info).Height(60);
        b.R.StartGrid().Columns(76, 76, 76, -1);
        //row 1
        b.R.AddButton("Capture", _bCapture_Click);
        b.AddButton(out _bTest, "Test", _Test).Disabled().Tooltip("Executes the code now (except wait/fail/mouse) and shows the found image");
        b.AddButton(out _bInsert, "Insert", _Insert).Disabled();
        b.Add(out _cbAction).Align("L").Width(140).Items("|MouseMove|MouseClick|MouseClickD|MouseClickR|PostClick|PostClickD|PostClickR|waitNot|new uiimageFinder").Select(2);
        //row 3
        b.R.AddButton("More ▾", _bEtc_Click).Align("L");
        b.StartStack();
        waitC = b.xAddCheckText("Wait", "1", check: true); b.Width(53);
        (waitnoC = b.xAddCheckText("Timeout", "5")).Visible = false; b.Width(53);
        b.xAddCheck(out exceptionC, "Fail if not found").Checked();
        b.xAddCheck(out exceptionnoC, "Fail on timeout").Checked().Hidden(null);
        b.End();
        b.End();
        //row 4
        b.R.AddButton("Window...", _bWnd_Click).And(-70).Add(out controlC, "Control").Disabled();
        b.xStartPropertyGrid();
        rectC    = b.xAddCheckText("Rectangle", "0, 0, ^0, ^0"); b.And(21).AddButton("...", _bRect_Click);
        wiflagsC = b.xAddCheckCombo("Window pixels", "WindowDC|PrintWindow");
        diffC    = b.xAddCheckText("Color diff", "10");
        skipC    = b.xAddCheckText("Skip");
        b.xAddCheck(out allC, "Get all", noR: true);
        b.xEndPropertyGrid(); b.SpanRows(2);

        b.Row(80).xAddInBorder(out _pict); b.Span(1);
        b.Row(-1).xAddInBorder(out _code);
        b.End();
        _noeventValueChanged = false;

        WndSavedRect.Restore(this, App.Settings.wndpos.uiimage, o => App.Settings.wndpos.uiimage = o);
    }
Example #6
0
    DCommandline()
    {
        Title         = "Script command line triggers";
        ShowInTaskbar = false;
        Owner         = App.Wmain;
        var b = _b = new wpfBuilder(this).WinSize(440);

        b.R.Add(out TextBlock info).Text("This tool creates a command line string to run current script from other programs and scripts (cmd, PowerShell, Task Scheduler, shortcut, etc).\nMore info in Cookbook folder \"Script\".");
        info.TextWrapping = TextWrapping.Wrap;
        b.R.AddSeparator();
        b.R.Add(out _cEditorNoPath, "Editor program name without path");
        b.R.Add(out _cScriptNoPath, "Script name without path");
        b.R.Add("Script arguments", out _tArgs);
        b.R.Add(out _cWait, "Can wait and capture script.writeResult text");
        b.R.AddSeparator();
        b.R.StartStack();
        b.AddButton("Copy to clipboard", _ => { clipboard.text = _FormatCL(1); });
        b.AddButton("Create shortcut...", _ => _Shortcut());
        b.AddButton("Create or edit scheduled task", _ => _Schedule());
        b.End();
        b.End();
    }
Example #7
0
    DOptions()
    {
        Title = "Options";
        Owner = App.Wmain;
        WindowStartupLocation = WindowStartupLocation.CenterOwner;
        ShowInTaskbar         = false;

        _b = new wpfBuilder(this).WinSize(550);
        _b.Row(-1).Add(out _tc).Height(300..);
        _b.R.AddOkCancel(apply: "_Apply");

        _General();
        //_Files();
        _Font();
        _Templates();
        _Code();
        _Hotkeys();
        _OS();

        //_tc.SelectedIndex = 2;

        _b.End();
    }
Example #8
0
    ///
    public DialogClass()
    {
        Title = "Dialog";
        var b = new wpfBuilder(this).WinSize(400);

        b.R.Add("Text", out TextBox text1).Focus().Validation(_ => string.IsNullOrWhiteSpace(text1.Text) ? "Text cannot be empty" : null);
        b.R.Add("Combo", out _combo1).Items("Zero|One|Two");
        b.R.Add(out _c1, "Check");
        b.R.AddOkCancel();
        b.End();

        //if need, add initialization code (set control properties, events, etc) here or/and in Loaded event handler below

        //b.Loaded += () => {

        //};

        b.OkApply += e => {
            print.it($"Text: \"{text1.Text.Trim()}\"");
            print.it($"Combo index: {_combo1.SelectedIndex}");
            print.it($"Check: {_c1.IsChecked == true}");
        };
    }
Example #9
0
    public DProperties(FileNode f)
    {
        _f       = f;
        _isClass = f.IsClass;

        Owner = App.Wmain;
        Title = "Properties of " + _f.Name;

        var b = new wpfBuilder(this).WinSize(600).Columns(-1, 0);

        b.WinProperties(WindowStartupLocation.CenterOwner, showInTaskbar: false);
        b.R.Add(out info).Height(80).Margin("B8").Span(-1);
        b.R.StartStack(vertical: true);         //left column
        b.StartGrid().Columns(0, -1, 20, 0, -1.15)
        .R.Add("role", out role).Skip()
        .Add("testScript", out testScript).Validation(o => _ValidateFile(o, "testScript", FNFind.CodeFile));
        b.End();

        b.StartStack(out gRun, "Run", vertical: true);
        b.StartGrid().Columns(0, 120, -1, 0, 80)
        .Add("ifRunning", out ifRunning).Skip()
        .Add("uac", out uac);
        b.End();
        b.End().Brush(Brushes.OldLace);

        b.StartGrid(out gCompile, "Compile").Columns(0, 50, 20, 0, -1);
        b.R.Add(out optimize, "optimize").Skip(2)
        .Add("define", out define);
        b.R.Add("warningLevel", out warningLevel).Editable().Skip()
        .Add("noWarnings", out noWarnings);
        b.R.Add("testInternal", out testInternal);
        b.R.StartGrid().Columns(0, -1, 20, 0, -1)
        .Add("preBuild", out preBuild).Skip().Validation(o => _ValidateFile(o, "preBuild", FNFind.CodeFile))
        .Add("postBuild", out postBuild).Validation(o => _ValidateFile(o, "postBuild", FNFind.CodeFile));
        b.End();
        b.End().Brush(Brushes.OldLace);

        b.StartStack(out gAssembly, "Assembly", vertical: true);
        b.StartGrid().Columns(0, -1, 30)
        .Add("outputPath", out outputPath)
        .AddButton(out outputPathB, "...", _ButtonClick_outputPath)
        .End();
        b.StartGrid().Columns(0, -1, 20, 0, -1);
        b.R.Add("icon", out icon).Skip().Validation(o => _ValidateFile(o, "icon", FNFind.Any))
        .Add("manifest", out manifest).Validation(o => _ValidateFile(o, "manifest", FNFind.File));
        b.R.Add("sign", out sign).Skip().Validation(o => _ValidateFile(o, "sign", FNFind.File));
        b.StartStack()
        .Add(out console, "console")
        .Add(out bit32, "bit32").Margin(15)
        .Add(out xmlDoc, "xmlDoc").Margin(15)
        .End();
        b.End();
        b.End().Brush(Brushes.OldLace);

        b.End();
        b.StartStack(vertical: true).Margin("L20");         //right column
        b.StartGrid <GroupBox>("Add reference");
        b.R.AddButton(out addLibrary, "Library...", _ButtonClick_addLibrary);
        b.R.AddButton(out addNuget, "NuGet ▾", _ButtonClick_addNuget);
        b.R.AddButton(out addComRegistry, "COM ▾", _bAddComRegistry_Click).AddButton(out addComBrowse, "...", _bAddComBrowse_Click).Width(30);
        b.AddButton(out addProject, "Project ▾", _ButtonClick_addProject);
        b.End();
        b.StartStack <GroupBox>("Add file", vertical: true);
        b.AddButton(out addClassFile, "Class file ▾", _ButtonClick_addClass);
        b.AddButton(out addResource, "Resource ▾", _ButtonClick_addResource);
        b.End();
        b.StartStack(vertical: true).Add("Find in lists", out findInLists).Tooltip("In button drop-down lists show only items containing this text").End();
        //b.AddButton("Change icon", _ => DIcons.ZShow(true, _f.CustomIconName)).Margin("T8B8"); //rejected
        b.End();
        b.R.AddOkCancel();
        b.End();

        _meta = new MetaCommentsParser(_f);

        _role = _meta.role switch {
            "miniProgram" => Au.Compiler.ERole.miniProgram,
            "exeProgram" => Au.Compiler.ERole.exeProgram,
            "editorExtension" => Au.Compiler.ERole.editorExtension,
            "classLibrary" when _isClass => Au.Compiler.ERole.classLibrary,
            "classFile" when _isClass => Au.Compiler.ERole.classFile,
            _ => _isClass ? Au.Compiler.ERole.classFile : Au.Compiler.ERole.miniProgram,
        };
        _InitCombo(role, _isClass ? "miniProgram|exeProgram|editorExtension|classLibrary|classFile" : "miniProgram|exeProgram|editorExtension", null, (int)_role);
        testScript.Text = _f.TestScript?.ItemPath;
        //Run
        _InitCombo(ifRunning, "warn_restart|warn|cancel_restart|cancel|wait_restart|wait|run_restart|run|restart", _meta.ifRunning);
        _InitCombo(uac, "inherit|user|admin", _meta.uac);
        //Assembly
        outputPath.Text = _meta.outputPath;
        void _ButtonClick_outputPath(WBButtonClickArgs e)
        {
            var m = new popupMenu();

            m[_GetOutputPath(getDefault: true)] = o => outputPath.Text = o.ToString();
            bool isLibrary = _role == Au.Compiler.ERole.classLibrary;

            if (isLibrary)
            {
                m[@"%folders.ThisApp%\Libraries"] = o => outputPath.Text = o.ToString();
            }
            m["Browse..."] = o => {
                var initf = _GetOutputPath(getDefault: false, expandEnvVar: true);
                filesystem.createDirectory(initf);
                var d = new FileOpenSaveDialog(isLibrary ? "{4D1F3AFB-DA1A-45AC-8C12-41DDA5C51CDD}" : "{4D1F3AFB-DA1A-45AC-8C12-51DDA5C51CDD}")
                {
                    InitFolderFirstTime = initf,
                };
                if (d.ShowOpen(out string s, this, selectFolder: true))
                {
                    outputPath.Text = folders.unexpandPath(s);
                }
            };
            m.Show();
        }

        icon.Text     = _meta.icon;
        manifest.Text = _meta.manifest;
        sign.Text     = _meta.sign;
        if (_meta.console == "true")
        {
            console.IsChecked = true;
        }
        if (_meta.bit32 == "true")
        {
            bit32.IsChecked = true;
        }
        if (_meta.xmlDoc == "true")
        {
            xmlDoc.IsChecked = true;
        }
        //Compile
        if (_meta.optimize == "true")
        {
            optimize.IsChecked = true;
        }
        define.Text = _meta.define;
        _InitCombo(warningLevel, "5|4|3|2|1|0", _meta.warningLevel);
        noWarnings.Text   = _meta.noWarnings;
        testInternal.Text = _meta.testInternal;
        preBuild.Text     = _meta.preBuild;
        postBuild.Text    = _meta.postBuild;
Example #10
0
File: Dwnd.cs Project: qmgindi/Au
    public Dwnd(wnd w = default, DwndFlags flags = 0, string title = "Find window")
    {
        _dontInsert   = flags.Has(DwndFlags.DontInsert);
        _noControl    = flags.Has(DwndFlags.NoControl);
        _checkControl = flags.Has(DwndFlags.CheckControl);
        _forTrigger   = flags.Has(DwndFlags.ForTrigger);

        Title = title;

        var b = new wpfBuilder(this).WinSize((500, 450..), (600, 430..)).Columns(-1);

        b.R.Add(out _info).Height(60);
        b.R.StartGrid().Columns(0, 76, 76, 0, 0, -1);
        _cCapture = b.xAddCheckIcon("*Unicons.Capture #FF4040", $"Enable capturing ({App.Settings.delm.hk_capture}) and show window/control rectangles");
        b.AddButton(out _bTest, "Test", _bTest_Click).Disabled().Tooltip("Executes the 'find' part of the code now and shows the rectangle");
        b.AddButton(out _bInsert, _dontInsert ? "OK" : "Insert", _Insert).Disabled(); if (!_dontInsert)
        {
            b.Tooltip("Insert code in editor");
        }
        b.Add(out _cbFunc).Items("find|findOrRun|runAndFind").Tooltip("Function").Width(90);         //rejected: |wndFinder. Rare, etc.
        _cbFunc.SelectionChanged += _cbFunc_SelectionChanged;
        b.Add(out _cActivate, "Activate").Tooltip("Activate the found window");
        b.Add(out _cException, "Fail if not found").Checked(!_forTrigger).Tooltip("Throw exception if not found");
        //cActivate.CheckChanged += (_, _) => { cException.Visibility = cActivate.IsChecked ? Visibility.Hidden : Visibility.Visible; }; //no, need for control too
        b.End();

        //window and control properties and search settings
        b.R.AddSeparator(false).Margin("B");
        b.Row(0);                                                   //auto height, else adds v scrollbar when textbox height changes when a textbox text is multiline or too long (with h scrollbar)
        _scroller            = b.xStartPropertyGrid("L2 T3 R2 B1"); //actually never shows scrollbar because of row auto height, but sets some options etc
        _scroller.Visibility = Visibility.Hidden;
        b.Columns(-3, 0, -1.2);
        //window
        b.R.Add <TextBlock>("Window").Margin("T1 B3").xSetHeaderProp();        //rejected: vertical headers. Tested, looks not good, too small for vertical Control checkbox.
        b.Row(0).StartGrid().Columns(70, -1);
        nameW     = b.xAddCheckText("name");
        classW    = b.xAddCheckText("class");
        programW  = b.xAddCheckTextDropdown("program");
        containsW = b.xAddCheckTextDropdown("contains");
        b.End();
        b.xAddSplitterV(span: 4, thickness: 12);
        b.StartGrid().Columns(44, -1);
        b.xAddCheck(out cHiddenTooW, "Find hidden too");
        b.xAddCheck(out cCloakedTooW, "Find cloaked too");
        alsoW = b.xAddCheckText("also", "o=>true");
        waitW = b.xAddCheckText("wait", "1", check: !_forTrigger);
        b.End();
        //control
        b.R.AddSeparator(false).Margin("T4 B0"); _sepControl = b.Last as Separator;
        b.R.Add(out _cControl, "Control").Margin("T5 B3").xSetHeaderProp();
        b.Row(0).StartGrid().Columns(70, -1); _gCon1 = b.Panel as Grid;
        nameC  = b.xAddCheckTextDropdown("name");
        classC = b.xAddCheckText("class");
        idC    = b.xAddCheckText("id");
        b.End().Skip();
        b.StartGrid().Columns(44, -1); _gCon2 = b.Panel as Grid;
        b.xAddCheck(out cHiddenTooC, "Find hidden too");
        alsoC = b.xAddCheckText("also", "o=>true");
        skipC = b.xAddCheckText("skip");
        b.End();
        b.xEndPropertyGrid();
        b.R.AddSeparator(false);

        if (_forTrigger)
        {
            _cActivate.Visibility  = Visibility.Hidden;
            _cException.Visibility = Visibility.Hidden;
            _cbFunc.Visibility     = Visibility.Hidden;
            waitW.Visible          = false;
        }

        //code
        b.Row(64).xAddInBorder(out _code, "B");

        //tree and window info
        b.xAddSplitterH(span: -1);
        b.Row(-1).StartGrid().Columns(-1, 0, -1);
        b.Row(-1).xAddInBorder(out _tree, "TR");
        b.xAddSplitterV();
        b.xAddInBorder(out _winInfo, "TL"); _winInfo.ZWrapLines = false; _winInfo.Name = "window_info";
        b.End();

        b.End();

        _InitTree();

        _con = w;

        b.WinProperties(
            topmost: true,
            showActivated: _dontInsert || w.Is0 ? null : false             //eg if captured a popup menu, activating this window closes the menu and we cannot get properties
            );

        WndSavedRect.Restore(this, App.Settings.wndpos.wnd, o => App.Settings.wndpos.wnd = o);
    }
Example #11
0
File: DIcons.cs Project: qmgindi/Au
    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);
                }
Example #12
0
    public PanelFind()
    {
        this.UiaSetName("Find panel");

        var b = new wpfBuilder(this).Columns(-1).Brush(SystemColors.ControlBrush);

        b.Options(modifyPadding: false, margin: new Thickness(2));
        b.AlsoAll((b, _) => { if (b.Last is Button k)
                              {
                                  k.Padding = new(1, 0, 1, 1);
                              }
                  });
        b.Row((-1, 22..)).Add(out _tFind).Margin(-1, 0, -1, 2).Multiline(wrap: TextWrapping.Wrap).Tooltip("Text to find");
        b.Row((-1, 22..)).Add(out _tReplace).Margin(-1, 0, -1, 2).Multiline(wrap: TextWrapping.Wrap).Tooltip("Replacement text");
        b.R.StartGrid().Columns((-1, ..80), (-1, ..80), (-1, ..80), 0);
        b.R.AddButton("Find", _bFind_Click).Tooltip("Find next in editor");
        b.AddButton(out var bReplace, "Replace", _bReplace_Click).Tooltip("Replace current found text in editor and find next.\nRight click - find next.");
        bReplace.MouseRightButtonUp += (_, _) => _bFind_Click(null);
        b.AddButton("Repl. all", _bReplaceAll_Click).Tooltip("Replace all in editor");

        b.R.AddButton("In files", _bFindIF_Click).Tooltip("Find text in files");
        b.StartStack();
        _cFolder = b.xAddCheckIcon("*Material.FolderSearchOutline #99BF00", "Let 'In files' search only in current project or root folder");
        b.Padding(1, 0, 1, 1);
        b.xAddButtonIcon("*EvaIcons.Options2 #99BF00", _bOptions_Click, "More options");

        var cmd1  = App.Commands[nameof(Menus.File.OpenCloseGo.Go_back)];
        var bBack = b.xAddButtonIcon("*EvaIcons.ArrowBack #585858", _ => Menus.File.OpenCloseGo.Go_back(), "Go back");

        b.Disabled(!cmd1.Enabled);
        cmd1.CanExecuteChanged += (o, e) => bBack.IsEnabled = cmd1.Enabled;

        b.End();

        b.Add(out _cName, "Name").Tooltip("Search in filenames, not in text");

        b.R.Add(out _cCase, "Case").Tooltip("Match case")
        .And(0).Add(out _cWildex, "Wildex").Hidden().Tooltip("Wildcard expression.\nExamples: start*.cs, *end.cs, *middle*.cs, **m green.cs||blue.cs.\nF1 - Wildex help.");
        b.Add(out _cWord, "Word").Tooltip("Whole word");
        b.Add(out _cRegex, "Regex").Tooltip("Regular expression.\nF1 - Regex tool and help.");
        b.End().End();

        //this.AccessibleName = this.Name = "Find";
        this.IsVisibleChanged += (_, _) => {
            if (!_cName.IsChecked)
            {
                Panels.Editor.ZActiveDoc?.InicatorsFind_(IsVisible ? _aEditor : null);
            }
        };

        _tFind.TextChanged += (_, _) => ZUpdateQuickResults(false);

        //prevent tooltip on set focus.
        //	Broken in .NET 6:  AppContext.SetSwitch("Switch.UseLegacyToolTipDisplay", true); //must be before creating Application object
        _tFind.ToolTipOpening += (o, e) => { if (o is UIElement k && !k.IsMouseOver)
                                             {
                                                 e.Handled = true;
                                             }
        };

        foreach (var v in new TextBox[] { _tFind, _tReplace })
        {
            v.AcceptsTab = true;
            v.IsInactiveSelectionHighlightEnabled = true;
            v.GotKeyboardFocus   += _tFindReplace_KeyboardFocus;
            v.LostKeyboardFocus  += _tFindReplace_KeyboardFocus;
            v.ContextMenu         = new KWpfMenu();
            v.ContextMenuOpening += _tFindReplace_ContextMenuOpening;
            v.PreviewMouseUp     += (o, e) => {         //use up, else up will close popup. Somehow on up ClickCount always 1.
                if (e.ChangedButton == MouseButton.Middle)
                {
                    var tb = o as TextBox;
                    if (tb.Text.NE())
                    {
                        _RecentPopupList(tb);
                    }
                    else
                    {
                        tb.Clear();
                    }
                }
            };
        }

        foreach (var v in new KCheckBox[] { _cCase, _cWildex, _cWord, _cRegex, _cName })
        {
            v.CheckChanged += _CheckedChanged;
        }
    }