Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add property for RibbonDesigner with path to XML file #73

Closed
Nick74k opened this issue Oct 20, 2017 · 6 comments
Closed

Add property for RibbonDesigner with path to XML file #73

Nick74k opened this issue Oct 20, 2017 · 6 comments
Assignees
Milestone

Comments

@Nick74k
Copy link

Nick74k commented Oct 20, 2017

Please add parameter with file name for RibbonDesigner at opening it from Delphi IDE (Double click on TUIRibbon) to skip need of pressing "Open file" and selecting file every time.
Add file name as published property, if it cannot be taken automatically from form itself.

@joachimmarder
Copy link
Contributor

joachimmarder commented Oct 20, 2017

I tried that earlier with no luck. The problem is that the TUIRibbon control does not know the source XML file name or the generated Pascal file at designtime. Opening the (empty) RibbonDesigner is possible using the right click menu in the designer.

@Nick74k
Copy link
Author

Nick74k commented Oct 23, 2017

Then just add published property for UIRibbon - path to XML file for DesignerEditor. It will be more convenient to use it then - opening designer without file has no sense.
Not sure is it possible to show file dialog at opening with not assigned property and save file name to it automatically - smth like this

procedure TMyRibbonFrameworkEditor.ExecuteVerb(pIndex: Integer);
var
  lRibbon: TUIRibbon;
  dlg: TOpenDialog;
begin
  inherited;
  if pIndex = 0 then begin
    lRibbon := (Self.Component as TUiRibbon);
    if lRibbon.DesignerXMLPath='' then begin
      dlg := TOpenDialog.Create( nil );
      try
        dlg.Filter := 'XML files|*.xml';
        if not dlg.Execute then exit;
        lRibbon.DesignerXMLPath := dlg.FileName;
      finally
        dlg.free;
      end;
    end;
    ShellExecute(0, 'open', PChar(GetDesignerPath() + ' "' + lRibbon.DesignerXMLPath + '"'), nil, nil, SW_SHOWNORMAL);
  end;
end;

@joachimmarder
Copy link
Contributor

Then just add published property for UIRibbon - path to XML file for DesignerEditor.

A kind of designtime-only property? Somewhat uncommon, but should work.

@joachimmarder joachimmarder changed the title Parameter for RibbonDesigner Property for RibbonDesigner with path to XML file Oct 24, 2017
@joachimmarder joachimmarder changed the title Property for RibbonDesigner with path to XML file Add property for RibbonDesigner with path to XML file Oct 24, 2017
@joachimmarder joachimmarder self-assigned this Oct 24, 2017
@joachimmarder joachimmarder added this to the V2.5 milestone Oct 24, 2017
@joachimmarder
Copy link
Contributor

joachimmarder commented Oct 24, 2017

Implemented. Let me know what you think, did not have much time for testing today.

@Nick74k
Copy link
Author

Nick74k commented Oct 25, 2017

Wonderful. Some changes to your functions - marked with long arrows in comments.
Added initial dir for current project, added project path in two places and two ShowMessages removed.
Not sure that relative paths are good enough - what will be if ribbon files are located outside of project path? Then we need some additional checks if the specified file name is relative or not to check - is it needed to add project path.

Besides that there is a small problem - changing of published property (lRibbon.RibbonSourceFile := BrowseForXmlFile();) does not mark file as changed, so if unit was saved before and closed right after this operation, property value will not be saved - Delphi thinks that nothing changed.
Dont know is there exist some function like unit.Touch() to mark unit as changed.

function BrowseForXmlFile(): string;
begin
  With TOpenDialog.Create(nil) do
    try
      Filter := 'XML files|*.xml';
      InitialDir := ExtractFilePath( getActiveProject.FileName );   // <------------------------------------
      if not Execute then
        Exit;
      Result := FileName;
    finally
      Free;
    end;
  // Make the path relative tothe project, so the the settings is portable
  Result :=  ExtractRelativePath(getActiveProject.FileName, Result);
//  ShowMessage(getActiveProject.FileName);                        // <------------------------------------   
//  ShowMessage(Result);                                           // <------------------------------------
end;

procedure TMyRibbonFrameworkEditor.ExecuteVerb(pIndex: Integer);
var
  lRibbon: TUIRibbon;
begin
  inherited;
  lRibbon := (Self.Component as TUiRibbon);
  if lRibbon.RibbonSourceFile.IsEmpty or 
     not FileExists(ExtractFilePath(getActiveProject.FileName)+'\'+lRibbon.RibbonSourceFile) then   // <------------------------------------
    lRibbon.RibbonSourceFile := BrowseForXmlFile();
  case pIndex of
    0: ShellExecute(0, 'open', PChar(GetDesignerPath()),
   PChar('"'+ExtractFilePath(getActiveProject.FileName)+'\'+lRibbon.RibbonSourceFile+'"'), nil, SW_SHOWNORMAL);  // <------------------------------------
  end;
end;

joachimmarder pushed a commit that referenced this issue Oct 26, 2017
joachimmarder pushed a commit that referenced this issue Oct 26, 2017
@joachimmarder
Copy link
Contributor

joachimmarder commented Oct 26, 2017

Placing the XML file outside the project dir sounds like a strange idea. I used absolute paths at first (which lead to the wrong code in my commit), but with absolute paths a projects is not portable any more, so this is a no-go. Thanks for your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants