Exemple #1
0
 private void EnginePicker_Load(object sender, EventArgs e)
 {
     _tooltip           = new ToolTip();
     _tooltip.IsBalloon = true;
     //_tooltip.ShowAlways = true;
     _tooltip.Active       = true;
     _tooltip.ToolTipIcon  = ToolTipIcon.Error;
     _tooltip.ToolTipTitle = "Error";
     //_tooltip.AutoPopDelay = 3000;
     _tooltip.InitialDelay = 0;
     //_tooltip.ReshowDelay = 500;
     ContextLib.DataContainers.Multimedia.MultiLevelData data = UserContext.Instance.GetSelectedContent();
     if (data.FileList != null && data.FileList.Length > 0)
     {
         string path = data.FileList[data.FileList.Length - 1];
         if (File.Exists(path))
         {
             FileInfo info = new FileInfo(path);
             nameTextBox.Text = FileNameManipulator.GetFileName(info.Name);
             pathTextBox.Text = path;
             data.Dispose();
             return;
         }
         else if (Directory.Exists(path))
         {
             DirectoryInfo info = new DirectoryInfo(path);
             nameTextBox.Text = FileNameManipulator.GetFolderName(path);
             pathTextBox.Text = path;
             data.Dispose();
             return;
         }
     }
     if (data.Text != null && data.Text.Trim() != string.Empty)
     {
         string path = data.Text.Trim();
         if (File.Exists(path))
         {
             FileInfo info = new FileInfo(path);
             nameTextBox.Text = FileNameManipulator.GetFileName(info.Name);
             pathTextBox.Text = path;
             data.Dispose();
             return;
         }
         else if (Directory.Exists(path))
         {
             DirectoryInfo info = new DirectoryInfo(path);
             nameTextBox.Text = FileNameManipulator.GetFolderName(path);
             pathTextBox.Text = path;
             data.Dispose();
             return;
         }
     }
     data.Dispose();
 }
Exemple #2
0
 private void EnginePicker_Load(object sender, EventArgs e)
 {
     _tooltip              = new ToolTip();
     _tooltip.IsBalloon    = true;
     _tooltip.Active       = true;
     _tooltip.ToolTipIcon  = ToolTipIcon.Error;
     _tooltip.ToolTipTitle = "Error";
     _tooltip.InitialDelay = 0;
     if (!_edit_mode)
     {
         ContextLib.DataContainers.Multimedia.MultiLevelData data = UserContext.Instance.GetSelectedContent();
         if (data.Text != null && data.Text.Trim() != string.Empty)
         {
             textBox.Text = data.Text;
         }
         data.Dispose();
     }
 }
Exemple #3
0
 private void EnginePicker_Load(object sender, EventArgs e)
 {
     _tooltip           = new ToolTip();
     _tooltip.IsBalloon = true;
     //_tooltip.ShowAlways = true;
     _tooltip.Active       = true;
     _tooltip.ToolTipIcon  = ToolTipIcon.Error;
     _tooltip.ToolTipTitle = "Error";
     //_tooltip.AutoPopDelay = 3000;
     _tooltip.InitialDelay = 0;
     //_tooltip.ReshowDelay = 500;
     ContextLib.DataContainers.Multimedia.MultiLevelData data = UserContext.Instance.GetSelectedContent();
     if (data.Text != null && data.Text.Trim() != string.Empty && _parent.UrlRegex.IsMatch(data.Text.Trim()))
     {
         siteUrlTextBox.Text = data.Text;
     }
     else
     {
         siteNameTextBox.Text = UserContext.Instance.GetBrowserPageName();
         siteUrlTextBox.Text  = UserContext.Instance.GetBrowserUrl();
         siteIconTextBox.Text = siteUrlTextBox.Text;
     }
     data.Dispose();
 }
Exemple #4
0
        protected override void SetupCommands()
        {
            LoadSettings();

            // Build the Add command
            _add_command = new Command("Add New Quick Text", "Add a new quick text.");
            _add_command.SetIsOwnerDelegate(new Command.OwnershipDelegate(delegate(string parameters)
            {
                return(false);
            }));
            _add_command.SetNameDelegate(new Command.EvaluationDelegate(delegate(string parameters)
            {
                return(_add_command.Name);
            }));
            _add_command.SetDescriptionDelegate(new Command.EvaluationDelegate(delegate(string parameters)
            {
                return(_add_command.Description);
            }));
            _add_command.SetAutoCompleteDelegate(new Command.EvaluationDelegate(delegate(string parameters)
            {
                return(_add_command.Name);
            }));
            _add_command.SetIconDelegate(new Command.IconDelegate(delegate(string parameters)
            {
                return(_add_icon.ToBitmap());
            }));
            _add_command.SetUsageDelegate(new Command.UsageDelegate(delegate(string parameters)
            {
                List <string> args             = new List <string>();
                Dictionary <string, bool> comp = new Dictionary <string, bool>();

                return(new CommandUsage(_add_command.Name, args, comp));
            }));
            _add_command.SetExecuteDelegate(new Command.ExecutionDelegate(delegate(string parameters, Keys modifiers)
            {
                QuickTextPicker ep = new QuickTextPicker(this);
                if (ep.ShowDialog() == DialogResult.OK)
                {
                    SaveSettings();
                }
                ep.Dispose();
            }));
            Commands.Add(_add_command);

            // Build the to lower command
            _to_lower_command = new Command("To Lower", "Convert selected text to lower case.");
            _to_lower_command.SetIsOwnerDelegate(new Command.OwnershipDelegate(delegate(string parameters)
            {
                return(false);
            }));
            _to_lower_command.SetNameDelegate(new Command.EvaluationDelegate(delegate(string parameters)
            {
                return(_to_lower_command.Name);
            }));
            _to_lower_command.SetDescriptionDelegate(new Command.EvaluationDelegate(delegate(string parameters)
            {
                return(_to_lower_command.Description);
            }));
            _to_lower_command.SetAutoCompleteDelegate(new Command.EvaluationDelegate(delegate(string parameters)
            {
                return(_to_lower_command.Name);
            }));
            _to_lower_command.SetIconDelegate(new Command.IconDelegate(delegate(string parameters)
            {
                return(_insert_icon.ToBitmap());
            }));
            _to_lower_command.SetUsageDelegate(new Command.UsageDelegate(delegate(string parameters)
            {
                List <string> args             = new List <string>();
                Dictionary <string, bool> comp = new Dictionary <string, bool>();

                return(new CommandUsage(_to_lower_command.Name, args, comp));
            }));
            _to_lower_command.SetExecuteDelegate(new Command.ExecutionDelegate(delegate(string parameters, Keys modifiers)
            {
                UserContext.Instance.SelectedTextToLower(true);
            }));
            Commands.Add(_to_lower_command);

            // Build the to upper command
            _to_upper_command = new Command("To Upper", "Convert selected text to upper case.");
            _to_upper_command.SetIsOwnerDelegate(new Command.OwnershipDelegate(delegate(string parameters)
            {
                return(false);
            }));
            _to_upper_command.SetNameDelegate(new Command.EvaluationDelegate(delegate(string parameters)
            {
                return(_to_upper_command.Name);
            }));
            _to_upper_command.SetDescriptionDelegate(new Command.EvaluationDelegate(delegate(string parameters)
            {
                return(_to_upper_command.Description);
            }));
            _to_upper_command.SetAutoCompleteDelegate(new Command.EvaluationDelegate(delegate(string parameters)
            {
                return(_to_upper_command.Name);
            }));
            _to_upper_command.SetIconDelegate(new Command.IconDelegate(delegate(string parameters)
            {
                return(_insert_icon.ToBitmap());
            }));
            _to_upper_command.SetUsageDelegate(new Command.UsageDelegate(delegate(string parameters)
            {
                List <string> args             = new List <string>();
                Dictionary <string, bool> comp = new Dictionary <string, bool>();

                return(new CommandUsage(_to_upper_command.Name, args, comp));
            }));
            _to_upper_command.SetExecuteDelegate(new Command.ExecutionDelegate(delegate(string parameters, Keys modifiers)
            {
                UserContext.Instance.SelectedTextToUpper(true);
            }));
            Commands.Add(_to_upper_command);

            // Build the sort command
            _sort_command = new Command("Sort Text", "Sort selected text.");
            _sort_command.SetIsOwnerDelegate(new Command.OwnershipDelegate(delegate(string parameters)
            {
                return(false);
            }));
            _sort_command.SetNameDelegate(new Command.EvaluationDelegate(delegate(string parameters)
            {
                return(_sort_command.Name);
            }));
            _sort_command.SetDescriptionDelegate(new Command.EvaluationDelegate(delegate(string parameters)
            {
                return(_sort_command.Description);
            }));
            _sort_command.SetAutoCompleteDelegate(new Command.EvaluationDelegate(delegate(string parameters)
            {
                return(_sort_command.Name);
            }));
            _sort_command.SetIconDelegate(new Command.IconDelegate(delegate(string parameters)
            {
                return(_insert_icon.ToBitmap());
            }));
            _sort_command.SetUsageDelegate(new Command.UsageDelegate(delegate(string parameters)
            {
                List <string> args             = new List <string>();
                Dictionary <string, bool> comp = new Dictionary <string, bool>();

                return(new CommandUsage(_sort_command.Name, args, comp));
            }));
            _sort_command.SetExecuteDelegate(new Command.ExecutionDelegate(delegate(string parameters, Keys modifiers)
            {
                UserContext.Instance.SelectedTextSortLines(true);
            }));
            Commands.Add(_sort_command);

            // Build the insert command
            _insert_command = new Command("Insert");
            _insert_command.SetIsOwnerDelegate(new Command.OwnershipDelegate(delegate(string parameters)
            {
                return(false);
            }));
            _insert_command.SetNameDelegate(new Command.EvaluationDelegate(delegate(string parameters)
            {
                Insertion insertion = BuildInsertion(parameters);
                if (insertion.Text == string.Empty)
                {
                    return("Insert clipboard...");
                }
                else
                {
                    return("Insert " + insertion.Text);
                }
            }));
            _insert_command.SetDescriptionDelegate(new Command.EvaluationDelegate(delegate(string parameters)
            {
                Insertion insertion = BuildInsertion(parameters);
                if (insertion.Target == string.Empty)
                {
                    return("... into top window.");
                }
                else
                {
                    return("... into " + insertion.Target);
                }
            }));
            _insert_command.SetAutoCompleteDelegate(new Command.EvaluationDelegate(delegate(string parameters)
            {
                string auto         = _insert_command.Name;
                Insertion insertion = BuildInsertion(parameters);
                if (insertion.Text != string.Empty)
                {
                    auto += " " + insertion.Text;
                }
                if (insertion.Target != string.Empty)
                {
                    auto += " " + insertion.Target;
                }
                return(auto);
            }));
            _insert_command.SetIconDelegate(new Command.IconDelegate(delegate(string parameters)
            {
                return(_insert_icon.ToBitmap());
            }));
            _insert_command.SetUsageDelegate(new Command.UsageDelegate(delegate(string parameters)
            {
                List <string> args             = new List <string>(new string[] { "\"text\"", "\"file\"" });
                Dictionary <string, bool> comp = new Dictionary <string, bool>();
                foreach (string arg in args)
                {
                    comp.Add(arg, false);
                }

                Insertion insertion = BuildInsertion(parameters);
                if (insertion.Text != string.Empty)
                {
                    comp["\"text\""] = true;
                }
                if (insertion.Target != string.Empty)
                {
                    comp["\"file\""] = true;
                }

                return(new CommandUsage(_insert_command.Name, args, comp));
            }));
            _insert_command.SetExecuteDelegate(new Command.ExecutionDelegate(delegate(string parameters, Keys modifiers)
            {
                Insertion insertion = BuildInsertion(parameters);
                string text         = insertion.Text;
                if (text == string.Empty)
                {
                    ContextLib.DataContainers.Multimedia.MultiLevelData data = UserContext.Instance.GetClipboardContent();
                    if (data.Text != null)
                    {
                        text = data.Text;
                    }
                    data.Dispose();
                }
                if (insertion.Target == string.Empty)
                {
                    UserContext.Instance.InsertText(text, true);
                }
                else
                {
                    StreamWriter writer = new StreamWriter(insertion.Target, true);
                    writer.WriteLine(text);
                    writer.Close();
                }
            }));
            Commands.Add(_insert_command);

            // Build user quick text commands
            foreach (QuickText quick_text in _quick_texts)
            {
                QuickText qtext = new QuickText(quick_text);
                Command   cmd   = new Command("Insert " + qtext.Name);

                cmd.SetIsOwnerDelegate(new Command.OwnershipDelegate(delegate(string parameters)
                {
                    return(true);
                }));
                cmd.SetNameDelegate(new Command.EvaluationDelegate(delegate(string parameters)
                {
                    return("Insert " + qtext.Name);
                }));
                cmd.SetDescriptionDelegate(new Command.EvaluationDelegate(delegate(string parameters)
                {
                    return("Insert quick text in active window.");
                }));
                cmd.SetAutoCompleteDelegate(new Command.EvaluationDelegate(delegate(string parameters)
                {
                    return("Insert " + qtext.Name);
                }));
                cmd.SetIconDelegate(new Command.IconDelegate(delegate(string parameters)
                {
                    return(_insert_icon.ToBitmap());
                }));
                cmd.SetUsageDelegate(new Command.UsageDelegate(delegate(string parameters)
                {
                    List <string> args             = new List <string>();
                    Dictionary <string, bool> comp = new Dictionary <string, bool>();

                    return(new CommandUsage(cmd.Name, args, comp));
                }));
                cmd.SetExecuteDelegate(new Command.ExecutionDelegate(delegate(string parameters, Keys modifiers)
                {
                    UserContext.Instance.InsertText(qtext.Text, true);
                }));
                _commands.Add(cmd);
            }
        }
        private string ReplaceSpecialKeywords(string text, string[] tokens)
        {
            string ret                = text;
            string this_keyword       = @"!this";
            string clipboard_keyword  = @"!clipboard";
            string process_keyword    = @"!topapp";
            string desktop_keyword    = @"!desktop";
            string explorer_keyword   = @"!here";
            string item_keyword       = @"!selected";
            string url_keyword        = @"!url";
            bool   look_for_this      = true;
            bool   look_for_clipboard = true;
            bool   look_for_process   = true;
            bool   look_for_desktop   = true;
            bool   look_for_explorer  = true;
            bool   look_for_item      = true;
            bool   look_for_url       = true;

            if (tokens != null)
            {
                if (Array.IndexOf <string>(tokens, this_keyword) != -1)
                {
                    look_for_this = false;
                }
                if (Array.IndexOf <string>(tokens, clipboard_keyword) != -1)
                {
                    look_for_clipboard = false;
                }
                if (Array.IndexOf <string>(tokens, process_keyword) != -1)
                {
                    look_for_process = false;
                }
                if (Array.IndexOf <string>(tokens, desktop_keyword) != -1)
                {
                    look_for_desktop = false;
                }
                if (Array.IndexOf <string>(tokens, explorer_keyword) != -1)
                {
                    look_for_explorer = false;
                }
                if (Array.IndexOf <string>(tokens, item_keyword) != -1)
                {
                    look_for_item = false;
                }
                if (Array.IndexOf <string>(tokens, url_keyword) != -1)
                {
                    look_for_url = false;
                }
            }
            if (!look_for_this && !look_for_clipboard && !look_for_process &&
                !look_for_desktop && !look_for_explorer && !look_for_item &&
                !look_for_url)
            {
                return(text);
            }
            if (look_for_this)
            {
                if (text.Contains(this_keyword))
                {
                    ContextLib.DataContainers.Multimedia.MultiLevelData data = UserContext.Instance.GetSelectedContent();
                    if (data.Text != null)
                    {
                        ret = ret.Replace(this_keyword, data.Text);
                    }
                    data.Dispose();
                }
            }
            if (look_for_clipboard)
            {
                if (text.Contains(clipboard_keyword))
                {
                    ContextLib.DataContainers.Multimedia.MultiLevelData data = UserContext.Instance.GetClipboardContent();
                    if (data.Text != null)
                    {
                        ret = ret.Replace(clipboard_keyword, data.Text);
                    }
                    data.Dispose();
                }
            }
            if (look_for_process)
            {
                if (text.Contains(process_keyword))
                {
                    ContextLib.DataContainers.GUI.Window window = UserContext.Instance.GetTopWindow();
                    if (window != null)
                    {
                        ret = ret.Replace(process_keyword, window.ProcessName);
                    }
                }
            }
            if (look_for_desktop)
            {
                if (text.Contains(desktop_keyword))
                {
                    ret = ret.Replace(desktop_keyword, CommonInfo.UserDesktop);
                }
            }
            if (look_for_explorer)
            {
                if (text.Contains(explorer_keyword))
                {
                    ret = ret.Replace(explorer_keyword, UserContext.Instance.GetExplorerPath(false));
                }
            }
            if (look_for_item)
            {
                if (text.Contains(item_keyword))
                {
                    ret = ret.Replace(item_keyword, StringUtility.ArrayToStr(UserContext.Instance.GetExplorerSelectedItems(false)));
                }
            }
            if (look_for_url)
            {
                if (text.Contains(url_keyword))
                {
                    ret = ret.Replace(url_keyword, UserContext.Instance.GetBrowserUrl());
                }
            }
            //string[] args = StringUtility.GenerateKeywords(text, false);
            //for (int i = 0; i < args.Length; i++)
            //{
            //    string arg = args[i].Trim(new char[] { '\"', '\'', ',', ';' });
            //    if (arg == this_keyword)
            //    {
            //        if (look_for_this)
            //        {
            //            ContextLib.DataContainers.Multimedia.MultiLevelData data = UserContext.Instance.GetSelectedContent();
            //            if (data.Text != null)
            //                args[i] = data.Text;
            //            else
            //                args[i] = string.Empty;
            //            data.Dispose();
            //        }
            //    }
            //    else if (arg == clipboard_keyword)
            //    {
            //        if (look_for_clipboard)
            //        {
            //            ContextLib.DataContainers.Multimedia.MultiLevelData data = UserContext.Instance.GetClipboardContent();
            //            if (data.Text != null)
            //                args[i] = data.Text;
            //            else
            //                args[i] = string.Empty;
            //            data.Dispose();
            //        }
            //    }
            //    else if (arg == process_keyword)
            //    {
            //        if (look_for_process)
            //        {
            //            ContextLib.DataContainers.GUI.Window window = UserContext.Instance.GetTopWindow();
            //            if (window != null)
            //                args[i] = window.ProcessName;
            //        }
            //    }
            //    else if (arg == desktop_keyword)
            //    {
            //        if (look_for_desktop)
            //        {
            //            return CommonInfo.UserDesktop;
            //        }
            //    }
            //    else if (arg == explorer_keyword)
            //    {
            //        if (look_for_explorer)
            //        {
            //            args[i] = UserContext.Instance.GetExplorerPath(false);
            //        }
            //    }
            //    else if (arg == item_keyword)
            //    {
            //        if (look_for_item)
            //        {
            //            string items = StringUtility.ArrayToStr(UserContext.Instance.GetExplorerSelectedFiles(false));
            //            args[i] = items;
            //        }
            //    }
            //}
            //foreach (string arg in args)
            //    ret += arg + " ";
            //return ret.TrimEnd();
            return(ret);
        }