Example #1
0
	/// <summary>
	/// Shows "Open" dialog to select an existing workspace.
	/// On OK loads the selected workspace and returns FilesModel. On Cancel return null.
	/// </summary>
	public FilesModel ZLoadAnotherWorkspace()
	{
		var d = new OpenFileDialog { Title = "Open workspace", Filter = "files.xml|files.xml" };
		if(d.ShowDialog(this) != DialogResult.OK) return null;
		var filesXml = d.FileName;
		if(!APath.GetFileName(filesXml).Eqi("files.xml")) {
			ADialog.ShowError("Must be files.xml");
			return null;
		}
		return ZLoadWorkspace(APath.GetDirectoryPath(filesXml));
	}
Example #2
0
        string                 _exe; //for errors only

        /// <summary>
        /// Prepares parameters for API <msdn>CreateProcess</msdn> and similar.
        /// </summary>
        /// <param name="exe">
        /// Full path of program file. If not full path, uses <see cref="AFolders.ThisApp"/>. Uses <see cref="APath.Normalize"/>.
        /// If <i>rawExe</i> true, does not use <b>Normalize</b>/<b>ThisApp</b>.
        /// </param>
        /// <param name="args">null or command line arguments.</param>
        /// <param name="curDir">
        /// Initial current directory of the new process.
        /// - If null, uses <c>Directory.GetCurrentDirectory()</c>.
        /// - Else if <i>rawCurDir</i>==true, uses raw <i>curDir</i> value.
        /// - Else if "", calls <c>APath.GetDirectoryPath(exe)</c>.
        /// - Else calls <see cref="APath.ExpandEnvVar"/>.
        /// </param>
        /// <param name="envVar">null or environment variables to pass to the new process together with variables of this process. Format: "var1=value1\0var2=value2\0". If ends with "\0\0", will pass only these variables.</param>
        /// <param name="rawExe">Don't normalize <i>exe</i>.</param>
        /// <param name="rawCurDir">Don't normalize <i>curDir</i>.</param>
        public ProcessStarter_(string exe, string args = null, string curDir = null, string envVar = null, bool rawExe = false, bool rawCurDir = false) : this()
        {
            if (!rawExe)
            {
                exe = APath.Normalize(exe, AFolders.ThisApp, PNFlags.DontExpandDosPath | PNFlags.DontPrefixLongPath);
            }
            _exe = exe;
            cl   = (args == null ? ("\"" + exe + "\"" + "\0") : ("\"" + exe + "\" " + args + "\0")).ToCharArray();
            if (curDir == null)
            {
                this.curDir = Directory.GetCurrentDirectory();                            //if null passed to CreateProcessWithTokenW, the new process does not inherit current directory of this process
            }
            else
            {
                this.curDir = rawCurDir ? curDir : (curDir.Length == 0 ? APath.GetDirectoryPath(exe) : APath.ExpandEnvVar(curDir));
            }

            si.cb      = Api.SizeOf <Api.STARTUPINFO>();
            si.dwFlags = Api.STARTF_FORCEOFFFEEDBACK;

            flags = Api.CREATE_UNICODE_ENVIRONMENT;

            if (envVar != null && !envVar.Ends("\0\0"))
            {
                var es = Api.GetEnvironmentStrings();
                int len1; for (var k = es; ; k++)
                {
                    if (k[0] == 0 && k[1] == 0)
                    {
                        len1 = (int)(k - es) + 2; break;
                    }
                }
                int len2 = envVar.Length;
                var t    = new string('\0', len1 + len2);
                fixed(char *p = t)
                {
                    Api.memcpy(p, es, --len1 * 2);
                    for (int i = 0; i < envVar.Length; i++)
                    {
                        p[len1 + i] = envVar[i];
                    }
                }

                this.envVar = t;
                Api.FreeEnvironmentStrings(es);
            }
            else
            {
                this.envVar = null;
            }
        }
Example #3
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);
        }