]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlForks.C
Overhaul the branches code.
[lyx.git] / src / frontends / controllers / ControlForks.C
1 /**
2  * \file ControlForks.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "ControlForks.h"
14 #include "ViewBase.h"
15
16 #include "lyxfunc.h"
17 #include "funcrequest.h"
18
19 #include "support/forkedcontr.h"
20 #include "support/tostr.h"
21
22 #include <boost/bind.hpp>
23
24
25 using lyx::support::ForkedcallsController;
26
27 using std::string;
28 using std::vector;
29
30
31 ControlForks::ControlForks(LyXView & lv, Dialogs & d)
32         : ControlDialogBI(lv, d)
33 {}
34
35
36 vector<pid_t> const ControlForks::getPIDs() const
37 {
38         return ForkedcallsController::get().getPIDs();
39 }
40
41
42 string const ControlForks::getCommand(pid_t pid) const
43 {
44         return ForkedcallsController::get().getCommand(pid);
45 }
46
47
48 void ControlForks::kill(pid_t pid)
49 {
50         pids_.push_back(pid);
51 }
52
53
54 void ControlForks::apply()
55 {
56         if (!bufferIsAvailable())
57                 return;
58
59         view().apply();
60
61         // Nothing to apply?
62         if (pids_.empty())
63                 return;
64
65         for (vector<pid_t>::const_iterator it = pids_.begin();
66              it != pids_.end(); ++it) {
67                 lyxfunc().dispatch(FuncRequest(LFUN_FORKS_KILL, tostr(*it)));
68         }
69
70         pids_.clear();
71 }
72
73
74 void ControlForks::setParams()
75 {
76         if (childrenChanged_.connected())
77                 return;
78
79         pids_.clear();
80
81         ForkedcallsController & fcc = ForkedcallsController::get();
82         childrenChanged_ =
83                 fcc.childrenChanged.connect(boost::bind(&ControlForks::update, this));
84 }
85
86
87 void ControlForks::clearParams()
88 {
89         pids_.clear();
90         childrenChanged_.disconnect();
91 }