File: recent_files_menu.py

package info (click to toggle)
secrets 12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,616 kB
  • sloc: python: 6,838; xml: 7; makefile: 4
file content (30 lines) | stat: -rw-r--r-- 827 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# SPDX-License-Identifier: GPL-3.0-only
from __future__ import annotations

from gettext import gettext as _

from gi.repository import Gio

from gsecrets.recent_manager import RecentManager


class RecentFilesMenu:
    def __init__(self):
        """Recently opened files page menu.

        The `menu` attribute contains a GMenuModel to be used on popovers.
        """
        self.menu = Gio.Menu.new()
        self.section = Gio.Menu.new()
        self.is_empty = True

        recents = RecentManager()

        for item in reversed(recents):
            basename = item.get_basename()
            path = item.get_path()
            self.section.append(basename, f"win.open_database::{path}")
            self.is_empty = False

        self.menu.append_section(_("Recent Files"), self.section)
        self.menu.freeze()