r7-labs / R7.Webmate

Desktop productivity toolbox
GNU General Public License v3.0
1 stars 1 forks source link

Clipboard watcher #4

Open roman-yagodin opened 4 years ago

roman-yagodin commented 4 years ago

Clipboard watcher updates paste buttons state depending on the content of the clipboard, so user will not need to guess which button to click.

Skeleton implementation:

void InitTimer ()
{
    var timer = new ThreadStart (() => {
        while (true) {
            Thread.Sleep (500);

            if (Clipboard.ContainsData (TransferDataType.Html)) {
                Application.Invoke (() => {
        // TODO: Check widget state before change it
        TextCleanerWidget.btnPasteHtml.Sensitive = true;
                });

                // Console.WriteLine ("Clipboard contains HTML.");
            }
            else {
                Application.Invoke (() => {
        // TODO: Check widget state before change it
                    TextCleanerWidget.btnPasteHtml.Sensitive = false;
                });
            }

            if (Clipboard.ContainsData (TransferDataType.Text)) {
                // Console.WriteLine ("Clipboard contains text.");
            }
        }
    });

    var timerThread = new Thread (timer);
    timerThread.Start ();
}