def refresh_all(force=False):
    """Remove/close all libraries and state machines and reloads them freshly from the file system

    :param bool force: Force flag to avoid any checks
    """
    state_machines_editor_ctrl = rafcon.gui.singleton.main_window_controller.get_controller('state_machines_editor_ctrl')
    states_editor_ctrl = rafcon.gui.singleton.main_window_controller.get_controller('states_editor_ctrl')

    if force:
        pass  # no checks direct refresh
    else:

        # check if a state machine is still running
        if not is_state_machine_stopped_to_proceed(root_window=states_editor_ctrl.get_root_window()):
            return

        # check if the a dirty flag is still set
        all_tabs = list(states_editor_ctrl.tabs.values())
        all_tabs.extend(states_editor_ctrl.closed_tabs.values())
        dirty_source_editor = [tab_dict['controller'] for tab_dict in all_tabs if
                               tab_dict['source_code_view_is_dirty'] is True]
        if state_machine_manager.has_dirty_state_machine() or dirty_source_editor:

            message_string = "Are you sure you want to reload the libraries and all state machines?\n\n" \
                             "The following elements have been modified and not saved. " \
                             "These changes will get lost:"
            for sm_id, sm in state_machine_manager.state_machines.items():
                if sm.marked_dirty:
                    message_string = "%s\n* State machine #%s and name '%s'" % (
                        message_string, str(sm_id), sm.root_state.name)
            for ctrl in dirty_source_editor:
                message_string = "%s\n* Source code of state with name '%s' and path '%s'" % (
                    message_string, ctrl.model.state.name, ctrl.model.state.get_path())
            dialog = RAFCONButtonDialog(message_string, ["Reload anyway", "Cancel"],
                                        message_type=Gtk.MessageType.WARNING, parent=states_editor_ctrl.get_root_window())
            response_id = dialog.run()
            dialog.destroy()
            if response_id == 1:  # Reload anyway
                pass
            else:
                logger.debug("Refresh canceled")
                return

    library_manager.clean_loaded_libraries()
    refresh_libraries()
    states_editor_ctrl.close_all_pages()
    state_machines_editor_ctrl.refresh_all_state_machines()