diff options
author | i026e <klev.paul@gmail.com> | 2016-12-15 09:17:49 +0300 |
---|---|---|
committer | i026e <klev.paul@gmail.com> | 2016-12-15 09:17:49 +0300 |
commit | d20d173a98599cd67ebfb94a0d83bf7abb429189 (patch) | |
tree | 1b13fc0cbd5fb50f58b433fa2c506040fc15e472 | |
parent | mark all behavior (diff) | |
download | mime_types_editor-d20d173a98599cd67ebfb94a0d83bf7abb429189.tar.gz mime_types_editor-d20d173a98599cd67ebfb94a0d83bf7abb429189.tar.bz2 mime_types_editor-d20d173a98599cd67ebfb94a0d83bf7abb429189.zip |
app mode
-rw-r--r-- | src/app_mode/mime_editor_app_mode.py | 65 | ||||
-rw-r--r-- | src/app_mode/ui_app_mode.glade | 55 | ||||
-rw-r--r-- | src/common/mime_operations.py | 7 | ||||
-rw-r--r-- | 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 @@ <object class="GtkLabel" id="add_new_app_lable"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="halign">start</property> <property name="label" translatable="yes">Add new app</property> </object> <packing> @@ -190,7 +189,7 @@ <object class="GtkLabel" id="add_mimetype_label"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="label" translatable="yes">Select from list</property> + <property name="label" translatable="yes">Add new mime type</property> </object> <packing> <property name="expand">False</property> @@ -199,44 +198,26 @@ </packing> </child> <child> - <object class="GtkScrolledWindow" id="add_mimetype_scrolledwindow"> + <object class="GtkEntry" id="new_mtype_entry"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="shadow_type">in</property> - <child> - <object class="GtkTreeView" id="all_mime_types_treeview"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <child internal-child="selection"> - <object class="GtkTreeSelection" id="all_mime_types_treeview_selection"/> - </child> - </object> - </child> </object> <packing> - <property name="expand">True</property> + <property name="expand">False</property> <property name="fill">True</property> <property name="position">1</property> </packing> </child> <child> - <object class="GtkExpander" id="add_new_expander"> + <object class="GtkCheckButton" id="register_mtype_button"> + <property name="label" translatable="yes">Add association</property> <property name="visible">True</property> + <property name="sensitive">False</property> <property name="can_focus">True</property> - <child> - <object class="GtkEntry" id="add_mimetype_entry"> - <property name="visible">True</property> - <property name="can_focus">True</property> - </object> - </child> - <child type="label"> - <object class="GtkLabel" id="add_new_mtype_label"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">Add new</property> - <property name="lines">0</property> - </object> - </child> + <property name="receives_default">False</property> + <property name="xalign">0</property> + <property name="active">True</property> + <property name="draw_indicator">True</property> </object> <packing> <property name="expand">False</property> @@ -244,6 +225,22 @@ <property name="position">2</property> </packing> </child> + <child> + <object class="GtkCheckButton" id="set_default_mtype_button"> + <property name="label" translatable="yes">Set default application</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="xalign">0</property> + <property name="active">True</property> + <property name="draw_indicator">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">3</property> + </packing> + </child> </object> <packing> <property name="expand">True</property> 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 @@ <object class="GtkMenuItem" id="file_menuitem"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="label" translatable="yes">_Файл</property> + <property name="label" translatable="yes">_File</property> <property name="use_underline">True</property> <child type="submenu"> <object class="GtkMenu" id="file_menu"> @@ -53,7 +53,7 @@ <child> <object class="GtkMenuItem" id="edit_menuitem"> <property name="can_focus">False</property> - <property name="label" translatable="yes">_Правка</property> + <property name="label" translatable="yes">_Edit</property> <property name="use_underline">True</property> <child type="submenu"> <object class="GtkMenu" id="menu2"> @@ -103,7 +103,7 @@ <object class="GtkMenuItem" id="view_menuitem"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="label" translatable="yes">_Вид</property> + <property name="label" translatable="yes">_View</property> <property name="use_underline">True</property> <child type="submenu"> <object class="GtkMenu" id="menu4"> @@ -134,7 +134,7 @@ <object class="GtkMenuItem" id="help_menuitem"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="label" translatable="yes">_Справка</property> + <property name="label" translatable="yes">_Help</property> <property name="use_underline">True</property> <child type="submenu"> <object class="GtkMenu" id="menu3"> |