diff options
| author | Tomas Bzatek <tbzatek@redhat.com> | 2025-11-27 21:37:04 +0100 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@redhat.com> | 2025-11-27 21:43:01 +0100 |
| commit | 0ea64a41e1499d25296bdcc69fe207e20e545efd (patch) | |
| tree | 7967ec49a0cfa1a92cec0501ada90ae7c2d4d5e2 /UConfig.pas | |
| parent | 2af0113561115645809b19e5200d433fe13199a1 (diff) | |
| download | tuxcmd-0ea64a41e1499d25296bdcc69fe207e20e545efd.tar.xz | |
Port to GOptionContext commandline argument parser
+ rework GTK initialization
Diffstat (limited to 'UConfig.pas')
| -rw-r--r-- | UConfig.pas | 150 |
1 files changed, 93 insertions, 57 deletions
diff --git a/UConfig.pas b/UConfig.pas index 836c107..6e33947 100644 --- a/UConfig.pas +++ b/UConfig.pas @@ -88,7 +88,7 @@ var ConfPanelSep, ConfRowHeight, ConfRowHeightReal, ConfNumHistoryItems, ConfDiffCommand, ConfDiffDirCommand: string; ParamDebug, ConfShowDotFiles, ConfClearReadOnlyAttr, ConfDisableMouseRename, ConfUseSystemFont, ConfUseFileTypeIcons, - ConfFocusRefresh, ConfNewStyleAltO, ConfDirsInBold, ConfDisableDirectoryBrackets, ParamDisableGnome, + ConfFocusRefresh, ConfNewStyleAltO, ConfDirsInBold, ConfDisableDirectoryBrackets, ConfUseLibcSystem, ConfUseInternalViewer, ParamDisablePlugins: boolean; ConfNormalItemDefaultColors, ConfCursorDefaultColors, ConfInactiveItemDefaultColors, ConfSelectedItemDefaultColors, ConfLinkItemDefaultColors, ConfDotFileItemDefaultColors, ConfLynxLikeMotion, ConfSizeGroupRequestZeroDigits, @@ -136,9 +136,9 @@ function CheckConfFilesMod(var ChangedMainGUI, ChangedAssoc, ChangedBookmarks, C implementation -uses ULibc, lazglib2, SysUtils, UCoreUtils, UCore, UFileAssoc, UCoreClasses, UGnome, UVFSCore; +uses ULibc, lazglib2, lazgtk3, SysUtils, UCoreUtils, UCore, UFileAssoc, UCoreClasses, UVFSCore, GTKForms; -var InternalQuickExit, InternalDeleteHistory: boolean; +var InternalDeleteHistory: boolean; InternalMainGUIConfmtime, InternalBookmarksConfmtime, InternalFAssocConfmtime, InternalMounterConfmtime, InternalConnMgrConfmtime: Longint; @@ -155,7 +155,6 @@ begin InternalFAssocConfmtime := -1; InternalMounterConfmtime := -1; InternalConnMgrConfmtime := -1; - InternalQuickExit := False; ConfPanelSep := 50; ConfLeftPath := '/'; ConfRightPath := '/'; @@ -212,7 +211,6 @@ begin ConfNewStyleAltO := True; ConfDirsInBold := False; ConfDisableDirectoryBrackets := False; - ParamDisableGnome := False; ConfDisableFileTips := False; ConfInsMoveDown := True; ConfSpaceMovesDown := False; @@ -366,7 +364,6 @@ var s: string; IniFile: TMyIniFile; i: integer; begin - if InternalQuickExit then Exit; ConfLeftPath := LeftLocalEngine.Path; ConfRightPath := RightLocalEngine.Path; try @@ -539,7 +536,6 @@ procedure WriteMainGUISettings; var s: string; IniFile: TMyIniFile; begin - if InternalQuickExit then Exit; try s := IncludeTrailingPathDelimiter(GetHomePath) + ConfDefaultSettingsDir; if not DirectoryExists(s) then @@ -707,7 +703,6 @@ var i, j: integer; IniFile: TMyIniFile; s, SectionTitle: string; begin - if InternalQuickExit then Exit; try s := IncludeTrailingPathDelimiter(GetHomePath) + ConfDefaultSettingsDir; if not DirectoryExists(s) then @@ -771,7 +766,6 @@ procedure WriteBookmarks; var s: string; i: integer; begin - if InternalQuickExit then Exit; try s := IncludeTrailingPathDelimiter(IncludeTrailingPathDelimiter(GetHomePath) + ConfDefaultSettingsDir) + 'bookmarks'; if Bookmarks.Count > 0 then @@ -841,7 +835,6 @@ var i: integer; IniFile: TMyIniFile; s, SectionTitle: string; begin - if InternalQuickExit then Exit; try s := IncludeTrailingPathDelimiter(GetHomePath) + ConfDefaultSettingsDir; if not DirectoryExists(s) then @@ -929,7 +922,6 @@ var s, Section: string; IniFile: TMyIniFile; i: integer; begin - if InternalQuickExit then Exit; try s := IncludeTrailingPathDelimiter(GetHomePath) + ConfDefaultSettingsDir; if not DirectoryExists(s) then @@ -1033,7 +1025,6 @@ var i: integer; IniFile: TMyIniFile; s, SectionTitle: string; begin - if InternalQuickExit then Exit; try s := IncludeTrailingPathDelimiter(GetHomePath) + ConfDefaultSettingsDir; if not DirectoryExists(s) then @@ -1138,11 +1129,11 @@ begin ChangedMounter := (GetFileTime(s + 'mounter') > 0) and (GetFileTime(s + 'mounter') > InternalMounterConfmtime); ChangedConnections := (GetFileTime(s + 'connmgr') > 0) and (GetFileTime(s + 'connmgr') > InternalConnMgrConfmtime); Result := ChangedMainGUI or ChangedAssoc or ChangedBookmarks or ChangedMounter or ChangedConnections; - InternalMainGUIConfmtime := GetFileTime(s + 'gui'); - InternalFAssocConfmtime := GetFileTime(s + 'filetypes'); - InternalBookmarksConfmtime := GetFileTime(s + 'bookmarks'); - InternalMounterConfmtime := GetFileTime(s + 'mounter'); - InternalConnMgrConfmtime := GetFileTime(s + 'connmgr'); + InternalMainGUIConfmtime := LongInt(GetFileTime(s + 'gui')); + InternalFAssocConfmtime := LongInt(GetFileTime(s + 'filetypes')); + InternalBookmarksConfmtime := LongInt(GetFileTime(s + 'bookmarks')); + InternalMounterConfmtime := LongInt(GetFileTime(s + 'mounter')); + InternalConnMgrConfmtime := LongInt(GetFileTime(s + 'connmgr')); end; (********************************************************************************************************************************) @@ -1175,47 +1166,93 @@ end; (********************************************************************************************************************************) (********************************************************************************************************************************) +var arg_profile_name: Pgchar = nil; + arg_left_path: Pgchar = nil; + arg_right_path: Pgchar = nil; + arg_lang: Pgchar = nil; + procedure ParseCMDLine; -var i: integer; +var xargc: LongInt; + xargv: PPChar; s: string; + error: PGError; + + OptionEntries: array[0..7] of TGOptionEntry = ( + ( + long_name: 'debug'; + short_name: #0; flags: 0; arg: G_OPTION_ARG_NONE; + arg_data: @ParamDebug; + description: 'Enable debug messages'; + arg_description: nil; + ), + ( + long_name: 'profile'; + short_name: #0; flags: 0; arg: G_OPTION_ARG_STRING; + arg_data: @arg_profile_name; + description: 'Use different configuration profile'; + arg_description: 'profilename'; + ), + ( + long_name: 'delete-history'; + short_name: #0; flags: 0; arg: G_OPTION_ARG_NONE; + arg_data: @InternalDeleteHistory; + description: 'Delete commandline, selection and search history (use in case of locale problems)'; + arg_description: nil; + ), + ( + long_name: 'disable-plugins'; + short_name: #0; flags: 0; arg: G_OPTION_ARG_NONE; + arg_data: @ParamDisablePlugins; + description: 'Don''t load VFS modules'; + arg_description: nil; + ), + ( + long_name: 'left'; + short_name: #0; flags: 0; arg: G_OPTION_ARG_STRING; + arg_data: @arg_left_path; + description: 'Start left panel at <path>'; + arg_description: 'path'; + ), + ( + long_name: 'right'; + short_name: #0; flags: 0; arg: G_OPTION_ARG_STRING; + arg_data: @arg_left_path; + description: 'Start right panel at <path>'; + arg_description: 'path'; + ), + ( + long_name: 'lang'; + short_name: #0; flags: 0; arg: G_OPTION_ARG_STRING; + arg_data: @arg_lang; + description: 'Force specific GUI language (where <language> is a standard two-char language id)'; + arg_description: 'language'; + ), + { NULL sentinel } + ( long_name: nil; short_name: #0; flags: 0; arg: G_OPTION_ARG_NONE; arg_data: nil; description: nil; arg_description: nil; ) + ); + begin - if ParamCount > 0 then - for i := 1 to ParamCount do begin - s := UpperCase(ParamStr(i)); - if s = '--DEBUG' then ParamDebug := True else - if s = '--DISABLE-GNOME' then ParamDisableGnome := True else - if s = '--DELETE-HISTORY' then InternalDeleteHistory := True else - if s = '--ENABLE-URI' then ConfUseURI := True else - if s = '--DISABLE-PLUGINS' then ParamDisablePlugins := True else - if Pos('--PROFILE=', s) = 1 then begin - ConfProfileName := 'Profile_' + Trim(Copy(ParamStr(i), 11, Length(s) - 10)); - if ConfProfileName = '' then ConfProfileName := 'Default'; - end else - if Pos('--LEFT=', s) = 1 then ParamLeftDir := Copy(ParamStr(i), 8, Length(s) - 7) else - if Pos('--RIGHT=', s) = 1 then ParamRightDir := Copy(ParamStr(i), 9, Length(s) - 8) else - if Pos('--LANG=', s) = 1 then ConfParamForceLang := Copy(ParamStr(i), 8, Length(s) - 7) else - if (s = '--HELP') or (s = '-H') then begin - WriteLn('Tux Commander v', ConstAboutVersion, ' [built ', ConstAboutBuildDate, ']'); - WriteLn('Copyright (c) 2002-2024 Tomas Bzatek'); - WriteLn('Website: tuxcmd.sourceforge.net'); - WriteLn; - WriteLn('Usage: tuxcmd [options...]'); - WriteLn; - WriteLn('Options:'); - WriteLn(' --debug Enable debug messages'); - WriteLn(' --profile=<profilename> Use different configuration profile'); - WriteLn(' --delete-history Delete command-line, selection and search history'); - WriteLn(' (use in case of locale problems)'); - WriteLn(' --disable-gnome Don''t load GNOME libraries'); - WriteLn(' --disable-plugins Don''t load VFS modules'); - WriteLn(' --left=<path> Start left panel at <path>'); - WriteLn(' --right=<path> Start right panel at <path>'); - WriteLn(' --lang=<language> Force GUI language (the string <language> is'); - WriteLn(' standard two-char language id)'); - InternalQuickExit := True; - Halt(1); - end else WriteLn('tuxcmd: Unknown commandline option: ', ParamStr(i)); - end; + xargc := argc; + xargv := g_strdupv(argv); + + s := 'Tux Commander v' + ConstAboutVersion + ' [built ' + ConstAboutBuildDate + ']'; + error := nil; + if not gtk_init_with_args(@xargc, @xargv, PChar(s), @OptionEntries, nil, @error) then begin + WriteLn(xargv[0], ': ', error^.message); + g_error_free(error); + Halt(1); + end; + + if Assigned(arg_profile_name) then ConfProfileName := 'Profile_' + String(arg_profile_name); + if Assigned(arg_left_path) then ParamLeftDir := String(arg_left_path); + if Assigned(arg_right_path) then ParamRightDir := String(arg_right_path); + if Assigned(arg_lang) then ConfParamForceLang := String(arg_lang); + + g_free(arg_profile_name); + g_free(arg_left_path); + g_free(arg_right_path); + g_free(arg_lang); + g_strfreev(xargv); end; @@ -1229,8 +1266,7 @@ initialization {$IFDEF CPU64} {$IFDEF ENDIAN_LITTLE}'x86_64'{$ELSE}'ppc64'{$ENDIF} {$ELSE} {$IFNDEF CPUPOWERPC}'i386'{$ELSE}'ppc' {$ENDIF} {$ENDIF}, ', compiled on ', ConstFPCCompilerOSString, '/', ConstFPCCompilerHostProcessorString, ' for ', ConstFPCTargetOSString, '/', ConstFPCTargetProcessorString, ')']); - // Load GNOME libs - if not ParamDisableGnome then LoadGnomeLibs; + InitGTK(); // Create basic objects CommandLineHistory := TStringList.Create; CommandLineHistory.CaseSensitive := True; |
