forked from Mirrors/apostrophe
recents menu refactoring
parent
540671186e
commit
fcab2687f1
|
@ -0,0 +1,31 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- Generated with glade 3.22.1 -->
|
||||||
|
<interface>
|
||||||
|
<requires lib="gtk+" version="3.20"/>
|
||||||
|
<object class="GtkRecentFilter" id="recent_md_filter">
|
||||||
|
<mime-types>
|
||||||
|
<mime-type>text/x-markdown</mime-type>
|
||||||
|
</mime-types>
|
||||||
|
</object>
|
||||||
|
<object class="GtkPopoverMenu" id="recent_md_popover">
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="hexpand">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkRecentChooserWidget" id="recent_md_widget">
|
||||||
|
<property name="width_request">200</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="valign">start</property>
|
||||||
|
<property name="filter">recent_md_filter</property>
|
||||||
|
<property name="limit">20</property>
|
||||||
|
<property name="show_icons">False</property>
|
||||||
|
<property name="show_not_found">False</property>
|
||||||
|
<property name="sort_type">mru</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="submenu">main</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</interface>
|
|
@ -986,43 +986,13 @@ class UberwriterWindow(Gtk.ApplicationWindow):
|
||||||
def open_recent(self, _widget, data=None):
|
def open_recent(self, _widget, data=None):
|
||||||
"""open the given recent document
|
"""open the given recent document
|
||||||
"""
|
"""
|
||||||
|
print("open")
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
if self.check_change() == Gtk.ResponseType.CANCEL:
|
if self.check_change() == Gtk.ResponseType.CANCEL:
|
||||||
return
|
return
|
||||||
self.load_file(data)
|
self.load_file(data)
|
||||||
|
|
||||||
def generate_recent_files_menu(self):
|
|
||||||
"""Generate a menu of recent opened .md files
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
GtkMenu -- the menu of recent items
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Recent file filter
|
|
||||||
self.recent_manager = Gtk.RecentManager.get_default()
|
|
||||||
|
|
||||||
self.recent_files_menu = Gtk.RecentChooserMenu.new_for_manager(
|
|
||||||
self.recent_manager)
|
|
||||||
self.recent_files_menu.set_sort_type(Gtk.RecentSortType.MRU)
|
|
||||||
|
|
||||||
recent_filter = Gtk.RecentFilter.new()
|
|
||||||
recent_filter.add_mime_type('text/x-markdown')
|
|
||||||
self.recent_files_menu.set_filter(recent_filter)
|
|
||||||
menu = Gtk.Menu.new()
|
|
||||||
|
|
||||||
for entry in self.recent_files_menu.get_items():
|
|
||||||
if entry.exists():
|
|
||||||
item = Gtk.MenuItem.new_with_label(entry.get_display_name())
|
|
||||||
item.connect('activate', self.open_recent, entry.get_uri())
|
|
||||||
menu.append(item)
|
|
||||||
item.show()
|
|
||||||
|
|
||||||
menu.show()
|
|
||||||
return menu
|
|
||||||
# menu.attach_to_widget(widget)
|
|
||||||
# parent_menu.show()
|
|
||||||
|
|
||||||
def poll_for_motion(self):
|
def poll_for_motion(self):
|
||||||
"""check if the user has moved the cursor to show the headerbar
|
"""check if the user has moved the cursor to show the headerbar
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ from gettext import gettext as _
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
from uberwriter_lib.helpers import get_builder
|
from uberwriter_lib.helpers import get_builder
|
||||||
|
|
||||||
|
from uberwriter_lib.AppWindow import Application as app
|
||||||
|
|
||||||
class MainHeaderbar: #pylint: disable=too-few-public-methods
|
class MainHeaderbar: #pylint: disable=too-few-public-methods
|
||||||
"""Sets up the main application headerbar
|
"""Sets up the main application headerbar
|
||||||
|
@ -104,8 +105,13 @@ def buttons():
|
||||||
Returns:
|
Returns:
|
||||||
[NamedTupple] -- tupple of Gtk.Buttons
|
[NamedTupple] -- tupple of Gtk.Buttons
|
||||||
"""
|
"""
|
||||||
|
|
||||||
builder_window_menu = get_builder('Menu')
|
builder_window_menu = get_builder('Menu')
|
||||||
model = builder_window_menu.get_object("Menu")
|
model = builder_window_menu.get_object("Menu")
|
||||||
|
recents_builder = get_builder('Recents')
|
||||||
|
recents = recents_builder.get_object("recent_md_popover")
|
||||||
|
recents_wd = recents_builder.get_object("recent_md_widget")
|
||||||
|
recents_wd.connect('item-activated', app.on_open_recent)
|
||||||
|
|
||||||
Button = namedtuple("Button", "new open recent save search menu")
|
Button = namedtuple("Button", "new open recent save search menu")
|
||||||
btn = Button(Gtk.Button().new_with_label(_("New")),
|
btn = Button(Gtk.Button().new_with_label(_("New")),
|
||||||
|
@ -119,6 +125,7 @@ def buttons():
|
||||||
btn.recent.set_image(Gtk.Image.new_from_icon_name("go-down-symbolic",
|
btn.recent.set_image(Gtk.Image.new_from_icon_name("go-down-symbolic",
|
||||||
Gtk.IconSize.BUTTON))
|
Gtk.IconSize.BUTTON))
|
||||||
btn.recent.set_tooltip_text(_("Open Recent"))
|
btn.recent.set_tooltip_text(_("Open Recent"))
|
||||||
|
btn.recent.set_popover(recents)
|
||||||
btn.search.set_tooltip_text(_("Search and replace"))
|
btn.search.set_tooltip_text(_("Search and replace"))
|
||||||
btn.menu.set_tooltip_text(_("Menu"))
|
btn.menu.set_tooltip_text(_("Menu"))
|
||||||
btn.menu.set_image(Gtk.Image.new_from_icon_name("open-menu-symbolic",
|
btn.menu.set_image(Gtk.Image.new_from_icon_name("open-menu-symbolic",
|
||||||
|
@ -127,7 +134,6 @@ def buttons():
|
||||||
btn.menu.set_menu_model(model)
|
btn.menu.set_menu_model(model)
|
||||||
btn.new.set_action_name("app.new")
|
btn.new.set_action_name("app.new")
|
||||||
btn.open.set_action_name("app.open")
|
btn.open.set_action_name("app.open")
|
||||||
btn.recent.set_action_name("app.open_recent")
|
|
||||||
btn.save.set_action_name("app.save")
|
btn.save.set_action_name("app.save")
|
||||||
btn.search.set_action_name("app.search")
|
btn.search.set_action_name("app.search")
|
||||||
|
|
||||||
|
|
|
@ -230,8 +230,9 @@ class Application(Gtk.Application):
|
||||||
def on_open(self, _action, _value):
|
def on_open(self, _action, _value):
|
||||||
self.window.open_document()
|
self.window.open_document()
|
||||||
|
|
||||||
def on_open_recent(self, action, value):
|
def on_open_recent(self):
|
||||||
pass
|
print(self)
|
||||||
|
#self.window.load_file(self.get_current_uri())
|
||||||
|
|
||||||
def on_example(self, _action, _value):
|
def on_example(self, _action, _value):
|
||||||
self.window.open_uberwriter_markdown()
|
self.window.open_uberwriter_markdown()
|
||||||
|
|
Loading…
Reference in New Issue