Example #1
0
        /// <summary>
        /// Handles image received from keyboard clipboard.
        /// </summary>
        /// <param name="clip">Clipboard.</param>
        /// <param name="pixbuf">Image.</param>
        private void OnKeyboardImageReceived(Gtk.Clipboard clip, Pixbuf pixbuf)
        {
            if (pixbuf == null)
            {
                return;
            }

            if (Settings.Instance[Settings.Keys.Core.SynchronizeClipboards].AsBoolean() && Settings.Instance[Settings.Keys.Core.MouseClipboard].AsBoolean())
            {
                this.MouseItem = null;
                this.mouseClipboard.Clear();
            }

            Item item = new Item(pixbuf);

            ClipboardChangedArgs args = new ClipboardChangedArgs(Gdk.Selection.Clipboard, this.KeyboardItem, item);

            this.KeyboardItem = item;

            this.Items.Insert(0, item);

            if (this.ClipboardChanged != null)
            {
                this.ClipboardChanged(this, args);
            }
        }
Example #2
0
        /// <summary>
        /// Handles text received from keyboard clipboard.
        /// </summary>
        /// <param name="clip">Clipboard.</param>
        /// <param name="text">Text.</param>
        private void OnKeyboardTextReceived(Gtk.Clipboard clip, string text)
        {
            if (string.IsNullOrEmpty(text) || (this.KeyboardItem != null && text == this.KeyboardItem.Text))
            {
                return;
            }

            if (this.synchronizing)
            {
                this.synchronizing = false;
                this.KeyboardItem  = this.MouseItem;

                if (this.ClipboardChanged != null)
                {
                    this.ClipboardChanged(this, null);
                }

                return;
            }

            Item item = this.Items.FirstOrDefault(i => i.Text == text);

            if (item != null)
            {
                this.Items.MoveTop(item);
            }
            else
            {
                item = new Item(text);
                string label = item.Label;
                int    c     = 1;

                while (this.Items.Any(i => i.Label == item.Label))
                {
                    item.Label = label + c.ToString();
                    c++;
                }

                this.Items.Insert(0, item);
            }

            ClipboardChangedArgs args = new ClipboardChangedArgs(Gdk.Selection.Clipboard, this.KeyboardItem, item);

            this.KeyboardItem = item;

            if (Settings.Instance[Settings.Keys.Core.SynchronizeClipboards].AsBoolean() && Settings.Instance[Settings.Keys.Core.MouseClipboard].AsBoolean() && !this.synchronizing)
            {
                this.synchronizing       = true;
                this.mouseClipboard.Text = text;
            }
            else
            {
                if (this.ClipboardChanged != null)
                {
                    this.ClipboardChanged(this, args);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Stores temporary mouse item.
        /// </summary>
        /// <param name="args">Event arguments.</param>
        private void StoreTemporaryMouseItem(ClipboardChangedArgs args)
        {
            lock (this.mouseContentRestorationTimerLock)
            {
                if (args == null || args.Clipboard != Gdk.Selection.Primary)
                    return;

                if (!Clipboard.Instance.LockMouseClipboard)
                    Clipboard.Instance.LockMouseClipboard = true;

                if (this.ignoreTemporaryItem)
                {
                    this.ignoreTemporaryItem = false;
                    return;
                }

                if (args.OldValue == null || args.NewValue == null || args.OldValue.Text == args.NewValue.Text)
                    return;

                if (this.temporaryMouseItem != null	&& this.temporaryMouseItem.Text == args.OldValue.Text)
                    return;

                if (this.mouseContentRestorationTimer != null)
                {
                    this.mouseContentRestorationTimer = new Timer((o) =>
                    {
                        lock (this.mouseContentRestorationTimerLock)
                        {
                            Gtk.Application.Invoke((s, e) => Clipboard.Instance.SetAsMouseContent((Item)o));
                            this.mouseContentRestorationTimer.Dispose();
                            this.mouseContentRestorationTimer = null;
                        }
                    }, args.OldValue, 1000, Timeout.Infinite);
                }

                this.temporaryMouseItem = args.NewValue;
            }
        }
Example #4
0
        /// <summary>
        /// Sends Clipboard's ClipboardChanged event to tray plugins.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="args">Event arguments.</param>
        private void OnClipboardChanged(object sender, ClipboardChangedArgs args)
        {
            if (Settings.Instance[Settings.Keys.Hotkeys.CopyMouse].AsBoolean())
                this.StoreTemporaryMouseItem(args);

            foreach (ITray tray in this.Trays)
            {
                tray.OnClipboardChanged(sender, args);
            }
        }
Example #5
0
 /// <summary>
 /// Handles Clipboard's ClipboardChanged event.
 /// </summary>
 /// <param name="sender">Sender.</param>
 /// <param name="args">Event arguments.</param>
 public void OnClipboardChanged(object sender, ClipboardChangedArgs args)
 {
 }
Example #6
0
 /// <summary>
 /// Handles Clipboard's ClipboardChanged event.
 /// </summary>
 /// <param name="sender">Sender.</param>
 /// <param name="args">Event arguments.</param>
 public void OnClipboardChanged(object sender, ClipboardChangedArgs args)
 {
     this.RefreshMenu();
 }
Example #7
0
        /// <summary>
        /// Handles more complicated content from keyboard clipboard.
        /// </summary>
        /// <param name="clipboard">Clipboard.</param>
        /// <param name="selectionData">Data.</param>
        private void OnKeyboardContentReceived(Gtk.Clipboard clipboard, SelectionData selectionData)
        {
            Item item = this.Items.FirstOrDefault(i => i.IsData && i.Target.Name == selectionData.Target.Name && i.Data.SequenceEqual(selectionData.Data));

            if (item != null)
            {
                this.Items.MoveTop(item);
            }
            else
            {
                Gtk.SelectionData sub_data = this.keyboardClipboard.WaitForContents(Targets.Atoms[Targets.UtfString]);

                if (sub_data == null)
                {
                    sub_data = this.keyboardClipboard.WaitForContents(Targets.Atoms[Targets.String]);
                }

                if (Settings.Instance[Settings.Keys.Core.SupportedFilesAsImages].AsBoolean() && selectionData.Target.Name == Targets.File && sub_data != null && sub_data.Text != null && sub_data.Text.Length > 1)
                {
                    string ext = System.IO.Path.GetExtension(sub_data.Text);

                    if (ext.Length > 1)
                    {
                        ext = ext.Substring(1, ext.Length - 1).ToLower();
                        PixbufFormat format = this.pixbufFormats.FirstOrDefault(f => f.Extensions.Contains(ext));

                        if (format != null)
                        {
                            try
                            {
                                this.OnKeyboardImageReceived(clipboard, new Pixbuf(sub_data.Text));
                                return;
                            }
                            catch (Exception ex)
                            {
                                Tools.PrintInfo(ex, this.GetType());
                            }
                        }
                    }
                }

                string sub_text = sub_data != null ? sub_data.Text : System.Text.Encoding.UTF8.GetString(selectionData.Data);

                item = new Item(selectionData.Target, selectionData.Data, sub_text);

                string label = item.Label;
                int    c     = 1;

                while (this.Items.Any(i => i.Label == item.Label))
                {
                    item.Label = label + c.ToString();
                    c++;
                }

                this.Items.Insert(0, item);
            }

            Item text_item = this.Items.FirstOrDefault(i => !i.IsData && i.Text == item.Text);

            if (text_item != null)
            {
                this.Items.Remove(text_item);

                if (this.MouseItem == text_item)
                {
                    this.SetAsMouseContent(item);
                    MouseItem = item;
                }
            }

            ClipboardChangedArgs args = new ClipboardChangedArgs(Gdk.Selection.Clipboard, this.KeyboardItem, item);

            this.KeyboardItem = item;

            if (Settings.Instance[Settings.Keys.Core.SynchronizeClipboards].AsBoolean() && Settings.Instance[Settings.Keys.Core.MouseClipboard].AsBoolean() && item.Target.Name == Targets.Html)
            {
                synchronizing = true;
                this.SetAsMouseContent(item);
            }
            else
            {
                if (this.ClipboardChanged != null)
                {
                    this.ClipboardChanged(this, args);
                }
            }
        }
Example #8
0
        /// <summary>
        /// Handles text received from keyboard clipboard.
        /// </summary>
        /// <param name="clip">Clipboard.</param>
        /// <param name="text">Text.</param>
        private void OnKeyboardTextReceived(Gtk.Clipboard clip, string text)
        {
            if (string.IsNullOrEmpty(text) || (this.KeyboardItem != null && text == this.KeyboardItem.Text))
                return;

            if (this.synchronizing)
            {
                this.synchronizing = false;
                this.KeyboardItem = this.MouseItem;

                if (this.ClipboardChanged != null)
                    this.ClipboardChanged(this, null);

                return;
            }

            Item item = this.Items.FirstOrDefault(i => i.Text == text);

            if (item != null)
            {
                this.Items.MoveTop(item);
            }
            else
            {
                item = new Item(text);
                string label = item.Label;
                int c = 1;

                while (this.Items.Any(i => i.Label == item.Label))
                {
                    item.Label = label + c.ToString();
                    c++;
                }

                this.Items.Insert(0, item);
            }

            ClipboardChangedArgs args = new ClipboardChangedArgs(Gdk.Selection.Clipboard, this.KeyboardItem, item);

            this.KeyboardItem = item;

            if (Settings.Instance[Settings.Keys.Core.SynchronizeClipboards].AsBoolean() && Settings.Instance[Settings.Keys.Core.MouseClipboard].AsBoolean() && !this.synchronizing)
            {
                this.synchronizing = true;
                this.mouseClipboard.Text = text;
            }
            else
            {
                if (this.ClipboardChanged != null)
                    this.ClipboardChanged(this, args);
            }
        }
Example #9
0
        /// <summary>
        /// Handles image received from keyboard clipboard.
        /// </summary>
        /// <param name="clip">Clipboard.</param>
        /// <param name="pixbuf">Image.</param>
        private void OnKeyboardImageReceived(Gtk.Clipboard clip, Pixbuf pixbuf)
        {
            if (pixbuf == null)
                return;

            if (Settings.Instance[Settings.Keys.Core.SynchronizeClipboards].AsBoolean() && Settings.Instance[Settings.Keys.Core.MouseClipboard].AsBoolean())
            {
                this.MouseItem = null;
                this.mouseClipboard.Clear();
            }

            Item item = new Item(pixbuf);

            ClipboardChangedArgs args = new ClipboardChangedArgs(Gdk.Selection.Clipboard, this.KeyboardItem, item);

            this.KeyboardItem = item;

            this.Items.Insert(0, item);

            if (this.ClipboardChanged != null)
                this.ClipboardChanged(this, args);
        }
Example #10
0
        /// <summary>
        /// Handles more complicated content from keyboard clipboard.
        /// </summary>
        /// <param name="clipboard">Clipboard.</param>
        /// <param name="selectionData">Data.</param>
        private void OnKeyboardContentReceived(Gtk.Clipboard clipboard, SelectionData selectionData)
        {
            Item item = this.Items.FirstOrDefault(i => i.IsData && i.Target.Name == selectionData.Target.Name && i.Data.SequenceEqual(selectionData.Data));

            if (item != null)
            {
                this.Items.MoveTop(item);
            }
            else
            {
                Gtk.SelectionData sub_data = this.keyboardClipboard.WaitForContents(Targets.Atoms[Targets.UtfString]);

                if (sub_data == null)
                    sub_data = this.keyboardClipboard.WaitForContents(Targets.Atoms[Targets.String]);

                if (Settings.Instance[Settings.Keys.Core.SupportedFilesAsImages].AsBoolean() && selectionData.Target.Name == Targets.File && sub_data != null && sub_data.Text != null && sub_data.Text.Length > 1)
                {
                    string ext = System.IO.Path.GetExtension(sub_data.Text);

                    if (ext.Length > 1)
                    {
                        ext = ext.Substring(1, ext.Length - 1).ToLower();
                        PixbufFormat format = this.pixbufFormats.FirstOrDefault(f => f.Extensions.Contains(ext));

                        if (format != null)
                        {
                            try
                            {
                                this.OnKeyboardImageReceived(clipboard, new Pixbuf(sub_data.Text));
                                return;
                            }
                            catch (Exception ex)
                            {
                                Tools.PrintInfo(ex, this.GetType());
                            }
                        }
                    }
                }

                string sub_text = sub_data != null ? sub_data.Text : System.Text.Encoding.UTF8.GetString(selectionData.Data);

                item = new Item(selectionData.Target ,selectionData.Data, sub_text);

                string label = item.Label;
                int c = 1;

                while (this.Items.Any(i => i.Label == item.Label))
                {
                    item.Label = label + c.ToString();
                    c++;
                }

                this.Items.Insert(0, item);
            }

            Item text_item = this.Items.FirstOrDefault(i => !i.IsData && i.Text == item.Text);

            if (text_item != null)
            {
                this.Items.Remove(text_item);

                if (this.MouseItem == text_item)
                {
                    this.SetAsMouseContent(item);
                 	MouseItem = item;
                }
            }

            ClipboardChangedArgs args = new ClipboardChangedArgs(Gdk.Selection.Clipboard, this.KeyboardItem, item);

            this.KeyboardItem = item;

            if (Settings.Instance[Settings.Keys.Core.SynchronizeClipboards].AsBoolean() && Settings.Instance[Settings.Keys.Core.MouseClipboard].AsBoolean() && item.Target.Name == Targets.Html)
            {
                synchronizing = true;
                this.SetAsMouseContent(item);
            }
            else
            {
                if (this.ClipboardChanged != null)
                    this.ClipboardChanged(this, args);
            }
        }