Search in sources :

Example 1 with ReloadCodeCommand

use of org.python.pydev.debug.model.remote.ReloadCodeCommand in project Pydev by fabioz.

the class PyReloadCode method onSave.

@Override
public void onSave(BaseEditor baseEditor, IProgressMonitor monitor) {
    if (!DebugPrefsPage.getReloadModuleOnChange()) {
        return;
    }
    PyEdit edit = (PyEdit) baseEditor;
    File file = edit.getEditorFile();
    if (file != null) {
        IDebugTarget[] debugTargets = DebugPlugin.getDefault().getLaunchManager().getDebugTargets();
        if (debugTargets.length > 0) {
            ICallback<Boolean, IDebugTarget> callbackThatFilters = new ICallback<Boolean, IDebugTarget>() {

                @Override
                public Boolean call(IDebugTarget arg) {
                    return arg instanceof AbstractDebugTarget;
                }
            };
            List<IDebugTarget> filter = ArrayUtils.filter(debugTargets, callbackThatFilters);
            if (filter.size() > 0) {
                try {
                    IPythonNature pythonNature = edit.getPythonNature();
                    if (pythonNature != null) {
                        String moduleName = pythonNature.resolveModule(file);
                        if (moduleName != null) {
                            for (IDebugTarget iDebugTarget : filter) {
                                AbstractDebugTarget target = (AbstractDebugTarget) iDebugTarget;
                                target.postCommand(new ReloadCodeCommand(target, moduleName));
                            }
                        }
                    }
                } catch (MisconfigurationException e) {
                    Log.log(e);
                }
            }
        }
    }
}
Also used : MisconfigurationException(org.python.pydev.core.MisconfigurationException) IPythonNature(org.python.pydev.core.IPythonNature) ICallback(org.python.pydev.shared_core.callbacks.ICallback) IDebugTarget(org.eclipse.debug.core.model.IDebugTarget) ReloadCodeCommand(org.python.pydev.debug.model.remote.ReloadCodeCommand) File(java.io.File) PyEdit(org.python.pydev.editor.PyEdit)

Aggregations

File (java.io.File)1 IDebugTarget (org.eclipse.debug.core.model.IDebugTarget)1 IPythonNature (org.python.pydev.core.IPythonNature)1 MisconfigurationException (org.python.pydev.core.MisconfigurationException)1 ReloadCodeCommand (org.python.pydev.debug.model.remote.ReloadCodeCommand)1 PyEdit (org.python.pydev.editor.PyEdit)1 ICallback (org.python.pydev.shared_core.callbacks.ICallback)1