Esempio n. 1
0
bool ICmdProcTextEntryStc::DoReplaceAll(ICmdParam& cmd)
{
	cmd.param2=1;

	Target.SetInsertionPoint(0);
	if(!TestSelection() && !DoFind(cmd))
	{
		Wrapper::MsgsDialog(_hT("no results"),0);
		return false;
	}

	int n=0;
	Target.BeginUndoAction();
	try
	{
		while(DoReplace(cmd)) n++;
	}
	catch(std::exception&)
	{
			
	}
	Target.EndUndoAction();
	Wrapper::MsgsDialog(String::Format(_hT("%d results replaced"),n),0);
	return true;
}
Esempio n. 2
0
bool ICmdProcTextEntryStc::DoFind(ICmdParam& cmd)
{		
	long p1=Target.GetInsertionPoint();

	Target.SetTargetStart(p1);
	Target.SetTargetEnd(Target.GetLastPosition());

	if(Target.SearchInTarget(str2wx(data.text_old))==-1)
	{

		if(cmd.param2==1) return false;
		
		Target.SetTargetStart(0);
		Target.SetTargetEnd(Target.GetLastPosition());

		if(Target.SearchInTarget(str2wx(data.text_old))!=-1)
		{
			int rt=Wrapper::MsgsDialog(_hT("no more results, restart?"),IDefs::BTN_YES|IDefs::BTN_NO|IDefs::ICON_QUESTION);
			if(rt!=IDefs::BTN_YES)
			{
				return false;
			}
		}
		else
		{
			Wrapper::MsgsDialog(_hT("no more results!"),IDefs::ICON_MESSAGE|IDefs::BTN_OK);
			return false;
		}
	}

	Target.GotoPos(Target.GetTargetStart());
	Target.SetSelection(Target.GetTargetStart(),Target.GetTargetEnd());
	Target.SetInsertionPoint(Target.GetTargetEnd());

	return true;
}
Esempio n. 3
0
bool CmdProc::DoExecId(ICmdParam& cmd)
{
	Logger& logger(this_logger());

	if (cmd.param1 == CP_LOAD_FILE)
	{
		if(!DoLoad(cmd.extra1))
		{
			logger.LogError(_hT("failed_to_load_file %s!"),cmd.extra1);
			return false;
		}
		return true;
	}
	else if (cmd.param1 == CP_SAVE_FILE)
	{
		return DoSave(cmd.extra1);
	}
	else if (cmd.param1 == CP_INIT)
	{
		if (cmd.extra1 != "")
		{

		}
		else if (!TestId(CmdProc::CP_SAVEAS, cmd.extra1))
		{
			return false;
		}

		//if (cmd.extra1 == "")
		//{
		//	return true;
		//}

		cmd.param1 = CP_LOAD_FILE;
		if (!DoExecId(cmd)) return false;
		return true;
	}
	else if (cmd.param1 == CP_LOAD)
	{

		if (cmd.extra1 != "")
		{

		}
		else if (!TestId(CmdProc::CP_SAVEAS, cmd.extra1))
		{
			return false;
		}

		if (cmd.extra1 == "")
		{
			String exts;
			TestId(CP_FILEEXT, exts);

			if (Wrapper::FileDialog(cmd.extra1, IDefs::FD_OPEN, "", exts) == IDefs::BTN_CANCEL)
			{
				return false;
			}
		}
		cmd.param1 = CP_LOAD_FILE;
		if (!DoExecId(cmd)) return false;
		return true;
	}

	else if(cmd.param1==CP_SAVE_TEMP)
	{
		if (cmd.extra1 != "")
		{

		}
		else if (cmd.extra2 == "")
		{
			return false;
		}
		else
		{
			cmd.extra1 = cmd.extra2 + ".temp";
		}

		cmd.param1 = CP_SAVE_FILE;
		return DoExecId(cmd);
	}

	else if(cmd.param1==CP_SAVE_POST)
	{
		if (cmd.extra1 == ""||cmd.extra2=="")
		{
			return false;
		}

		if (cmd.extra1 != cmd.extra2)
		{
			if (!FSObject::current().Rename(cmd.extra1, cmd.extra2, 1))
			{
				logger.LogError(_hT("failed_to_save_file %s!"),cmd.extra2);
				return false;
			}
		}

		fn.SetFilename(cmd.extra2);

		return true;
	}
	else if(cmd.param1==CP_SAVE||cmd.param1==CP_SAVEAS)
	{

		if(!TestId(CmdProc::CP_SAVEAS,cmd.extra1))
		{
			cmd.param2 = -1;
			return false;
		}

		if(cmd.extra1==""||cmd.param1==CP_SAVEAS)
		{
			String exts;
			TestId(CP_FILEEXT,exts);

			if (Wrapper::FileDialog(cmd.extra1, IDefs::FD_SAVE | IDefs::FD_OVERWRITE_PROMPT, "", exts) == IDefs::BTN_CANCEL)
			{
				cmd.param2 = -2;
				return false;
			}
		}


		if (!FSObject::current().FileExists(cmd.extra1))
		{
			cmd.extra2 = cmd.extra1;
		}
		else
		{
			std::swap(cmd.extra1,cmd.extra2);
		}

		cmd.param2 = 0;

		cmd.param1=CP_SAVE_TEMP;
		if(!DoExecId(cmd))
		{
			logger.LogError(_hT("failed_to_save_file %s!"),cmd.extra2);
			return false;
		}

		cmd.param1=CP_SAVE_POST;
		if(!DoExecId(cmd)) return false;

		return true;
	}
	else
	{
		return false;
	}
}