-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a new action "panel.show_context_menu" showing the context menu. …
…fixed #423
- Loading branch information
1 parent
83f880f
commit 136501c
Showing
26 changed files
with
217 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
Source/NimbleCommander/NimbleCommander/States/FilePanels/Actions/ShowContextMenu.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (C) 2024 Michael Kazakov. Subject to GNU General Public License version 3. | ||
#pragma once | ||
|
||
#include "DefaultAction.h" | ||
|
||
namespace nc::panel::actions { | ||
|
||
struct ShowContextMenu final : PanelAction { | ||
void Perform(PanelController *_target, id _sender) const override; | ||
}; | ||
|
||
} // namespace nc::panel::actions |
42 changes: 42 additions & 0 deletions
42
Source/NimbleCommander/NimbleCommander/States/FilePanels/Actions/ShowContextMenu.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2024 Michael Kazakov. Subject to GNU General Public License version 3. | ||
#include "ShowContextMenu.h" | ||
#include "../PanelView.h" | ||
#include <Panel/PanelData.h> | ||
#include "../PanelController.h" | ||
#include "../ContextMenu.h" | ||
#include <fmt/format.h> | ||
|
||
namespace nc::panel::actions { | ||
|
||
void ShowContextMenu::Perform(PanelController *_target, id /* _sender*/) const | ||
{ | ||
PanelView *const view = _target.view; | ||
|
||
const int curpos = view.curpos; | ||
if( curpos < 0 ) { | ||
NSBeep(); | ||
return; | ||
} | ||
|
||
NCPanelContextMenu *const menu = [_target panelView:view requestsContextMenuForItemNo:curpos]; | ||
if( menu == nil ) { | ||
NSBeep(); | ||
return; | ||
} | ||
|
||
const int sort_pos = _target.data.SortPositionOfEntry(menu.items.front()); | ||
const std::optional<NSRect> frame = [view frameOfItemAtSortPos:sort_pos]; | ||
const NSSize view_size = view.frame.size; | ||
if( frame ) { | ||
// align the top of the menu's chrome with the item's frame and | ||
// clamp by the view's bounds | ||
const NSPoint p = NSMakePoint(std::clamp(frame->origin.x, 0., view_size.width), | ||
std::clamp(frame->origin.y - 5., 0., view_size.height)); | ||
[menu popUpMenuPositioningItem:nil atLocation:p inView:view]; | ||
} | ||
else { | ||
[menu popUpMenuPositioningItem:nil atLocation:NSMakePoint(0., view_size.height) inView:view]; | ||
} | ||
} | ||
|
||
} // namespace nc::panel::actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.