{"size": 2621, "ext": "js", "max_stars_repo_path": "synchronize/sync.js", "max_stars_repo_name": "tablacus/TablacusExplorerAddons", "max_stars_repo_stars_event_min_datetime": "2015-07-30T17:42:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T17:57:14.000Z", "max_issues_repo_path": "synchronize/sync.js", "max_issues_repo_name": "tablacus/TablacusExplorerAddons", "max_issues_repo_issues_event_min_datetime": "2015-01-25T17:02:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-15T00:46:30.000Z", "max_forks_repo_path": "synchronize/sync.js", "max_forks_repo_name": "tablacus/TablacusExplorerAddons", "max_forks_repo_forks_event_min_datetime": "2016-08-21T00:38:04.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-27T09:35:59.000Z"}
{"max_stars_count": 64, "max_issues_count": 324, "max_forks_count": 16, "avg_line_length": 29.1222222222, "max_line_length": 143, "alphanum_fraction": 0.6528042732}
const Addon_Id = "synchronize";
const item = GetAddonElement(Addon_Id);

Sync.Synchronize = {
	strName: item.getAttribute("MenuName") || GetAddonInfo(Addon_Id).Name,
	nPos: GetNum(item.getAttribute("MenuPos")),
	Disabled: !GetNum(item.getAttribute("Start")),

	Exec: function (Ctrl, pt) {
		Sync.Synchronize.Disabled = !Sync.Synchronize.Disabled;
		InvokeUI("Addons.Synchronize.State", Sync.Synchronize.Disabled);
	},

	Run: function (Ctrl, Prev, fn) {
		if (!Prev) {
			return;
		}
		const parent = GetFileName(Prev.Path);
		const TC = Ctrl.Parent;
		const Id = TC.Id;
		Sync.Synchronize.Id = Id;
		Sync.Synchronize.tm = new Date().getTime() + 5000;
		const cTC = te.Ctrls(CTRL_TC, true);
		for (let i in cTC) {
			if (Id != cTC[i].Id) {
				fn(Ctrl, cTC[i].Selected, parent);
			}
		}
	}
};

AddEvent("Load", function () {
	AddEvent("BeforeNavigate", function (Ctrl, fs, wFlags, Prev) {
		if (Sync.Synchronize.Disabled) {
			return;
		}
		if (Sync.Synchronize.Id) {
			if (new Date().getTime() < Sync.Synchronize.tm) {
				return;
			}
		}
		if (api.ILIsParent(Prev, Ctrl, true) || (/\.cfu$/i.test((Prev || {}).Path) || /\.cfu$/i.test((Ctrl.FolderItem || {}).Path))) {
			Sync.Synchronize.Run(Ctrl, Prev, function (Ctrl, FV, parent) {
				if (FV.FolderItem.IsFolder) {
					const f = FV.FolderItem.GetFolder;
					if (f) {
						const pid = f.ParseName(GetFileName(Ctrl.FolderItem.Path));
						if (pid) {
							FV.Navigate(pid, SBSP_SAMEBROWSER);
						}
					}
				}
			});
		} else if (api.ILIsParent(Ctrl, Prev, true)) {
			Sync.Synchronize.Run(Ctrl, Prev, function (Ctrl, FV, parent) {
				if (SameText(parent, GetFileName(FV.FolderItem.Path))) {
					FV.Navigate(null, SBSP_PARENT);
				}
			});
		}
	});

	AddEvent("NavigateComplete", function (Ctrl) {
		if (Sync.Synchronize.Id == Ctrl.Parent.Id) {
			delete Sync.Synchronize.Id;
			setTimeout(function () {
				Ctrl.Focus();
			}, 999);
		}
	});
});

//Menu
if (GetNum(item.getAttribute("MenuExec"))) {
	AddEvent(item.getAttribute("Menu"), function (Ctrl, hMenu, nPos) {
		api.InsertMenu(hMenu, Sync.Synchronize.nPos, MF_BYPOSITION | (Sync.Synchronize.Disabled ? 0 : MF_CHECKED), ++nPos, Sync.Synchronize.strName);
		ExtraMenuCommand[nPos] = Sync.Synchronize.Exec;
		return nPos;
	});
}
//Key
if (GetNum(item.getAttribute("KeyExec"))) {
	SetKeyExec(item.getAttribute("KeyOn"), item.getAttribute("Key"), Sync.Synchronize.Exec, "Func");
}
//Mouse
if (GetNum(item.getAttribute("MouseExec"))) {
	SetGestureExec(item.getAttribute("MouseOn"), item.getAttribute("Mouse"), Sync.Synchronize.Exec, "Func");
}
AddTypeEx("Add-ons", "Synchronize", Sync.Synchronize.Exec);
