private void loadPicture(TextRepresentationEntry tre) { bool success = false; try { success = Program.State.LoadPicture(tre); } catch (ImageViewLoadException e) { MessageBox.Show(String.Format(Settings.Get.General.GetString("ErrorImageLoad"), e.Entry.FullName), Settings.Get.General.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (FileNotFoundException notfounde) { MessageBox.Show(String.Format(Settings.Get.General.GetString("ErrorFileNotFound"), notfounde.FileName), Settings.Get.General.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (DirectoryNotFoundException notfounde) { MessageBox.Show(String.Format(Settings.Get.General.GetString("ErrorPathNotFound"), (string)notfounde.Data["fullname"]), Settings.Get.General.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (success) { loadPictureUI(); } } }
/// <summary> /// History is made of simple strings that represent enough information to load a file: /// - The picture full name /// - The archive file (if any) from which the file derives /// </summary> /// <param name="tre"></param> public bool LoadPicture(TextRepresentationEntry tre) { if (tre.ArchiveFile == String.Empty) { //it's just a regular file, go load it return(LoadPicture(tre.FullName)); } else { if (File.Exists(tre.ArchiveFile)) { List <ArchiveEntry> imagesFiles = ArchiveEntry.GetImageFiles(tre.ArchiveFile); if (imagesFiles.Count > 0) { int index = imagesFiles.FindIndex(x => x.InternalArchiveFullName.Equals(tre.FullName)); //check if image still exist inside this archive. Could have been deleted for whatever reason if (index != -1) { directoryIndex = index; entries = imagesFiles.ToList <IEntry>(); return(loadPicture(entries[index])); } } } } return(false); }
public void Load(XmlDocument doc) { XmlNode n; int ivalue; bool bvalue; //max size n = doc.SelectSingleNode("/Settings/History/MaxSize"); if (n != null && int.TryParse(n.InnerText, out ivalue) && ivalue >= 0 && ivalue <= MAXIMUM_HISTORY_SIZE) { size = ivalue; } else { size = DEFAULT_HISTORY_SIZE; } //save on exit n = doc.SelectSingleNode("/Settings/History/SaveOnExit"); if (n != null && bool.TryParse(n.InnerText, out bvalue)) { SaveOnExit = bvalue; } //history XmlNodeList nlist = doc.SelectNodes("/Settings/History/Files/File"); if (nlist != null) { int i = 1; foreach (XmlNode nd in nlist) { TextRepresentationEntry tre = new TextRepresentationEntry(nd.InnerText); //if there's an archive attribute get that too var attrib = nd.SelectSingleNode("@archive"); if (attrib != null && attrib.Value != String.Empty) { tre.ArchiveFile = attrib.Value; } history.Add(tre); if (i > size) { break; } else { i++; } } } }
public void AddFile(TextRepresentationEntry file) { //attemp to delete from history history.Remove(file); history.Insert(0, file); //reinsert as index 0 == last viewed if (history.Count > MaxSize) { //delete everything after max size history.RemoveRange(MaxSize, history.Count - MaxSize); } }
private void toolStripComboBoxNavigation_SelectedIndexChanged(object sender, EventArgs e) { #if DEBUG System.Diagnostics.Debug.WriteLine("toolStripComboBoxNavigation_SelectedIndexChanged" + sender.ToString()); #endif TextRepresentationEntry tre = (TextRepresentationEntry)toolStripComboBoxNavigation.SelectedItem; this.ActiveControl = null; loadPicture(tre); //This fixes a weird refresh issue where the button to expand the dropdown stays focused after the selection change toolStripComboBoxNavigation.Select(0, 0); toolStripComboBoxNavigation.Invalidate(); toolStripComboBoxNavigation.Select(0, 0); }
private bool loadPicture(IEntry entry) { this.Dispose(); this.activeEntry = entry; Exception exception = null; //load image #if DEBUG Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); #endif Stream stream = entry.GetStream(); try { this.nativeImage = new ImageMagick.MagickImage(stream); } catch (Exception e) { this.nativeImage = new MagickImage(Properties.Resources.error); exception = e; } stream.Dispose(); #if DEBUG stopWatch.Stop(); System.Diagnostics.Debug.WriteLine(String.Format("Loading image in {0} ms", stopWatch.Elapsed.Milliseconds)); #endif //convert to bitmap if (Settings.Get.Display.AutoRotate && nativeImage.Orientation != OrientationType.Undefined) { nativeImage.AutoOrient(); } bitmap = nativeImage.ToBitmap(); //Add loaded file to history if necessary TextRepresentationEntry tre = activeEntry.ToText(); Settings.Get.History.AddFile(tre); //if there was an exception throw it if (exception != null) { throw new ImageViewLoadException(exception, entry); } return(true); }