[IDE Tool] CompareSources

Working on new editor enhancements?
AZJIO
Addict
Addict
Posts: 2154
Joined: Sun May 14, 2017 1:48 am

[IDE Tool] CompareSources

Post by AZJIO »

CompareSources
Download: yandex

1. Add a tool with two parameters "%FILE" "%TEMPFILE". If the file is not saved, then "%FILE" will be empty, and "%TEMPFILE" will be used.
2. Make a call to the hotkey on the first source, then make a call on the second source, and eventually the program for comparing the two sources will open.

ini file is created upon first launch.
firstsrc = here the path to the first source is saved
prog = C:\Program Files\WinMerge\WinMergeU.exe - comparison program
arg = "%f1" "%f2" - parameters where %f1 will be replaced with the 1st source, and %f2 with the second one. You can add /e /x
time = 1734071247 - the timestamp for resetting the first source
timediff = 300 - the time interval after which the first source is reset if the comparison is not performed

Code: Select all

;- TOP
; AZJIO 13.12.2024

EnableExplicit

#q$ = Chr(34)

Define UserIntLang

;- Get Language
CompilerSelect #PB_Compiler_OS
	CompilerCase #PB_OS_Windows
		Define *Lang
		If OpenLibrary(0, "kernel32.dll")
			*Lang = GetFunction(0, "GetUserDefaultUILanguage")
			If *Lang And CallFunctionFast(*Lang) = 1049 ; ru (embed your language natively)
				UserIntLang = 1
			EndIf
			CloseLibrary(0)
		EndIf
	CompilerCase #PB_OS_Linux
		If ExamineEnvironmentVariables()
			While NextEnvironmentVariable()
				If Left(EnvironmentVariableName(), 4) = "LANG" And Left(EnvironmentVariableValue(), 2) = "ru" ; (embed your language natively)
					; LANG=ru_RU.UTF-8
					; LANGUAGE=ru
					UserIntLang = 1
					Break
				EndIf
			Wend
		EndIf
CompilerEndSelect

;- Language En
Define Dim Lng.s(4)
Lng(0) = "First launch"
Lng(1) = "Check that the comparison program exists:"
Lng(2) = "Comparison program missing:"
Lng(3) = "Parameter error"
Lng(4) = "The program should receive one parameter - the path to the source"

If UserIntLang
	Lng(0) = "Певый запуск"
	Lng(1) = "Проверте, что программа сравнения существует:"
	Lng(2) = "Отсутствует программа сравнения:"
	Lng(3) = "Ошибка параметров"
	Lng(4) = "Программа должна получить один параметр - путь к исходнику"
EndIf

; Читаем ini-файл, чтобы определить является ли это первый вызов
;- ini
Define time, timediff
Define firstsrc$, prog$, SourceFile$, arg$
Define ini$
ini$ = GetPathPart(ProgramFilename()) + GetFilePart(ProgramFilename(), #PB_FileSystem_NoExtension) + ".ini"

If OpenPreferences(ini$)
; 	call = ReadPreferenceInteger("call", 0)
	firstsrc$ = ReadPreferenceString("firstsrc", "")
	prog$ = ReadPreferenceString("prog", "")
	arg$ = ReadPreferenceString("arg", #q$ + "%f1" + #q$ + " " + #q$ + "%f2" + #q$)
	time = ReadPreferenceInteger("time", 0)
	timediff = ReadPreferenceInteger("timediff", 300)
	ClosePreferences()
Else
	; 	тут надо создать ini-файл, вместо выхода
	If CreatePreferences(ini$)
		WritePreferenceString("firstsrc", ProgramParameter())
		CompilerIf #PB_Compiler_OS = #PB_OS_Windows
			prog$ = "C:\Program Files\WinMerge\WinMergeU.exe"
		CompilerElse
			prog$ = "meld"
		CompilerEndIf
		WritePreferenceString("prog", prog$)
		WritePreferenceString("arg", #q$ + "%f1" + #q$ + " " + #q$ + "%f2" + #q$)
		WritePreferenceInteger("time", Date())
		WritePreferenceInteger("timediff", 300)
		ClosePreferences()
		RunProgram(ini$)
		CompilerIf #PB_Compiler_OS = #PB_OS_Windows
			If FileSize(prog$) < 5
				MessageRequester(Lng(0), Lng(1) + #LF$ + #LF$ + prog$)
			EndIf
		CompilerEndIf
		End
	EndIf
EndIf

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
	If FileSize(prog$) < 5
		MessageRequester("", Lng(2) + #LF$ + #LF$ + prog$)
		End
	EndIf
CompilerEndIf

;- Parameters
; CountParam = CountProgramParameters()
If CountProgramParameters() > 0 And CountProgramParameters() < 3
	SourceFile$ = ProgramParameter()
	If Not Asc(SourceFile$) And CountProgramParameters() = 2
		SourceFile$ = ProgramParameter()
	EndIf
	If Asc(firstsrc$) And ((Date() - time) < timediff)
		If firstsrc$ <> SourceFile$ And FileSize(firstsrc$) > -1 And FileSize(SourceFile$) > -1
			arg$ = ReplaceString(arg$, "%f1", firstsrc$)
			arg$ = ReplaceString(arg$, "%f2", SourceFile$)
			RunProgram(prog$, arg$, "")
; 			RunProgram(prog$, firstsrc$ + " " + SourceFile$, "")
			; Сбрасываем путь
			If OpenPreferences(ini$)
				WritePreferenceString("firstsrc", "")
				ClosePreferences()
				End
			EndIf
		EndIf
	Else
		If OpenPreferences(ini$)
			; Если путь не существует в ini-файле, то это вызов для первого файла. Соответственно сохраняем путь и закрываем.
			WritePreferenceString("firstsrc", SourceFile$)
			WritePreferenceInteger("time", Date())
			ClosePreferences()
			End
		EndIf
	EndIf
Else
	MessageRequester(Lng(3), Lng(4))
	End
EndIf
Quin
Addict
Addict
Posts: 1132
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: [IDE Tool] CompareSources

Post by Quin »

Nice work as always, and thanks for sharing! :)
BarryG
Addict
Addict
Posts: 4159
Joined: Thu Apr 18, 2019 8:17 am

Re: [IDE Tool] CompareSources

Post by BarryG »

Not bashing it, but the IDE already has a file/source comparison tool built-in; so how is this better?
AZJIO
Addict
Addict
Posts: 2154
Joined: Sun May 14, 2017 1:48 am

Re: [IDE Tool] CompareSources

Post by AZJIO »

BarryG wrote: Fri Dec 27, 2024 4:10 am Not bashing it, but the IDE already has a file/source comparison tool built-in; so how is this better?
1. By showing not only the difference in the lines, but also the difference within the line.
2. In the black theme, I did not find a setting in the IDE to change the color of highlighting line differences.
3. Do you really think that developers who write the comparison program directly will be the losers? Check out the paid program "Beyond Compare". From the free WinMerge and Meld. But Meld is written for Linux and it is not native to Windows, as it uses GTK.

screenshot
BarryG
Addict
Addict
Posts: 4159
Joined: Thu Apr 18, 2019 8:17 am

Re: [IDE Tool] CompareSources

Post by BarryG »

As I said: I wasn't bashing your work. Sounds like you got offended (due to point 3 you listed).
AZJIO
Addict
Addict
Posts: 2154
Joined: Sun May 14, 2017 1:48 am

Re: [IDE Tool] CompareSources

Post by AZJIO »

This idea came to me from AkelPad. Check out the script winMergeTabs.js. But in AkelPad, this is done more conveniently: when you click on a tab, a comparison takes place. To do the same trick, I need to check for a change in the Scintilla handle. If this were integrated into the IDE, then a tab change event would be required.
Post Reply