Skip to content
Permalink
Browse files

Refactor: rename helper function sstr() to something more readable, a…

…nd optimize it slightly
  • Loading branch information...
ansgarbecker committed Nov 4, 2019
1 parent ffebc6d commit 17e75e70dad1a3ec82a26427540133e9931b57a1
Showing with 25 additions and 26 deletions.
  1. +7 −8 source/apphelpers.pas
  2. +1 −1 source/copytable.pas
  3. +1 −1 source/dbconnection.pas
  4. +15 −15 source/main.pas
  5. +1 −1 source/searchreplace.pas
@@ -271,7 +271,7 @@ TAppSettings = class(TObject)
function implodestr(seperator: String; a: TStrings) :String;
function Explode(Separator, Text: String) :TStringList;
procedure ExplodeQuotedList(Text: String; var List: TStringList);
function sstr(str: String; len: Integer) : String;
function StrEllipsis(const S: String; MaxLen: Integer): String;
function encrypt(str: String): String;
function decrypt(str: String): String;
function HTMLSpecialChars(str: String): String;
@@ -456,14 +456,13 @@ function Explode(Separator, Text: String): TStringList;
@param integer Wished Length of string
@return string
}
function sstr(str: String; len: Integer) : String;
function StrEllipsis(const S: String; MaxLen: Integer): String;
begin
if length(str) > len then
begin
str := copy(str, 0, len-1);
str := str + '…';
end;
result := str;
Result := S;
if Length(Result) <= MaxLen then
Exit;
SetLength(Result, MaxLen);
Result[MaxLen] := '…';
end;


@@ -149,7 +149,7 @@ procedure TCopyTableForm.FormShow(Sender: TObject);
if IsEmpty(Filter) then
Continue;
Item := TMenuItem.Create(popupRecentFilters);
Item.Caption := IntToStr(i) + ' ' + sstr(Filter, 100);
Item.Caption := IntToStr(i) + ' ' + StrEllipsis(Filter, 100);
Item.Hint := Filter;
Item.OnClick := RecentFilterClick;
popupRecentFilters.Items.Add(Item);
@@ -3647,7 +3647,7 @@ function TDBConnection.GetResults(SQL: String): TDBQuery;
for Query in FPrefetchResults do begin
if Query.SQL = SQL then begin
Result := Query;
Log(lcDebug, 'Using cached result for query: '+sstr(SQL, 100));
Log(lcDebug, 'Using cached result for query: '+StrEllipsis(SQL, 100));
Break;
end;
end;
@@ -1348,7 +1348,7 @@ procedure TMainForm.StatusBarMouseMove(Sender: TObject; Shift: TShiftState; X, Y
Infos := ActiveConnection.ConnectionInfo;
HintText := '';
for i:=0 to Infos.Count-1 do begin
HintText := HintText + Infos.Names[i] + ': ' + sstr(Infos.ValueFromIndex[i], 200) + CRLF;
HintText := HintText + Infos.Names[i] + ': ' + StrEllipsis(Infos.ValueFromIndex[i], 200) + CRLF;
end;
BalloonHint1.Description := Trim(HintText);
OffsetRect(PanelRect, Bar.ClientOrigin.X, Bar.ClientOrigin.Y);
@@ -1794,7 +1794,7 @@ procedure TMainForm.FormCreate(Sender: TObject);
// Prevent generating a seperator line
if miFunction.Caption = '-' then
miFunction.Caption := '&-';
miFunction.Hint := MySqlFunctions[j].Name + MySqlFunctions[j].Declaration + ' - ' + sstr(MySqlFunctions[j].Description, 200);
miFunction.Hint := MySqlFunctions[j].Name + MySqlFunctions[j].Declaration + ' - ' + StrEllipsis(MySqlFunctions[j].Description, 200);
// Prevent generating a seperator for ShortHint and LongHint
miFunction.Hint := StringReplace( miFunction.Hint, '|', '¦', [rfReplaceAll] );
miFunction.Tag := j;
@@ -4414,7 +4414,7 @@ procedure TMainForm.SynMemoQueryReplaceText(Sender: TObject; const ASearch,
AReplace: string; Line, Column: Integer; var Action: TSynReplaceAction);
begin
// Fires when "Replace all" in search dialog was pressed with activated "Prompt on replace"
case MessageDialog(f_('Replace this occurrence of "%s"?', [sstr(ASearch, 100)]), mtConfirmation, [mbYes, mbYesToAll, mbNo, mbCancel]) of
case MessageDialog(f_('Replace this occurrence of "%s"?', [StrEllipsis(ASearch, 100)]), mtConfirmation, [mbYes, mbYesToAll, mbNo, mbCancel]) of
mrYes: Action := raReplace;
mrYesToAll: Action := raReplaceAll;
mrNo: Action := raSkip;
@@ -6977,7 +6977,7 @@ procedure TMainForm.popupDataGridPopup(Sender: TObject);
and (menuQuickFilter[i].Count = 0) // Not a menu with subitems
and (menuQuickFilter[i].Action = nil) // Not some special item
then
menuQuickFilter[i].Caption := sstr(menuQuickFilter[i].Hint, 100);
menuQuickFilter[i].Caption := StrEllipsis(menuQuickFilter[i].Hint, 100);
end;

end;
@@ -7032,7 +7032,7 @@ procedure TMainForm.QFvaluesClick(Sender: TObject);
Item.Hint := Conn.QuoteIdent(Col)+' IS NULL'
else
Item.Hint := Conn.QuoteIdent(Col)+'='+esc(Data.Col(Col));
Item.Caption := sstr(Item.Hint, 100) + ' (' + FormatNumber(Data.Col('c')) + ')';
Item.Caption := StrEllipsis(Item.Hint, 100) + ' (' + FormatNumber(Data.Col('c')) + ')';
if SynMemoFilter.Text <> '' then begin
if Pos(Item.Hint, SynMemoFilter.Text) > 0 then
Item.Hint := SynMemoFilter.Text
@@ -7057,7 +7057,7 @@ procedure TMainForm.QFvaluesClick(Sender: TObject);
QFvalues.Add(Item);
end;
Item.Hint := Conn.QuoteIdent(Col)+'='+esc(ValueList[i]);
Item.Caption := sstr(Item.Hint, 100);
Item.Caption := StrEllipsis(Item.Hint, 100);
Item.OnClick := QuickFilterClick;
end;
Break;
@@ -7367,12 +7367,12 @@ procedure TMainForm.tabsetQueryMouseMove(Sender: TObject; Shift: TShiftState; X,
HintSQL := TStringList.Create;
HintSQL.Text := Trim(ResultTab.Results.SQL);
for i:=0 to HintSQL.Count-1 do begin
HintSQL[i] := sstr(HintSQL[i], 100);
HintSQL[i] := StrEllipsis(HintSQL[i], 100);
HintSQL[i] := StringReplace(HintSQL[i], #9, ' ', [rfReplaceAll]);
end;
BalloonHint1.Description := FormatNumber(ResultTab.Results.ColumnCount) + ' columns × ' +
FormatNumber(ResultTab.Results.RecordCount) + ' rows' + CRLF + CRLF +
Trim(sstr(HintSQL.Text, SIZE_KB));
Trim(StrEllipsis(HintSQL.Text, SIZE_KB));
Rect := Tabs.ItemRect(idx);
Org := Tabs.ClientOrigin;
OffsetRect(Rect, Org.X, Org.Y);
@@ -7809,7 +7809,7 @@ procedure TMainForm.AnyGridGetHint(Sender: TBaseVirtualTree; Node:

if HintText.IsEmpty then begin
HintText := Tree.Text[Node, Column];
HintText := sstr(HintText, SIZE_KB);
HintText := StrEllipsis(HintText, SIZE_KB);
end;
// See http://www.heidisql.com/forum.php?t=20458#p20548
if Sender = DBtree then
@@ -8329,7 +8329,7 @@ procedure TMainForm.HostListGetText(Sender: TBaseVirtualTree; Node: PVirtualNode

end else begin
// Values directly from a query result
CellText := sstr(Results.Col(Column), SIZE_KB*50);
CellText := StrEllipsis(Results.Col(Column), SIZE_KB*50);
end;
end;

@@ -8710,8 +8710,8 @@ procedure TMainForm.DBtreeFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualN
InvalidateVT(ListTables, VTREE_NOTLOADED, True);
if FActiveDbObj.NodeType = lntGroup then
InvalidateVT(ListTables, VTREE_NOTLOADED, True);
tabHost.Caption := _('Host')+': '+sstr(FActiveDbObj.Connection.Parameters.HostName, 20);
tabDatabase.Caption := _('Database')+': '+sstr(FActiveDbObj.Connection.Database, 20);
tabHost.Caption := _('Host')+': '+StrEllipsis(FActiveDbObj.Connection.Parameters.HostName, 20);
tabDatabase.Caption := _('Database')+': '+StrEllipsis(FActiveDbObj.Connection.Database, 20);
ShowStatusMsg(FActiveDbObj.Connection.Parameters.NetTypeName(FActiveDbObj.Connection.Parameters.NetType, False)+' '+FActiveDbObj.Connection.ServerVersionStr, 3);
end else begin
LogSQL('DBtreeFocusChanged without node.', lcDebug);
@@ -10592,7 +10592,7 @@ procedure TMainForm.EnumerateRecentFilters;
Break;
capt := rx.Replace(capt, ' ', True);
item.Hint := capt;
item.Caption := sstr(capt, 50);
item.Caption := StrEllipsis(capt, 50);
item.Tag := i;
item.OnClick := LoadRecentFilter;
menuRecentFilters.Add(item);
@@ -10671,7 +10671,7 @@ procedure TMainForm.UpdateEditorTab;
if ActiveObjectEditor.DBObject.Name = '' then
Cap := Cap + '['+_('Untitled')+']'
else
Cap := sstr(Cap + ActiveObjectEditor.DBObject.Name, 30);
Cap := StrEllipsis(Cap + ActiveObjectEditor.DBObject.Name, 30);
SetTabCaption(tabEditor.PageIndex, Cap);
end;

@@ -13339,7 +13339,7 @@ function TQueryTab.BindParamsActivated: Boolean;
procedure TQueryTab.SetMemoFilename(Value: String);
begin
FMemoFilename := Value;
MainForm.SetTabCaption(TabSheet.PageIndex, sstr(ExtractFilename(FMemoFilename), 70));
MainForm.SetTabCaption(TabSheet.PageIndex, StrEllipsis(ExtractFilename(FMemoFilename), 70));
MainForm.ValidateQueryControls(Self);
if FMemoFilename <> '' then begin
DirectoryWatch.Directory := ExtractFilePath(FMemoFilename);
@@ -366,7 +366,7 @@ procedure TfrmSearchReplace.DoSearchReplaceData;
if ssoPrompt in Options then begin
// Ask user
Prompt := MessageDialog(f_('Replace this occurrence of "%s"?', [Search]),
sstr(CellText, 500),
StrEllipsis(CellText, 500),
mtConfirmation,
[mbYes, mbYesToAll, mbNo, mbCancel]);
case Prompt of

0 comments on commit 17e75e7

Please sign in to comment.
You can’t perform that action at this time.