mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-07 00:19:27 +00:00
MacPDF: Add a "Debug" menu with a "Show Clipping Paths" entry
...and hook it up. I opened MainMenu.xib in Xcode, added a new "Submenu Menu Item" from the Library (cmd-shift-l), added a User Defined "toggleShowClippingPaths:" action on First Responder and connected the menu item's action to that action. (I first tried duplicating the existing Window menu and editing that, but the Window menu is marked as `systemMenu="window"` in the xib and I couldn't find a way to undo that in Xcode. So the Debug menu first acted as a second Window menu.) I made "Debug" a toplevel menu to make it consistent with Ladybird.app for now, but I'll probably make it a submenu of "View" in the future.
This commit is contained in:
parent
64a48065b0
commit
2650e64bd4
|
@ -26,4 +26,6 @@
|
|||
- (IBAction)goToNextPage:(id)sender;
|
||||
- (IBAction)goToPreviousPage:(id)sender;
|
||||
|
||||
- (IBAction)toggleShowClippingPaths:(id)sender;
|
||||
|
||||
@end
|
||||
|
|
|
@ -16,10 +16,11 @@
|
|||
NSBitmapImageRep* _cachedBitmap;
|
||||
int _page_index;
|
||||
__weak id<MacPDFViewDelegate> _delegate;
|
||||
PDF::RenderingPreferences _preferences;
|
||||
}
|
||||
@end
|
||||
|
||||
static PDF::PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> render(PDF::Document& document, int page_index, NSSize size)
|
||||
static PDF::PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> render(PDF::Document& document, int page_index, NSSize size, PDF::RenderingPreferences const& preferences)
|
||||
{
|
||||
auto page = TRY(document.get_page(page_index));
|
||||
|
||||
|
@ -29,7 +30,7 @@ static PDF::PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> render(PDF::Document& documen
|
|||
|
||||
auto bitmap = TRY(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, page_size));
|
||||
|
||||
auto errors = PDF::Renderer::render(document, page, bitmap, Color::White, PDF::RenderingPreferences {});
|
||||
auto errors = PDF::Renderer::render(document, page, bitmap, Color::White, preferences);
|
||||
if (errors.is_error()) {
|
||||
for (auto const& error : errors.error().errors())
|
||||
NSLog(@"warning: %@", @(error.message().characters()));
|
||||
|
@ -129,7 +130,7 @@ static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr<Gfx::Bitmap> bitmap_p)
|
|||
if (NSEqualSizes([_cachedBitmap size], pixel_size))
|
||||
return;
|
||||
|
||||
if (auto bitmap_or = render(*_doc, _page_index, pixel_size); !bitmap_or.is_error())
|
||||
if (auto bitmap_or = render(*_doc, _page_index, pixel_size, _preferences); !bitmap_or.is_error())
|
||||
_cachedBitmap = ns_from_gfx(bitmap_or.value());
|
||||
}
|
||||
|
||||
|
@ -158,6 +159,23 @@ static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr<Gfx::Bitmap> bitmap_p)
|
|||
[self goToPage:current_page - 1];
|
||||
}
|
||||
|
||||
- (BOOL)validateMenuItem:(NSMenuItem*)item
|
||||
{
|
||||
if ([item action] == @selector(toggleShowClippingPaths:)) {
|
||||
[item setState:_preferences.show_clipping_paths ? NSControlStateValueOn : NSControlStateValueOff];
|
||||
return _doc ? YES : NO;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (IBAction)toggleShowClippingPaths:(id)sender
|
||||
{
|
||||
if (_doc) {
|
||||
_preferences.show_clipping_paths = !_preferences.show_clipping_paths;
|
||||
[self invalidateCachedBitmap];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)keyDown:(NSEvent*)event
|
||||
{
|
||||
// Calls moveLeft: or moveRight: below.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22154" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22155" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22154"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22155"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
|
||||
|
@ -660,26 +660,39 @@
|
|||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Window" id="aUF-d1-5bR">
|
||||
<menuItem title="Debug" id="jWy-In-lcG">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Window" systemMenu="window" id="Td7-aD-5lo">
|
||||
<menu key="submenu" title="Debug" id="9JC-3n-6oc">
|
||||
<items>
|
||||
<menuItem title="Minimize" keyEquivalent="m" id="OY7-WF-poV">
|
||||
<connections>
|
||||
<action selector="performMiniaturize:" target="-1" id="VwT-WD-YPe"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Zoom" id="R4o-n2-Eq4">
|
||||
<menuItem title="Show Clipping Paths" id="mNt-xL-mVw">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="performZoom:" target="-1" id="DIl-cC-cCs"/>
|
||||
<action selector="toggleShowClippingPaths:" target="-1" id="ZXz-gM-52n"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="eu3-7i-yIM"/>
|
||||
<menuItem title="Bring All to Front" id="LE2-aR-0XJ">
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem title="Window" id="rRF-Br-Pu3">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Window" systemMenu="window" id="ipJ-MA-vaP">
|
||||
<items>
|
||||
<menuItem title="Minimize" keyEquivalent="m" id="iQm-go-526">
|
||||
<connections>
|
||||
<action selector="performMiniaturize:" target="-1" id="ysV-jh-lhh"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Zoom" id="3fA-VK-sIE">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="arrangeInFront:" target="-1" id="DRN-fu-gQh"/>
|
||||
<action selector="performZoom:" target="-1" id="3eR-Yk-WOl"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="fk3-NL-Gg9"/>
|
||||
<menuItem title="Bring All to Front" id="q3x-yl-EEv">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="arrangeInFront:" target="-1" id="9GN-Lx-lIK"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
|
|
Loading…
Reference in a new issue