Ejemplo n.º 1
0
partial class Script : AScript { [STAThread] static void Main(string[] a) => new Script(a); Script(string[] args) //;;;
//This is an example script used by ATask.Run examples in files "Hotkey triggers" (Ctrl+Shift+3) and "Common toolbars".
//It runs in separate process. You can edit and run it without restarting the main script process (triggers and toolbars).

                                 {
                                     ADialog.Show("Example");

//Although this script is in the project folder, it is not part of the project (only the first script is).
//Therefore other files of the project folder are not included in the compilation, and their classes/functions are not available.
//But you can explicitly specify class files. Use the Properties dialog. See the "c ..." in the first line.
                                     Class1.Function1();
                                 }
Ejemplo n.º 2
0
            private void _bClick(object sender, EventArgs e)
            {
                if (!(_lb.SelectedItem is AToolbar tb))
                {
                    return;
                }
                if (tb._c.IsDisposed)
                {
                    ADialog.Show("Closed", owner: this);
                    return;
                }
                var w = tb._c.Hwnd();
                var r = w.Rect;

                if (sender == _bShow)
                {
                    if (AScreen.IsInAnyScreen(r))
                    {
                        r.Inflate(2, 2);
                        var osd = new AOsdRect {
                            Rect = r, Color = 0xff0000
                        };
                        osd.Show();
                        ATimer.After(1000, _ => osd.Dispose());
                    }
                    else
                    {
                        ADialog.Show("Offscreen", "Rectangle: " + r.ToString(), owner: this);
                    }
                }
                else if (sender == _bMove)
                {
                    if (!w.IsVisible && !ADialog.ShowOkCancel("Hidden", "Move this hidden toolbar?", owner: this))
                    {
                        return;
                    }
                    var xy = AMouse.XY;
                    w.MoveLL(xy.x, xy.y);
                    var w2 = this.Hwnd();
                    if (!w.ZorderIsAbove(w2))
                    {
                        w.ZorderAbove(w2);
                    }
                }
            }
Ejemplo n.º 3
0
    //void TestMenu2()
    //{
    //	var m = new AMenu();
    //	m["One"] = o => AOutput.Write(o);
    //	m["Two"] = o => AOutput.Write(o);
    //	m.LazySubmenu("Submenu 1").Fill = _ => {
    //		AOutput.Write("adding items of " + m.CurrentAddMenu.OwnerItem);
    //		m["Three"] = o => AOutput.Write(o);
    //		m["Four"] = o => AOutput.Write(o);
    //		m.LazySubmenu("Submenu 2", _ => {
    //			AOutput.Write("adding items of " + m.CurrentAddMenu.OwnerItem);
    //			m["Five"] = o => AOutput.Write(o);
    //			m["Six"] = o => AOutput.Write(o);
    //		});
    //		m["Seven"] = o => AOutput.Write(o);
    //	};
    //	m["Eight"] = o => AOutput.Write(o);
    //	m.Show();

    //}

    //void TestMenu2()
    //{
    //	var m = new AMenu();
    //	m["One"] = o => AOutput.Write(o);
    //	m["Two"] = o => AOutput.Write(o);
    //	m.LazySubmenu("Submenu 1");
    //	m.LazyFill = _ => {
    //		AOutput.Write("adding items of " + m.CurrentAddMenu.OwnerItem);
    //		m["Three"] = o => AOutput.Write(o);
    //		m["Four"] = o => AOutput.Write(o);
    //		m.LazySubmenu("Submenu 2", _ => {
    //			AOutput.Write("adding items of " + m.CurrentAddMenu.OwnerItem);
    //			m["Five"] = o => AOutput.Write(o);
    //			m["Six"] = o => AOutput.Write(o);
    //		});
    //		m["Seven"] = o => AOutput.Write(o);
    //	};
    //	m["Eight"] = o => AOutput.Write(o);
    //	m.Show();

    //}

#if false
    void TestToolbar()
    {
        for (int i = 0; i < 1; i++)
        {
            var t = new AToolbar("123");
            //t.NoText = true;
            //t.Border= TBBorder.Sizable3;t.Control.Text = "Toolbar";
            //t.Border = TBBorder.SizableWithCaptionX;

            //t["Find", @"Q:\app\find.ico"] = o => AOutput.Write(o);
            //t["Copy", @"Q:\app\copy.ico"] = o => AOutput.Write(o);
            //t.Separator("Tpi group");
            //t["Delete", @"Q:\app\delete.ico"] = o => AOutput.Write(o);
            //t["No image"] = o => AOutput.Write(o);
            //t["TT", tooltip: "WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW WWWWWWWWWWWW "] = o => AOutput.Write(o);
            ////t.LastButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
            ////t.LastButton.AutoToolTip = false;
            ////t.LastButton.ToolTipText = "ggg";
            //t.Separator();
            //t["Run", @"Q:\app\run.ico"] = o => AOutput.Write(o);
            //t.Separator("");
            //t["Paste text", @"Q:\app\paste.ico"] = o => AOutput.Write(o);
            //t.LastButton.ToolTipText = "Toooooltip";

            //t.ExtractIconPathFromCode = true;
            //t["Auto icon"] = o => AOutput.Write("notepad.exe");
            //t["Failed icon", @"Q:\app\-.ico"] = o => AOutput.Write(o);
            ////t.LastButton.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
            ////t.Separator("");
            ////t.Add(new ToolStripTextBox { ToolTipText= "ToolStripTextBox", AutoSize=false, Width=50 });
            ////t.Add(new ToolStripComboBox { ToolTipText= "ToolStripComboBox", AutoSize=false, Width=50 });
            ////t.Add(new ToolStripTextBox());
            ////t.Add(new ToolStripTextBox());
            ////t.Add(new ToolStripTextBox());
            ////t.Add(new ToolStripButton("aaa"));
            ////t.Add(new ToolStripButton("bbb"));
            ////t["Multi\r\nline"] = o => AOutput.Write(o);

            //t["None"] = o => _B(TBBorder.None);
            //t["SWC"] = o => _B(TBBorder.SizableWithCaption);
            //t["Sizable1"] = o => _B(TBBorder.Sizable1);
            //t["Sizable2"] = o => _B(TBBorder.Sizable2);
            //t["Sizable3"] = o => _B(TBBorder.Sizable3);
            //t["Sizable3D"] = o => _B(TBBorder.Sizable3D);
            //t["Sizable"] = o => _B(TBBorder.Sizable);
            //t["FixedWithCaption"] = o => _B(TBBorder.FixedWithCaption);
            //t["SizableWithCaption"] = o => _B(TBBorder.SizableWithCaption);
            //t["Close"] = o => t.Close();

#if false
            var dd = new ToolStripDropDownButton("DD");
            t.Add(dd, @"Q:\app\find.ico");
            dd.DropDownOpening += (unu, sed) => {
                var m = new AMenu(dd);
                m["one"] = o => AOutput.Write(o);
                using (m.Submenu("Sub")) {
                    m["si"] = o => AOutput.Write(o);
                }
            };
            var sb = new ToolStripSplitButton("SB");
            t.Add(sb, @"Q:\app\copy.ico", o => AOutput.Write(o));
#elif true
            //t.Control.Font = new Font("Courier New", 16);
            //t.Control.RightToLeft = RightToLeft.Yes;
            t.MenuButton("DD", m => {
                AOutput.Write("dd");
                //m.MultiShow = false;
                m["one"] = o => AOutput.Write(o);
                using (m.Submenu("Sub")) {
                    m["si"] = o => AOutput.Write(o);
                }
            }, @"Q:\app\find.ico", "MenuButton");
            t.SplitButton("SB", m => {
                m["one"] = o => AOutput.Write(o);
                //var sb = m.Control.OwnerItem as ToolStripSplitButton;
                //AOutput.Write(sb);
                //sb.DefaultItem = m.LastItem;
                using (m.Submenu("Sub")) {
                    m["si"] = o => AOutput.Write(o);
                }
            }, @"Q:\app\copy.ico", "SplitButton", o => AOutput.Write(o));
            t.Separator("");
            t[true, "DD2", @"Q:\app\delete.ico"] = m => {
                AOutput.Write("create menu");
                //m.MultiShow = false;
                m["one"] = o => AOutput.Write(o);
                using (m.Submenu("Sub")) {
                    m["si"] = o => AOutput.Write(o);
                }
            };
            //t.SplitButton("SB", o => {
            //	AOutput.Write(o);
            //}, m => {
            //	m["one"] = o => AOutput.Write(o);
            //	using(m.Submenu("Sub")) {
            //		m["si"] = o => AOutput.Write(o);
            //	}
            //}, @"Q:\app\copy.ico", "SplitButton");
            //Action<AMenu> menu1 = m => {
            //	m["one"] = o => AOutput.Write(o);
            //	using(m.Submenu("Sub")) {
            //		m["si"] = o => AOutput.Write(o);
            //	}
            //};
            //t.MenuButton("DD", menu1, @"Q:\app\find.ico", "MenuButton");
#elif false
            t.MenuButton("DD", @"Q:\app\find.ico");
            t.Menu = m => {
                m["one"] = o => AOutput.Write(o);
                using (m.Submenu("Sub")) {
                    m["si"] = o => AOutput.Write(o);
                }
            };
#else
            t.MenuButton("DD", @"Q:\app\find.ico").Menu = m => {
                AOutput.Write("dd");
                //m.MultiShow = false;
                m["one"] = o => AOutput.Write(o);
                using (m.Submenu("Sub")) {
                    m["two"] = o => AOutput.Write(o);
                }
            };
            t.SplitButton("SB", o => AOutput.Write(o), @"Q:\app\copy.ico").Menu = m => {
                AOutput.Write("dd");
                m["one"] = o => AOutput.Write(o);
                using (m.Submenu("Sub")) {
                    m["two"] = o => AOutput.Write(o);
                }
            };
#endif
            //t.Separator("");
            ////t["GC"] = o => GC.Collect();

            //var dd = new ToolStripSplitButton("SB2", null, (unu,sed)=>AOutput.Write("click"));
            //t.Add(dd, @"Q:\app\delete.ico");
            //dd.DropDownOpening += (unu, sed) => {
            //	var m = new AMenu();
            //	dd.DropDown = m.Control;
            //	m["one"] = o => AOutput.Write(o);
            //};
            //dd.ButtonClick += (unu, sed) => AOutput.Write("button click");
            //dd.DoubleClickEnabled = true;
            //dd.ButtonDoubleClick += (unu, sed) => AOutput.Write("button double click");

            //ATimer.After(3000, _ => {
            //	var c = t.Control.Items[0];
            //	c.Select();
            //});

            //void _B(TBBorder b){
            //	t.Border = b;
            //	//AOutput.Write(AWnd.More.BorderWidth((AWnd)t.Control));
            //}

            //t.Bounds = new Rectangle(i * 300 + 700, 200, 200, 200);
            t.Show();
            //t.Window.ActivateLL();
            ATime.SleepDoEvents(200);

            //for(int j = 1; j <= (int)TBBorder.SizableWithCaptionX; j++) {
            //	ATime.SleepDoEvents(1000);
            //	t.Border = (TBBorder)j;
            //}

            //ATime.SleepDoEvents(1000);
            //t.Border = TBBorder.FixedWithCaption;
            //ATime.SleepDoEvents(3000);
            //t.Border = TBBorder.SizableWithCaption;

            //var m = new AMenu();
            //using(m.Submenu("Sub")) {

            //}
            //m.Show()
        }

        //var c = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(VisualStyleElement.Window.FrameLeft.Inactive).GetColor(ColorProperty.BorderColor);
        //AOutput.Write((uint)c.ToArgb());

        //ATimer.After(500, _ => {
        //	var w = (AWnd)t.Control;
        //	//w.SetStyle(WS.DLGFRAME, SetAddRemove.Add);
        //});

        ADialog.Options.TopmostIfNoOwnerWindow = true;
        ADialog.Show();

        //ATimer.After(10000, _ => Application.Exit());
        //Application.Run();
    }
Ejemplo n.º 4
0
        /// <summary>
        /// Toolbar button MouseUp handler. Implements context menu that allows to customize.
        /// </summary>
        private void _OnMouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                return;
            }
            var  item        = sender as ToolStripItem;
            var  ts          = item.Owner;
            var  dd          = ts as ToolStripDropDownMenu;
            bool isMenu      = dd != null;
            bool isCustom    = ts == _tsCustom1 || ts == _tsCustom2;
            bool isSeparator = item is ToolStripSeparator;
            bool isHidden    = item.Overflow == ToolStripItemOverflow.Always;
            var  x           = item.Tag as XElement;

            var m = new AMenu();

            m["Properties..."] = o => {
                using (var f = new FSMProperties(this, item.Tag as XElement, isMenu)) {
                    if (f.ShowDialog(_form) == DialogResult.OK)
                    {
                        _Strips_Customize(6, item, null, f);
                    }
                }
            };
            if (!isMenu)
            {
                if (!isSeparator)
                {
                    m["Hide"] = o => _Strips_Customize(5, item); if (isHidden)
                    {
                        m.LastMenuItem.Checked = true;
                    }
                }
                if (isCustom || isSeparator)
                {
                    m["Remove"] = o => _Strips_Customize(3, item);
                }
                if (!isHidden)
                {
                    m["Add separator"] = o => _Strips_Customize(4, item, ts);
                }
            }
            if (isCustom)
            {
                if (_tsCustom1 != null && _tsCustom2 != null)
                {
                    if (ts == _tsCustom1)
                    {
                        m["Move to toolbar Custom2"] = o => _Strips_Customize(2, item, _tsCustom2);
                    }
                    else
                    {
                        m["Move to toolbar Custom1"] = o => _Strips_Customize(2, item, _tsCustom1);
                    }
                }
            }
            else
            {
                if (_tsCustom1 != null)
                {
                    m["Copy to toolbar Custom1"] = o => _Strips_Customize(1, item, _tsCustom1);
                }
                if (_tsCustom2 != null)
                {
                    m["Copy to toolbar Custom2"] = o => _Strips_Customize(1, item, _tsCustom2);
                }
            }
            if (!isMenu)
            {
                m.Separator();
                m["How to customize..."] = o => ADialog.ShowInfo("Customizing toolbars and menus",
                                                                 @"There are several standard toolbars and two custom toolbars (initially empty). Standard toolbar buttons cannot be added and removed, but can be hidden and reordered. Menu items cannot be added, removed, hidden and reordered.

You can find most customization options in two context menus. Right-clicking a button or menu item shows its context menu. Right-clicking before the first button shows toolbar's context menu. You can Alt+drag toolbar buttons to reorder them on the same toolbar. You can Alt+drag toolbars to dock them somewhere else. Use splitters to resize. Right click a splitter to change its thickness."
                                                                 );
                string folder = APath.GetDirectoryPath(_xmlFileCustom), link = $"<a href=\"{folder}\">{folder}</a>";
                m["How to backup, restore, reset..."] = o => {
                    ADialog.Show("How to backup, restore or reset customizations",
                                 $@"All customizations are saved in XML files in folder
{link}

To backup:  copy the file.
To restore:  exit this application and replace the file with the backup file.
To reset:  exit this application and delete the file."
                                 , icon: DIcon.Info, onLinkClick: h => { AExec.Run(h.LinkHref); });
                };
            }

            m.Show(ts);
        }
Ejemplo n.º 5
0
        public static void Dialog(object text, [CallerFilePath] string cp = null, [CallerLineNumber] int cln = 0, [CallerMemberName] string cmn = null)
        {
            string s = AOutput.ObjectToString_(text);

            ADialog.Show("Debug", s, flags: DFlags.ExpandDown, expandedText: $"{cmn} ({APath.GetFileName(cp)}:{cln})");
        }
Ejemplo n.º 6
0
    static void _Main()
    {
        bool isConsole = AOutput.IsConsoleProcess;

        if (!isConsole)
        {
            AOutput.QM2.UseQM2 = true;
            AOutput.Clear();
        }

        var docfx   = @"Q:\Programs\DocFx\docfx.exe";
        var objDir  = @"Q:\Temp\Au\DocFX\obj";
        var docDir  = @"Q:\app\Au\Other\DocFX\_doc";
        var siteDir = docDir + @"\_site";
        var apiDir  = docDir + @"\api";

        //ProcessYamlFile(apiDir + @"\Au.AaaDocFX.yml", true); return;
        //ProcessHtmlFiles(siteDir, true); return;
        //ProcessToc(siteDir); return;

        //Compress(docDir); return;
        //Upload(docDir); return;
        //CompressAndUpload(docDir); return;

        foreach (var v in Process.GetProcessesByName("docfx"))
        {
            v.Kill();
        }
        if (isConsole)
        {
            int k = 0;
            foreach (var v in AWnd.FindAll(@"C:\WINDOWS\system32\cmd.exe", "ConsoleWindowClass"))
            {
                if (k++ > 0)
                {
                    v.Close();
                }
            }
        }

        AFile.Delete(siteDir);
        Directory.SetCurrentDirectory(docDir);

        var t1 = ATime.PerfMilliseconds;

        using (var fw = new FileSystemWatcher(apiDir, "*.yml")) {
            fw.Changed += (sen, e) => {
                //AOutput.Write(e.Name);
                if (e.Name.Starts("Au.", true))
                {
                    ProcessYamlFile(e.FullPath, false);
                }
            };
            fw.EnableRaisingEvents = true;
            fw.NotifyFilter        = NotifyFilters.LastWrite;

            bool serving = false;
            try {
                AExec.RunConsole(o => {
                    AOutput.Write(o);
                    if (o.Starts("Serving"))
                    {
                        throw new OperationCanceledException();
                    }
                }, docfx, $@"docfx.json --intermediateFolder ""{objDir}"" --serve");
                // --force
            }
            catch (OperationCanceledException) {
                serving = true;
            }
            //if(!serving) { ADialog.Show("error?"); return; } //need if this process is not hosted
            if (!serving)
            {
                return;
            }
        }

        var t2 = ATime.PerfMilliseconds;

        ProcessHtmlFiles(siteDir, false);

        var t3 = ATime.PerfMilliseconds; AOutput.Write("speed (s):", (t2 - t1) / 1000, (t3 - t2) / 1000);

        //AWnd.Find("* Chrome").Activate();
        //AKeys.Key("F5");

        1.s();
        if (1 == ADialog.Show("Upload?", null, "1 Yes|2 No" /*, secondsTimeout: 5*/))
        {
            CompressAndUpload(docDir);
        }

        //Delete obj folder if big. Each time it grows by 10 MB, and after a day or two can be > 1 GB. After deleting builds slower by ~50%.
        if (AFile.More.CalculateDirectorySize(objDir) / 1024 / 1024 > 500)
        {
            AOutput.Write("Deleting obj folder."); AFile.Delete(objDir);
        }
        //info: if DocFX starts throwing stack overflow exception, delete the obj folder manually. It is likely to happen after many refactorings in the project.
    }
Ejemplo n.º 7
0
    /// <summary>
    /// Processes command line of this program.
    /// Returns true if this instance must exit: 1. If finds previous program instance; then sends the command line to it if need. 2. If incorrect command line.
    /// </summary>
    public static bool OnProgramStarted(string[] a)
    {
        string s           = null;
        int    cmd         = 0;
        bool   activateWnd = true;

        if (a.Length > 0)
        {
            //AOutput.Write(a);

            for (int i = 0; i < a.Length; i++)
            {
                if (a[i].Starts('-'))
                {
                    a[i] = a[i].ReplaceAt(0, 1, "/");
                }
                if (a[i].Starts('/'))
                {
                    a[i] = a[i].Lower();
                }
            }

            s = a[0];
            if (s.Starts('/'))
            {
                for (int i = 0; i < a.Length; i++)
                {
                    s = a[i];
                    switch (s)
                    {
                    case "/test":
                        if (++i < a.Length)
                        {
                            TestArg = a[i];
                        }
                        break;

                    case "/v":
                        StartVisible = true;
                        break;

                    default:
                        ADialog.ShowError("Unknown command line parameter", s);
                        return(true);
                    }
                    //rejected: /h start hidden. Not useful.
                }
            }
            else                 //one or more files
            {
                if (a.Length == 1 && FilesModel.IsWorkspaceDirectory(s))
                {
                    switch (cmd = ADialog.Show("Workspace", s, "1 Open|2 Import|0 Cancel", footerText: FilesModel.GetSecurityInfo("v|")))
                    {
                    case 1: WorkspaceDirectory = s; break;

                    case 2: _importWorkspace = s; break;
                    }
                }
                else
                {
                    cmd          = 3;
                    _importFiles = a;
                }
            }
        }

        //single instance
        s_mutex = new Mutex(true, "Au.Mutex.1", out bool createdNew);
        if (createdNew)
        {
            return(false);
        }

        var w = AWnd.FindFast(null, "Au.Editor.Msg", true);

        if (!w.Is0)
        {
            if (activateWnd)
            {
                AWnd wMain = (AWnd)w.Send(Api.WM_USER);
                if (!wMain.Is0)
                {
                    try { wMain.Activate(); }
                    catch (Exception ex) { ADebug.Print(ex); }
                }
            }

            switch (cmd)
            {
            case 3:             //import files
                s = string.Join("\0", a);
                break;
            }
            if (cmd != 0)
            {
                AWnd.More.CopyDataStruct.SendString(w, cmd, s);
            }
        }
        return(true);
    }
Ejemplo n.º 8
0
partial class Script : AScript { [STAThread] static void Main(string[] a) => new Script(a); Script(string[] args) { //;;;

/*
The programming language is C#.

In scripts you can use classes/functions of the automation library provided by
this program, as well as of .NET Core and everything that can be used in C#.
Also you can create and use new functions, classes, libraries and .exe programs.

Script properties are saved in /*/ /*/ comments at the very start of script.
You can change them in the Properties dialog.

Like all C# programs, a script starts with standard code: using directives,
class and function Main where the program starts. Click the small [+] box at
the top-left to see and edit that code when need. The //. and //; are used to
fold (hide) code.

To avoid 'static' everywhere, function Main creates a class instance. Your script
code is in the constructor function. The function and the class end with } and }.

To run a script, you can click the ► Run button on the toolbar, or use command line,
or call ATask.Run from another scrit, or in Options set to run at startup.

Triggers such as hotkeys, autotext, mouse and window are used to execute functions
in a running script. Also you can create custom toolbars and menus. To start
using them: menu File -> New -> Examples -> @Triggers and toolbars.
*/

//Examples of automation functions.

AOutput.Write("Main script code.");

ADialog.Show("Message box.");

AExec.Run(AFolders.System + "notepad.exe");
var w = AWnd.Wait(0, true, "*- Notepad");
AKeys.Key("F5 Enter*2");
AKeys.Text(w.Name);
2.s();
w.Close();
var w2 = AWnd.Wait(-3, true, "Notepad", "#32770");
if(!w2.Is0) {
	500.ms();
	var c = +w2.Child(null, "Button", skip: 1); // "Don't Save"
	AMouse.Click(c);
	500.ms();
}

//Examples of .NET functions.

string s = "Example";
var b = new System.Text.StringBuilder();
for(int i = 0; i < s.Length; i++) {
	b.Append(s[i]).AppendLine();
}
MessageBox.Show(b.ToString());

//Example of your function and how functions can share variables.

_sharedVariable = 1;
FunctionExample("Example");
AOutput.Write(_sharedVariable);

} //end of main function