private void SaveAs()
        {
            string file = this.Editor.File;

            if (!Mainframe.IsFilePathValid(file))
            {
                file = Settings.User.RecentFile();
                string dir;
                if (Mainframe.IsFilePathValid(file))
                {
                    dir = Path.GetDirectoryName(file);
                }
                else
                {
                    dir = Mainframe.DefaultProjectFolder();
                }
                file = Path.Combine(dir, this.Editor.Project.Name + Mainframe.FileExtention);
            }
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.InitialDirectory = Path.GetDirectoryName(Path.GetFullPath(file));
            dialog.FileName         = Path.GetFileName(file);
            dialog.Filter           = Mainframe.FileFilter;
            dialog.DefaultExt       = Mainframe.FileExtention;
            bool?result = dialog.ShowDialog(this);

            if (result.HasValue && result.Value)
            {
                this.Save(dialog.FileName);
            }
        }
 private void Import()
 {
     if (this.Editor != null && this.Editor.InEditMode)
     {
         string dir    = Mainframe.DefaultProjectFolder();
         string recent = Settings.User.RecentFile();
         if (Mainframe.IsFilePathValid(recent))
         {
             dir = Path.GetDirectoryName(recent);
         }
         SettingsStringCache location = new SettingsStringCache(Settings.User, "ImportFile.Folder", dir);
         OpenFileDialog      dialog   = new OpenFileDialog {
             Filter           = Mainframe.FileFilter,
             DefaultExt       = Mainframe.FileExtention,
             InitialDirectory = Mainframe.IsDirectoryPathValid(location.Value) ? location.Value : Mainframe.DefaultProjectFolder()
         };
         bool?result = dialog.ShowDialog(this);
         if (result.HasValue && result.Value)
         {
             string file = dialog.FileName;
             location.Value = Path.GetDirectoryName(file);
             this.Editor.Import(file);
         }
     }
 }
 private void Open()
 {
     if (this.Editor == null || this.EnsureSaved())
     {
         OpenFileDialog dialog = new OpenFileDialog();
         string         file   = Settings.User.RecentFile();
         if (Mainframe.IsFilePathValid(file))
         {
             dialog.InitialDirectory = Path.GetDirectoryName(Path.GetFullPath(file));
         }
         else
         {
             dialog.InitialDirectory = Mainframe.DefaultProjectFolder();
         }
         dialog.Filter     = Mainframe.FileFilter;
         dialog.DefaultExt = Mainframe.FileExtention;
         bool?result = dialog.ShowDialog(this);
         if (result.HasValue && result.Value)
         {
             file = dialog.FileName;
             this.Edit(file);
         }
     }
 }
Exemple #4
0
        protected DialogMemoryEditor(Memory memory)
        {
            string typeName = this.GetType().Name;

            this.openFileFolder = new SettingsStringCache(Settings.User, typeName + ".OpenFile.Folder", Mainframe.DefaultProjectFolder());
            this.DataHeight     = new SettingsGridLengthCache(Settings.User, typeName + ".Data.Height", memory.Writable ? "0.25*" : "0.75*");
            this.NoteHeight     = new SettingsGridLengthCache(Settings.User, typeName + ".Note.Height", memory.Writable ? "0.75*" : "0.25*");

            this.Memory = memory;
            this.data   = memory.MemoryValue();

            this.DataContext = this;
            this.InitializeComponent();

            this.addressBitWidth.ItemsSource = MemoryDescriptor.AddressBitWidthRange;
            this.dataBitWidth.ItemsSource    = PinDescriptor.BitWidthRange;
            IEnumerable <EnumDescriptor <bool> > writeOnList = MemoryDescriptor.WriteOnList;

            this.writeOn.ItemsSource = writeOnList;
            EnumDescriptor <MemoryOnStart>[] onStartList = new EnumDescriptor <MemoryOnStart>[] {
                new EnumDescriptor <MemoryOnStart>(MemoryOnStart.Random, Properties.Resources.MemoryOnStartRandom),
                new EnumDescriptor <MemoryOnStart>(MemoryOnStart.Zeros, Properties.Resources.MemoryOnStartZeros),
                new EnumDescriptor <MemoryOnStart>(MemoryOnStart.Ones, Properties.Resources.MemoryOnStartOnes),
                new EnumDescriptor <MemoryOnStart>(MemoryOnStart.Data, Properties.Resources.MemoryOnStartData)
            };
            this.onStart.ItemsSource = onStartList;

            this.addressBitWidth.SelectedItem = this.currentAddressBitWidth = this.Memory.AddressBitWidth;
            this.dataBitWidth.SelectedItem    = this.currentDataBitWidth = this.Memory.DataBitWidth;
            this.writeOn.SelectedItem         = writeOnList.First(d => d.Value == this.Memory.WriteOn1);
            this.onStart.SelectedItem         = onStartList.First(d => d.Value == (this.Memory.Writable ? this.Memory.OnStart : MemoryOnStart.Data));
            this.note.Text = this.Memory.Note;

            this.FunctionMemory = new MemoryEditor(this.data, this.Memory.AddressBitWidth, this.DataBitWidth);

            this.initialized = true;
        }
Exemple #5
0
 private void ButtonSaveClick(object sender, RoutedEventArgs e)
 {
     try {
         SaveFileDialog dialog = new SaveFileDialog {
             InitialDirectory = Mainframe.IsDirectoryPathValid(this.openFileFolder.Value) ? this.openFileFolder.Value : Mainframe.DefaultProjectFolder()
         };
         bool?result = dialog.ShowDialog(this);
         if (result.HasValue && result.Value)
         {
             string file = dialog.FileName;
             this.openFileFolder.Value = Path.GetDirectoryName(file);
             using (FileStream stream = File.Open(file, FileMode.Create, FileAccess.Write, FileShare.Write)) {
                 stream.Write(this.data, 0, this.data.Length);
                 stream.Flush();
             }
         }
     } catch (Exception exception) {
         App.Mainframe.ReportException(exception);
     }
 }
Exemple #6
0
 private void ButtonLoadClick(object sender, RoutedEventArgs e)
 {
     try {
         OpenFileDialog dialog = new OpenFileDialog {
             InitialDirectory = Mainframe.IsDirectoryPathValid(this.openFileFolder.Value) ? this.openFileFolder.Value : Mainframe.DefaultProjectFolder()
         };
         bool?result = dialog.ShowDialog(this);
         if (result.HasValue && result.Value)
         {
             this.openFileFolder.Value = Path.GetDirectoryName(dialog.FileName);
             int    addressBitWidth = this.AddressBitWidth;
             int    dataBitWidth    = this.DataBitWidth;
             byte[] buffer          = new byte[Memory.BytesPerCellFor(dataBitWidth)];
             int    cellCount       = Memory.NumberCellsFor(addressBitWidth);
             Tracer.Assert(cellCount * buffer.Length == this.data.Length);
             using (FileStream stream = File.Open(dialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                 for (int i = 0; i < cellCount; i++)
                 {
                     int readed = stream.Read(buffer, 0, buffer.Length);
                     if (readed <= 0)
                     {
                         Array.Clear(this.data, i * buffer.Length, this.data.Length - i * buffer.Length);
                         break;
                     }
                     int value = Memory.CellValue(buffer, Math.Min(8 * readed, dataBitWidth), 0);
                     Memory.SetCellValue(this.data, dataBitWidth, i, value);
                 }
             }
             this.FunctionMemory = new MemoryEditor(this.data, addressBitWidth, dataBitWidth);
         }
     } catch (Exception exception) {
         App.Mainframe.ReportException(exception);
     }
 }