///<summary> /// Load the files specified ///</summary> public void LoadFiles(string[] files) { // should we replace the current page or create a new one? bool replaceCurrentPage = dataBook.CanReplacePage(dataBook.CurrentPage); foreach (string file in files) { // try to open the file ByteBuffer bb = OpenFile(file); // if open was successful if (bb != null) { DataView newDv = CreateDataView(bb); if (replaceCurrentPage) // replace current page { DataView dv = ((DataViewDisplay)dataBook.CurrentPageWidget).View; dataBook.ReplaceView(dv, newDv, new CloseViewDelegate(CloseFile), Path.GetFileName(bb.Filename)); // promptly free resources memory (eg pixmaps) dv.Buffer.CloseFile(); dv.Cleanup(); replaceCurrentPage = false; } else // create new page // create and setup a DataView { dataBook.AppendView(newDv, new CloseViewDelegate(CloseFile), Path.GetFileName(bb.Filename)); } } } }
///<summary> /// Load a session from the specified file. ///</summary> public void Load(string path) { Session session = new Session(); // try to load session file try { session.Load(path); } catch (Exception ex) { System.Console.WriteLine(ex.Message); return; } // set the size of main window if (Preferences.Instance["Session.RememberWindowGeometry"] == "True") { mainWindow.Resize(session.WindowWidth, session.WindowHeight); } // add files to the DataBook foreach (SessionFileInfo sfi in session.Files) { ByteBuffer bb = Services.File.OpenFile(sfi.Path); // if file was opened successfully if (bb != null) { DataView dv = Services.File.CreateDataView(bb); // try to load layout file try { dv.Display.Layout = new Bless.Gui.Layout(sfi.Layout); } catch (Exception ex) { ErrorAlert ea = new ErrorAlert("Error loading layout '" + sfi.Layout + "' for file '" + sfi.Path + "'. Loading default layout.", ex.Message, mainWindow); ea.Run(); ea.Destroy(); } long cursorOffset = sfi.CursorOffset; // sanity check cursor offset and view offset if (cursorOffset > bb.Size) { cursorOffset = bb.Size; } long offset = sfi.Offset; if (offset >= bb.Size) { offset = 0; } if (Preferences.Instance["Session.RememberCursorPosition"] == "True") { dv.MoveCursor(cursorOffset, sfi.CursorDigit); dv.Offset = offset; } dataBook.AppendView(dv, new CloseViewDelegate(Services.File.CloseFile), Path.GetFileName(bb.Filename)); //OnBufferChanged(bb); } } foreach (DataViewDisplay dvd in dataBook.Children) { DataView dv = dvd.View; if (dv.Buffer.Filename == session.ActiveFile) { dataBook.CurrentPage = dataBook.PageNum(dvd); break; } } }