Skip to content

Commit 672c9e4

Browse files
committed
Refactor tab path display and apply code style cleanup
Replaced magic boolean with configurable integer option for tab path display depth. Applied consistent code formatting across multiple files, including spacing around control flow statements (if, switch, for) and braces in initializer lists. Key changes: * Modified SetTabShowPath() and IsTabShowPath() to use integer count parameter instead of boolean, allowing display of multiple directory levels * Added GetFileNameWithDirPart() utility function to extract filename with configurable directory depth * Updated tab label rendering to use new utility function with path depth configuration * Changed modified file indicator in tabs from asterisk to floppy disk emoji (💾) * Fixed line-length violations by reformatting long function signatures and calls * Corrected loop variable types from size_t to int in PatchApplier for consistency with comparison operations **Generated by CodeLite** Signed-off-by: Eran Ifrah <eran@codelite.org>
1 parent dfc6dd1 commit 672c9e4

File tree

9 files changed

+205
-155
lines changed

9 files changed

+205
-155
lines changed

CodeLite/fileutils.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,3 +976,39 @@ wxFileName FileUtils::wxReadLink(const wxFileName& filename)
976976
return filename;
977977
#endif
978978
}
979+
980+
wxString FileUtils::GetFileNameWithDirPart(const wxString& fullpath, size_t count)
981+
{
982+
wxString normalize_path = fullpath;
983+
normalize_path.Replace("\\", "/");
984+
985+
// Split the path into parts
986+
wxArrayString parts = ::wxStringTokenize(normalize_path, "/", wxTOKEN_STRTOK);
987+
988+
// If there are no parts, return the original path
989+
if (parts.IsEmpty()) {
990+
return fullpath;
991+
}
992+
993+
// Get the filename (last part)
994+
wxString filename = parts[parts.GetCount() - 1];
995+
996+
// Calculate the number of directory parts to include
997+
size_t dirCount = parts.GetCount() - 1; // total dir parts (excluding filename)
998+
size_t partsToInclude = (dirCount > count) ? count : dirCount;
999+
1000+
// If no directory parts to include, just return the filename
1001+
if (partsToInclude == 0) {
1002+
return filename;
1003+
}
1004+
1005+
// Build the result: get the last 'partsToInclude' directory parts + filename
1006+
wxString result;
1007+
size_t startIdx = parts.GetCount() - 1 - partsToInclude; // index to start from
1008+
for (size_t i = startIdx; i < parts.GetCount(); ++i) {
1009+
result += parts[i];
1010+
if (i < parts.GetCount() - 1)
1011+
result += "/";
1012+
}
1013+
return result;
1014+
}

CodeLite/fileutils.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class WXDLLIMPEXP_CL FileUtils
4848

4949
~Deleter()
5050
{
51-
if(m_filename.Exists()) {
51+
if (m_filename.Exists()) {
5252
clRemoveFile(m_filename);
5353
}
5454
}
@@ -99,16 +99,16 @@ class WXDLLIMPEXP_CL FileUtils
9999
* @param password the password
100100
* @param port ssh port
101101
*/
102-
static void OpenSSHTerminal(const wxString& sshClient, const wxString& connectString, const wxString& password,
103-
int port = 22);
102+
static void
103+
OpenSSHTerminal(const wxString& sshClient, const wxString& connectString, const wxString& password, int port = 22);
104104

105105
/**
106106
* @brief OSX only: open Terminal and return its TTY
107107
* @param path working directory
108108
* @param [output] tty the TTY of the launched terminal
109109
*/
110-
static void OSXOpenDebuggerTerminalAndGetTTY(const wxString& path, const wxString& appname, wxString& tty,
111-
long& pid);
110+
static void
111+
OSXOpenDebuggerTerminalAndGetTTY(const wxString& path, const wxString& appname, wxString& tty, long& pid);
112112

113113
/**
114114
* @brief file masking search
@@ -214,7 +214,7 @@ class WXDLLIMPEXP_CL FileUtils
214214
/**
215215
* @brief (on Linux) makes-absolute filepath, and dereferences it and any symlinked dirs in the path
216216
*/
217-
static wxString RealPath(const wxString& filepath, bool forced=false);
217+
static wxString RealPath(const wxString& filepath, bool forced = false);
218218
static bool RealPathGetModeResolveSymlinks();
219219
static void RealPathSetModeResolveSymlinks(bool resolveSymlinks);
220220

@@ -244,7 +244,9 @@ class WXDLLIMPEXP_CL FileUtils
244244
* passing suffix_list = {"-10", "-9"...} will also check for these files (in order)
245245
* @return true if a filepath was found
246246
*/
247-
static bool FindExe(const wxString& name, wxFileName& exepath, const wxArrayString& hint = {},
247+
static bool FindExe(const wxString& name,
248+
wxFileName& exepath,
249+
const wxArrayString& hint = {},
248250
const wxArrayString& suffix_list = {});
249251

250252
/**
@@ -259,8 +261,8 @@ class WXDLLIMPEXP_CL FileUtils
259261
* @param extensions
260262
* @param [out] the files found
261263
*/
262-
static size_t FindSimilar(const wxFileName& filename, const std::vector<wxString>& extensions,
263-
std::vector<wxFileName>& vout);
264+
static size_t
265+
FindSimilar(const wxFileName& filename, const std::vector<wxString>& extensions, std::vector<wxFileName>& vout);
264266

265267
/**
266268
* @brief convert path to uri
@@ -310,6 +312,8 @@ class WXDLLIMPEXP_CL FileUtils
310312
* \return true on success, false otherwise
311313
*/
312314
static bool CopyDir(const wxString& src, const wxString& target);
315+
316+
static wxString GetFileNameWithDirPart(const wxString& fullpath, size_t count = 1);
313317
};
314318

315319
#endif // FILEUTILS_H

LiteEditor/editorsettingsdockingwidows.cpp

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,21 @@ EditorSettingsDockingWindows::EditorSettingsDockingWindows(wxWindow* parent, Opt
3232
{
3333
AddHeader(_("Tabs"));
3434

35-
const std::unordered_map<wxString, int> tab_height_map = { { "TALL", OptionsConfig::nbTabHt_Tall },
36-
{ "MEDIUM", OptionsConfig::nbTabHt_Medium },
37-
{ "SHORT", OptionsConfig::nbTabHt_Short },
38-
{ "TINY", OptionsConfig::nbTabHt_Tiny } };
35+
const std::unordered_map<wxString, int> tab_height_map = {{"TALL", OptionsConfig::nbTabHt_Tall},
36+
{"MEDIUM", OptionsConfig::nbTabHt_Medium},
37+
{"SHORT", OptionsConfig::nbTabHt_Short},
38+
{"TINY", OptionsConfig::nbTabHt_Tiny}};
3939

40-
std::unordered_map<int, wxString> tab_height_map_reverse = { { OptionsConfig::nbTabHt_Tall, "TALL" },
41-
{ OptionsConfig::nbTabHt_Medium, "MEDIUM" },
42-
{ OptionsConfig::nbTabHt_Short, "SHORT" },
43-
{ OptionsConfig::nbTabHt_Tiny, "TINY" } };
40+
std::unordered_map<int, wxString> tab_height_map_reverse = {{OptionsConfig::nbTabHt_Tall, "TALL"},
41+
{OptionsConfig::nbTabHt_Medium, "MEDIUM"},
42+
{OptionsConfig::nbTabHt_Short, "SHORT"},
43+
{OptionsConfig::nbTabHt_Tiny, "TINY"}};
4444

45-
std::vector<wxString> tab_heights = { "TALL", "MEDIUM", "SHORT", "TINY" };
45+
std::vector<wxString> tab_heights = {"TALL", "MEDIUM", "SHORT", "TINY"};
4646

47-
AddProperty(_("Height"), tab_heights, tab_height_map_reverse.find(m_options->GetNotebookTabHeight())->second,
47+
AddProperty(_("Height"),
48+
tab_heights,
49+
tab_height_map_reverse.find(m_options->GetNotebookTabHeight())->second,
4850
[this, tab_height_map](const wxString& label, const wxAny& value) {
4951
wxString value_str;
5052
if (value.GetAs(&value_str)) {
@@ -53,23 +55,23 @@ EditorSettingsDockingWindows::EditorSettingsDockingWindows(wxWindow* parent, Opt
5355
});
5456

5557
std::unordered_map<wxString, wxDirection> orientation_map = {
56-
{ "UP", wxUP }, { "DOWN", wxDOWN }, { "LEFT", wxLEFT }, { "RIGHT", wxRIGHT }, { "VERTICAL", wxLEFT }
57-
};
58+
{"UP", wxUP}, {"DOWN", wxDOWN}, {"LEFT", wxLEFT}, {"RIGHT", wxRIGHT}, {"VERTICAL", wxLEFT}};
5859

5960
std::unordered_map<int, wxString> orientation_map_reverse = {
60-
{ wxUP, "UP" }, { wxDOWN, "DOWN" }, { wxLEFT, "LEFT" }, { wxRIGHT, "RIGHT" }, { wxLEFT, "VERTICAL" }
61-
};
61+
{wxUP, "UP"}, {wxDOWN, "DOWN"}, {wxLEFT, "LEFT"}, {wxRIGHT, "RIGHT"}, {wxLEFT, "VERTICAL"}};
6262

63-
std::vector<wxString> sidebar_tab_orientation = { "VERTICAL", "UP", "DOWN" };
64-
AddProperty(_("Sidebar buttons position"), sidebar_tab_orientation,
63+
std::vector<wxString> sidebar_tab_orientation = {"VERTICAL", "UP", "DOWN"};
64+
AddProperty(_("Sidebar buttons position"),
65+
sidebar_tab_orientation,
6566
orientation_map_reverse[m_options->GetWorkspaceTabsDirection()],
6667
[this, orientation_map](const wxString&, const wxAny& value) mutable {
6768
wxString str_value;
6869
if (value.GetAs(&str_value)) {
6970
m_options->SetWorkspaceTabsDirection(orientation_map[str_value]);
7071
}
7172
});
72-
AddProperty(_("Output tabs orientation"), std::vector<wxString>{ "UP", "DOWN" },
73+
AddProperty(_("Output tabs orientation"),
74+
std::vector<wxString>{"UP", "DOWN"},
7375
orientation_map_reverse[m_options->GetOutputTabsDirection()],
7476
[this, orientation_map](const wxString&, const wxAny& value) mutable {
7577
wxString str_value;
@@ -79,28 +81,32 @@ EditorSettingsDockingWindows::EditorSettingsDockingWindows(wxWindow* parent, Opt
7981
});
8082

8183
AddProperty(_("Show close button on tabs"), m_options->IsTabHasXButton(), UPDATE_BOOL_CB(SetTabHasXButton));
82-
AddProperty(_("Show file path on tab label"), m_options->IsTabShowPath(), UPDATE_BOOL_CB(SetTabShowPath));
84+
AddProperty(_("Dir parts in tab label"), m_options->GetTabShowPath(), UPDATE_INT_CB(SetTabShowPath));
8385

8486
#if !MAINBOOK_AUIBOOK
85-
AddProperty(_("Mouse scroll switch bewtween tabs"), m_options->IsMouseScrollSwitchTabs(),
87+
AddProperty(_("Mouse scroll switch bewtween tabs"),
88+
m_options->IsMouseScrollSwitchTabs(),
8689
UPDATE_BOOL_CB(SetMouseScrollSwitchTabs));
87-
AddProperty(_("Sort tab file list"), m_options->IsSortTabsDropdownAlphabetically(),
90+
AddProperty(_("Sort tab file list"),
91+
m_options->IsSortTabsDropdownAlphabetically(),
8892
UPDATE_BOOL_CB(SetSortTabsDropdownAlphabetically));
8993
#endif
9094

9195
AddProperty(_("Use Ctrl+TAB to switch tabs"), m_options->IsCtrlTabEnabled(), UPDATE_BOOL_CB(SetCtrlTabEnabled));
9296
#ifndef __WXGTK__
93-
AddProperty(_("Hide main tab bar"), clConfig::Get().Read("HideTabBar", false),
94-
UPDATE_CLCONFIG_BOOL_CB("HideTabBar"));
97+
AddProperty(
98+
_("Hide main tab bar"), clConfig::Get().Read("HideTabBar", false), UPDATE_CLCONFIG_BOOL_CB("HideTabBar"));
9599
#endif
96100
AddHeader(_("Find in files"));
97-
AddProperty(_("Don't automatically fold search results"), m_options->GetDontAutoFoldResults(),
101+
AddProperty(_("Don't automatically fold search results"),
102+
m_options->GetDontAutoFoldResults(),
98103
UPDATE_BOOL_CB(SetDontAutoFoldResults));
99104
AddProperty(_("When searching, don't override search string with current selection"),
100105
m_options->GetDontOverrideSearchStringWithSelection(),
101106
UPDATE_BOOL_CB(SetDontOverrideSearchStringWithSelection));
102107
AddHeader(_("Find next/Find previous"));
103-
AddProperty(_("Find next/Find previous actions override search string with current selection (like Find next at caret/prev at caret)"),
108+
AddProperty(_("Find next/Find previous actions override search string with current selection (like Find next at "
109+
"caret/prev at caret)"),
104110
m_options->GetFindNextOrPreviousUseSelection(),
105111
UPDATE_BOOL_CB(SetFindNextOrPreviousUseSelection));
106112
}

LiteEditor/mainbook.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,15 +1200,15 @@ void MainBook::ApplyTabLabelChanges()
12001200
{
12011201
// We only want to do this if there *is* a change, and it's hard to be sure
12021202
// by looking. So store any previous state in:
1203-
static int previousShowParentPath = -1;
1203+
static std::optional<int> previousShowParentPath{std::nullopt};
12041204

1205-
if (previousShowParentPath < 0 ||
1206-
EditorConfigST::Get()->GetOptions()->IsTabShowPath() != (bool)previousShowParentPath) {
1207-
previousShowParentPath = EditorConfigST::Get()->GetOptions()->IsTabShowPath();
1205+
if (!previousShowParentPath.has_value() ||
1206+
EditorConfigST::Get()->GetOptions()->GetTabShowPath() != previousShowParentPath.value()) {
1207+
previousShowParentPath = EditorConfigST::Get()->GetOptions()->GetTabShowPath();
12081208

12091209
std::vector<clEditor*> editors = GetAllEditors();
12101210
for (size_t i = 0; i < editors.size(); i++) {
1211-
SetPageTitle(editors[i], editors[i]->GetFileName(), editors[i]->IsEditorModified());
1211+
SetPageTitle(editors[i], editors[i]->GetRemotePathOrLocal(), editors[i]->IsEditorModified());
12121212
}
12131213
}
12141214
}
@@ -1967,17 +1967,11 @@ void MainBook::SetPageTitle(wxWindow* page, const wxFileName& filename, bool mod
19671967
wxString MainBook::CreateLabel(const wxFileName& fn, bool modified) const
19681968
{
19691969
wxString label = fn.GetFullName();
1970-
if (fn.GetDirCount() && EditorConfigST::Get()->GetOptions()->IsTabShowPath()) {
1971-
label.Prepend(fn.GetDirs().Last() + wxFileName::GetPathSeparator());
1972-
}
1970+
label = FileUtils::GetFileNameWithDirPart(fn.GetFullPath(), EditorConfigST::Get()->GetOptions()->GetTabShowPath());
19731971

19741972
#if CL_USE_NATIVEBOOK || MAINBOOK_AUIBOOK
19751973
if (modified) {
1976-
#if defined(__WXMSW__) || defined(__WXMAC__)
19771974
label.Prepend(wxT(" \U0001F4BE "));
1978-
#else
1979-
label.Prepend(wxT(" * "));
1980-
#endif
19811975
}
19821976
#else
19831977
wxUnusedVar(modified);

LiteEditor/openwindowspanel.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "cl_config.h"
3131
#include "editor_config.h"
3232
#include "event_notifier.h"
33+
#include "fileutils.h"
3334
#include "globals.h"
3435
#include "imanager.h"
3536
#include "macros.h"
@@ -471,7 +472,7 @@ wxVariant OpenWindowsPanel::PrepareValue(const clTab& tab, bool* isModified)
471472
int imgId = clGetManager()->GetStdIcons()->GetMimeImageId(ft);
472473
if (editor && editor->GetModify()) {
473474
*isModified = true;
474-
title.Prepend("*");
475+
title.Prepend(wxT(" \U0001F4BE "));
475476
}
476477

477478
wxVariant value = ::MakeBitmapIndexText(title, imgId);
@@ -519,13 +520,10 @@ wxString OpenWindowsPanel::GetDisplayName(const clTab& tab) const
519520
wxString title;
520521
if (tab.isFile) {
521522
const wxFileName& fn = tab.filename;
522-
if (fn.GetDirCount() && EditorConfigST::Get()->GetOptions()->IsTabShowPath()) {
523-
title = fn.GetDirs().Last() + wxFileName::GetPathSeparator() + fn.GetFullName();
524-
} else {
525-
title = tab.filename.GetFullName();
526-
}
523+
title =
524+
FileUtils::GetFileNameWithDirPart(fn.GetFullPath(), EditorConfigST::Get()->GetOptions()->GetTabShowPath());
527525
} else {
528526
title = tab.text;
529527
}
530528
return title;
531-
}
529+
}

Plugin/Diff/clPatchApplier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ clStatusOr<int> PatchApplier::ApplyHunk(ITextArea* ctrl, const wxArrayString& li
192192

193193
// First pass: locate the hunk.
194194
int hunk_found_line{wxNOT_FOUND};
195-
for (size_t current_editor_line_number = start_line; current_editor_line_number < totalLines;
195+
for (int current_editor_line_number = start_line; current_editor_line_number < totalLines;
196196
++current_editor_line_number) {
197197
wxString editor_line = ctrl->GetLine(current_editor_line_number);
198198
editor_line.Trim();
@@ -201,7 +201,7 @@ clStatusOr<int> PatchApplier::ApplyHunk(ITextArea* ctrl, const wxArrayString& li
201201
}
202202

203203
bool hunk_found{true};
204-
for (size_t hunk_line_number = 0; hunk_line_number < lines_to_find.size(); ++hunk_line_number) {
204+
for (int hunk_line_number = 0; hunk_line_number < lines_to_find.size(); ++hunk_line_number) {
205205
wxString hunk_line = lines_to_find[hunk_line_number];
206206
// These lines must exist and match in the control
207207
if (current_editor_line_number + hunk_line_number >= totalLines) {

0 commit comments

Comments
 (0)