From d20d173a98599cd67ebfb94a0d83bf7abb429189 Mon Sep 17 00:00:00 2001 From: i026e Date: Thu, 15 Dec 2016 09:17:49 +0300 Subject: app mode --- src/app_mode/mime_editor_app_mode.py | 65 ++++++++++++------------------------ src/app_mode/ui_app_mode.glade | 55 +++++++++++++++--------------- src/common/mime_operations.py | 7 ++++ src/ui_main_window.glade | 8 ++--- 4 files changed, 58 insertions(+), 77 deletions(-) diff --git a/src/app_mode/mime_editor_app_mode.py b/src/app_mode/mime_editor_app_mode.py index a6917a9..d6210ab 100644 --- a/src/app_mode/mime_editor_app_mode.py +++ b/src/app_mode/mime_editor_app_mode.py @@ -30,35 +30,6 @@ print(os.path.dirname(os.path.realpath(__file__))) GLADE_FILE = os.path.join(DIR,"./ui_app_mode.glade") -""" -class AddMimesView(mime_types_view.MimesViewWithFlags): - def __init__(self, builder): - super(AddMimesView, self).__init__(builder, "all_mime_types_treeview") - - self._init_context_menu() - - def _init_context_menu(self): - pass - - def get_initial_data(self, *args): - return mime_operations.get_known_mtypes() - - def get_model_data_row(self, mtype, app): - flag = mime_operations.is_app_default(app, mtype) - descr, icon = mime_operations.get_mime_bio(mtype, ICON_SIZE) - - # mtype, mtype_description, mtype_icon, - # mtype_selected. mtype_selected_by_default, - # mtype_possible_to change_selection - # mtype_deleted, background_color - - return [mtype, descr, icon, - flag, flag, not flag, - False, self.CELL_COLOR_NORMAL] - - -""" - class AppCard: def __init__(self, builder): self.builder = builder @@ -178,7 +149,7 @@ class AddMTypeDialog: self.dialog.set_transient_for(parent_window) self.dialog.connect("delete-event", self.hide) - #self.view = AddMimesView(self.builder) + self._init_buttons() def _init_buttons(self): self.ok_button = self.builder.get_object("add_mtype_ok_button") @@ -188,25 +159,22 @@ class AddMTypeDialog: self.cancel_button.connect("clicked", self.hide) def hide(self, *args): - self.dialog.hide() - #self.list_store.clear() - - - return True #!!! def show(self, app): - #self.set_data() - #self.indicate_default() - - #self.mtypes_dialog_label.set_text(" \n".join(self.mtypes)) - - self.view.set_data(app) - self.dialog.run() + def on_ok_button_clicked(self, *args): - pass + text_box = self.builder.get_object("new_mtype_entry") + reg_button = self.builder.get_object("register_mtype_button") + def_button = self.builder.get_object("set_default_mtype_button") + + mtype = text_box.get_text() + set_registered = reg_button.get_active() + set_default = def_button.get_active() + + self.on_dialog_ok(mtype, set_registered, set_default) self.hide() class AddAppDialog: @@ -383,7 +351,7 @@ class MainWidget: def on_add_mtype_button_clicked(self, *args): if self.add_mtype_dialog is None: self.add_mtype_dialog = AddMTypeDialog(self.builder, - self.window, print) + self.window, self.on_add_mtype_ok) self.add_mtype_dialog.show(self.current_app) def on_add_app_button_clicked(self, *args): @@ -404,5 +372,14 @@ class MainWidget: def on_category_changed(self, category): self.mimes_view.filter_category(category) + + def on_add_mtype_ok(self, mtype, set_registered, set_default): + if set_registered: + mime_operations.add_associations(self.current_app, [mtype]) + + if set_default: + mime_operations.set_app_default(self.current_app, [mtype]) + + self.on_app_selected(self.current_app) diff --git a/src/app_mode/ui_app_mode.glade b/src/app_mode/ui_app_mode.glade index 494eb18..7a1c0f0 100644 --- a/src/app_mode/ui_app_mode.glade +++ b/src/app_mode/ui_app_mode.glade @@ -57,7 +57,6 @@ True False - start Add new app @@ -190,7 +189,7 @@ True False - Select from list + Add new mime type False @@ -199,44 +198,26 @@ - + True True - in - - - True - True - - - - - - True + False True 1 - + + Add association True + False True - - - True - True - - - - - True - False - Add new - 0 - - + False + 0 + True + True False @@ -244,6 +225,22 @@ 2 + + + Set default application + True + True + False + 0 + True + True + + + False + True + 3 + + True diff --git a/src/common/mime_operations.py b/src/common/mime_operations.py index 64d4c61..aab7b28 100644 --- a/src/common/mime_operations.py +++ b/src/common/mime_operations.py @@ -114,6 +114,13 @@ def reset_associations(mtypes): Gio.AppInfo.reset_type_associations(mtype) except Exception as e: print(e) + +def add_associations(app, mtypes): + for mtype in mtypes: + try: + app.add_supports_type(mtype) + except Exception as e: + print(e) def remove_associations(app, mtypes): for mtype in mtypes: diff --git a/src/ui_main_window.glade b/src/ui_main_window.glade index a9197c2..4f695f5 100644 --- a/src/ui_main_window.glade +++ b/src/ui_main_window.glade @@ -23,7 +23,7 @@ True False - _Файл + _File True @@ -53,7 +53,7 @@ False - _Правка + _Edit True @@ -103,7 +103,7 @@ True False - _Вид + _View True @@ -134,7 +134,7 @@ True False - _Справка + _Help True -- cgit