Improve document file handling.

Fixes: lp:1779512
* https://bugs.launchpad.net/kicad/+bug/1779512
This commit is contained in:
Jeff Young 2018-08-13 23:27:54 +01:00
parent 3c455949fc
commit 122d7ed3b3
4 changed files with 47 additions and 19 deletions

View File

@ -372,9 +372,8 @@ void CONTEXT_MENU::onMenuEvent( wxMenuEvent& aEvent )
}
}
wxASSERT( m_tool ); // without tool & tool manager we cannot handle events
// forward the action/update event to the TOOL_MANAGER
// clients that don't supply a tool will have to check GetSelected() themselves
if( evt && m_tool )
{
//aEvent.StopPropagation();

View File

@ -208,8 +208,13 @@ protected:
void OnButtonClick() override
{
wxString uri = ResolveUriByEnvVars( GetValue() );
GetAssociatedDocument( m_dlg, uri );
wxString filename = GetValue();
if( !filename.IsEmpty() && filename != wxT( "~" ) )
{
wxString uri = ResolveUriByEnvVars( GetValue() );
GetAssociatedDocument( m_dlg, uri );
}
}
DIALOG_SHIM* m_dlg;

View File

@ -170,21 +170,31 @@ protected:
{
case DATASHEET:
{
if( text.IsEmpty() )
text = m_module->GetDocFileName();
text = m_module->GetDocFileName();
wxString datasheetlink = DatasheetLinkFormat;
datasheetlink.Replace( "__HREF__", EscapedHTML( text ) );
if( text.IsEmpty() || text == wxT( "~" ) )
{
fieldhtml.Replace( "__VALUE__", text );
}
else
{
wxString datasheetlink = DatasheetLinkFormat;
datasheetlink.Replace( "__HREF__", EscapedHTML( text ) );
if( text.Length() > 75 )
text = text.Left( 72 ) + wxT( "..." );
if( text.Length() > 75 )
text = text.Left( 72 ) + wxT( "..." );
datasheetlink.Replace( "__TEXT__", EscapedHTML( text ) );
datasheetlink.Replace( "__TEXT__", EscapedHTML( text ) );
fieldhtml.Replace( "__VALUE__", datasheetlink );
fieldhtml.Replace( "__VALUE__", datasheetlink );
}
}
break;
case VALUE:
// showing the value just repeats the name, so that's not much use...
return wxEmptyString;
default:
fieldhtml.Replace( "__VALUE__", EscapedHTML( text ) );
}

View File

@ -65,7 +65,7 @@
#include <menus_helpers.h>
#include <wx/progdlg.h>
#include <tool/context_menu.h>
int LIB_EDIT_FRAME:: m_unit = 1;
int LIB_EDIT_FRAME:: m_convert = 1;
@ -570,18 +570,32 @@ void LIB_EDIT_FRAME::OnViewEntryDoc( wxCommandEvent& event )
if( !part )
return;
wxString fileName;
wxString filename;
// TODO: it would be nice to offer a menu here of aliases....
LIB_ALIAS* alias = part->GetAlias( part->GetName() );
if( part->GetAliasCount() > 1 )
{
CONTEXT_MENU popup;
wxString msg;
fileName = alias->GetDocFileName();
for( LIB_ALIAS* alias : part->GetAliases() )
{
msg.Printf( wxT( "%s (%s)" ), alias->GetName(), alias->GetDocFileName() );
popup.Append( wxID_ANY, msg );
}
if( !fileName.IsEmpty() )
PopupMenu( &popup );
if( popup.GetSelected() >= 0 )
filename = part->GetAlias( (unsigned) popup.GetSelected() )->GetDocFileName();
}
else
filename = part->GetAlias( 0 )->GetDocFileName();
if( !filename.IsEmpty() && filename != wxT( "~" ) )
{
SEARCH_STACK* lib_search = Prj().SchSearchS();
GetAssociatedDocument( this, fileName, lib_search );
GetAssociatedDocument( this, filename, lib_search );
}
}