Example #1
0
        private void _miRestore_Click(object sender, RoutedEventArgs e)
        {
            BackupView view = _listView.SelectedItem as BackupView;

            if (view != null)
            {
                ProgressDialog dialog = new ProgressDialog("Restoring databases...", "Restoring...");
                dialog.Loaded += delegate {
                    IsEnabled = false;

                    GrfThread.Start(delegate {
                        try {
                            BackupEngine.Instance.Restore(view.BackupDate);
                            dialog.Dispatch(p => p.Terminate());
                            this.Dispatch(p => p.IsEnabled = true);
                            ErrorHandler.HandleException("Successfully restored to " + view.Date + ". Reload your database for the changes to take effect.", ErrorLevel.NotSpecified);
                        }
                        catch (Exception err) {
                            dialog.Dispatch(p => p.Terminate());
                            this.Dispatch(p => p.IsEnabled = true);
                            ErrorHandler.HandleException(err);
                        }
                    });
                };

                dialog.ShowDialog();
            }
        }
        private void _sbFrameIndex_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            lock (_lock) {
                _pending++;
            }

            OnAnimationPlaying(0);

            GrfThread.Start(delegate {
                int max = 20;

                while (max-- > 0)
                {
                    if (e.LeftButton == MouseButtonState.Pressed)
                    {
                        return;
                    }

                    Thread.Sleep(100);
                }

                // Resets the mouse operations to 0
                lock (_lock) {
                    _pending = 0;
                }
            });
        }
Example #3
0
        private void _filter(object sender)
        {
            string currentSearch = _searchItemsFilter;

            IsFiltering = true;
            _validateLoaded();
            GrfThread.Start(() => _filterInternal(currentSearch), "CDEditor - Search filter items thread");
        }
Example #4
0
        private void _reloadDatabase(bool alreadyAsync)
        {
            try {
                if (!alreadyAsync)
                {
                    AProgress.Init(this);
                    _mainTabControl.Dispatch(p => p.IsEnabled = false);
                }

                _debugList.Dispatch(p => _debugItems.Clear());
                _debugList.Dispatch(p => ((TabItem)_mainTabControl.Items[1]).Header = new DisplayLabel {
                    DisplayText = "Error console", FontWeight = FontWeights.Bold
                });
                _clientDatabase.Reload(this);
                _delayedReloadDatabase = false;
            }
            catch (OperationCanceledException) {
                _mainTabControl.Dispatch(p => p.SelectedIndex = 0);
                _delayedReloadDatabase = true;
                GrfThread.Start(delegate {
                    Thread.Sleep(300);
                    _mainTabControl.Dispatch(p => Keyboard.Focus(_tviItemDb.TextBoxItem));
                });
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
                _mainTabControl.Dispatch(p => p.SelectedIndex = 0);
                _delayedReloadDatabase = true;
                GrfThread.Start(delegate {
                    Thread.Sleep(300);
                    _mainTabControl.Dispatch(p => Keyboard.Focus(_tviItemDb.TextBoxItem));
                });
            }
            finally {
                if (!alreadyAsync)
                {
                    AProgress.Finalize(this);
                    _mainTabControl.Dispatch(p => p.IsEnabled = true);
                }

                _debugList.Dispatch(delegate {
                    if (_debugItems.Count > 0)
                    {
                        _debugList.Dispatch(p => ((TabItem)_mainTabControl.Items[1]).Header = new DisplayLabel {
                            DisplayText = "Error console *", FontWeight = FontWeights.Bold
                        });
                        _debugList.ScrollIntoView(_debugItems.Last());
                        ((TabItem)_mainTabControl.Items[1]).IsSelected = true;
                    }
                });
            }
        }
Example #5
0
 private void _selectLastSelected(bool executed)
 {
     if (executed)
     {
     }
     else
     {
         if (_listView.SelectedItem != null)
         {
             GrfThread.Start(() => _listView.Dispatch(p => p.ScrollToCenterOfView(_listView.SelectedItem)));
         }
     }
 }
        private void _play_Click(object sender, RoutedEventArgs e)
        {
            _play.Dispatch(delegate {
                _play.IsPressed         = !_play.IsPressed;
                _sbFrameIndex.IsEnabled = !_play.IsPressed;
                _updatePlay();
            });

            if (_play.Dispatch(() => _play.IsPressed))
            {
                GrfThread.Start(_playAnimation);
            }
        }
        private void _filter(object sender, Action finished)
        {
            if (!_filterEnabled)
            {
                return;
            }

            string currentSearch = _searchItemsFilter;

            IsFiltering = true;
            _validateLoaded();
            GrfThread.Start(() => _filterInternal(currentSearch, finished), "SDEditor - Search filter items thread");
        }
        private void _setListing(string s)
        {
            if (!_eventsEnabled)
            {
                return;
            }

            if (String.IsNullOrEmpty(s))
            {
                s = "/";
            }

            _eventsEnabled = false;
            GrfThread.Start(() => _setListingSub(s));
        }
Example #9
0
        /// <summary>
        /// Clears the temporary files, this method is different than GRFE's (and it is better).
        /// </summary>
        public static void ClearTemporaryFiles()
        {
            GrfThread.Start(delegate {
                int errorCount = 0;

                // Clear root files only
                if (Directory.Exists(GrfPath.Combine(SdeAppConfiguration.ProgramDataPath, "~tmp")))
                {
                    foreach (string file in Directory.GetFiles(GrfPath.Combine(SdeAppConfiguration.ProgramDataPath, "~tmp"), "*", SearchOption.TopDirectoryOnly))
                    {
                        if (!GrfPath.Delete(file))
                        {
                            errorCount++;
                        }

                        if (errorCount > 20)
                        {
                            break;
                        }
                    }

                    // There will be no files in the temporary folder anymore
                    foreach (var directory in Directory.GetDirectories(GrfPath.Combine(SdeAppConfiguration.ProgramDataPath, "~tmp"), "*"))
                    {
                        string folderName = Path.GetFileName(directory);
                        int processId;

                        if (Int32.TryParse(folderName, out processId))
                        {
                            try {
                                Process.GetProcessById(processId);
                                // Do not bother if the process exists, even if it's not SDE
                            }
                            catch (ArgumentException) {
                                // The process is not running
                                try {
                                    Directory.Delete(directory, true);
                                }
                                catch { }
                            }
                            catch {
                                // Do nothing
                            }
                        }
                    }
                }
            }, "GRF - TemporaryFilesManager cleanup");
        }
Example #10
0
        protected override void OnClosing(CancelEventArgs e)
        {
            if (_allowClosing2)
            {
                return;
            }

            if (!_allowClosing)
            {
                e.Cancel = true;
            }
            else
            {
                _allowClosing2 = true;
                e.Cancel       = true;

                GrfThread.Start(delegate {
                    Thread.Sleep(350);
                    this.Dispatch(p => p.Close());
                });
            }
        }
Example #11
0
 public void Start()
 {
     GrfThread.Start(_start);
 }
Example #12
0
        public static void Edit(Window dialog, TextBox tb, Button button)
        {
            IInputWindow inputWindow = (IInputWindow)dialog;

            bool isScript = dialog is ScriptEditDialog && SdeAppConfiguration.UseIntegratedDialogsForScripts;
            bool isLevel  = dialog is LevelEditDialog && SdeAppConfiguration.UseIntegratedDialogsForLevels;
            bool isFlag   = dialog is GenericFlagDialog && SdeAppConfiguration.UseIntegratedDialogsForFlags;
            bool isJob    = dialog is JobEditDialog && SdeAppConfiguration.UseIntegratedDialogsForJobs;
            bool isTime   = dialog is TimeEditDialog && SdeAppConfiguration.UseIntegratedDialogsForTime;
            bool isRate   = dialog is RateEditDialog;
            bool isOther  = !(dialog is ScriptEditDialog || dialog is LevelEditDialog || dialog is GenericFlagDialog || dialog is JobEditDialog || dialog is TimeEditDialog) && SdeAppConfiguration.UseIntegratedDialogsForFlags;

            if (isScript || isLevel || isFlag || isJob || isTime || isRate || isOther)
            {
                inputWindow.Footer.Visibility = Visibility.Collapsed;
                dialog.WindowStyle            = WindowStyle.None;
                var content = dialog.Content;

                Border border = new Border {
                    BorderBrush = Brushes.Black, BorderThickness = new Thickness(1)
                };
                dialog.Content = null;
                border.Child   = content as UIElement;
                dialog.Content = border;

                dialog.Owner = null;

                Extensions.SetMinimalSize(dialog);
                dialog.ResizeMode = ResizeMode.NoResize;

                Point p   = button.PointToScreen(new Point(0, 0));
                var   par = WpfUtilities.FindParentControl <Window>(button);

                dialog.Loaded += delegate {
                    if (dialog == null)
                    {
                        return;
                    }

                    button.IsEnabled             = false;
                    dialog.WindowStartupLocation = WindowStartupLocation.Manual;

                    dialog.Left = p.X - dialog.MinWidth + button.ActualWidth;
                    dialog.Top  = p.Y + button.ActualHeight;

                    if (dialog.Left < 0)
                    {
                        dialog.Left = 0;
                    }

                    if (dialog.Top + dialog.Height > SystemParameters.WorkArea.Bottom)
                    {
                        dialog.Top = p.Y - dialog.MinHeight;
                    }

                    if (dialog.Top < 0)
                    {
                        dialog.Top = 0;
                    }

                    dialog.Owner = par;
                };

                inputWindow.ValueChanged += () => tb.Text = inputWindow.Text;
                dialog.Closed            += delegate {
                    button.IsEnabled = true;
                };
                dialog.Deactivated += (sender, args) => GrfThread.Start(() => dialog.Dispatch(() => Debug.Ignore(dialog.Close)));

                dialog.Show();
            }
            else
            {
                dialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;

                Extensions.SetMinimalSize(dialog);

                dialog.Loaded += delegate {
                    dialog.SizeToContent = SizeToContent.Manual;
                    dialog.Left          = dialog.Owner.Left + (dialog.Owner.Width - dialog.MinWidth) / 2;
                    dialog.Top           = dialog.Owner.Top + (dialog.Owner.Height - dialog.MinHeight) / 2;
                };

                dialog.Owner = WpfUtilities.FindParentControl <Window>(button);

                if (dialog.ShowDialog() == true)
                {
                    tb.Text = ((IInputWindow)dialog).Text;
                }
            }
        }
        private void _sbFrameIndex_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (_act == null)
            {
                lock (_lock) {
                    _pending--;
                }
                return;
            }

            Point position = e.GetPosition(_sbFrameIndex);

            bool isLeft   = position.X > 0 && position.Y > 0 && position.Y < _sbFrameIndex.ActualHeight && position.X < SystemParameters.HorizontalScrollBarButtonWidth;
            bool isRight  = position.X > (_sbFrameIndex.ActualWidth - SystemParameters.HorizontalScrollBarButtonWidth) && position.Y > 0 && position.Y < _sbFrameIndex.ActualHeight && position.X < _sbFrameIndex.ActualWidth;
            bool isWithin = position.X > 0 && position.Y > 0 && position.X < _sbFrameIndex.ActualWidth && position.Y < _sbFrameIndex.ActualHeight;

            if (isWithin)
            {
                OnAnimationPlaying(2);
            }

            if (!isLeft && !isRight)
            {
                lock (_lock) {
                    _pending--;
                }
                return;
            }

            GrfThread.Start(delegate {
                int count = 0;
                while (this.Dispatch(() => Mouse.LeftButton) == MouseButtonState.Pressed)
                {
                    _sbFrameIndex.Dispatch(delegate {
                        position = e.GetPosition(_sbFrameIndex);

                        isLeft  = position.X > 0 && position.Y > 0 && position.Y < _sbFrameIndex.ActualHeight && position.X < SystemParameters.HorizontalScrollBarButtonWidth;
                        isRight = position.X > (_sbFrameIndex.ActualWidth - SystemParameters.HorizontalScrollBarButtonWidth) && position.Y > 0 && position.Y < _sbFrameIndex.ActualHeight && position.X < _sbFrameIndex.ActualWidth;
                    });

                    if (isLeft)
                    {
                        SelectedFrame--;
                        if (SelectedFrame < 0)
                        {
                            SelectedFrame = _act[SelectedAction].NumberOfFrames - 1;
                        }
                    }

                    if (isRight)
                    {
                        SelectedFrame++;
                        if (SelectedFrame >= _act[SelectedAction].NumberOfFrames)
                        {
                            SelectedFrame = 0;
                        }
                    }

                    _sbFrameIndex.Dispatch(p => p.Value = SelectedFrame);

                    Thread.Sleep(count == 0 ? 400 : 50);

                    lock (_lock) {
                        if (_pending > 0)
                        {
                            _pending--;
                            return;
                        }
                    }

                    count++;
                }
            });

            e.Handled = true;
        }
Example #14
0
 public void SelectInternalQuiet <TKey>(ServerDbs tabName, List <TKey> tuplesGen)
 {
     GrfThread.Start(() => _selectInternal(tabName, tuplesGen, false), "TabNavigationEngine - Select tuple");
 }