Example #1
0
        void mainForm_Load(object sender, EventArgs e)
        {
            MapTree tree;

            if (MetaModel.MetaModel.Instance.LastOpenedFile == null)
            {
                tree = PersistenceManager.NewTree().Tree;
            }
            else
            {
                try
                {
                    tree = PersistenceManager.OpenTree(MetaModel.MetaModel.Instance.LastOpenedFile).Tree;
                }
                catch (Exception exp)
                {
                    tree = PersistenceManager.NewTree().Tree;
                    MetaModel.MetaModel.Instance.LastOpenedFile = null;
                    System.Diagnostics.Trace.TraceWarning(DateTime.Now.ToString() + ": Couldn't load last opened file. " + exp.Message);
                }
            }

            noteCrtl = new NoteEditorCtrl(mainForm.NoteEditor, PersistenceManager);

            pluginManager.InitializeContextMenu(NodeContextMenu);

            new ContextMenuCtrl(this, NodeContextMenu);

            pluginManager.InitializeSideBarWindow(mainForm.SideBarTabs);

            pluginManager.InitializeMainMenu(mainForm);

            mainForm.NoteEditor.OnDirty += (a) => {
                if (PersistenceManager.CurrentTree != null)
                {
                    PersistenceManager.CurrentTree.IsDirty = true;
                }
            };     // register for NoteEditor changes

            mainForm.FormClosing += mainForm_FormClosing;
        }
Example #2
0
        void mainForm_Load(object sender, EventArgs e)
        {
            MapTree tree;

            string fileArg = ProgramMainHelper.GetFileToOpenFromAppArguments(mainForm);

            if (fileArg != null)
            {
                try
                {
                    tree = PersistenceManager.OpenTree(fileArg);
                }
                catch (Exception exp)
                {
                    tree = PersistenceManager.NewTree();
                    MetaModel.MetaModel.Instance.LastOpenedFile = null;
                    Log.Write("Couldn't load the file provided in application argument. " + exp.Message);
                }
            }
            else if (MetaModel.MetaModel.Instance.LastOpenedFile == null)
            {
                tree = PersistenceManager.NewTree();
            }
            else
            {
                try
                {
                    tree = PersistenceManager.OpenTree(MetaModel.MetaModel.Instance.LastOpenedFile);
                }
                catch (Exception exp)
                {
                    tree = PersistenceManager.NewTree();
                    MetaModel.MetaModel.Instance.LastOpenedFile = null;
                    Log.Write("Couldn't load last opened file. " + exp.Message);
                }
            }

            noteCrtl = new NoteEditorCtrl(mainForm.NoteEditor, PersistenceManager, Dialogs);

            pluginManager.InitializeContextMenu(NodeContextMenu);

            new ContextMenuCtrl(this, NodeContextMenu);

            pluginManager.InitializeSideBarWindow(mainForm.SideBarTabs);

            pluginManager.InitializeMainMenu(mainForm);

            mainForm.NoteEditor.OnDirty += (a) => {
                if (PersistenceManager.CurrentTree != null)
                {
                    PersistenceManager.CurrentTree.IsDirty = true;
                }
            };     // register for NoteEditor changes

            mainForm.NoteEditor.OnSave += (obj) =>
            {
                if (this.PersistenceManager.CurrentTree.IsNewMap)
                {
                    // bug fix: if the map is new and following call will trigger a file save dialog, we have to do it through a separate thread to avoid 'S' being written in the note editor
                    Action action = () => SaveCurrentMap();
                    this.schedular.AddTask(() => ((Control)mainForm).Invoke(action), DateTime.Now);
                }
                else
                {
                    SaveCurrentMap();
                }
            };

            mainForm.FormClosing += mainForm_FormClosing;
        }