mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Add SCM API for disabling updates
This is to be used when the application is in the background. Rather than completely disable updates, it might perhaps be better simply to increase the delay used to throttle updates.
This commit is contained in:
@@ -17,11 +17,14 @@ namespace scm
|
||||
|
||||
namespace scm { namespace ng
|
||||
{
|
||||
static bool Disabled = true;
|
||||
static std::map<std::string, shared_info_weak_ptr> PendingUpdates;
|
||||
|
||||
// =================
|
||||
// = shared_info_t =
|
||||
// =================
|
||||
|
||||
struct shared_info_t
|
||||
struct shared_info_t : std::enable_shared_from_this<shared_info_t>
|
||||
{
|
||||
shared_info_t (std::string const& rootPath, scm::driver_t const* driver);
|
||||
~shared_info_t ();
|
||||
@@ -35,6 +38,8 @@ namespace scm { namespace ng
|
||||
void remove_client (info_t* client);
|
||||
|
||||
private:
|
||||
friend void enable ();
|
||||
|
||||
void background_update ();
|
||||
void fs_did_change (std::set<std::string> const& changedPaths);
|
||||
|
||||
@@ -177,6 +182,12 @@ namespace scm { namespace ng
|
||||
|
||||
void shared_info_t::background_update ()
|
||||
{
|
||||
if(Disabled)
|
||||
{
|
||||
PendingUpdates[_root_path] = shared_from_this();
|
||||
return;
|
||||
}
|
||||
|
||||
if(_pending_update)
|
||||
return;
|
||||
_pending_update = true;
|
||||
@@ -262,6 +273,22 @@ namespace scm { namespace ng
|
||||
return shared_info_ptr();
|
||||
}
|
||||
|
||||
void disable ()
|
||||
{
|
||||
Disabled = true;
|
||||
}
|
||||
|
||||
void enable ()
|
||||
{
|
||||
Disabled = false;
|
||||
for(auto pair : PendingUpdates)
|
||||
{
|
||||
if(shared_info_ptr info = pair.second.lock())
|
||||
info->background_update();
|
||||
}
|
||||
PendingUpdates.clear();
|
||||
}
|
||||
|
||||
std::string root_for_path (std::string const& path)
|
||||
{
|
||||
if(path == NULL_STR || path == "" || path[0] != '/')
|
||||
|
||||
@@ -36,6 +36,8 @@ namespace scm { namespace ng
|
||||
shared_info_ptr _shared_info;
|
||||
};
|
||||
|
||||
PUBLIC void disable ();
|
||||
PUBLIC void enable ();
|
||||
PUBLIC std::string root_for_path (std::string const& path);
|
||||
PUBLIC info_ptr info (std::string path);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user