private void AnimateFilter()
        {
            double from = filterShown ? 0 : gdFilter.RenderSize.Height;
            double to   = filterShown ? gdFilter.RenderSize.Height : 0;

            VisualHelpers.GenerateDoubleAnimation(from, to, show_duration, gdFilter, HeightProperty, new System.Windows.Media.Animation.QuadraticEase()).Begin();
        }
 public SaveStateDisplayer()
 {
     timer                      = new Timer(delay);
     timer.Elapsed             += Animate;
     timer.AutoReset            = false;
     fadeto                     = VisualHelpers.GenerateDoubleAnimation(1, 0, fade_duration, this, OpacityProperty, new QuadraticEase());
     fadeto.Completed          += FadeToDone;
     fadefrom                   = VisualHelpers.GenerateDoubleAnimation(0, 1, fade_duration, this, OpacityProperty, new QuadraticEase());
     fadefrom.Completed        += FadeFromDone;
     App.Data.SaveStateChanged += SaveStateChanged;
     SaveStateChanged();
 }
 private bool DoUnsavedDialog()
 {
     if (App.Data.Unsaved)
     {
         bool?result = VisualHelpers.UnsavedDialog();
         if (result == true)
         {
             SaveFile(null, null);
         }
         return(result != null);
     }
     return(true);
 }
        public void OpenFile(object sender, ExecutedRoutedEventArgs e)
        {
            bool?save = VisualHelpers.UnsavedDialog();

            if (DoUnsavedDialog())
            {
                string fpath = OpenFileDialogHelper();
                if (fpath != null && fpath != App.FilePath)
                {
                    //ClearData();
                    LoadData(fpath, owner: ParentWindow);
                }
            }
        }
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     foreach (TabItem tab in GetMainPage().tcMainTabControl.Items)
     {
         if (!(tab is DataClassTabItem))
         {
             if (VisualHelpers.ShowWarningBox("Data has not been saved. Close Window?", "Data Unsaved") == MessageBoxResult.Cancel)
             {
                 e.Cancel = true;
             }
         }
         return;
     }
 }
        private void ExecuteDeleteItem(object sender, ExecutedRoutedEventArgs e)
        {
            int    num_sel  = dgMainDataGrid.SelectedItems.Count;
            string conf_str = num_sel == 1 ? $"'{((BaseDataClass)dgMainDataGrid.SelectedItem).Name}'" : $"{num_sel} {DataType.Name.Pluralize()}";

            if (VisualHelpers.ShowWarningBox("Are you sure you want to delete " + conf_str + "?", $"Delete {conf_str}?") == MessageBoxResult.Cancel)
            {
                return;
            }
            IList <BaseDataClass> list = dgMainDataGrid.SelectedItems.Cast <BaseDataClass>().ToList();

            for (int i = 0; i < list.Count; i++)
            {
                list[i].Delete(); // deletes items
            }
        }
Example #7
0
        public App()
        {
            //GenericHelpers.LogTime("A");
            InitializeComponent();
            Data.SetTimer();
            Directory.CreateDirectory(BkPath);
            EventManager.RegisterClassHandler(typeof(FrameworkElement), UIElement.GotFocusEvent, new RoutedEventHandler((s, e) => ((FrameworkElement)s).FocusVisualStyle = null), true);
            TimetableStructure.SetData(new List <TimetableStructureWeek>()
            {
                new TimetableStructureWeek("A", DataHelpers.ShortenedDaysOfTheWeek,
                                           new List <string>()
                {
                    "1", "2", "Brk", "3", "4", "Lch", "5"
                }, new List <int>()
                {
                    2, 5, 9, 12, 16, 19, 23, 26, 30, 33
                }),
                new TimetableStructureWeek("B", DataHelpers.ShortenedDaysOfTheWeek,
                                           new List <string>()
                {
                    "1", "2", "Brk", "3", "4", "Lch", "5"
                }, new List <int>()
                {
                    2, 5, 9, 12, 16, 19, 23, 26, 30, 33
                })
            });
            SessionEnding += delegate(object sender, SessionEndingCancelEventArgs e)
            {
                if (MainWindow is StartWindow)
                {
                    return;
                }
                MessageBoxResult result = VisualHelpers.ShowUnsavedBox();
                if (result == MessageBoxResult.Cancel)
                {
                    e.Cancel = true;
                    return;
                }
                if (result == MessageBoxResult.Yes)
                {
                    FileHelpers.SaveData(FilePath);
                }
            };

            //GenericHelpers.LogTime("B");
        }
 public WindowBase()
 {
     Icon     = BitmapFrame.Create(new Uri("../../Media/AppIcon2.png", UriKind.Relative));
     Closing += delegate(object sender, CancelEventArgs e)
     {
         if (Application.Current.Windows.Count == 1)
         {
             MessageBoxResult result = VisualHelpers.ShowUnsavedBox();
             if (result == MessageBoxResult.Yes)
             {
                 FileHelpers.SaveData(App.FilePath);
             }
             if (result == MessageBoxResult.Cancel)
             {
                 e.Cancel = true;
                 return;
             }
         }
     };
 }
Example #9
0
        private void RestoreLoad(object sender, RoutedEventArgs e)
        {
            BackupInfo pinfo = (BackupInfo)lbMain.SelectedItem;

            if (!string.IsNullOrEmpty(App.FilePath))
            {
                if (App.Data.Unsaved)
                {
                    bool?result = VisualHelpers.UnsavedDialog();
                    if (result == null)
                    {
                        return;
                    }
                    if (result == true)
                    {
                        SaveData(App.FilePath);
                    }
                }
            }
            Close();
            LoadingAction(pinfo.BackupPath);
        }
Example #10
0
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(VisualHelpers.TintColour((Color)value, double.Parse((string)parameter, CultureInfo.InvariantCulture)));
 }
Example #11
0
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(VisualHelpers.GenerateTimetable((IEnumerable <TimetableSlot>)value));
 }
Example #12
0
        public static void LoadData(string fpath, Action <RunWorkerCompletedEventArgs> done = null, Action <RunWorkerCompletedEventArgs> onCancel = null,
                                    Action <RunWorkerCompletedEventArgs> exception          = null, Window owner = null, bool save = true)
        {
            BackgroundWorker worker = new BackgroundWorker()
            {
                WorkerReportsProgress      = true,
                WorkerSupportsCancellation = true
            };

            worker.Dispose(); //Doesn't do anything
            Application.Current.Dispatcher.Invoke(() =>
            {
                string newPath    = null;
                LoadingDialog box = new LoadingDialog("Loading...")
                {
                    Owner = owner
                };
                SavingMode?mode      = null;
                long skip            = 0;
                MemoryStream mstream = null;
                BinaryReader reader  = null;
                worker.DoWork       += delegate(object sender, DoWorkEventArgs e)
                {
                    if (!File.Exists(fpath))
                    {
                        VisualHelpers.ShowErrorBox($"File path {fpath} does not exist.", "File not found!");
                        RecentFilesRemove(fpath);
                        e.Result = new FileNotFoundException();
                        return;
                    }
                    mstream = new MemoryStream(File.ReadAllBytes(fpath));
                    reader  = new BinaryReader(mstream);
                    mode    = (SavingMode)reader.ReadInt32();
                    skip    = mstream.Position;
                    if (mode == SavingMode.Backup)
                    {
                        if (!save)
                        {
                            VisualHelpers.ShowErrorBox("Backup files cannot be used for this function. Please restore it first.");
                            e.Cancel = true;
                            return;
                        }
                        newPath = SaveFileDialogHelper("Restore Backup");
                        if (newPath == null)
                        {
                            e.Cancel = true;
                            return;
                        }
                        _    = reader.ReadString();
                        skip = mstream.Position;
                    }
                    e.Result = Loading.StartLoad(reader, Version.Parse(reader.ReadString()), worker, e);
                    if (worker.CancellationPending)
                    {
                        e.Cancel = true;
                    }
                };
                worker.ProgressChanged += delegate(object sender, ProgressChangedEventArgs e)
                {
                    box.pbProgressBar.Value = e.ProgressPercentage;
                    box.tbTextBlock.Text    = (string)e.UserState;
                };
                worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
                {
                    box.Close();
                    mstream?.Dispose();
                    reader?.Dispose();
                    if (e.Cancelled)
                    {
                        onCancel?.Invoke(e);
                        return;
                    }
                    if (e.Result is Exception)
                    {
                        exception?.Invoke(e);
                        return;
                    }
                    if (e.Error != null)
                    {
                        VisualHelpers.ShowErrorBox($"A {e.Error.GetType().Name} error occured:  {e.Error.Message}");
                        return;
                    }
                    if (save)
                    {
                        DataContainer data = (DataContainer)e.Result;
                        SetDataContainer(data);
                        App.Data.UpdateSave();
                        RegisterOpenFile(mode == SavingMode.Normal ? fpath : newPath);
                        using (FileStream stream = new FileStream(fpath, FileMode.Open))
                        {
                            stream.Seek(skip, SeekOrigin.Begin);
                            if (mode == SavingMode.Backup)
                            {
                                RestoreBackup(stream, newPath);
                            }
                        }
                        if (mode == SavingMode.Backup)
                        {
                            File.Delete(fpath);
                        }
                    }
                    done?.Invoke(e);
                };
                box.Show();
                worker.RunWorkerAsync();
            });
        }
        public DataClassTabItem(Type type)
        {
            InitializeComponent();
            DataType = type;
            void attachButtonCommand(ButtonBase item, CommandBinding binding, // local function to assist attaching commands
                                     object parameter = null)
            {
                item.CommandParameter = parameter;
                item.Command          = binding.Command;
                item.CommandBindings.Add(binding);
            }

            void attachMICommand(MenuItem item, CommandBinding binding, // local function to assist attaching commands
                                 object parameter = null)
            {
                item.CommandParameter = parameter;
                item.Command          = binding.Command;
                item.CommandBindings.Add(binding);
            }

            CommandBinding editBinding = new CommandBinding(DataGridCommands.EditItem, ExecuteEditItem, CanExecuteEditItem);
            CommandBinding newBinding  = new CommandBinding(DataGridCommands.NewItem, ExecuteNewItem, CanAlwaysExecute);
            CommandBinding dupBinding  = new CommandBinding(DataGridCommands.DuplicateItem, ExecuteDuplicateItem, CanExecuteDuplicateItem);
            CommandBinding delBinding  = new CommandBinding(DataGridCommands.DeleteItem, ExecuteDeleteItem, CanExecuteDeleteItem);

            attachMICommand(miEditItem, editBinding);
            attachMICommand(miNewItem, newBinding);
            attachMICommand(miDeleteItem, delBinding);     // attach commands to the context menu
            attachMICommand(miDuplicateItem, dupBinding);

            dgMainDataGrid.CommandBindings.Add(delBinding);
            dgMainDataGrid.InputBindings.Add(new KeyBinding(DataGridCommands.DeleteItem, new KeyGesture(Key.Delete)));

            attachButtonCommand(btNewToolbar, newBinding);
            attachButtonCommand(btEditToolbar, editBinding);
            attachButtonCommand(btDuplicateToolbar, dupBinding); // attach commands to the toolbar
            attachButtonCommand(btDeleteToolbar, delBinding);
            searchtimer.Elapsed += delegate(object sender, ElapsedEventArgs e)
            {
                Dispatcher.Invoke(() => RefreshFilter());
            };
            void handler(object sender, TextChangedEventArgs e)
            {
                searchtimer.Stop();
                searchtimer.Start();
            };
            filterName.TextChanged += handler;
            filterSh.TextChanged   += handler;
            cbRemove.Click         += delegate(object sender, RoutedEventArgs e) { RefreshFilter(); };
            Filtering <BaseDataClass> data = ((INotifyCollectionChanged)App.Data.FromType(type)).Casting <BaseDataClass>().Filtering(o => o.Visible);

            defaultView                = new ListCollectionView(data);
            data.CollectionChanged    += delegate(object sender, NotifyCollectionChangedEventArgs e) { defaultView.Refresh(); };
            dgMainDataGrid.ItemsSource = defaultView;
            dgMainDataGrid.Columns.Add(new DataGridTemplateColumn()
            {
                CanUserSort    = true,
                SortMemberPath = "Name",
                Width          = new DataGridLength(1, DataGridLengthUnitType.Star),
                MinWidth       = 20,
                Header         = "Name",
                CellTemplate   = (DataTemplate)Resources["NameTemplate"]
            });
            dgMainDataGrid.Columns.Add(new DataGridTemplateColumn()
            {
                CanUserSort    = true,
                SortMemberPath = "Shorthand",
                Width          = new DataGridLength(1, DataGridLengthUnitType.Star),
                MinWidth       = 20,
                Header         = "Shorthand",
                CellTemplate   = (DataTemplate)Resources["ShTemplate"]
            });
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(type.TypeHandle);
            int width = BaseDataClass.ExposedProperties[type].Count(prop => prop.Type.IsInterface <IList>());

            width = width == 1 ? 4 : width;
            foreach (CustomPropertyInfo prop in BaseDataClass.ExposedProperties[type])
            {
                bool                    islist       = prop.Type.IsInterface <IList>();
                DataTemplate            cellTemplate = new DataTemplate(type);
                FrameworkElementFactory tbFactory    = new FrameworkElementFactory(typeof(TextBlock));
                tbFactory.SetValue(StyleProperty, Resources["tbStyle"]);
                Binding binding = new Binding(prop.PropertyInfo.Name);
                if (prop.Type == typeof(ObservableCollectionExtended <TimetableSlot>))
                {
                    binding.Converter = new ListReportLength();
                    TextBlock tb = new TextBlock()
                    {
                        Text = "Loading..."
                    };
                    ToolTip tt = new ToolTip()
                    {
                        Content = tb
                    };
                    tbFactory.SetValue(ToolTipProperty, tt);
                    scrolltimer.Elapsed += delegate(object sender_i, ElapsedEventArgs e_i)
                    {
                        Dispatcher.Invoke(() =>
                        {
                            if (tt.IsOpen)
                            {
                                DateTime date = DateTime.Now;
                                tt.Content    = VisualHelpers.GenerateTimetable((IEnumerable <TimetableSlot>)prop.PropertyInfo.GetValue(tt.DataContext));
                            }
                        });
                    };
                    tt.Opened += delegate(object sender, RoutedEventArgs e)
                    {
                        if (!scrolltimer.Enabled)
                        {
                            tt.Content = VisualHelpers.GenerateTimetable((IEnumerable <TimetableSlot>)prop.PropertyInfo.GetValue(tt.DataContext));
                        }
                    };
                    tt.Closed     += delegate(object sender, RoutedEventArgs e) { tt.Content = tb; };
                    tb.MouseLeave += delegate(object sender, MouseEventArgs e) { tt.IsOpen = false; };
                }
                else if (islist)
                {
                    binding.Converter = new ListFormatter();
                }
                else
                {
                    binding.Converter = new PropertyConverter(prop);
                }
                tbFactory.SetBinding(TextBlock.TextProperty, binding);
                cellTemplate.VisualTree = tbFactory;

                dgMainDataGrid.Columns.SmartInsert(islist ? -1 : 2, new DataGridTemplateColumn()
                {
                    Width        = new DataGridLength(width, islist ? DataGridLengthUnitType.Star : DataGridLengthUnitType.Auto),
                    Header       = prop.Alias,
                    CellTemplate = cellTemplate
                });
            }
            dgMainDataGrid.MouseDoubleClick += delegate(object sender, MouseButtonEventArgs e)
            {
                if (e.LeftButton == MouseButtonState.Pressed && dgMainDataGrid.SelectedItems.Count == 1)
                {
                    new InformationWindow((BaseDataClass)dgMainDataGrid.SelectedItem).Show();
                }
            };
            searches = BaseDataClass.SearchParameters.DefaultDictGet <Type, IList <SearchFactory>, List <SearchFactory> >(type).Select(sf => sf.GenerateSearch()).ToObservable();
            searches.CollectionChanged += SearchChanged;
            foreach (SearchBase search in searches)
            {
                wpAdvanced.Children.Add(search.GenerateUI());
            }
            dgMainDataGrid.UnselectAll();
        }