Exemple #1
0
        void EnforceColumnPrefs()
        {
            try
            {
                if (GridPref != null)
                {
                    foreach (var pair in GridPref.ColumnPrefs.OrderBy(p => p.Value.VisiblePosition))
                    {
                        ColumnPref pref = pair.Value;
                        ColumnBase cb   = this.Grid.Columns[pair.Key];
                        if (cb == null) // no longer exists
                        {
                            continue;
                        }

                        if (pref.Width > 0)
                        {
                            cb.Width = pref.Width;
                        }

                        cb.VisiblePosition = pref.VisiblePosition;
                    }

                    GridPref.Completed = true;
                }
            }
            catch (Exception ex)
            {
                AbnakiLog.Exception(ex);
            }
        }
Exemple #2
0
        bool ReloadBounds()
        {
            bool changed = false;

            Prefs pref = Abnaki.Windows.Software.Wpf.Profile.Preference.ReadClassPrefs <MainWindow, Prefs>();

            if (pref != null)
            {
                if (WpfScreenHelper.Screen.AllScreens.Any(sc => sc.WorkingArea.IntersectsWith(pref.Bounds)))
                {
                    this.Hide(); // show later
                    Top    = pref.Bounds.Top;
                    Left   = pref.Bounds.Left;
                    Width  = pref.Bounds.Width;
                    Height = pref.Bounds.Height;

                    this.WindowState = pref.State;
                    changed          = true;
                }
                else
                {
                    AbnakiLog.Comment(GetType().Name + " disregarded undisplayable bounds " + pref.Bounds);
                }
            }

            return(changed);
        }
Exemple #3
0
        static void CompleteSetup(Abnaki.Windows.GUI.IWindow mainWindow, IDockSystem ds)
        {
            if (ds == null)
            {
                AbnakiLog.Comment("IDockSystem null");
            }
            else
            {
                ds.Defaults();

                mainWindow.SavingPanelLayout    += fi => ds.SerializeLayout(fi);
                mainWindow.RestoringPanelLayout += fi => ds.DeserializeLayout(fi);
            }
        }
Exemple #4
0
        static void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args)
        {
            string filepath = null;

            if (args.LoadedAssembly.IsDynamic)
            {
                // no file
            }
            else
            {
                filepath = args.LoadedAssembly.Location;
            }

            AbnakiLog.FileInfo(filepath, "Load " + args.LoadedAssembly.GetName());
        }
Exemple #5
0
        /// <summary>
        /// Starts Application having Twindow as first thing user sees.
        /// </summary>
        /// <typeparam name="Tapp">System.Windows.Application, or subclass if necessary</typeparam>
        /// <typeparam name="Twindow">class of window</typeparam>
        /// <example>
        /// <code>
        /// [STAThread]
        /// public static int Main(string[] args)
        /// {  return Starter.Start &lt; YourApp,YourWin &gt;(args); }
        /// </code>
        /// </example>
        public static int Start <Twindow, Tapp>(string[] args, Func <Twindow> initWindow = null)
            where Tapp : System.Windows.Application, new()
            where Twindow : System.Windows.Window, new()
        {
            //Process proc = System.Diagnostics.Process.GetCurrentProcess();
            //ProcessStartInfo pistart = proc.StartInfo; // no use
            try
            {
                var starta = System.Reflection.Assembly.GetEntryAssembly();
                AbnakiLog.Comment("Start", starta.Location);
                AbnakiLog.Comment("Version", starta.GetName().Version);
                AbnakiLog.Comment("Operating System", Environment.OSVersion);
                AbnakiLog.Comment("Culture", System.Globalization.CultureInfo.CurrentCulture);

                // reconcile FrameworkElement Language with CurrentCulture, which is independent by default
                FrameworkElement.LanguageProperty.OverrideMetadata(
                    typeof(FrameworkElement),
                    new FrameworkPropertyMetadata(
                        System.Windows.Markup.XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

                System.AppDomain.CurrentDomain.AssemblyLoad += CurrentDomain_AssemblyLoad;

                Tapp app = new Tapp();

                app.DispatcherUnhandledException += Current_DispatcherUnhandledException;

                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

                Twindow mw;
                if (initWindow == null)
                {
                    mw = new Twindow();
                }
                else
                {
                    mw = initWindow();
                }

                return(app.Run(mw));
            }
            catch (Exception ex)
            {
                Diplomat.Notifier.Error(ex);
                Diplomat.Troubleshooter.DialogSaveLog();
            }
            return(1); // failed
        }
Exemple #6
0
        public void TestEntryOfEntries()
        {
            string f1 = "log1.xml";

            AbnakiLog.Comment("Vote Labour");
            AbnakiLog.Comment("Vote Tory");
            AbnakiLog.Write(f1);

            AbnakiLog.Comment("Should be followed by EntryOfEntries");
            AbnakiLog.Incorporate(f1);

            string f2 = "log2.xml";

            AbnakiLog.Write(f2);

            Debug.WriteLine("Wrote logs in " + Environment.CurrentDirectory);
        }
Exemple #7
0
 void InvokeRestoringPanelLayout(FileInfo fi)
 {
     if (fi.Exists)
     {
         var h = RestoringPanelLayout;
         if (h != null)
         {
             using (new WaitCursor())
             {
                 h(fi);
             }
         }
     }
     else
     {
         AbnakiLog.FileInfo(fi, "Nonexistent, ignored");
     }
 }
Exemple #8
0
        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            // but in OnClosed(), note that RestoreBounds is Empty

            base.OnClosing(e);

            try
            {
                SaveBounds();

                MessageTube.Publish(new FarewellMessage());

                FileInfo fi = LayoutFileInfo();
                InvokeSavingPanelLayout(fi);
            }
            catch (Exception ex)
            {
                AbnakiLog.Exception(ex);
            }
        }
Exemple #9
0
        public static Tpref ReadClassPrefs <Tclass, Tpref>()
            where Tpref : class
        {
            FileInfo fi = ClassPrefsFile <Tclass>();

            if (fi.Exists)
            {
                try
                {
                    using (StreamReader sr = new StreamReader(fi.FullName, PrefEncoding))
                    {
                        XmlSerializer xs = new XmlSerializer(typeof(Tpref));
                        return((Tpref)xs.Deserialize(sr));
                    }
                }
                catch (Exception ex)
                {
                    AbnakiLog.Exception(ex);
                }
            }
            return(null);
        }