1#!/usr/bin/env python3 2# coding: utf-8 3 4# Copyright (C) 2017, 2018 Robert Griesel 5# This program is free software: you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation, either version 3 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program. If not, see <http://www.gnu.org/licenses/> 17 18import setzer.document.context_menu.context_menu_controller as context_menu_controller 19import setzer.document.context_menu.context_menu_presenter as context_menu_presenter 20import setzer.document.context_menu.context_menu_viewgtk as context_menu_view 21from setzer.app.service_locator import ServiceLocator 22 23 24class ContextMenu(object): 25 26 def __init__(self, document, document_view): 27 self.document = document 28 self.document_view = document_view 29 30 self.scbar_view = context_menu_view.ContextMenuView(document) 31 stack = document_view.shortcuts_bar_bottom.more_actions_popover.get_child() 32 stack.add_named(self.scbar_view, 'main') 33 self.controller = context_menu_controller.ContextMenuController(self, self.scbar_view) 34 self.presenter = context_menu_presenter.ContextMenuPresenter(self, self.scbar_view) 35 36 self.can_sync = False 37 self.forward_sync_manager = ServiceLocator.get_forward_sync_manager() 38 self.forward_sync_manager.register_observer(self) 39 40 self.font_manager = ServiceLocator.get_font_manager() 41 self.font_manager.register_observer(self) 42 43 document.register_observer(self) 44 45 def change_notification(self, change_code, notifying_object, parameter): 46 47 if change_code == 'update_sync_state': 48 self.can_sync = self.forward_sync_manager.can_sync 49 if self.document.is_latex_document(): 50 self.presenter.on_can_sync_changed(self.can_sync) 51 52 if change_code == 'font_string_changed': 53 zoom_level = self.font_manager.get_zoom_level() 54 self.presenter.set_zoom_level(zoom_level) 55 56 def on_undo(self, widget=None): 57 self.document.undo() 58 59 def on_redo(self, widget=None): 60 self.document.redo() 61 62 def on_cut(self, widget=None): 63 self.document.cut() 64 65 def on_copy(self, widget=None): 66 self.document.copy() 67 68 def on_paste(self, widget=None): 69 self.document.paste() 70 71 def on_delete(self, widget=None): 72 self.document.delete_selection() 73 74 def on_select_all(self, widget=None): 75 self.document.select_all() 76 77 def on_zoom_out(self, widget=None, event=None): 78 ServiceLocator.get_main_window().zoom_out_action.activate() 79 return True 80 81 def on_zoom_in(self, widget=None, event=None): 82 ServiceLocator.get_main_window().zoom_in_action.activate() 83 return True 84 85 def on_reset_zoom(self, widget=None, event=None): 86 ServiceLocator.get_main_window().reset_zoom_action.activate() 87 return True 88 89 def on_show_in_preview(self, widget=None): 90 self.forward_sync_manager.forward_sync(self.document) 91 92 def on_toggle_comment(self, menu_item): 93 self.document.comment_uncomment() 94 95 96