Beispiel #1
0
        ///<summary>Create a DataView</summary>
        public DataView()
        {
            dvControl = new DataViewControl(this);
            dvDisplay = new DataViewDisplay(this);

            dvDisplay.Control = dvControl;
            dvControl.Display = dvDisplay;

            // initialize clipdata buffer
            // and clipboard
            clipdata  = new byte[0];
            clipboard = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", true));

            // initialize undo/redo cursor offset stacks
            cursorUndoDeque = new Deque <CursorState>();
            cursorRedoDeque = new Deque <CursorState>();

            prefID = "dv" + this.GetHashCode().ToString();
            PreferencesChangedHandler handler = new PreferencesChangedHandler(OnPreferencesChanged);

            Preferences.Proxy.Subscribe("Undo.Limited", prefID, handler);
            Preferences.Proxy.Subscribe("Undo.Actions", prefID, handler);
            Preferences.Proxy.Subscribe("Highlight.PatternMatch", prefID, handler);
            Preferences.Proxy.Subscribe("ByteBuffer.TempDir", prefID, handler);
        }
Beispiel #2
0
        private void HandlerPintaCoreActionsEditCopyActivated(object sender, EventArgs e)
        {
            Gtk.Clipboard cb = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
            if (PintaCore.Tools.CurrentTool.TryHandleCopy(cb))
            {
                return;
            }

            Document doc = PintaCore.Workspace.ActiveDocument;

            PintaCore.Tools.Commit();

            ImageSurface src = doc.GetClippedLayer(doc.CurrentLayerIndex);

            Gdk.Rectangle rect = doc.GetSelectedBounds(true);

            ImageSurface dest = new ImageSurface(Format.Argb32, rect.Width, rect.Height);

            using (Context g = new Context(dest)) {
                g.SetSourceSurface(src, -rect.X, -rect.Y);
                g.Paint();
            }

            cb.Image = dest.ToPixbuf();

            (src as IDisposable).Dispose();
            (dest as IDisposable).Dispose();
        }
        void PasteJson(Clipboard c, string text)
        {
            if (string.IsNullOrEmpty (text)) {
                InsertCSharp (string.Empty);
                return;
            }

            var gen = new JsonClassGenerator {
                Example = text,
                MainClass = "RootObject",
                UseProperties = true,
                CodeWriter = new CSharpCodeWriter ()
            };

            try {
                using (var sw = new StringWriter ()) {
                    gen.OutputStream = sw;
                    gen.GenerateClasses ();
                    sw.Flush ();
                    var generatedString = sw.ToString ();
                    InsertCSharp (generatedString);
                }
            } catch (Exception ex) {
                Console.WriteLine (ex.Message);
                MessageService.ShowWarning (string.Format ("Invalid JSON: {0}", ex.Message));
            }

            gen = null;
        }
Beispiel #4
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);
            }
        }
Beispiel #5
0
        public void CopySelection()
        {
            TreeModel     model;
            StringBuilder sb = new StringBuilder();

            foreach (Gtk.TreePath p in treeviewSearchResults.Selection.GetSelectedRows(out model))
            {
                TreeIter iter;
                if (!model.GetIter(out iter, p))
                {
                    continue;
                }
                SearchResult result = store.GetValue(iter, SearchResultColumn) as SearchResult;
                if (result == null)
                {
                    continue;
                }
                DocumentLocation         loc = GetLocation(result);
                Mono.TextEditor.Document doc = GetDocument(result);
                LineSegment line             = doc.GetLine(loc.Line - 1);

                sb.AppendFormat("{0} ({1}, {2}):{3}", result.FileName, loc.Line, loc.Column, doc.GetTextAt(line.Offset, line.EditableLength));
                sb.AppendLine();
            }
            Gtk.Clipboard clipboard = Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
            clipboard.Text = sb.ToString();

            clipboard      = Clipboard.Get(Gdk.Atom.Intern("PRIMARY", false));
            clipboard.Text = sb.ToString();
        }
Beispiel #6
0
        private void HandlerPintaCoreActionsEditCopyActivated(object sender, EventArgs e)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            Gtk.Clipboard cb = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
            if (PintaCore.Tools.CurrentTool?.DoHandleCopy(doc, cb) == true)
            {
                return;
            }

            PintaCore.Tools.Commit();

            using (ImageSurface src = doc.Layers.GetClippedLayer(doc.Layers.CurrentUserLayerIndex)) {
                Gdk.Rectangle rect = doc.GetSelectedBounds(true);
                if (rect.Width == 0 || rect.Height == 0)
                {
                    return;
                }

                ImageSurface dest = CairoExtensions.CreateImageSurface(Format.Argb32, rect.Width, rect.Height);

                using (Context g = new Context(dest)) {
                    g.SetSourceSurface(src, -rect.X, -rect.Y);
                    g.Paint();
                }

                cb.Image = dest.ToPixbuf();

                (dest as IDisposable).Dispose();
            }
        }
        void TextViewKeyPressed(object sender, KeyPressEventArgs args)
        {
            if (args.Event.State.HasFlag(Gdk.ModifierType.ControlMask) &&
                (args.Event.Key == Gdk.Key.c || args.Event.Key == Gdk.Key.C))
            {
                TextView tv = (TextView)sender;

                Gtk.Clipboard clipboard = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
                Gtk.TextIter  start, end;
                string        text;

                if (!tv.Buffer.GetSelectionBounds(out start, out end) || start.Offset == end.Offset)
                {
                    start = tv.Buffer.StartIter;
                    end   = tv.Buffer.EndIter;
                }

                text = tv.Buffer.GetText(start, end, true);

                if (Platform.IsWindows)
                {
                    // Windows specific hack
                    text = text.Replace("\r\n", "\n");
                }

                clipboard.Text = text;

                args.RetVal = true;
            }
        }
Beispiel #8
0
		static HttpListener listener; // http server providing clipboard history selection

		public static void Main (string[] args)
		{
			// make UI methods for clipboard access available
			Application.Init ();

			// setup http interface
			listener = new HttpListener();
			listener.Prefixes.Add("http://*:5544/");
			listener.Start();
			listener.BeginGetContext(ProcessRequest, null);

			// initialize access to clipboard
			clippy = Gtk.Clipboard.Get(Gdk.Atom.Intern("PRIMARY", false));

			// schedule polling of clipboard content
			timer = new System.Timers.Timer(300);
			timer.Elapsed += new System.Timers.ElapsedEventHandler(ReadClipboardUI);
			timer.Start();

			// just to prevent termination of the app
			Application.Run();

			// shutdown http interface
			listener.Stop();
		}
Beispiel #9
0
        /// <summary>
        /// Get whatever text is currently on a specific clipboard.
        /// </summary>
        /// <param name="clipboardName">Name of the clipboard.</param>
        /// <returns></returns>
        public static string GetClipboardText(string clipboardName)
        {
            Gdk.Atom      modelClipboard = Gdk.Atom.Intern(clipboardName, false);
            Gtk.Clipboard cb             = Gtk.Clipboard.Get(modelClipboard);

            return(cb.WaitForText());
        }
    private void ReceivedFunc(Gtk.Clipboard clipboard, Gtk.SelectionData selection)
    {
        var temp = _encoding.GetString(selection.Data);

        if (temp == null)
        {
            return;
        }

        var items = temp.Split();

        for (int i = 1; i < items.Length; i++)
        {
            var fileFrom = items[i].Substring("file://".Length);
            var fileTo   = System.IO.Path.Combine(_destination, System.IO.Path.GetFileName(fileFrom));
            if (items[0] == "copy")
            {
                File.Copy(fileFrom, fileTo);
            }
            else if (items[1] == "cut")
            {
                File.Move(fileFrom, fileTo);
            }
        }
    }
Beispiel #11
0
    protected void on_pasteAction_Activated(object sender, EventArgs e)
    {
        Gtk.Clipboard clipboard = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
        string        text      = clipboard.WaitForText();

        Widget widget = this.Focus;

        if (widget.GetType().IsAssignableFrom(typeof(TextView)))
        {
            TextView tv = (TextView)widget;
            if (tv.Editable)
            {
                string selectedText = tv.Buffer.GetSelectedText();
                if (selectedText.Length > 0)
                {
                    tv.Buffer.ReplaceSelection(text);
                }
                else
                {
                    tv.Buffer.InsertAtCursor(text);
                }
            }
        }
        else if (widget.GetType().IsAssignableFrom(typeof(Entry)))
        {
            Entry en = (Entry)widget;
            if (en.IsEditable)
            {
                ((Entry)widget).ReplaceSelection(new string (text.Where(c => !char.IsControl(c)).ToArray()));    //.InsertText (text);
            }
        }
    }
Beispiel #12
0
    protected void on_cutAction_Activated(object sender, EventArgs e)
    {
        Gtk.Clipboard clipboard = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));

        Widget widget = this.Focus;

        if (widget.GetType().IsAssignableFrom(typeof(TextView)))
        {
            TextView tv = (TextView)widget;
            clipboard.Text = tv.Buffer.GetSelectedText();
            if (tv.Editable)
            {
                tv.Buffer.ReplaceSelection("", false);
            }
        }
        else if (widget.GetType().IsAssignableFrom(typeof(Entry)))
        {
            Entry en = (Entry)widget;
            clipboard.Text = en.GetSelectedText();
            if (en.IsEditable)
            {
                en.ReplaceSelection("");
            }
        }
    }
Beispiel #13
0
        private void Activated(object sender, EventArgs e)
        {
            Gtk.Clipboard cb = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));

            if (cb.WaitIsImageAvailable())
            {
                PintaCore.Tools.Commit();

                Gdk.Pixbuf image = cb.WaitForImage();

                Layer l = PintaCore.Layers.AddNewLayer(string.Empty);

                using (Cairo.Context g = new Cairo.Context(l.Surface))
                    g.DrawPixbuf(image, new Cairo.Point(0, 0));

                // Make new layer the current layer
                PintaCore.Layers.SetCurrentLayer(l);

                PintaCore.Workspace.Invalidate();

                AddLayerHistoryItem hist = new AddLayerHistoryItem(Stock.Paste, Catalog.GetString("Paste Into New Layer"), PintaCore.Layers.IndexOf(l));
                PintaCore.History.PushNewItem(hist);
            }
            else
            {
                Pinta.Dialogs.ClipboardEmptyDialog.Show();
            }
        }
Beispiel #14
0
    void CbGetFunc(Gtk.Clipboard cb, ref Gtk.SelectionData sd, uint info, object o)
    {
        if (info == 0)
        {
            // string
            // so we want to return filenames

            StringBuilder sb = new StringBuilder();
            foreach (string iid in cb_currently_selected)
            {
                sb.Append(repo.GetImage(iid).FullFilename);
                sb.Append(" ");
            }

            sd.Text = sb.ToString();
        }
        else if (info == 1)
        {
            // mphoto_imageid_list
            StringBuilder sb = new StringBuilder();
            foreach (string iid in cb_currently_selected)
            {
                sb.Append(iid);
                Console.WriteLine(" cb append: " + iid);
                sb.Append(";");
            }
            // we cheat here and tell it to just set it as a string
            sd.Text = sb.ToString();
        }
    }
Beispiel #15
0
		void ClearProxy (Clipboard clipboard)
		{
			if (Data ["clear_func"] != null)  {
				ClipboardClearFunc clear = Data ["clear_func"] as ClipboardClearFunc;
				clear (clipboard);
			}
			SetPersistentData (null, null, null);
		}
Beispiel #16
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);
                }
            }
        }
Beispiel #17
0
        protected void OnShowDefinitionOnClipboard()
        {
            TableNode           node           = CurrentNode.DataItem as TableNode;
            IEditSchemaProvider schemaProvider = (IEditSchemaProvider)node.ConnectionContext.SchemaProvider;

            Gtk.Clipboard clp = Clipboard.Get(Gdk.Selection.Clipboard);
            clp.Text = schemaProvider.GetTableCreateStatement(node.Table);
            MessageService.ShowMessage(AddinCatalog.GetString("CREATE Statement has been copied to Clipboard."));
        }
Beispiel #18
0
        //upload image and copy link to clipboard
        public void UploadImageToImgur()
        {
            //upload to imgur
            var a = imgurAPIClass.UploadImage();

            //copy link to clipboard
            Gtk.Clipboard clipboard = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
            clipboard.Text = a.link;
        }
Beispiel #19
0
        void itemPathCMS_CopyPathClicked(object sender, EventArgs e)
        {
#if __MonoCS__
            gtkalias.Clipboard clipboard = gtkalias.Clipboard.Get(gdkalias.Atom.Intern("CLIPBOARD", false));
            clipboard.Text = itemPathLabel.Text;
#else
            System.Windows.Clipboard.SetText(ItemPathLabel.Text);
#endif
        }
Beispiel #20
0
        protected void OnInsertQueryOnClipboard()
        {
            TableNode           node           = CurrentNode.DataItem as TableNode;
            IEditSchemaProvider schemaProvider = (IEditSchemaProvider)node.ConnectionContext.SchemaProvider;

            Gtk.Clipboard clp = Clipboard.Get(Gdk.Selection.Clipboard);
            clp.Text = schemaProvider.GetInsertQuery(node.Table);
            MessageService.ShowMessage(AddinCatalog.GetString("INSERT INTO Statement has been copied to Clipboard."));
        }
 protected void clipboardTextReceived(Clipboard clipboard, string text)
 {
     try{
         XmlTextReader reader = new XmlTextReader(new StringReader(text));
         KMLDistance myKmlDistance = new KMLDistance(reader);
         fillDistancesToTreeview(myKmlDistance);
     }catch{
     }
 }
 public void ClipboardGetFunc(Clipboard clipboard, SelectionData selection_data, uint info)
 {
     if (selection_data == null)
         return;
     switch (info) {
         case TextType:
             selection_data.Text = Utils.ToNormalString (lyrics_text);
             break;
     }
 }
Beispiel #23
0
 protected void OnButton3Clicked(object sender, EventArgs e)
 {
     try {
         //set the expression into the clipboard
         Gtk.Clipboard clipboard = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
         string        content   = g_selection;
         clipboard.SetText(content);
     } catch {
     }
 }
Beispiel #24
0
    public void Copy(object obj, EventArgs args)
    {
        Gdk.Atom      _atom      = Gdk.Atom.Intern("CLIPBOARD", false);
        Gtk.Clipboard _clipBoard = Gtk.Clipboard.Get(_atom);

        if (pixBuf != null)
        {
            _clipBoard.Image = pixBuf;
        }
    }
Beispiel #25
0
        protected void OnTogglebutton1Clicked(object sender, EventArgs e)
        {
            try {
                Gtk.Clipboard clipboard = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));

                string content = g_selection;
                clipboard.SetText(content);
            } catch {
            }
        }
Beispiel #26
0
        static void completecrop(string finalString)
        {
            int startx = Convert.ToInt32((upx < downx) ? upx : downx);
            int starty = Convert.ToInt32((upy < downy) ? upy : downy);
            int sizex  = Convert.ToInt32((upx > downx) ? (upx - downx) : (downx - upx));
            int sizey  = Convert.ToInt32((upy > downy) ? (upy - downy) : (downy - upy));

            cropAtRect(System.Drawing.Image.FromFile(finalString.Replace(".png", "_pre.png")), new System.Drawing.Rectangle(new System.Drawing.Point(startx, starty), new System.Drawing.Size(sizex, sizey))).Save(configpath + finalString);

            win.HideAll();

            try
            {
                var request = (FtpWebRequest)WebRequest.Create(File.ReadAllText(configpath + "ftpdir.txt").Replace("imagename", finalString));
                request.Method = WebRequestMethods.Ftp.UploadFile;

                request.Credentials = new NetworkCredential(File.ReadAllText(configpath + "ftpuser.txt"), File.ReadAllText(configpath + "ftppass.txt"));

                var fileContents = File.ReadAllBytes(configpath + finalString);
                request.ContentLength = fileContents.Length;

                var requestStream = request.GetRequestStream();
                requestStream.Write(fileContents, 0, fileContents.Length);
                requestStream.Close();

                var link     = File.ReadAllText(configpath + "serverlink.txt").Replace("imagename", finalString);
                var response = (FtpWebResponse)request.GetResponse();

                var proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName               = "/usr/bin/notify-send";
                proc.StartInfo.Arguments              = ("'Screenshot Get!' '" + link + "' --icon=dialog-information");
                proc.StartInfo.UseShellExecute        = false;
                proc.StartInfo.RedirectStandardOutput = false;
                proc.Start();

                Gtk.Clipboard clipboard = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));

                clipboard.Text = link;

                requestStream.Dispose();
                response.Close();
            }
            catch (Exception ex)
            {
                File.WriteAllText(configpath + "log.log", ex.Message);
                var proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName               = "/usr/bin/notify-send";
                proc.StartInfo.Arguments              = ("'Error while uploading!' 'Please try again!' --icon=dialog-error");
                proc.StartInfo.UseShellExecute        = false;
                proc.StartInfo.RedirectStandardOutput = false;
                proc.Start();
            }
            Application.Quit();
        }
Beispiel #27
0
		public ClippyItem ()
		{
			Icon = "edit-cut";

			if (trackMouseSelections)
				clipboard = Gtk.Clipboard.Get (Gdk.Selection.Primary);
			else
				clipboard = Gtk.Clipboard.Get (Gdk.Selection.Clipboard);

			timer = GLib.Timeout.Add (timerDelay, CheckClipboard);
			Updated ();
		}
Beispiel #28
0
 /// <summary>
 /// Copy textview content to a clipboard
 /// </summary>
 /// <param name='sender'>
 /// Sender.
 /// </param>
 /// <param name='e'>
 /// E.
 /// </param>
 protected virtual void OnActionCopyActivated(object sender, System.EventArgs e)
 {
     if (lsTasksSelected != null)
     {
         if (lsTasksSelected.Count > 0)
         {
             Gtk.Clipboard cb = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", true));
             cb.Text = TasksToText(lsTasksSelected);
             cb.Store();
         }
     }
 }
Beispiel #29
0
        void CopyButton_Clicked(object?sender, EventArgs e)
        {
            String delimeter = ",";
            String linesep   = Environment.NewLine;

            StringBuilder vinfo = new StringBuilder();
            //copy the version information is 'csv style'
            TreeIter iter;

            if (!treeView.Model.GetIterFirst(out iter))
            {
                return;
            }

            //do headers
            for (int col = 0; col < treeView.Model.NColumns; col++)
            {
                if (col != 0)
                {
                    vinfo.Append(delimeter);
                }

                vinfo.Append(treeView.GetColumn(col).Title);
            }

            vinfo.Append(linesep);


            do
            {
                for (int col = 0; col < treeView.Model.NColumns; col++)
                {
                    String val = (string)treeView.Model.GetValue(iter, col);
                    if (col != 0)
                    {
                        vinfo.Append(delimeter);
                    }

                    vinfo.Append(val);
                }

                vinfo.Append(linesep);
            } while (treeView.Model.IterNext(ref iter));



            if (vinfo.Length > 0)
            {
                Gtk.Clipboard clipboard = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
                clipboard.Text = vinfo.ToString();
            }
        }
Beispiel #30
0
 //Copy stream URL to Clipboard
 protected void Url(object sender, EventArgs e)
 {
     if (cbox.Active == -1)
     {
     }
     else
     {
         string        stream    = cbox.ActiveText;
         Gtk.Clipboard clipboard = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
         clipboard.Text = "http://localhost:9980/renter/stream/" + stream;
         txt.Text       = "http://localhost:9980/renter/stream/" + stream;
     }
 }
Beispiel #31
0
        public override bool Load()
        {
            clipboard = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", true));
            dataBook  = (DataBook)GetDataBook(mainWindow);

            Preferences.Proxy.Subscribe("CopyOffset.NumberBase", "co",
                                        new PreferencesChangedHandler(OnPreferencesChanged));

            AddActions(uiManager);

            loaded = true;
            return(true);
        }
Beispiel #32
0
        /// <summary>
        /// Gets complex data from item and sets as content when requested.
        /// </summary>
        /// <param name="clipboard">Clipboard.</param>
        /// <param name="selectionData">Selection data.</param>
        /// <param name="info">Target index.</param>
        internal void GetDataFunc(Gtk.Clipboard clipboard, SelectionData selectionData, uint info)
        {
            switch (info)
            {
            case 0:
                selectionData.Set(this.Target, 8, this.Data);
                break;

            case 1:
            default:
                selectionData.Set(Targets.Atoms[Targets.UtfString], 8, this.DataText);
                break;
            }
        }
Beispiel #33
0
 /// <summary>
 /// Creates clipboard object.
 /// </summary>
 private Clipboard()
 {
     this.timerLock = new object();
     this.KeyboardItem = null;
     this.MouseItem = null;
     this.Items = new ItemsCollection();
     this.keyboardClipboard = Gtk.Clipboard.Get(Gdk.Selection.Clipboard);
     this.keyboardClipboard.OwnerChange += this.OnKeyboardClipboardOwnerChanged;
     this.mouseClipboard = Gtk.Clipboard.Get(Gdk.Selection.Primary);
     this.mouseClipboard.OwnerChange += this.OnMouseClipboardOwnerChanged;
     this.pixbufFormats = Pixbuf.Formats;
     this.OnKeyboardClipboardOwnerChanged(this, null);
     this.OnMouseClipboardOwnerChanged(this, null);
 }
Beispiel #34
0
 /// <summary>
 /// Creates clipboard object.
 /// </summary>
 private Clipboard()
 {
     this.timerLock                      = new object();
     this.KeyboardItem                   = null;
     this.MouseItem                      = null;
     this.Items                          = new ItemsCollection();
     this.keyboardClipboard              = Gtk.Clipboard.Get(Gdk.Selection.Clipboard);
     this.keyboardClipboard.OwnerChange += this.OnKeyboardClipboardOwnerChanged;
     this.mouseClipboard                 = Gtk.Clipboard.Get(Gdk.Selection.Primary);
     this.mouseClipboard.OwnerChange    += this.OnMouseClipboardOwnerChanged;
     this.pixbufFormats                  = Pixbuf.Formats;
     this.OnKeyboardClipboardOwnerChanged(this, null);
     this.OnMouseClipboardOwnerChanged(this, null);
 }
Beispiel #35
0
    protected void on_copyAction_Activated(object sender, EventArgs e)
    {
        Gtk.Clipboard clipboard = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));

        Widget widget = this.Focus;

        if (widget.GetType().IsAssignableFrom(typeof(TextView)))
        {
            clipboard.Text = ((TextView)widget).Buffer.GetSelectedText();
        }
        else if (widget.GetType().IsAssignableFrom(typeof(Entry)))
        {
            clipboard.Text = ((Entry)widget).GetSelectedText();
        }
    }
Beispiel #36
0
        private void HandlerPintaCoreActionsEditCutActivated(object sender, EventArgs e)
        {
            Gtk.Clipboard cb = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
            if (PintaCore.Tools.CurrentTool.TryHandleCut(cb))
            {
                return;
            }
            PintaCore.Tools.Commit();

            // Copy selection
            HandlerPintaCoreActionsEditCopyActivated(sender, e);

            // Erase selection
            HandlePintaCoreActionsEditEraseSelectionActivated("Cut", e);
        }
		private void ReceivedFunc(Clipboard clipboard, SelectionData selection) {
			string temp = Encoding.ASCII.GetString(selection.Data);
			if (temp==null) return;
			
			string[] items = temp.Split('\n', '\r');
			List<Uri> paths = new List<Uri>(items.Length);
			for(int i = 1; i < items.Length; ++i) {
				if(items[i] == string.Empty) continue;
				Uri fileFrom = new Uri(items[i]);
				paths.Add(fileFrom);
			}
			
			inData = new ClipboardData(paths, items[0] == "cut" ? ClipboardOperationType.Cut : ClipboardOperationType.Copy);
			evt(null, null);
		}
Beispiel #38
0
        public ClippyItem()
        {
            Icon = "edit-cut";

            if (trackMouseSelections)
            {
                clipboard = Gtk.Clipboard.Get(Gdk.Selection.Primary);
            }
            else
            {
                clipboard = Gtk.Clipboard.Get(Gdk.Selection.Clipboard);
            }

            timer = GLib.Timeout.Add(timerDelay, CheckClipboard);
            Updated();
        }
 public void ClipboardClearFunc(Clipboard clipboard)
 {
 }
		void OnGenTaskCopied (object o, EventArgs args)
		{
			Task task = SelectedTask;
			if (task != null) {
				clipboard = Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false));
				clipboard.Text = task.ToString ();
				clipboard = Clipboard.Get (Gdk.Atom.Intern ("PRIMARY", false));
				clipboard.Text = task.ToString ();
			}
		}
Beispiel #41
0
		void OnGenTaskCopied (object o, EventArgs args)
		{
			TaskListEntry task = SelectedTask;
			if (task != null) {
				clipboard = Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false));
				clipboard.Text = task.Description;
				clipboard = Clipboard.Get (Gdk.Atom.Intern ("PRIMARY", false));
				clipboard.Text = task.Description;
			}
		}
		static int PasteFrom (Clipboard clipboard, TextEditorData data, bool preserveSelection, int insertionOffset)
		{
			return PasteFrom (clipboard, data, preserveSelection, insertionOffset, false);
		}
			public void ClipboardGetFunc (Clipboard clipboard, SelectionData selection_data, uint info)
			{
				SetData (selection_data, info);
			}
		void OnUserTaskCopied (object o, EventArgs args)
		{
			Task task;
			TreeModel model;
			TreeIter iter;

			if (view.Selection.GetSelected (out model, out iter))
			{
				task = (Task) model.GetValue (iter, (int)Columns.UserTask);
			}
			else return; // no one selected

			clipboard = Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false));
			clipboard.Text = task.ToString ();
			clipboard = Clipboard.Get (Gdk.Atom.Intern ("PRIMARY", false));
			clipboard.Text = task.ToString ();
		}
Beispiel #45
0
 public override bool TryHandleCopy(Clipboard cb)
 {
     if (engine.EditMode == EditingMode.NotEditing) {
         return false;
     }
     engine.PerformCopy (cb);
     return true;
 }
Beispiel #46
0
        public override bool TryHandlePaste(Clipboard cb)
        {
            if (CurrentTextEngine.EditMode == EditingMode.NotEditing) {
                return false;
            }

            if (!CurrentTextEngine.PerformPaste (cb)) {
                return false;
            }
            RedrawText (true, true);
            return true;
        }
Beispiel #47
0
 public override bool TryHandleCut(Clipboard cb)
 {
     if (CurrentTextEngine.EditMode == EditingMode.NotEditing) {
         return false;
     }
     CurrentTextEngine.PerformCut (cb);
     RedrawText (true, true);
     return true;
 }
Beispiel #48
0
 public virtual bool TryHandlePaste(Clipboard cb)
 {
     return false;
 }
Beispiel #49
0
 public virtual bool TryHandleCopy(Clipboard cb)
 {
     return false;
 }
		internal void OnCopy ()
		{
			TreeModel model;
			StringBuilder txt = new StringBuilder ();
			foreach (Gtk.TreePath p in view.Selection.GetSelectedRows (out model)) {
				TreeIter it;
				if (!model.GetIter (out it, p))
					continue;
				LogMessage msg = (LogMessage) model.GetValue (it, (int) Columns.Message);
				if (txt.Length > 0)
					txt.Append ('\n');
				txt.AppendFormat ("{0} - {1} - {2}", msg.Level, msg.TimeStamp.ToLongTimeString (), msg.Message);
			}
			clipboard = Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false));
			clipboard.Text = txt.ToString ();
			clipboard = Clipboard.Get (Gdk.Atom.Intern ("PRIMARY", false));
			clipboard.Text = txt.ToString ();
		}
		public override void InitPlugin() {
			clip = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
		}
Beispiel #52
0
		static int PasteFrom (Clipboard clipboard, TextEditorData data, bool preserveSelection, int insertionOffset, bool preserveState)
		{
			int result = -1;
			if (!data.CanEdit (data.Document.OffsetToLineNumber (insertionOffset)))
				return result;
			clipboard.RequestContents (CopyOperation.MD_ATOM, delegate(Clipboard clp, SelectionData selectionData) {
				if (selectionData.Length > 0) {
					byte[] selBytes = selectionData.Data;

					string text = System.Text.Encoding.UTF8.GetString (selBytes, 1, selBytes.Length - 1);
					bool pasteBlock = (selBytes[0] & 1) == 1;
					bool pasteLine = (selBytes[0] & 2) == 2;
					if (!pasteBlock && !pasteLine)
						return;
					
					data.Document.BeginAtomicUndo ();
					if (preserveSelection && data.IsSomethingSelected)
						data.DeleteSelectedText ();
					
					data.Caret.PreserveSelection = true;
					if (pasteBlock) {
						string[] lines = text.Split ('\r');
						int lineNr = data.Document.OffsetToLineNumber (insertionOffset);
						int col = insertionOffset - data.Document.GetLine (lineNr).Offset;
						int visCol = data.Document.GetLine (lineNr).GetVisualColumn (data, col);
						LineSegment curLine;
						int lineCol = col;
						result = 0;
						for (int i = 0; i < lines.Length; i++) {
							while (data.Document.LineCount <= lineNr + i) {
								data.Insert (data.Document.Length, Environment.NewLine);
								result += Environment.NewLine.Length;
							}
							curLine = data.Document.GetLine (lineNr + i);
							if (lines[i].Length > 0) {
								lineCol = curLine.GetLogicalColumn (data, visCol);
								if (curLine.EditableLength + 1 < lineCol) {
									result += lineCol - curLine.EditableLength;
									data.Insert (curLine.Offset + curLine.EditableLength, new string (' ', lineCol - curLine.EditableLength));
								}
								data.Insert (curLine.Offset + lineCol, lines[i]);
								result += lines[i].Length;
							}
							if (!preserveState)
								data.Caret.Offset = curLine.Offset + lineCol + lines[i].Length;
						}
					} else if (pasteLine) {
						result += text.Length;
						LineSegment curLine = data.Document.GetLine (data.Caret.Line);
						data.Insert (curLine.Offset, text + data.EolMarker);
						if (!preserveState)
							data.Caret.Offset += text.Length + data.EolMarker.Length;
					}
					/*				data.MainSelection = new Selection (data.Document.OffsetToLocation (insertionOffset),
					                                    data.Caret.Location,
					                                    lines.Length > 1 ? SelectionMode.Block : SelectionMode.Normal);*/
					if (!preserveState)
						data.ClearSelection ();
					data.Caret.PreserveSelection = false;
					data.Document.EndAtomicUndo ();
				}
			});

			if (result < 0) {
				clipboard.WaitIsTextAvailable ();
				clipboard.RequestText (delegate(Clipboard clp, string text) {
					if (string.IsNullOrEmpty (text))
						return;
					data.Document.BeginAtomicUndo ();
					int caretPos = data.Caret.Offset;
					if (data.IsSomethingSelected && data.MainSelection.SelectionMode == SelectionMode.Block) {
						data.Caret.PreserveSelection = true;
						if (!data.MainSelection.IsDirty) {
							data.DeleteSelectedText (false);
							data.MainSelection.IsDirty = true;
						}
						int textLength = 0;
						int column = data.Caret.Column;
						int minLine = data.MainSelection.MinLine;
						int maxLine = data.MainSelection.MaxLine;
						for (int lineNumber = minLine; lineNumber <= maxLine; lineNumber++) {
							int offset = data.Document.GetLine (lineNumber).Offset + column;
							textLength = data.Insert (offset, text);
							data.PasteText (offset, text);
						}
						
						data.Caret.Offset += textLength;
						data.MainSelection.Anchor = new DocumentLocation (data.Caret.Line == minLine ? maxLine : minLine, data.Caret.Column - textLength);
						data.MainSelection.Lead = new DocumentLocation (data.Caret.Line, data.Caret.Column);
						data.Caret.PreserveSelection = false;
						data.Document.CommitMultipleLineUpdate (data.MainSelection.MinLine, data.MainSelection.MaxLine);
					} else {
						ISegment selection = data.SelectionRange;
						if (preserveSelection && data.IsSomethingSelected)
							data.DeleteSelectedText ();
						data.Caret.PreserveSelection = true;
						//int oldLine = data.Caret.Line;
						int textLength = data.Insert (insertionOffset, text);
						result = textLength;
	
						if (data.IsSomethingSelected && data.SelectionRange.Offset >= insertionOffset)
							data.SelectionRange.Offset += textLength;
						if (data.IsSomethingSelected && data.MainSelection.GetAnchorOffset (data) >= insertionOffset)
							data.MainSelection.Anchor = data.Document.OffsetToLocation (data.MainSelection.GetAnchorOffset (data) + textLength);
						
						data.Caret.PreserveSelection = false;
						if (!preserveState) {
							data.Caret.Offset += textLength;
						} else {
							if (caretPos >= insertionOffset)
								data.Caret.Offset += textLength;
							if (selection != null) {
								int offset = selection.Offset;
								if (offset >= insertionOffset)
									offset += textLength;
								data.SelectionRange = new Segment (offset, selection.Length);
							}
						}
						data.PasteText (insertionOffset, text);
					}
					data.Document.EndAtomicUndo ();
				});
			}
			
			return result;
		}
Beispiel #53
0
		static int PasteFrom (Clipboard clipboard, TextEditorData data, bool preserveSelection, int insertionOffset, bool preserveState)
		{
			int result = -1;
			if (!data.CanEdit (data.Document.OffsetToLineNumber (insertionOffset)))
				return result;
			if (clipboard.WaitIsTargetAvailable (CopyOperation.MD_ATOM)) {
				clipboard.RequestContents (CopyOperation.MD_ATOM, delegate(Clipboard clp, SelectionData selectionData) {
					if (selectionData.Length > 0) {
						byte[] selBytes = selectionData.Data;
	
						string text = System.Text.Encoding.UTF8.GetString (selBytes, 1, selBytes.Length - 1);
						bool pasteBlock = (selBytes [0] & 1) == 1;
						bool pasteLine = (selBytes [0] & 2) == 2;
						
						using (var undo = data.OpenUndoGroup ()) {
							if (preserveSelection && data.IsSomethingSelected)
								data.DeleteSelectedText ();
							
							data.Caret.PreserveSelection = true;
							if (pasteBlock) {
								string[] lines = text.Split ('\r');
								int lineNr = data.Document.OffsetToLineNumber (insertionOffset);
								int col = insertionOffset - data.Document.GetLine (lineNr).Offset;
								int visCol = data.Document.GetLine (lineNr).GetVisualColumn (data, col);
								DocumentLine curLine;
								int lineCol = col;
								result = 0;
								for (int i = 0; i < lines.Length; i++) {
									while (data.Document.LineCount <= lineNr + i) {
										data.Insert (data.Document.TextLength, Environment.NewLine);
										result += Environment.NewLine.Length;
									}
									curLine = data.Document.GetLine (lineNr + i);
									if (lines [i].Length > 0) {
										lineCol = curLine.GetLogicalColumn (data, visCol);
										if (curLine.Length + 1 < lineCol) {
											result += lineCol - curLine.Length;
											data.Insert (curLine.Offset + curLine.Length, new string (' ', lineCol - curLine.Length));
										}
										data.Insert (curLine.Offset + lineCol, lines [i]);
										result += lines [i].Length;
									}
									if (!preserveState)
										data.Caret.Offset = curLine.Offset + lineCol + lines [i].Length;
								}
							} else if (pasteLine) {
								result = text.Length;
								DocumentLine curLine = data.Document.GetLine (data.Caret.Line);
								data.Insert (curLine.Offset, text + data.EolMarker);
							} else {
								int offset = data.Caret.Offset;
								data.InsertAtCaret (text);
								data.PasteText (offset, text, data.Caret.Offset - offset);
							}
							/*				data.MainSelection = new Selection (data.Document.OffsetToLocation (insertionOffset),
							                                    data.Caret.Location,
							                                    lines.Length > 1 ? SelectionMode.Block : SelectionMode.Normal);*/
							if (!preserveState)
								data.ClearSelection ();
							data.Caret.PreserveSelection = false;
						}
					}
				});
				// we got MD_ATOM text - no need to request text. (otherwise buffer may get copied twice).
				return result;
			}
			
			if (result < 0 && clipboard.WaitIsTextAvailable ()) {
				clipboard.RequestText (delegate(Clipboard clp, string text) {
					if (string.IsNullOrEmpty (text))
						return;
					using (var undo = data.OpenUndoGroup ()) {
						int caretPos = data.Caret.Offset;
						if (data.IsSomethingSelected && data.MainSelection.SelectionMode == SelectionMode.Block) {
							data.Caret.PreserveSelection = true;
							data.DeleteSelectedText (false);
							int textLength = 0;
							int minLine = data.MainSelection.MinLine;
							int maxLine = data.MainSelection.MaxLine;
							var visualInsertLocation = data.LogicalToVisualLocation (data.Caret.Location);
							for (int lineNumber = minLine; lineNumber <= maxLine; lineNumber++) {
								DocumentLine lineSegment = data.GetLine (lineNumber);
								int insertOffset = lineSegment.GetLogicalColumn (data, visualInsertLocation.Column) - 1;
								if (lineSegment.Length < insertOffset) {
									int visualLastColumn = lineSegment.GetVisualColumn (data, lineSegment.Length + 1);
									int charsToInsert = visualInsertLocation.Column - visualLastColumn;
									int spaceCount = charsToInsert % data.Options.TabSize;
									string textToInsert = new string ('\t', (charsToInsert - spaceCount) / data.Options.TabSize) + new string (' ', spaceCount) + text;
									insertOffset = lineSegment.Length;
									int insertedChars = data.Insert (lineSegment.Offset + insertOffset, textToInsert);
									data.PasteText (lineSegment.Offset + insertOffset, textToInsert, insertedChars);
								} else {
									textLength = data.Insert (lineSegment.Offset + insertOffset, text);
									data.PasteText (lineSegment.Offset + insertOffset, text, textLength);
								}
							}
							
							data.MainSelection.Anchor = new DocumentLocation (System.Math.Max (DocumentLocation.MinLine, data.Caret.Line == minLine ? maxLine : minLine), System.Math.Max (DocumentLocation.MinColumn, data.Caret.Column - textLength));
							data.MainSelection.Lead = new DocumentLocation (data.Caret.Line, data.Caret.Column);
							data.Caret.PreserveSelection = false;
							data.Document.CommitMultipleLineUpdate (data.MainSelection.MinLine, data.MainSelection.MaxLine);
						} else {
							TextSegment selection = data.SelectionRange;
							if (preserveSelection && data.IsSomethingSelected)
								data.DeleteSelectedText ();
							data.Caret.PreserveSelection = true;
							//int oldLine = data.Caret.Line;
							int textLength = data.Insert (insertionOffset, text);
							result = textLength;
		
							if (data.IsSomethingSelected && data.SelectionRange.Offset >= insertionOffset)
								data.SelectionRange = new TextSegment (data.SelectionRange.Offset + textLength, data.SelectionRange.Length);
							if (data.IsSomethingSelected && data.MainSelection.GetAnchorOffset (data) >= insertionOffset)
								data.MainSelection.Anchor = data.Document.OffsetToLocation (data.MainSelection.GetAnchorOffset (data) + textLength);
							
							data.Caret.PreserveSelection = false;
							if (!preserveState) {
							} else {
								if (!selection.IsInvalid) {
									int offset = selection.Offset;
									if (offset >= insertionOffset)
										offset += textLength;
									data.SelectionRange = new TextSegment (offset, selection.Length);
								}
							}
							data.PasteText (insertionOffset, text, textLength);
						}
					}
				});
			}
			
			return result;
		}
		void PasteReceived (Clipboard clipboard, string text)
		{
			pasteEntry.Text = text;
		}
Beispiel #55
0
		void OnTaskCopied (object o, EventArgs args)
		{
			Task task = SelectedTask;
			if (task != null) {
				StringBuilder text = new StringBuilder ();
				if (!string.IsNullOrEmpty (task.FileName)) {
					text.Append (task.FileName);
					if (task.Line >= 1) {
						text.Append ("(").Append (task.Column);
						if (task.Column >= 0)
							text.Append (",").Append (task.Column);
						text.Append (")");
					}
					text.Append (": ");
				}
				text.Append (task.Severity);
				if (!string.IsNullOrEmpty (task.Code)) {
					text.Append (" ").Append (task.Code);
				}
				text.Append (": ");
				text.Append (task.Description);
				if (task.WorkspaceObject != null)
					text.Append (" (").Append (task.WorkspaceObject.Name).Append (")");
				
				clipboard = Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false));
				clipboard.Text = text.ToString ();
				clipboard = Clipboard.Get (Gdk.Atom.Intern ("PRIMARY", false));
				clipboard.Text = text.ToString ();
			}
		}
Beispiel #56
0
		void CopyUserTaskClicked (object o, EventArgs args)
		{
			TaskListEntry task;
			TreeModel model;
			TreeIter iter;

			if (view.Selection.GetSelected (out model, out iter))
			{
				task = (TaskListEntry) model.GetValue (iter, (int)Columns.UserTask);
			}
			else return; // no one selected

			clipboard = Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false));
			clipboard.Text = task.Description;
			clipboard = Clipboard.Get (Gdk.Atom.Intern ("PRIMARY", false));
			clipboard.Text = task.Description;
		}
			public void ClipboardClearFunc (Clipboard clipboard)
			{
				// NOTHING ?
			}
Beispiel #58
0
		static int PasteFrom (Clipboard clipboard, TextEditorData data, bool preserveSelection, int insertionOffset, bool preserveState)
		{
			int result = -1;
			if (!data.CanEdit (data.Document.OffsetToLineNumber (insertionOffset)))
				return result;
			if (clipboard.WaitIsTargetAvailable (CopyOperation.MD_ATOM)) {
				clipboard.RequestContents (CopyOperation.MD_ATOM, delegate(Clipboard clp, SelectionData selectionData) {
					if (selectionData.Length > 0) {
						byte[] selBytes = selectionData.Data;
						var upperBound = System.Math.Max (0, System.Math.Min (selBytes [1], selBytes.Length - 2));
						byte[] copyData = new byte[upperBound];
						Array.Copy (selBytes, 2, copyData, 0, copyData.Length);
						var rawTextOffset = 1 + 1 + copyData.Length;
						string text = Encoding.UTF8.GetString (selBytes, rawTextOffset, selBytes.Length - rawTextOffset);
						bool pasteBlock = (selBytes [0] & 1) == 1;
						bool pasteLine = (selBytes [0] & 2) == 2;
						if (pasteBlock) {
							using (var undo = data.OpenUndoGroup ()) {
								var version = data.Document.Version;
								if (!preserveSelection)
									data.DeleteSelectedText (!data.IsSomethingSelected || data.MainSelection.SelectionMode != SelectionMode.Block);
								int startLine = data.Caret.Line;
								data.EnsureCaretIsNotVirtual ();
								insertionOffset = version.MoveOffsetTo (data.Document.Version, insertionOffset);

								data.Caret.PreserveSelection = true;
								var lines = new List<string> ();
								int offset = 0;
								while (true) {
									var delimiter = LineSplitter.NextDelimiter (text, offset);
									if (delimiter.IsInvalid)
										break;

									int delimiterEndOffset = delimiter.EndOffset;
									lines.Add (text.Substring (offset, delimiter.Offset - offset));
									offset = delimiterEndOffset;
								}
								if (offset < text.Length)
									lines.Add (text.Substring (offset, text.Length - offset));

								int lineNr = data.Document.OffsetToLineNumber (insertionOffset);
								int col = insertionOffset - data.Document.GetLine (lineNr).Offset;
								int visCol = data.Document.GetLine (lineNr).GetVisualColumn (data, col);
								DocumentLine curLine;
								int lineCol = col;
								result = 0;
								for (int i = 0; i < lines.Count; i++) {
									while (data.Document.LineCount <= lineNr + i) {
										data.Insert (data.Document.TextLength, Environment.NewLine);
										result += Environment.NewLine.Length;
									}
									curLine = data.Document.GetLine (lineNr + i);
									if (lines [i].Length > 0) {
										lineCol = curLine.GetLogicalColumn (data, visCol);
										if (curLine.Length + 1 < lineCol) {
											result += lineCol - curLine.Length;
											data.Insert (curLine.Offset + curLine.Length, new string (' ', lineCol - curLine.Length));
										}
										data.Insert (curLine.Offset + lineCol, lines [i]);
										result += lines [i].Length;
									}
									if (!preserveState)
										data.Caret.Offset = curLine.Offset + lineCol + lines [i].Length;
								}
								if (!preserveState)
									data.ClearSelection ();
								data.FixVirtualIndentation (startLine); 
								data.Caret.PreserveSelection = false;
							}
						} else if (pasteLine) {
							using (var undo = data.OpenUndoGroup ()) {
								if (!preserveSelection)
									data.DeleteSelectedText (!data.IsSomethingSelected || data.MainSelection.SelectionMode != SelectionMode.Block);
								data.EnsureCaretIsNotVirtual ();

								data.Caret.PreserveSelection = true;
								result = text.Length;
								DocumentLine curLine = data.Document.GetLine (data.Caret.Line);

								result = PastePlainText (data, curLine.Offset,  text + data.EolMarker, preserveSelection, copyData);
								if (!preserveState)
									data.ClearSelection ();
								data.Caret.PreserveSelection = false;
								data.FixVirtualIndentation (curLine.LineNumber); 
							}
						} else {
							result = PastePlainText (data, insertionOffset, text, preserveSelection, copyData);
						}
					}
				});
				// we got MD_ATOM text - no need to request text. (otherwise buffer may get copied twice).
				return result;
			}
			
			if (result < 0 && clipboard.WaitIsTextAvailable ()) {
				clipboard.RequestText (delegate(Clipboard clp, string text) {
					if (string.IsNullOrEmpty (text))
						return;
					result = PastePlainText (data, insertionOffset, text, preserveSelection);
				});
			}
			
			return result;
		}
		static int PasteFrom (Clipboard clipboard, TextEditorData data, bool preserveSelection, int insertionOffset, bool preserveState)
		{
			int result = -1;
			if (!data.CanEdit (data.Document.OffsetToLineNumber (insertionOffset)))
				return result;
			if (clipboard.WaitIsTargetAvailable (CopyOperation.MD_ATOM)) {
				clipboard.RequestContents (CopyOperation.MD_ATOM, delegate(Clipboard clp, SelectionData selectionData) {
					if (selectionData.Length > 0) {
						byte[] selBytes = selectionData.Data;
	
						string text = System.Text.Encoding.UTF8.GetString (selBytes, 1, selBytes.Length - 1);
						bool pasteBlock = (selBytes [0] & 1) == 1;
						bool pasteLine = (selBytes [0] & 2) == 2;
						
//						var clearSelection = data.IsSomethingSelected ? data.MainSelection.SelectionMode != SelectionMode.Block : true;
						if (pasteBlock) {
							using (var undo = data.OpenUndoGroup ()) {
								var version = data.Document.Version;
								data.DeleteSelectedText (!data.IsSomethingSelected || data.MainSelection.SelectionMode != SelectionMode.Block);
								data.EnsureCaretIsNotVirtual ();
								insertionOffset = version.MoveOffsetTo (data.Document.Version, insertionOffset);

								data.Caret.PreserveSelection = true;
							
								string[] lines = text.Split ('\r');
								int lineNr = data.Document.OffsetToLineNumber (insertionOffset);
								int col = insertionOffset - data.Document.GetLine (lineNr).Offset;
								int visCol = data.Document.GetLine (lineNr).GetVisualColumn (data, col);
								DocumentLine curLine;
								int lineCol = col;
								result = 0;
								for (int i = 0; i < lines.Length; i++) {
									while (data.Document.LineCount <= lineNr + i) {
										data.Insert (data.Document.TextLength, Environment.NewLine);
										result += Environment.NewLine.Length;
									}
									curLine = data.Document.GetLine (lineNr + i);
									if (lines [i].Length > 0) {
										lineCol = curLine.GetLogicalColumn (data, visCol);
										if (curLine.Length + 1 < lineCol) {
											result += lineCol - curLine.Length;
											data.Insert (curLine.Offset + curLine.Length, new string (' ', lineCol - curLine.Length));
										}
										data.Insert (curLine.Offset + lineCol, lines [i]);
										result += lines [i].Length;
									}
									if (!preserveState)
										data.Caret.Offset = curLine.Offset + lineCol + lines [i].Length;
								}
								if (!preserveState)
									data.ClearSelection ();
								data.Caret.PreserveSelection = false;
							}
						} else if (pasteLine) {
							using (var undo = data.OpenUndoGroup ()) {
								data.DeleteSelectedText (!data.IsSomethingSelected || data.MainSelection.SelectionMode != SelectionMode.Block);
								data.EnsureCaretIsNotVirtual ();

								data.Caret.PreserveSelection = true;
								result = text.Length;
								DocumentLine curLine = data.Document.GetLine (data.Caret.Line);
								data.Insert (curLine.Offset, text + data.EolMarker);
								if (!preserveState)
									data.ClearSelection ();
								data.Caret.PreserveSelection = false;
							}
						} else {
							result = PastePlainText (data, insertionOffset, text);
						}
					}
				});
				// we got MD_ATOM text - no need to request text. (otherwise buffer may get copied twice).
				return result;
			}
			
			if (result < 0 && clipboard.WaitIsTextAvailable ()) {
				clipboard.RequestText (delegate(Clipboard clp, string text) {
					if (string.IsNullOrEmpty (text))
						return;
					using (var undo = data.OpenUndoGroup ()) {
						result = PastePlainText (data, insertionOffset, text);
					}
				});
			}
			
			return result;
		}
Beispiel #60
0
 public override bool TryHandleCopy(Clipboard cb)
 {
     if (!is_editing) {
         return false;
     }
     CurrentTextEngine.PerformCopy (cb);
     return true;
 }