public new void Resize()
 {
     if (_provider != null)
     {
         _provider.ReOrganize();
     }
 }
        public void SetFeedbackProvider(FeedbackProvider provider)
        {
            _provider = provider;

            _provider
            .OnGoToReference(
                (file, line, column) => {
                if (GoToReference != null)
                {
                    GoToReference(this, new GoToReferenceArgs(new CodePosition(file, line, column)));
                }
            })
            .OnGoToType(
                (assembly, typename) => {
                var args = new GoToTypeArgs(assembly, typename);
                if (GoToType != null)
                {
                    GoToType(this, args);
                }
                return(args.Handled);
            })
            .OnDebugTest(
                (test) => {
                if (DebugTest != null)
                {
                    DebugTest(this, new DebugTestArgs(test));
                }
            })
            .OnCancelRun(
                () => {
                if (CancelRun != null)
                {
                    CancelRun(this, new EventArgs());
                }
            })
            .OnPrepareForFocus(
                () => {
                if (listViewFeedback.Items.Count > 0 && listViewFeedback.SelectedItems.Count == 0)
                {
                    listViewFeedback.Items[0].Selected = true;
                }
                listViewFeedback.Select();
                _provider.ReOrganize();
            })
            .OnClearList(
                () => {
                if (!isWindows())
                {
                    listViewFeedback.SelectedItems.Clear();
                }
                listViewFeedback.Items.Clear();
            })
            .OnClearBuilds(
                (project) => {
                if (!isWindows())
                {
                    listViewFeedback.SelectedItems.Clear();
                }
                foreach (ListViewItem listItem in listViewFeedback.Items)
                {
                    if (listItem.Tag.GetType() == typeof(CacheBuildMessage))
                    {
                        var item = (CacheBuildMessage)listItem.Tag;
                        if (project == null || item.Project.Equals(project))
                        {
                            listViewFeedback.Items.Remove(listItem);
                        }
                    }
                }
            })
            .OnIsInFocus(
                () => {
                if (Focused)
                {
                    return(true);
                }
                return(Controls.Cast <Control>().Any(control => control.Focused));
            })
            .OnUpdatePicture(
                (picture, state, information) => {
                if (pictureBoxWorking.ImageLocation != picture)
                {
                    pictureBoxWorking.ImageLocation = picture;
                    pictureBoxWorking.Refresh();
                }
                pictureBoxRed.Visible     = state == ImageStates.Red;
                pictureMoose.Visible      = state == ImageStates.Green;
                pictureBoxGray.Visible    = state == ImageStates.None;
                pictureBoxWorking.Visible = state == ImageStates.Progress;
                _toolTipProvider.SetToolTip(pictureBoxWorking, information);
            })
            .OnPrintMessage(
                (msg, color, normal) => {
                if (normal)
                {
                    label1.Font = new Font(label1.Font, FontStyle.Regular);
                }
                else
                {
                    label1.Font = new Font(label1.Font, FontStyle.Bold);
                }

                label1.Text      = msg;
                label1.ForeColor = Color.FromName(color);
                label1.Refresh();
            })
            .OnStoreSelected(
                () => {
                _selected = null;
                if (listViewFeedback.SelectedItems.Count == 1)
                {
                    _selected = listViewFeedback.SelectedItems[0].Tag;
                }
                listViewFeedback.SuspendLayout();
            })
            .OnRestoreSelected(
                (check) => {
                foreach (ListViewItem item in listViewFeedback.Items)
                {
                    if (check(item.Tag, _selected))
                    {
                        item.Selected = true;
                        break;
                    }
                }
                listViewFeedback.ResumeLayout();
                listViewFeedback.Refresh();
            })
            .OnAddItem(
                (type, message, color, tag) => {
                string[] placeBefore = null;
                if (type == "Build warning")
                {
                    placeBefore = new[] { "Build warning", "Test ignored" }
                }
                ;
                else if (type == "Test failed")
                {
                    placeBefore = new[] { "Test failed", "Build warning", "Test ignored" }
                }
                ;
                else if (type == "Test ignored")
                {
                    placeBefore = new[] { "Test ignored" }
                }
                ;
                var position = 0;
                if (placeBefore != null)
                {
                    position = getFirstItemPosition(placeBefore);
                }
                var item = listViewFeedback.Items.Insert(position, type);
                item.SubItems.Add(message);
                item.ForeColor = Color.FromName(color);
                item.Tag       = tag;

                /*if (isWindows()) {
                 *  if (selected != null && tag.GetType() == selected.GetType() && tag.Equals(selected))
                 *      item.Selected = true;
                 * }*/
            })
            .OnRemoveBuildItem(
                (check) => {
                foreach (ListViewItem item in listViewFeedback.Items)
                {
                    if (item.Tag.GetType() == typeof(CacheBuildMessage))
                    {
                        if (check((CacheBuildMessage)item.Tag))
                        {
                            item.Remove();
                            break;
                        }
                    }
                }
            })
            .OnRemoveTest(
                (check) => {
                foreach (ListViewItem item in listViewFeedback.Items)
                {
                    if (item.Tag.GetType() == typeof(CacheTestMessage))
                    {
                        if (check((CacheTestMessage)item.Tag))
                        {
                            item.Remove();
                            break;
                        }
                    }
                }
            })
            .OnSetSummary(
                (m) => {
                _toolTipProvider.SetToolTip(label1, m);
            })
            .OnExists(
                (check) => {
                foreach (ListViewItem item in listViewFeedback.Items)
                {
                    if (check(item.Tag))
                    {
                        return(true);
                    }
                }
                return(false);
            })
            .OnGetSelectedItem(
                () => {
                if (listViewFeedback.SelectedItems.Count == 0)
                {
                    return(null);
                }
                return(listViewFeedback.SelectedItems[0].Tag);
            })
            .OnGetWidth(() => this.Width);

            _provider.CanGoToTypes       = CanGoToTypes;
            _provider.ShowRunInformation = ShowRunInformation;
            _provider.CanDebug           = CanDebug;
            _provider.Initialize();
            _provider.PrintMessage(new UI.RunMessages(UI.RunMessageType.Normal, "Collecting source and project information..."));
        }
        public void SetFeedbackProvider(FeedbackProvider provider) {
            _provider = provider;

            _provider
                .OnGoToReference(
                    (file,line,column) => {
                        if (GoToReference != null)
                            GoToReference(this, new GoToReferenceArgs(new CodePosition(file, line, column)));
                    })
                .OnGoToType(
                    (assembly,typename) => {
                        var args = new GoToTypeArgs(assembly, typename);
                        if (GoToType != null)
                            GoToType(this, args);
                        return args.Handled;
                    })
                .OnDebugTest(
                    (test) => {
                        if (DebugTest != null)
                            DebugTest(this, new DebugTestArgs(test));
                    })
                .OnCancelRun(
                    () => { 
                        if (CancelRun != null)
                            CancelRun(this, new EventArgs());
                    })
                .OnPrepareForFocus(
                    () => {
                        if (listViewFeedback.Items.Count > 0 && listViewFeedback.SelectedItems.Count == 0)
                            listViewFeedback.Items[0].Selected = true;
                        listViewFeedback.Select();
                        _provider.ReOrganize();
                    })
                .OnClearList(
                    () => {
                        if (!isWindows())
                            listViewFeedback.SelectedItems.Clear();
                        listViewFeedback.Items.Clear();
                    })
                .OnClearBuilds(
                    (project) => {
                        if (!isWindows())
                            listViewFeedback.SelectedItems.Clear();
                        foreach (ListViewItem listItem in listViewFeedback.Items) {
                            if (listItem.Tag.GetType() == typeof(CacheBuildMessage)) {
                                var item = (CacheBuildMessage)listItem.Tag;
                                if (project == null || item.Project.Equals(project))
                                    listViewFeedback.Items.Remove(listItem);
                            }
                        }
                    })
                .OnIsInFocus(
                    () => {
                        if (Focused)
                            return true;
                        return Controls.Cast<Control>().Any(control => control.Focused);
                    })
                .OnUpdatePicture(
                    (picture, state, information) => {
                        if (pictureBoxWorking.ImageLocation != picture)
                        {
                            pictureBoxWorking.ImageLocation = picture;
                            pictureBoxWorking.Refresh();
                        }
                        pictureBoxRed.Visible = state == ImageStates.Red;
                        pictureMoose.Visible = state == ImageStates.Green;
                        pictureBoxGray.Visible = state == ImageStates.None;
                        pictureBoxWorking.Visible = state == ImageStates.Progress;
                        _toolTipProvider.SetToolTip(pictureBoxWorking, information);
                    })
                .OnPrintMessage(
                    (msg, color, normal) => {
                        if (normal)
                            label1.Font = new Font(label1.Font, FontStyle.Regular);
                        else
                            label1.Font = new Font(label1.Font, FontStyle.Bold);

                        label1.Text = msg;
                        label1.ForeColor = Color.FromName(color);
                        label1.Refresh();
                    })
                .OnStoreSelected(
                    () => {
                        _selected = null;
                        if (listViewFeedback.SelectedItems.Count == 1)
                            _selected = listViewFeedback.SelectedItems[0].Tag;
                        listViewFeedback.SuspendLayout();
                    })
                .OnRestoreSelected(
                    (check) => {
                        foreach (ListViewItem item in listViewFeedback.Items) {
                            if (check(item.Tag, _selected)) {
                                item.Selected = true;
                                break;
                            }
                        }
                        listViewFeedback.ResumeLayout();
                        listViewFeedback.Refresh();
                    })
                .OnAddItem(
                    (type, message, color, tag) => {
                        string[] placeBefore = null;
                        if (type == "Build warning")
                            placeBefore = new[] { "Build warning", "Test ignored" };
                        else if (type == "Test failed")
                            placeBefore = new[] { "Test failed", "Build warning", "Test ignored" };
                        else if (type == "Test ignored")
                            placeBefore = new[] { "Test ignored" };
                        var position = 0;
                        if (placeBefore != null)
                            position = getFirstItemPosition(placeBefore);
                        var item = listViewFeedback.Items.Insert(position, type);
                        item.SubItems.Add(message);
                        item.ForeColor = Color.FromName(color);
                        item.Tag = tag;
                        /*if (isWindows()) {
                            if (selected != null && tag.GetType() == selected.GetType() && tag.Equals(selected))
                                item.Selected = true;
                        }*/
                    })
                .OnRemoveBuildItem(
                    (check) => {
                        foreach (ListViewItem item in listViewFeedback.Items) {
                            if (item.Tag.GetType() == typeof(CacheBuildMessage)) {
                                if (check((CacheBuildMessage)item.Tag)) {
                                    item.Remove();
                                    break;
                                }
                            }
                        }
                    })
                .OnRemoveTest(
                    (check) => {
                        foreach (ListViewItem item in listViewFeedback.Items) {
                            if (item.Tag.GetType() == typeof(CacheTestMessage)) {
                                if (check((CacheTestMessage)item.Tag)) {
                                    item.Remove();
                                    break;
                                }
                            }
                        }
                    })
                .OnSetSummary(
                    (m) => {
                        _toolTipProvider.SetToolTip(label1, m);
                    })
                .OnExists(
                    (check) => {
                        foreach (ListViewItem item in listViewFeedback.Items) {
                            if (check(item.Tag))
                                return true;
                        }
                        return false;
                    })
                .OnGetSelectedItem(
                    () => {
                        if (listViewFeedback.SelectedItems.Count == 0)
                            return null;
                        return listViewFeedback.SelectedItems[0].Tag;
                    })
                .OnGetWidth(() => this.Width);

            _provider.CanGoToTypes = CanGoToTypes;
            _provider.ShowRunInformation = ShowRunInformation;
            _provider.CanDebug = CanDebug;
            _provider.Initialize();
            _provider.PrintMessage(new UI.RunMessages(UI.RunMessageType.Normal, "Collecting source and project information..."));			
        }