Exemplo n.º 1
0
 /// <summary>
 /// Cammans needed before a File is saved
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void BeforeFileSave(LoadedPackage sender, FileNameEventArg e)
 {
     if (!resloader.Flush())
     {
         e.Cancel = true;
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Commands called before a File is loaded
 /// </summary>
 void BeforeFileLoad(LoadedPackage sender, FileNameEventArg e)
 {
     if (!ClosePackage())
     {
         e.Cancel = true;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Load a File from the Disc
        /// </summary>
        /// <param name="flname">The Filename</param>
        /// <param name="sync">
        /// Only needed if a PackageMaintainer is used. This will tell the Maintainer, that
        /// it should reload the Package from the Disk, and not only get the Package in Memory
        /// </param>
        /// <returns>true, if the file was loaded</returns>
        public bool LoadFromFile(string flname, bool sync)
        {
            bool res = false;

            try
            {
                FileNameEventArg e = new FileNameEventArg(flname);
                if (BeforeFileLoad != null)
                {
                    BeforeFileLoad(this, e);
                }
                if (e.Cancel)
                {
                    return(false);
                }

                Wait.SubStart();
                Wait.Message = "Loading File";

                if (pkg != null)
                {
                    this.SetupEvents(false);
                }

                pkg = SimPe.Packages.File.LoadFromFile(e.FileName, sync);
                if (pkg.Index.Length < Helper.WindowsRegistry.BigPackageResourceCount)
                {
                    pkg.LoadCompressedState();
                }

                this.SetupEvents(true);
                Helper.WindowsRegistry.AddRecentFile(flname);

                Wait.SubStop();

                if (AfterFileLoad != null)
                {
                    AfterFileLoad(this);
                }
                res = true;
            }
#if !DEBUG
            catch (Exception ex) { SimPe.Helper.ExceptionMessage(ex); }
#endif
            finally { }
            if (res != true)
            {
                pkg = null;
            }
            return(res);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Close the current Package
        /// </summary>
        /// <returns>true, if the Package was closed</returns>
        public bool Close()
        {
            if (pkg != null)
            {
                bool res = true;
                if (pkg.HasUserChanges)
                {
                    DialogResult dr = SimPe.Message.Show(
                        SimPe.Localization.Manager.GetString("savechanges").Replace("{filename}", FileName),
                        SimPe.Localization.Manager.GetString("savechanges?"),
                        MessageBoxButtons.YesNoCancel);

                    if (dr == DialogResult.Yes)
                    {
                        res = Save();
                    }
                    else if (dr == DialogResult.Cancel)
                    {
                        return(false);
                    }
                }
                if (res)
                {
                    FileNameEventArg e = new FileNameEventArg(this.FileName);
                    if (BeforeFileClose != null)
                    {
                        BeforeFileClose(this, e);
                    }
                    if (e.Cancel)
                    {
                        res = false;
                    }
                }

                if (res)
                {
                    pkg.Close();
                    this.SetupEvents(false);
                    pkg = null;
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Load another Package
        /// </summary>
        /// <param name="newpkg">the Package that should be the currently opened</param>
        /// <returns>true, if the file was loaded</returns>
        public bool LoadFromPackage(SimPe.Packages.GeneratableFile newpkg)
        {
            if (newpkg == null)
            {
                return(false);
            }
            string flname = newpkg.FileName;

            if (flname == null)
            {
                flname = "";
            }

            FileNameEventArg e = new FileNameEventArg(flname);

            if (BeforeFileLoad != null)
            {
                BeforeFileLoad(this, e);
            }
            if (e.Cancel)
            {
                return(false);
            }

            if (pkg != null)
            {
                this.SetupEvents(false);
            }

            pkg = newpkg;
            pkg.LoadCompressedState();

            if (pkg != null)
            {
                this.SetupEvents(true);
            }

            if (pkg.FileName != null)
            {
                Helper.WindowsRegistry.AddRecentFile(pkg.FileName);
            }
            if (AfterFileLoad != null)
            {
                AfterFileLoad(this);
            }

            return(true);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Save the current package
        /// </summary>
        /// <param name="filname">the new Filename</param>
        /// <param name="savetocopy">true if you want to save to a copy</param>
        /// <returns></returns>
        public bool Save(string filname, bool savetocopy)
        {
            if (!this.Loaded)
            {
                return(false);
            }
            try
            {
                FileNameEventArg e = new FileNameEventArg(filname);
                if (BeforeFileSave != null)
                {
                    BeforeFileSave(this, e);
                }
                if (e.Cancel)
                {
                    return(false);
                }

                Wait.SubStart();
                Wait.Message = "Saving File";

                string oname = this.FileName;
                this.Package.Save(e.FileName);

                if (savetocopy)
                {
                    Package.FileName = oname;
                }

                Helper.WindowsRegistry.AddRecentFile(e.FileName);


                Wait.SubStop();

                if (AfterFileSave != null)
                {
                    AfterFileSave(this);
                }
            }
            catch (Exception ex)
            {
                Helper.ExceptionMessage(ex);
                return(false);
            }

            return(true);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Executed when the user clicks on one of the RecentFiles Menu Items
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OpenRecent(object sender, System.EventArgs e)
        {
            if (sender is ToolStripMenuItem)
            {
                ToolStripMenuItem mbi = (ToolStripMenuItem)sender;

                FileNameEventArg me = new FileNameEventArg(mbi.Tag.ToString());
                if (BeforeRecentFileLoad != null)
                {
                    BeforeRecentFileLoad(this, me);
                }

                if (!me.Cancel)
                {
                    if (LoadFromFile(me.FileName))
                    {
                        if (AfterRecentFileLoad != null)
                        {
                            AfterRecentFileLoad(this);
                        }
                    }
                }
            }
        }