# # patch "main.cc" # from [1f179a25ce2dee322306ade507812ccd0c7de8f5] # to [220a72e95c8c0d10669952052d381e1dccc0787a] # # patch "misc.cc" # from [b632c3e08a89ac9a0045af913319d5e68e8444a1] # to [82fa13081825cc823344ce6b3620b5ab00248ac7] # # patch "misc.hh" # from [13e5b8e9966be45be74a07dfddff8c730f2304a0] # to [0dbce437cdb988dc841b1b5e4552e0151ca126aa] # # patch "monotone.cc" # from [71a4d5c7f44e1c0834efcda59ca776c8501ae66e] # to [fcbc08d47a1ccebdf94a2c0b749362f746050814] # # patch "monotone.hh" # from [faca8a5452650ddac597dcd331d3587d34f99aff] # to [e79d886231e39b6487871a4f39c1ced66afc9013] # ======================================================================== --- main.cc 1f179a25ce2dee322306ade507812ccd0c7de8f5 +++ main.cc 220a72e95c8c0d10669952052d381e1dccc0787a @@ -60,18 +60,8 @@ void update() { - std::vector rr; - if (!mtn.update(rr)) - { - chooser c(rr); - int result = c.run(); - if (result == Gtk::RESPONSE_OK) - { - std::string rev = c.result(); - if (!rev.empty()) - mtn.update(rev); - } - } + UpdateDialog ud(mtn); + ud.run(); } void sync() ======================================================================== --- misc.cc b632c3e08a89ac9a0045af913319d5e68e8444a1 +++ misc.cc 82fa13081825cc823344ce6b3620b5ab00248ac7 @@ -47,15 +47,15 @@ } namespace { - SyncDialog *sd; - void sd_lwcb() + ProgressDialog *pd; + void pd_lwcb() { - int r = sd->output.rfind("\r"); - int n = sd->output.rfind("\n", r); + int r = pd->output.rfind("\r"); + int n = pd->output.rfind("\n", r); if (r != string::npos && n != string::npos) - sd->output = sd->output.substr(0, n+1) + sd->output.substr(r+1); - Glib::RefPtr b = sd->tv.get_buffer(); - b->set_text(sd->output); + pd->output = pd->output.substr(0, n+1) + pd->output.substr(r+1); + Glib::RefPtr b = pd->tv.get_buffer(); + b->set_text(pd->output); Glib::RefPtr t = b->create_tag(); t->property_family() = "monospace"; b->apply_tag(t, b->begin(), b->end()); @@ -64,10 +64,10 @@ } }; -// mtn->sync() is called from a timeout so that we'll return first, +// mtn->whatever() is called from a timeout so that we'll return first, // and it will be called from the event loop, *after* our window exists, // and can continue to run the event loop itself. -SyncDialog::SyncDialog(monotone & m) +ProgressDialog::ProgressDialog(monotone & m) : mtn(&m), prev_lwcb(m.get_longwait_callback()) { get_vbox()->add(tv); @@ -76,20 +76,37 @@ cancelbtn = add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); okbtn = add_button("Done", Gtk::RESPONSE_OK); okbtn->set_sensitive(false); - sd = this; - mtn->set_longwait_callback(sd_lwcb); - Glib::signal_timeout().connect(sigc::mem_fun(this, &SyncDialog::timer), 0); + pd = this; + mtn->set_longwait_callback(pd_lwcb); + Glib::signal_timeout().connect(sigc::mem_fun(this, &ProgressDialog::timer), 0); } -SyncDialog::~SyncDialog() +ProgressDialog::~ProgressDialog() { mtn->set_longwait_callback(prev_lwcb); } -bool SyncDialog::timer() +bool ProgressDialog::timer() { - mtn->sync(output); + callmtn(); + pd_lwcb(); okbtn->set_sensitive(true); cancelbtn->set_sensitive(false); return false; } + +void UpdateDialog::callmtn() +{ + std::vector rr; + if (!mtn->update(rr, output)) + { + chooser c(rr); + int result = c.run(); + if (result == Gtk::RESPONSE_OK) + { + std::string rev = c.result(); + if (!rev.empty()) + mtn->update(rev, output); + } + } +} ======================================================================== --- misc.hh 13e5b8e9966be45be74a07dfddff8c730f2304a0 +++ misc.hh 0dbce437cdb988dc841b1b5e4552e0151ca126aa @@ -8,6 +8,8 @@ using std::string; using std::vector; +#include "monotone.hh" + std::string readfile(std::string const & f); class chooser: public Gtk::Dialog @@ -25,18 +27,29 @@ std::string result(); }; -struct monotone; - -struct SyncDialog : public Gtk::Dialog +struct ProgressDialog : public Gtk::Dialog { monotone *mtn; Gtk::Button *okbtn, *cancelbtn; Gtk::TextView tv; void(*prev_lwcb)(); string output; - SyncDialog(monotone & m); - ~SyncDialog(); + ProgressDialog(monotone & m); + ~ProgressDialog(); bool timer(); + virtual void callmtn() {} }; +struct SyncDialog : public ProgressDialog +{ + SyncDialog(monotone & m) : ProgressDialog(m) {} + virtual void callmtn() {mtn->sync(output);} +}; + +struct UpdateDialog : public ProgressDialog +{ + UpdateDialog(monotone & m) : ProgressDialog(m) {} + virtual void callmtn(); +}; + #endif ======================================================================== --- monotone.cc 71a4d5c7f44e1c0834efcda59ca776c8501ae66e +++ monotone.cc fcbc08d47a1ccebdf94a2c0b749362f746050814 @@ -532,34 +532,34 @@ } bool -monotone::update(std::vector & opts) +monotone::update(std::vector & opts, string & out) { opts.clear(); - std::string ign, err; + std::string ign; std::vector args; - runcmd("update", args, ign, err); - int p = err.find("multiple update candidates"); + runcmd("update", args, ign, out); + int p = out.find("multiple update candidates"); if (p == std::string::npos) return true; - p = err.find("monotone: ", p + 1); + p = out.find("monotone: ", p + 1); while (p != std::string::npos) { - p = err.find(":", p); - p = err.find_first_not_of(" ", p + 1); - opts.push_back(err.substr(p, 40)); - p = err.find("monotone: ", p + 1); + p = out.find(":", p); + p = out.find_first_not_of(" ", p + 1); + opts.push_back(out.substr(p, 40)); + p = out.find("monotone: ", p + 1); } return false; } void -monotone::update(std::string const & rev) +monotone::update(std::string const & rev, string & out) { - std::string ign, err; + std::string ign; std::vector args; args.push_back("--revision="+rev); - runcmd("update", args, ign, err); + runcmd("update", args, ign, out); } void ======================================================================== --- monotone.hh faca8a5452650ddac597dcd331d3587d34f99aff +++ monotone.hh e79d886231e39b6487871a4f39c1ced66afc9013 @@ -91,8 +91,8 @@ void drop(std::string const & file); void revert(std::string const & file); void rename(std::string const & oldname, std::string const & newname); - bool update(std::vector & opts); - void update(std::string const & rev); + bool update(std::vector & opts, string & out); + void update(std::string const & rev, string & out); void sync(string & res); };