示例#1
0
		public void UpdateRecentMenu()
		{
			// Make sure we know about the recent menu.
			if (object.ReferenceEquals(this.RecentMenu, null)) {
				Debug.Print("[MainWindow] UpdateRecentMenu(): Don't know about a recent menu, skipping.");
				return;
			}

			// Clear recent menu.
			foreach (Widget child in this.RecentMenu.AllChildren) {
				this.RecentMenu.Remove(child);
			}

			// Fill recent menu again.
			// TODO: Try to use RecentChooserMenu instead?
			int recentNumber = 1;
			RecentManager manager = RecentManager.Default;
			foreach (object item in new GLib.List(
				manager.Items.Handle, typeof(RecentInfo), false, false)) {
				// ^ We need to work-around known crash-bug
				//   when using manager.Items directly.

				if (recentNumber > 9)
					// Skip the rest.
					break;

				var info = item as RecentInfo;
				if (object.ReferenceEquals(info, null)) {
					Debug.Print("[MainWindow] UpdateRecentMenu(): RecentManager item is not a RecentInfo: {0}",
						item);
					continue;
				}

				// Only offer files in the recent menu that we registered ourselves.
				if (!info.HasApplication(_RecentApplicationName))
					continue;

				// Actually add a new entry in the recent menu.
				var menuItem = new MenuItem(string.Format("_{0} {1}",
					recentNumber++, info.UriDisplay));
				string uri = info.Uri;
				menuItem.Activated += (object sender, EventArgs e) => LoadFile(uri);
				this.RecentMenu.Add(menuItem);
			}

			Debug.Print("[MainWindow] UpdateRecentMenu(): Created recent menu with {0} entries",
				recentNumber - 1);

			this.RecentMenu.ShowAll();
		}
示例#2
0
		public void LoadFile(string filePath)
		{
			// First, ensure a clean state.
			CloseFile();
			this.statusbar1.Pop(_SbCtxState);

			// Indicate what we are there for early.
			//
			// (The idea is that a hypothetically long loading process
			// with the user placing the window in the background
			// would show up in the window list identifiably already.)
			this.FilePath = filePath;

			// Register file as recently used, so that it can be opened easily
			// via the File -> Recent submenu.
			try {
				this.statusbar1.Push(_SbCtxActivity, string.Format(
					"Registering file \"{0}\" as recently used...",
					_FilePath));
				Application.RunIteration(false);

				RecentManager manager = RecentManager.Default;
				var data = new RecentData();
				data.MimeType = "text/plain";
				data.AppName = this.RecentApplicationName;
				// Rather don't record current binary location,
				// it could be a development version...
				// But we have to enter something so that Gtk
				// will let us record the recent info at all,
				// so we make something up here that will be used
				// when the program would be installed system-wide...
				data.AppExec = this.RecentApplicationExec;
				if (manager.AddFull(_FilePath, data) == false) {
					// (I, Fabian, wanted to make this an error
					// that is always somehow reported, but I was told
					// that someone who disables the recent files list
					// would not want log info spam in return ...  So,)
					Debug.Print("[MainWindow] LoadFile(): " +
						"Adding file \"{0}\" to recently used files list did not work.",
						_FilePath);
				}
			}
			finally {
				this.statusbar1.Pop(_SbCtxActivity);
			}

			// Load file from stable storage.
			try {
				this.statusbar1.Push(_SbCtxActivity, string.Format(
					"Loading file \"{0}\"...",
					_FilePath));
				Application.RunIteration(false);

				using (var reader = new StreamReader(_FilePath)) {
					// TODO: Read in text for TextView and for Notes in parallel.
					//       Otherwise, they could diverge...
					// Read in text for TextView.
					TextBuffer buf = this.textviewText.Buffer;
					TextIter end = buf.EndIter;
					buf.Insert(ref end, reader.ReadToEnd());

					// For now, reset the reader to beginning
					// and read everything in again.
					// TODO: (Or can/should we read the data from the TextView?)
					reader.BaseStream.Seek(0, SeekOrigin.Begin);

					// Parse text as Notes.
					var notes = new Notes(reader);

					// Make parse visible to the user.
					AddNotesTree(notes);
				}
			}
			catch (IOException ex) {
				VisualizeError("Error processing file \"{0}\": {1}",
					_FilePath, ex.Message);
				this.FilePath = null;
				return;
			}
			catch (Exception ex) {
				VisualizeError("Unexpected error (file was \"{0}\"): {1}",
					_FilePath, ex.Message);
				this.FilePath = null;
				return;
			}
			finally {
				this.statusbar1.Pop(_SbCtxActivity);
			}

			// Consider file loaded.
			this.statusbar1.Push(_SbCtxState, "File loaded.");
		}
示例#3
0
        public MainWindow(string dbPath)
        {
            recentManager = RecentManager.Default;

            // retrieve the sort property from settings
            // (from default settings if the settings file does not exist yet)
            Widgets.VolumeSortProperty sp;
            bool desc;

            GetVolumeSortProperty(out sp, out desc);

            BuildGui();

            windowDeleted = false;
            lastSuccessfulSearchCriteria = null;

            SetWindowTitle(null);
            EnableGui(false);

            // set the volumeview's sort property
            // (before filling it with volumes)
            tvVolumes.SetSortProperty(sp, desc);

            // create default db on first startup
            if (!App.Settings.SettingsFileExists())
            {
                // creates (or opens existing) default db and if successful,
                // sets the db path and calls settings.Save()
                OpenOrCreateDefaultDB(false);
                return;
            }

            if (dbPath != null)
            {
                if (!File.Exists(dbPath))
                {
                    MsgDialog.ShowError(this,
                                        S._("Error"),
                                        S._("Database '{0}' not found."),
                                        dbPath);
                }
                else
                {
                    // volumes list will be refreshed asynchronously
                    OpenDB(dbPath, false, true, null);
                }

                return;
            }

            // reopen recent database
            dbPath = App.Settings.MostRecentDBPath;
            if (App.Settings.OpenMostRecentDB && dbPath.Length > 0)
            {
                if (!File.Exists(dbPath))
                {
                    MsgDialog.ShowError(this,
                                        S._("Error"),
                                        S._("Database '{0}' not found."),
                                        dbPath);

                    // clear path so the error won't occur again on next startup
                    App.Settings.MostRecentDBPath = string.Empty;
                    App.Settings.Save();
                }
                else
                {
                    // volumes list will be refreshed asynchronously
                    OpenDB(dbPath, false, true, null);
                }
            }
        }
示例#4
0
 public MainForm()
 {
     InitializeComponents();
     RecentManager = new RecentManager();
 }