Ide: Command line parameter now can be handle in separate class (CommandLineHandler). This is the only refactoring commit that doesn't bring new content. I am trying to limit length of the main method of TheIDE.

git-svn-id: svn://ultimatepp.org/upp/trunk@12102 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
klugier 2018-07-25 22:47:31 +00:00
parent 42f716ebe5
commit 0b683266bd
4 changed files with 109 additions and 24 deletions

View file

@ -0,0 +1,68 @@
#include "CommandLineHandler.h"
#include <Draw/Draw.h>
using namespace Upp;
CommandLineHandler::CommandLineHandler(const Vector<String>& args)
: args(clone(args))
{}
bool CommandLineHandler::Handle()
{
if(HandleManipulators())
return true;
if(HandleHelp())
return true;
return false;
}
bool CommandLineHandler::HandleManipulators()
{
if(HandleScale())
return true;
return false;
}
bool CommandLineHandler::HandleScale()
{
if(args.GetCount() < 2 || args[0].Compare("--scale") != 0)
return false;
int scale = StrInt(args[1]);
if(IsNull(scale)) {
Cout() << "Scale should be numeric value.";
return true;
}
Font::SetStdFont(StdFont().Height(GetStdFontCy() * minmax(scale, 50, 400) / 100));
args.Remove(0, 2);
return false;
}
bool CommandLineHandler::HandleHelp() const
{
if(args.IsEmpty() || findarg(args[0], "?", "--help", "-h", "-?", "/?") < 0)
return false;
Cout() << "Usage: theide assembly package\n"
" theide assembly package build_method [-[a][b][e][r][s][S][v][1][2][m][d][M][l][x][X][Hn]] [+FLAG[,FLAG]...] [out]\n"
" theide -f [file..]\n"
" theide [file..] // autodetection mode\n\n";
Cout() << "Common options:\n"
" -h or --help - displays this site.\n\n";
Cout() << "Advanced options:\n"
" --scale $percent - scale interface by \"percent\" represented by parameter x.\n\n";
Cout() << "Internal options (Should not be called by the user):\n"
" --debug_break_process $pid - breaks debug process represented by \"pid\" (MS Windows only).\n";
return true;
}

View file

@ -0,0 +1,30 @@
#ifndef _ide_Command_Line_Handler_h_
#define _ide_Command_Line_Handler_h_
#include <Core/Core.h>
namespace Upp {
// TODO: All TheIDE command line arguments should be handle in this class.
class CommandLineHandler {
public:
CommandLineHandler(const Vector<String>& args);
bool Handle();
public:
Vector<String> GetArgs() { return clone(args); }
private:
bool HandleManipulators();
bool HandleScale();
bool HandleHelp() const;
private:
Vector<String> args;
};
}
#endif

View file

@ -72,6 +72,8 @@ file
idebar.cpp,
idewin.cpp,
main.cpp,
CommandLineHandler.h,
CommandLineHandler.cpp,
About.h,
About.cpp,
Macro.cpp,

View file

@ -1,4 +1,5 @@
#include "ide.h"
#include "CommandLineHandler.h"
#define FUNCTION_NAME UPP_FUNCTION_NAME << "(): "
@ -116,12 +117,10 @@ void AppMain___()
SetLanguage(LNG_ENGLISH);
SetDefaultCharset(CHARSET_UTF8);
Vector<String> arg = clone(CommandLine());
if(arg.GetCount() && arg[0].StartsWith("--scale=")) {
int scale = atoi(Filter(arg[0], CharFilterDigit));
Font::SetStdFont(StdFont().Height(GetStdFontCy() * minmax(scale, 50, 400) / 100));
arg.Remove(0);
}
CommandLineHandler cmd_handler(CommandLine());
if (cmd_handler.Handle())
return;
auto arg = cmd_handler.GetArgs();
bool first_install = false;
@ -161,12 +160,6 @@ void AppMain___()
ResetBlitz();
for(int i = 0; i < arg.GetCount(); i++) {
/* if(arg[i] == "-uninstall") {
Uninstall();
return;
}
if(!firstinstall && arg[i] == "-install" && !Install()) return;
*/
#ifdef PLATFORM_WIN32
if(arg[i] == "!") {
String cmdline;
@ -226,19 +219,11 @@ void AppMain___()
Ide ide;
ide.Maximize();
bool clset = false;
if(arg.GetCount() && findarg(arg[0], "?", "--help", "-?", "/?") >= 0) {
Cout() << "Usage: theide assembly package\n"
" theide assembly package build_method [-[a][b][e][r][s][S][v][1][2][m][d][M][l][x][X][Hn]] [+FLAG[,FLAG]...] [out]\n"
" theide -f [file..]\n"
" theide [file..] // autodetection mode\n"
;
return;
}
if(arg.GetCount() >= 2 && IsAlpha(arg[0][0]) && IsAlpha(arg[1][0]) && IsAssembly(arg[0]) && arg[0] != "-f") {
bool build = arg.GetCount() >= 3 && IsAlpha(arg[2][0]);
#ifdef PLATFORM_WIN32
if(build) {
HMODULE hDLL = LoadLibrary ("kernel32");
HMODULE hDLL = LoadLibrary("kernel32");
bool attach = false;
if(hDLL) {
typedef BOOL (WINAPI *AttachConsoleType)(DWORD dwProcessId);
@ -484,16 +469,16 @@ void AppMain___()
#ifndef _DEBUG
}
catch(const CParser::Error& e) {
Exclamation("Parser error " + e);
ErrorOK("Parser error " + e);
LOG("!!!!! Parser error " + e);
}
catch(const Exc& e) {
Exclamation("Exception " + e);
ErrorOK("Exception " + e);
LOG("!!!!! Exception " << e);
}
#ifdef PLATFORM_POSIX
catch(...) {
Exclamation("Unknown exception !");
ErrorOK("Unknown exception !");
LOG("!!!!! Unknown exception");
}
#endif