예제 #1
0
        protected override void OnExecuted(EventArgs e)
        {
            var ofd = new OpenFileDialog();

            ofd.Title = "Select the file to open";
            var formats    = main.Settings.Infos.GetFormats();
            var allFormats = new List <string>();

            foreach (Format format in formats.Values)
            {
                if (format.CanLoad)
                {
                    var extensions = from ex in format.Extensions select "." + ex;
                    allFormats.AddRange(extensions);
                    ofd.Filters.Add(new FileDialogFilter {
                        Name = format.Name, Extensions = extensions.ToArray()
                    });
                }
            }
            ofd.Filters.Insert(0, new FileDialogFilter {
                Name = "All Formats", Extensions = allFormats.ToArray()
            });

            var dr = ofd.ShowDialog(main);

            if (dr == DialogResult.Ok)
            {
                if (FileModifiedDialog.Show(main) == DialogResult.Ok)
                {
                    Format format = (ofd.CurrentFilterIndex > 0) ? formats.Values.ElementAtOrDefault(ofd.CurrentFilterIndex - 1) : null;
                    if (format == null)
                    {
                        format = formats.Find(ofd.FileName, string.Empty);
                    }
                    if (format == null)
                    {
                        MessageBox.Show(main, "Cannot determine format to open based on file extension.");
                    }

                    if (format != null)
                    {
                        var stream = System.IO.File.OpenRead(ofd.FileName);
                        main.LoadFile(ofd.FileName, stream, format, main.EditMode, true, true);
                        // don't close stream as it could be used in background..
                    }
                }
            }
        }
예제 #2
0
        public void ReloadFile(bool hasSavePermissions, bool focus, bool checkModifications)
        {
            if (!shouldReload)
            {
                return;
            }

            if (checkModifications && FileModifiedDialog.Show(this) != DialogResult.Ok)
            {
                return;
            }

            EtoFileInfo file = fileList.SelectedFile;

            if (file != null)
            {
                //Console.WriteLine ("Reloading file: {0}, format:{1}", file.Name, currentFormat != null ? currentFormat.GetType () : null);
                if (file != currentFile)
                {
                    currentFormat = null;
                }
                currentFile = file;
                Format format = currentFormat ?? Settings.Infos.FindFormat(file.FullName, "character", "ansi");
                if (format != null)
                {
                    try
                    {
                        var stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
                        LoadFile(file.FullName, stream, format, EditMode, false, hasSavePermissions);
                        if (focus)
                        {
                            padpanel.Content.Focus();
                        }
                    }
                    catch (Exception ex)
                    {
                        SetDocument(null);
                        MessageBox.Show(this, string.Format("Error loading file '{0}'.  {1}", file.FullName, ex.Message));
#if DEBUG
                        Debug.Print("Error loading: {0}", ex);
                        throw;
#endif
                    }
                }
            }
        }
예제 #3
0
 protected override void OnExecuted(EventArgs e)
 {
     base.OnExecuted(e);
     if (!main.EditMode || FileModifiedDialog.Show(main) == DialogResult.Ok)
     {
         if (main.Client != null)
         {
             main.Client.SendCommand(this);
         }
         else
         {
             main.EditMode = !main.EditMode;
             //if (!main.EditMode)
             //	main.ReloadFile ();
         }
     }
 }
예제 #4
0
        public override bool Send(SendCommandArgs args)
        {
            base.Send(args);

            NewFileDialog nfd = new NewFileDialog(main.Settings);
            DialogResult  dr  = nfd.ShowModal(main);

            if (dr == DialogResult.Ok)
            {
                if (FileModifiedDialog.Show(main) == DialogResult.Ok)
                {
                    args.Message.Write(nfd.SelectedDocumentType.ID);
                    return(true);
                }
            }

            return(false);
        }
예제 #5
0
        public bool LoadFile(string fileName, bool hasSavePermissions)
        {
            if (FileModifiedDialog.Show(this) != DialogResult.Ok)
            {
                return(true);
            }

            currentFormat = null;
            currentFile   = null;
            Format format = Settings.Infos.FindFormat(fileName, "character", "ansi");

            if (format != null && File.Exists(fileName))
            {
                var stream = File.OpenRead(fileName);
                LoadFile(fileName, stream, format, EditMode, true, hasSavePermissions);
                return(true);
            }
            return(false);
        }
예제 #6
0
파일: Main.cs 프로젝트: cwensley/pablodraw
        public bool LoadFile(string fileName, bool hasSavePermissions, bool setFileList = true, bool?editMode = null)
        {
            if (FileModifiedDialog.Show(this) != DialogResult.Ok)
            {
                return(true);
            }

            currentFormat = null;
            currentFile   = null;

            if (File.Exists(fileName))
            {
                using (var stream = File.OpenRead(fileName))
                {
                    return(LoadFile(fileName, stream, null, editMode ?? EditMode, setFileList, hasSavePermissions));
                }
            }
            return(false);
        }
예제 #7
0
        protected override void Execute(CommandExecuteArgs args)
        {
            NewFileDialog nfd = new NewFileDialog(main.Settings);
            DialogResult  dr  = nfd.ShowModal(main);

            if (dr == DialogResult.Ok)
            {
                if (FileModifiedDialog.Show(main) == DialogResult.Ok)
                {
                    // create a new document then edit it
                    main.FileList.SelectedIndex = -1;

                    var doc = nfd.SelectedDocumentType.Create(main.Platform);
                    doc.IsNew    = true;
                    doc.EditMode = true;

                    main.SetDocument(doc, true);
                }
            }
        }