def _create_file_list(self, widget=None, data=None): """Create file list in parent notebook""" self.__update_path_from_pid() DefaultList = self._parent.plugin_classes['file_list'] options = Parameters() options.set('path', self.path) self._parent.create_tab(self._notebook, DefaultList, options) return True
def _close_tab(self, widget=None, data=None): """Provide additional functionality""" if self._notebook.get_n_pages() == 1: DefaultList = self._parent.plugin_classes['file_list'] options = Parameters() options.set('path', self.path) self._parent.create_tab(self._notebook, DefaultList, options) return Terminal._close_tab(self, widget, data)
def edit_file(self, selection): """Edit selected filename""" section = self._application.options.section('editor') command = section.get('default_editor') exec_string = self.__format_command_string(selection, command) # open selected file(s) split_command = shlex.split(exec_string) test_command = split_command[0] if len( split_command) > 1 else exec_string if (section.get('terminal_command') and section.get('type') == 1) \ or not is_gui_app(test_command): active_object = self._application.get_active_object() options = Parameters() options.set('close_with_child', True) options.set('shell_command', split_command[0]) options.set('arguments', split_command) options.set('path', os.path.dirname(selection[0])) self._application.create_terminal_tab(active_object._notebook, options) else: subprocess.Popen(split_command, cwd=os.path.dirname(selection[0]))
def __handle_open_terminal_click(self, widget, data=None): """Handle clicking on open in terminal button.""" selected_location = self.__get_selected_location() assert self._active_object is not None or selected_location is not None # close menu self._popover.popdown() # create options to pass to new tab options = Parameters() options.set('path', selected_location.get_location()) # create new tab TabClass = self._application.plugin_classes['system_terminal'] self._application.create_tab(self._active_object._notebook, TabClass, options) return True
def open_file(self, selection, application_info=None, exec_command=None): """Open filename using config file or specified execute command""" if application_info is not None: # launch application using GIO API application = self.get_gio_application_by_id(application_info.id) if application is not None: if application.supports_uris(): selection = [ 'file://{0}'.format( pathname2url(encode_file_name(path))) if not path.startswith('file://') else encode_file_name(path) for path in selection ] application.launch_uris(selection) else: application.launch([ Gio.File.new_for_path(encode_file_name(path)) for path in selection ]) elif exec_command is not None: # use specified command command = exec_command selection = [item.replace('"', '\\"') for item in selection] exec_string = self.__format_command_string(selection, command) # open selected file(s) split_command = shlex.split(exec_string, posix=False) test_command = split_command[0] if len( split_command) > 1 else exec_string if is_gui_app(test_command): subprocess.Popen(split_command, cwd=os.path.dirname(selection[0])) else: active_object = self._application.get_active_object() options = Parameters() options.set('close_with_child', True) options.set('shell_command', split_command[0]) options.set('arguments', split_command) options.set('path', os.path.dirname(selection[0])) self._application.create_terminal_tab(active_object._notebook, options)
def _change_path(self, widget=None, new_tab=False): """Change to selected path""" selection = self._history_list.get_selection() item_list, selected_iter = selection.get_selected() # if selection is valid, change to selected path if selected_iter is not None: path = item_list.get_value(selected_iter, Column.PATH) if not new_tab: # change path self._parent._handle_history_click(path=path) else: # create a new tab options = Parameters() options.set('path', path) self._application.create_tab(self._parent._notebook, self._parent.__class__, options) # close dialog self._close()
def execute_file(self, path, provider=None): """Execute specified item properly.""" mime_type = self.get_mime_type(path) terminal_type = self._application.options.section('terminal').get( 'type') should_execute = False if provider is not None and provider.is_local: # only allow local files which have execute # bit set to be executed locally should_execute = os.access(path, os.X_OK) # if we still don't know content type, try to guess if self.is_mime_type_unknown(mime_type): data = self.get_sample_data(path, provider) mime_type = self.get_mime_type(data=data) if Gio.content_type_can_be_executable(mime_type) and should_execute: # file type is executable if is_gui_app(path): subprocess.Popen((path, ), cwd=os.path.dirname(path)) else: # command is console based, create terminal tab and fork it active_object = self._application.get_active_object() options = Parameters() options.set('close_with_child', False) options.set('shell_command', path) options.set('path', os.path.dirname(path)) self._application.create_terminal_tab(active_object._notebook, options) else: # file type is not executable, try to open with default associated application default_application = self.get_default_application_for_type( mime_type) if default_application is not None: self.open_file((path, ), default_application) else: # no default application selected, show application selection dialog dialog = ApplicationSelectDialog(self._application, path) result = dialog.get_response() if result[0] == Gtk.ResponseType.OK: self.open_file(selection=(path, ), exec_command=result[2])