Skip to content

Commit

Permalink
- on macOS, dialogs are placed at the top of the editor
Browse files Browse the repository at this point in the history
- Outline dialog: use standard dialog for displaying the symbols
  • Loading branch information
eranif committed Jul 18, 2024
1 parent 34bb801 commit e15a6a2
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 93 deletions.
43 changes: 21 additions & 22 deletions LanguageServer/LSPOutlineViewDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ LSPOutlineViewDlg::LSPOutlineViewDlg(wxWindow* parent)
: LSPOutlineViewDlgBase(parent)
{
clSetDialogBestSizeAndPosition(this);
CenterOnParent();
DoInitialise();
}

Expand All @@ -36,7 +35,7 @@ void LSPOutlineViewDlg::DoInitialise()
m_dvTreeCtrll->SetSortFunction(nullptr);
m_textCtrlFilter->ClearAll();

if(m_symbols.empty()) {
if (m_symbols.empty()) {
clAnsiEscapeCodeColourBuilder builder;
builder.SetTheme(lexer->IsDark() ? eColourTheme::DARK : eColourTheme::LIGHT);
builder.Add(_("Language Server is still not ready... "), AnsiColours::NormalText(), false);
Expand All @@ -62,14 +61,14 @@ void LSPOutlineViewDlg::DoInitialise()
std::vector<std::pair<wxString, int>> containers;

clAnsiEscapeCodeColourBuilder builder;
for(const SymbolInformation& si : m_symbols) {
for (const SymbolInformation& si : m_symbols) {
const wxString& symbol_container = si.GetContainerName();
if(symbol_container.empty()) {
if (symbol_container.empty()) {
containers.push_back({ si.GetName(), 1 });
} else {
int parent_depth = 0;
while(!containers.empty()) {
if(containers.back().first == symbol_container) {
while (!containers.empty()) {
if (containers.back().first == symbol_container) {
parent_depth = containers.back().second;
break;
}
Expand All @@ -81,7 +80,7 @@ void LSPOutlineViewDlg::DoInitialise()
builder.Clear();

// determine the symbol
switch(si.GetKind()) {
switch (si.GetKind()) {
case kSK_File:
case kSK_Module:
case kSK_Package:
Expand All @@ -100,7 +99,7 @@ void LSPOutlineViewDlg::DoInitialise()
case kSK_Function:
case kSK_Constructor:
builder.Add(FUNCTION_SYMBOL + " ", AnsiColours::NormalText());
if(si.GetName().Contains("(") && si.GetName().Contains(")")) {
if (si.GetName().Contains("(") && si.GetName().Contains(")")) {
// the name also has the signature
wxString signature = si.GetName().AfterFirst('(');
signature = signature.BeforeLast(')');
Expand All @@ -126,7 +125,7 @@ void LSPOutlineViewDlg::DoInitialise()
}
m_dvTreeCtrll->AddLine(builder.GetString(), false, (wxUIntPtr)&si);
}
if(!m_dvTreeCtrll->IsEmpty()) {
if (!m_dvTreeCtrll->IsEmpty()) {
m_dvTreeCtrll->SelectRow(0);
}
m_dvTreeCtrll->Commit();
Expand All @@ -148,7 +147,7 @@ void LSPOutlineViewDlg::OnTextUpdated(wxCommandEvent& event)
wxDataViewItem starting_item =
m_dvTreeCtrll->GetSelection().IsOk() ? m_dvTreeCtrll->GetSelection() : wxDataViewItem{ nullptr };
auto match = m_dvTreeCtrll->FindNext(starting_item, filter_text, 0, wxTR_SEARCH_DEFAULT);
if(match.IsOk()) {
if (match.IsOk()) {
m_dvTreeCtrll->Select(match);
m_dvTreeCtrll->HighlightText(match, true);
m_dvTreeCtrll->EnsureVisible(match);
Expand All @@ -162,7 +161,7 @@ void LSPOutlineViewDlg::OnItemActivated(wxDataViewEvent& event)

void LSPOutlineViewDlg::OnKeyDown(wxKeyEvent& event)
{
switch(event.GetKeyCode()) {
switch (event.GetKeyCode()) {
case WXK_ESCAPE:
Hide();
break;
Expand All @@ -175,15 +174,15 @@ void LSPOutlineViewDlg::OnKeyDown(wxKeyEvent& event)
default: {
int modifier_key = event.GetModifiers();
wxChar ch = event.GetUnicodeKey();
if(modifier_key == wxMOD_CONTROL && ch == 'U') {
if (modifier_key == wxMOD_CONTROL && ch == 'U') {
m_dvTreeCtrll->PageUp();
DoFindNext();
} else if(modifier_key == wxMOD_CONTROL && ch == 'D') {
} else if (modifier_key == wxMOD_CONTROL && ch == 'D') {
m_dvTreeCtrll->PageDown();
DoFindPrev();
} else if(modifier_key == wxMOD_CONTROL && (ch == 'J' || ch == 'N')) {
} else if (modifier_key == wxMOD_CONTROL && (ch == 'J' || ch == 'N')) {
DoFindNext();
} else if(modifier_key == wxMOD_CONTROL && (ch == 'K' || ch == 'P')) {
} else if (modifier_key == wxMOD_CONTROL && (ch == 'K' || ch == 'P')) {
DoFindPrev();
} else {
event.Skip();
Expand All @@ -198,13 +197,13 @@ void LSPOutlineViewDlg::DoFindNext()
m_dvTreeCtrll->ClearAllHighlights();

int sel_row = m_dvTreeCtrll->GetSelectedRow();
if((sel_row + 1) >= m_dvTreeCtrll->GetItemCount()) {
if ((sel_row + 1) >= m_dvTreeCtrll->GetItemCount()) {
return;
}

wxDataViewItem next_item = m_dvTreeCtrll->RowToItem(sel_row + 1);
wxString find_what = m_textCtrlFilter->GetValue();
if(find_what.empty()) {
if (find_what.empty()) {
m_dvTreeCtrll->Select(next_item);
m_dvTreeCtrll->EnsureVisible(next_item);
} else {
Expand All @@ -220,13 +219,13 @@ void LSPOutlineViewDlg::DoFindPrev()
m_dvTreeCtrll->ClearAllHighlights();

int sel_row = m_dvTreeCtrll->GetSelectedRow();
if(sel_row < 1) {
if (sel_row < 1) {
return;
}

wxDataViewItem prev_item = m_dvTreeCtrll->RowToItem(sel_row - 1);
wxString find_what = m_textCtrlFilter->GetValue();
if(find_what.empty()) {
if (find_what.empty()) {
m_dvTreeCtrll->Select(prev_item);
m_dvTreeCtrll->EnsureVisible(prev_item);
} else {
Expand All @@ -239,7 +238,7 @@ void LSPOutlineViewDlg::DoFindPrev()

void LSPOutlineViewDlg::OnListKeyDown(wxKeyEvent& event)
{
if(event.GetKeyCode() == WXK_ESCAPE) {
if (event.GetKeyCode() == WXK_ESCAPE) {
Hide();
} else {
event.Skip();
Expand All @@ -255,7 +254,7 @@ void LSPOutlineViewDlg::SetSymbols(const std::vector<SymbolInformation>& symbols
void LSPOutlineViewDlg::DoSelectionActivate()
{
auto selection = m_dvTreeCtrll->GetSelection();
if(!selection.IsOk()) {
if (!selection.IsOk()) {
return;
}

Expand All @@ -268,7 +267,7 @@ void LSPOutlineViewDlg::DoSelectionActivate()
CHECK_PTR_RET(active_editor);

int sci_line = loc.GetRange().GetStart().GetLine();
if(loc.GetRange().GetStart().GetLine() != loc.GetRange().GetEnd().GetLine()) {
if (loc.GetRange().GetStart().GetLine() != loc.GetRange().GetEnd().GetLine()) {
// different lines, don't select the entire function
// just place the caret at the beginning of the function
int position = active_editor->PosFromLine(sci_line); // start of line
Expand Down
3 changes: 2 additions & 1 deletion LanguageServer/LanguageServerCluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,8 @@ void LanguageServerCluster::OnShowQuickOutlineDlg(LSPEvent& event)
}
if (!m_quick_outline_dlg->IsShown()) {
m_quick_outline_dlg->Show();
m_quick_outline_dlg->CenterOnParent();
// reposition the window
::clSetDialogBestSizeAndPosition(m_quick_outline_dlg);
}
m_quick_outline_dlg->SetSymbols({});
}
Expand Down
2 changes: 1 addition & 1 deletion LanguageServer/UI.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class LSPOutlineViewDlgBase : public wxDialog
wxPanel* GetPanel155() { return m_panel155; }
LSPOutlineViewDlgBase(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Outline View"),
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(500, 300),
long style = wxSTAY_ON_TOP);
long style = wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP | wxRESIZE_BORDER);
virtual ~LSPOutlineViewDlgBase();
};

Expand Down
2 changes: 1 addition & 1 deletion LanguageServer/UI.wxcp
Original file line number Diff line number Diff line change
Expand Up @@ -3098,7 +3098,7 @@
"border": 5,
"gbSpan": "1,1",
"gbPosition": "0,0",
"m_styles": ["wxSTAY_ON_TOP"],
"m_styles": ["wxDEFAULT_DIALOG_STYLE", "wxSTAY_ON_TOP", "wxRESIZE_BORDER"],
"m_sizerFlags": ["wxALL", "wxLEFT", "wxRIGHT", "wxTOP", "wxBOTTOM"],
"m_properties": [{
"type": "string",
Expand Down
36 changes: 13 additions & 23 deletions Plugin/GotoAnythingDlg.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
#include "GotoAnythingDlg.h"

#include "bitmap_loader.h"
#include "clAnagram.h"
#include "clKeyboardManager.h"
#include "cl_config.h"
#include "codelite_events.h"
#include "event_notifier.h"
#include "file_logger.h"
#include "globals.h"
#include "imanager.h"
#include "macros.h"
#include "windowattrmanager.h"

#include <algorithm>
#include <wx/app.h>

GotoAnythingDlg::GotoAnythingDlg(wxWindow* parent, const std::vector<clGotoEntry>& entries)
Expand All @@ -23,31 +17,27 @@ GotoAnythingDlg::GotoAnythingDlg(wxWindow* parent, const std::vector<clGotoEntry
CallAfter(&GotoAnythingDlg::UpdateLastSearch);

::clSetDialogBestSizeAndPosition(this);
CenterOnParent();
}

GotoAnythingDlg::~GotoAnythingDlg()
{
// clConfig::Get().Write("GotoAnything/LastSearch", m_textCtrlSearch->GetValue());
}
GotoAnythingDlg::~GotoAnythingDlg() {}

void GotoAnythingDlg::OnKeyDown(wxKeyEvent& event)
{
event.Skip();
if(event.GetKeyCode() == WXK_ESCAPE) {
if (event.GetKeyCode() == WXK_ESCAPE) {
event.Skip(false);
EndModal(wxID_CANCEL);
} else if(event.GetKeyCode() == WXK_DOWN) {
} else if (event.GetKeyCode() == WXK_DOWN) {
event.Skip(false);
int row = m_dvListCtrl->GetSelectedRow();
if((size_t)(row + 1) < m_dvListCtrl->GetItemCount()) {
if ((size_t)(row + 1) < m_dvListCtrl->GetItemCount()) {
row++;
DoSelectItem(m_dvListCtrl->RowToItem(row));
}
} else if(event.GetKeyCode() == WXK_UP) {
} else if (event.GetKeyCode() == WXK_UP) {
event.Skip(false);
int row = m_dvListCtrl->GetSelectedRow();
if((row - 1) >= 0) {
if ((row - 1) >= 0) {
row--;
DoSelectItem(m_dvListCtrl->RowToItem(row));
}
Expand All @@ -64,23 +54,23 @@ void GotoAnythingDlg::DoPopulate(const std::vector<clGotoEntry>& entries, const
{
m_dvListCtrl->DeleteAllItems();
m_dvListCtrl->Begin();
for(size_t i = 0; i < entries.size(); ++i) {
for (size_t i = 0; i < entries.size(); ++i) {
const clGotoEntry& entry = entries[i];
wxVector<wxVariant> cols;
cols.push_back(wxT("\u2022 ") + entry.GetDesc());
cols.push_back(entry.GetKeyboardShortcut());
m_dvListCtrl->AppendItem(cols, indexes.empty() ? i : indexes[i]);
}
m_dvListCtrl->Commit();
if(!entries.empty()) {
if (!entries.empty()) {
m_dvListCtrl->SelectRow(0);
}
}

void GotoAnythingDlg::DoExecuteActionAndClose()
{
int row = m_dvListCtrl->GetSelectedRow();
if(row == wxNOT_FOUND)
if (row == wxNOT_FOUND)
return;

// Execute the action
Expand All @@ -106,22 +96,22 @@ void GotoAnythingDlg::ApplyFilter()
{
// Create a list the matches the typed text
wxString filter = m_textCtrlSearch->GetValue();
if(m_currentFilter == filter)
if (m_currentFilter == filter)
return;

// Update the last applied filter
m_currentFilter = filter;
if(filter.IsEmpty()) {
if (filter.IsEmpty()) {
DoPopulate(m_allEntries);
} else {

// Filter the list
clAnagram anagram(filter);
std::vector<clGotoEntry> matchedEntries;
std::vector<int> matchedEntriesIndex;
for(size_t i = 0; i < m_allEntries.size(); ++i) {
for (size_t i = 0; i < m_allEntries.size(); ++i) {
const clGotoEntry& entry = m_allEntries[i];
if(anagram.MatchesInOrder(entry.GetDesc())) {
if (anagram.MatchesInOrder(entry.GetDesc())) {
matchedEntries.push_back(entry);
matchedEntriesIndex.push_back(i);
}
Expand Down
7 changes: 7 additions & 0 deletions Plugin/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,9 @@ void clSetTLWindowBestSizeAndPosition(wxWindow* win)
tlw->SetMinSize(frameSize.GetSize());
tlw->SetSize(frameSize.GetSize());
tlw->CentreOnParent();
#if defined(__WXMAC__)
tlw->Move(wxNOT_FOUND, parent_tlw->GetPosition().y);
#endif
tlw->PostSizeEvent();
}

Expand All @@ -1656,6 +1659,7 @@ static void DoSetDialogSize(wxDialog* win, double factor)
if (!win) {
return;
}

if (factor <= 0.0) {
factor = 1.0;
}
Expand All @@ -1674,6 +1678,9 @@ static void DoSetDialogSize(wxDialog* win, double factor)
win->SetSize(parentSize);
win->GetSizer()->Layout();
win->CentreOnParent();
#if defined(__WXMAC__)
win->Move(wxNOT_FOUND, parent->GetPosition().y);
#endif
}
}

Expand Down
Loading

0 comments on commit e15a6a2

Please sign in to comment.