public EditPartWindow(EditPartViewModel viewModel)
        {
            InitializeComponent();

            this.DataContext = viewModel;

            Global.Dialogs.Register(this, viewModel);
        }
        public EditPartWindow(EditPartViewModel viewModel)
        {
            InitializeComponent();

            this.DataContext = viewModel;

            Global.Dialogs.Register(this, viewModel);
        }
        private void AddCustom(object param)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter      = Global.PdfFilter;
            openFileDialog.Multiselect = true;
            openFileDialog.ShowDialog(Global.Dialogs.GetWindow(this));
            foreach (var fileName in openFileDialog.FileNames)
            {
                if (string.IsNullOrWhiteSpace(fileName) || !File.Exists(fileName))
                {
                    continue;
                }

                bool          add  = true;
                PartViewModel part = null;

                if (openFileDialog.FileNames.Length == 1) // if there is only one pdf to add, open window to edit properties of it
                {
                    EditPartViewModel dialogViewModel = new EditPartViewModel(openFileDialog.FileName);
                    Global.Dialogs.ShowDialog(this, dialogViewModel);
                    if (dialogViewModel.Result != EditPartViewModel.EditPartResult.Ok)
                    {
                        add = false;
                    }
                    else
                    {
                        part = dialogViewModel.Part;
                    }
                }
                else // if more then just add it
                {
                    part = PartViewModel.MakeCustom(fileName);
                    File.Copy(fileName, part.CustomPath);
                }

                if (add)
                {
                    m_searchResults.Add(part);
                    m_savedParts.Add(part);
                    part.LastUseDate = DateTime.MinValue;

                    ActionDialogViewModel actionDialogViewModel = new ActionDialogViewModel(part.ComputePagesCount(), Global.GetStringResource("StringCountingPages"));
                    Global.Dialogs.ShowDialog(this, actionDialogViewModel);
                }
            }

            m_filteredResults.Refresh();
        }
        private async void RequestMoreInfo(object param)
        {
            if (m_selectedResult == null)
            {
                return;
            }
            if (m_selectedResult.MoreInfoState == PartMoreInfoState.Downloading)
            {
                return;
            }
            else if (m_selectedResult.MoreInfoState == PartMoreInfoState.Available)
            {
                m_selectedResult.PushCopy();
                EditPartViewModel dialogViewModel = new EditPartViewModel(m_selectedResult);
                Global.Dialogs.ShowDialog(this, dialogViewModel);
                if (dialogViewModel.Result == EditPartViewModel.EditPartResult.Ok)
                {
                    m_selectedResult.PopCopy(WorkingCopyResult.Apply);
                }
                else if (dialogViewModel.Result == EditPartViewModel.EditPartResult.Cancel)
                {
                    m_selectedResult.PopCopy(WorkingCopyResult.Restore);
                }
                return;
            }

            try
            {
                ActionsCount++;
                await m_selectedResult.RequestMoreInfo();
            }
            catch
            {
                Global.MessageBox(this, Global.GetStringResource("StringMoreInfoError"), MessageBoxExPredefinedButtons.Ok);
            }
            finally
            {
                ActionsCount--;
            }
        }
        private void AddCustom(object param)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = Global.GetStringResource("StringPdfFiles") + "|*.pdf";
            openFileDialog.ShowDialog(Global.Dialogs.GetWindow(this));
            if (!string.IsNullOrWhiteSpace(openFileDialog.FileName) && File.Exists(openFileDialog.FileName))
            {
                EditPartViewModel dialogViewModel = new EditPartViewModel(openFileDialog.FileName);
                Global.Dialogs.ShowDialog(this, dialogViewModel);
                if (dialogViewModel.Result == EditPartViewModel.EditPartResult.Ok)
                {
                    PartViewModel part = dialogViewModel.Part;
                    m_searchResults.Add(part);
                    m_savedParts.Add(part);
                    part.LastUseDate = DateTime.MinValue;

                    ActionDialogViewModel actionDialogViewModel = new ActionDialogViewModel(part.ComputePagesCount(), Global.GetStringResource("StringCountingPages"));
                    Global.Dialogs.ShowDialog(this, actionDialogViewModel);
                }

                m_filteredResults.Refresh();
            }
        }
        private async void RequestMoreInfo(object param)
        {
            if (m_selectedResult == null) return;
            if (m_selectedResult.MoreInfoState == PartMoreInfoState.Downloading) return;
            else if (m_selectedResult.MoreInfoState == PartMoreInfoState.Available)
            {
                m_selectedResult.PushCopy();
                EditPartViewModel dialogViewModel = new EditPartViewModel(m_selectedResult);
                Global.Dialogs.ShowDialog(this, dialogViewModel);
                if (dialogViewModel.Result == EditPartViewModel.EditPartResult.Ok) m_selectedResult.PopCopy(WorkingCopyResult.Apply);
                else if (dialogViewModel.Result == EditPartViewModel.EditPartResult.Cancel) m_selectedResult.PopCopy(WorkingCopyResult.Restore);
                return;
            }

            try
            {
                ActionsCount++;
                await m_selectedResult.RequestMoreInfo();
            }
            catch
            {
                Global.MessageBox(this, Global.GetStringResource("StringMoreInfoError"), MessageBoxExPredefinedButtons.Ok);
            }
            finally
            {
                ActionsCount--;
            }
        }