Skip to content

"Edit in External Tool" Options #516

Closed

Description

@libreartist

Synfig version & platform: 1.31, Debian (Sid)

Issue description: I recently noticed in LibreOffice that it has right-click option on its objects (like vectors, images, sound files and video). If clicked, that particular object will be opened in external application (the default one for those kind of files in your system, e.g., gimp for raster images, inkscape for vector images, ardour for sound files, etc.), so that we can edit them and save them directly into the document, not externally. Thus, it allows a workflow where the parts can be updated while they being positioned in the document. Can it be done in Synfig, for its raster images, vector images and sound files -- if they be needing editing while the project has already crossed the half-way?

Activity

  1. morevnaproject commented on Apr 4, 2018

    @morevnaproject
    Member

    Sounds good!

  2. morevnaproject commented on Apr 4, 2018

    @morevnaproject
    Member

    Related to #513

  3. morevnaproject commented on Mar 3, 2019

    @morevnaproject
    Member

    Let's start by implementing this for Image Layers only.

    What is expected:

    1. New option in Preferences of Synfig Studio, which defines a path to application for opening image files ("krita" or "gimp" or similar).
    2. User can right-click any image and choose "Edit in external application..." menu item. This should open a image file in application specified in Preferences.
  4. ankit-kumar-dwivedi commented on Mar 3, 2019

    @ankit-kumar-dwivedi
    Member

    Thanks for referring this issue @morevnaproject have my exam on Monday so will be unresponsive for 2 days.
    And yes assign this one to me 😁

  5. morevnaproject commented on Mar 4, 2019

    @morevnaproject
    Member

    Great! This issue is yours now. ^__^

  6. added
    Assigned
    on Mar 4, 2019
  7. ankit-kumar-dwivedi commented on Mar 8, 2019

    @ankit-kumar-dwivedi
    Member

    @morevnaproject working on it now :)
    As far as I've seen synfig did not edit the images it only let the user change its dimensions. So where is that modified state saved in the app? If that image is internally saved as the format it was previously (i.e jpeg, png etc) then the "Edit in an external app..." option can link the image with the defined path provided in preferences. What are your views on this?

  8. morevnaproject commented on Mar 8, 2019

    @morevnaproject
    Member

    By default Synfig doesn't embeds images into its files. It just references them.
    You can obtain image path from image layer -

    screenshot_001

    So, all you need to do is to launch binary (the one specified in preferences) and pass an image path as an argument to it. I.e.:

    /usr/bin/krita /path/to/some/file.png
    
  9. ankit-kumar-dwivedi commented on Mar 8, 2019

    @ankit-kumar-dwivedi
    Member

    @morevnaproject will send a PR tomorrow :)

  10. ankit-kumar-dwivedi commented on Mar 9, 2019

    @ankit-kumar-dwivedi
    Member

    So, all you need to do is to launch binary (the one specified in preferences) and pass an image path as an argument to it. I.e.:

    /usr/bin/Krita /path/to/some/file.png
    

    @morevnaproject I saw the code of LibreOffice for "Edit in external tool" they save the image temporarily somewhere and "edit" works on that local copy, not on the original one.

    /usr/bin/krita /path/to/some/file.png

    This will, however, change the original file which I think not all user wants
    So what I am thinking now

    • add an option Preferred image editor in preferences
      Untitled Diagram

    • point the original image unless the user edits that using an external edit tool.

    • when the edit is done the local copy (not the original one) will be modified.

    • on subsequent edit local copy will be used.

    • As the local copy can be edited by external tool so it's source may not be needed by user hence will not be shown to him.

    I have started working as I described. kindly let me know if I need to change something else
    :)

  11. morevnaproject commented on Mar 9, 2019

    @morevnaproject
    Member

    /usr/bin/krita /path/to/some/file.png

    This will, however, change the original file which I think not all user wants

    Still, we would expect original file to be edited. So, here I have to insist - please make edits on original file. ^__^

  12. morevnaproject commented on Mar 9, 2019

    @morevnaproject
    Member

    Also, here is what I've just found:

    screenshot_002

    If you import an image, then expand a yellow group and right-click a layer inside, then you can see there is already "Open file ..." menu item exists.

    The code for it can be found here:

    Instance::add_special_layer_actions_to_menu(Gtk::Menu *menu, const synfigapp::SelectionManager::LayerList &layers) const
    {
    std::map<String, String> uris;
    gather_uri(uris, layers);
    for(std::map<String, String>::const_iterator i = uris.begin(); i != uris.end(); ++i)
    {
    Gtk::MenuItem *item = manage(new Gtk::ImageMenuItem(Gtk::Stock::OPEN));
    item->set_label( (String(_("Open file")) + " '" + i->first + "'").c_str() );
    item->signal_activate().connect(
    sigc::bind(sigc::ptr_fun(&App::open_uri), i->second) );
    item->show();
    menu->append(*item);
    }
    }
    void
    Instance::add_special_layer_actions_to_group(const Glib::RefPtr<Gtk::ActionGroup>& action_group, synfig::String& ui_info, const synfigapp::SelectionManager::LayerList &layers) const
    {
    std::map<String, String> uris;
    gather_uri(uris, layers);
    int index = 0;
    for(std::map<String, String>::const_iterator i = uris.begin(); i != uris.end(); ++i, ++index)
    {
    String action_name = etl::strprintf("special-action-open-file-%d", index);
    String local_name = String(_("Open file")) + " '" + i->first + "'";
    action_group->add(
    Gtk::Action::create(
    action_name,
    Gtk::Stock::OPEN,
    local_name, local_name ),
    sigc::bind(sigc::ptr_fun(&App::open_uri), i->second) );
    ui_info += strprintf("<menuitem action='%s' />", action_name.c_str());
    }
    }

    The problems with current implementation:

    • It uses App::open_uri() function, which relies on OS file associations. It doesn't works for me when I am trying to open PNG files. Also, the OS file associations could be not a best choice when we want to edit PNG files (I usually associate PNG files with some viewer, not editor). So, let's go with an Preferred Image Editor option in preferences.
    • Second: it is not very convenient to expand yellow group and right-click layer inside. This is not intuitive. It would be better to have this option for yellow group itself. The problem is that yellow groups are actually can contain something else than image layer (this is because they are general-purpose switch groups). As a solution we need a special condition, which will check if yellow group has (a single) image layer inside. If yes - then "Open file ..." option is displayed.

    How to achieve last requirement?

    There is already similar case, which can help to understand how to implement this.

    Synfig has support for Papagayo lipsync files - PGO. Here is how it works - https://www.youtube.com/watch?v=-Y0Ox0cnlL4

    This feature is interesting for us, because it adds "Open file ..." action to group menu, IF some of group's parameters references a filename:

    screenshot_006

    See gather_uri() functions responsible for this in https://github.com/synfig/synfig/blob/master/synfig-studio/src/gui/instance.cpp#L1597

    So, I think, it should be possible to add check if group has a single layer inside and this layer is image layer.

  13. 9 remaining items

  14. ankit-kumar-dwivedi commented on Mar 13, 2019

    @ankit-kumar-dwivedi
    Member

    paste->get_param("canvas").get(Canvas::Handle()) returns canvas and then you can get a list of its layers using get_layers_in_group() function.

    trying this now 😃

  15. ankit-kumar-dwivedi commented on Mar 13, 2019

    @ankit-kumar-dwivedi
    Member

    @morevnaproject
    I uncommented those lines

    I think the key is in lines 1657 and 1658 -

    and added some cout to get information

    	if (etl::handle<Layer_PasteCanvas> paste = etl::handle<Layer_PasteCanvas>::cast_dynamic(layer)){
    		std::cout<<"Some sweet info \n";
    		std::cout<<"SIZE ==> "<<paste->get_param("canvas").get(Canvas::Handle())->get_groups().size();
    		
    	}
    

    I am getting 0 here

    //! Gets all the groups
    std::set get_groups()const;

  16. ankit-kumar-dwivedi commented on Mar 13, 2019

    @ankit-kumar-dwivedi
    Member

    @ankit-kumar-dwivedi I need some time to think on the solution. While I am doing this (^__^) I suggest to make a PR for first part of this issue (about Preferred Image Editor option).

    Sure I will do that :)

  17. ankit-kumar-dwivedi commented on Mar 14, 2019

    @ankit-kumar-dwivedi
    Member

    @morevnaproject please have a look at PR :)

  18. ankit-kumar-dwivedi commented on Apr 2, 2019

    @ankit-kumar-dwivedi
    Member

    @morevnaproject I am not getting any output for ⬇️ after changing

    Instance::add_special_layer_actions_to_menu(Gtk::Menu *menu, const synfig::Layer::Handle &layer) const
    {
    add_special_layer_actions_to_menu(menu, synfigapp::SelectionManager::LayerList(1, layer));
    }

    to

    void
    Instance::add_special_layer_actions_to_menu(Gtk::Menu *menu, const synfig::Layer::Handle &layer) const
    {
    	std::cout<<"You called me line 1706\n";
    	add_special_layer_actions_to_menu(menu, synfigapp::SelectionManager::LayerList(1, layer));
    }
    

    However it is being called on line

    get_instance()->add_special_layer_actions_to_menu(menu, layer);

    This is the function responsible for adding "open file.." option in group menu right?

  19. morevnaproject commented on Apr 3, 2019

    @morevnaproject
    Member

    @ankit-kumar-dwivedi The part of code you referenced is called when you right-click a layer in workarea (CanvasView).

    When you select a layer in Layer Panel it calls this -

    Instance::add_special_layer_actions_to_group(const Glib::RefPtr<Gtk::ActionGroup>& action_group, synfig::String& ui_info, const synfigapp::SelectionManager::LayerList &layers) const
    {
    vector <String> img_ext{".jpg",".jpeg",".png",".bmp",".gif"};
    std::map<String, String> uris;
    gather_uri(uris, layers);
    int index = 0;
    for(std::map<String, String>::const_iterator i = uris.begin(); i != uris.end(); ++i, ++index)
    {
    String action_name = etl::strprintf("special-action-open-file-%d", index);
    //if the import layer is type image
    if(std::find(img_ext.begin(), img_ext.end(), filename_extension(i->second)) != img_ext.end())
    {
    String local_name = String(_("Edit image in external tool..."));
    action_group->add(
    Gtk::Action::create(
    action_name,
    Gtk::Stock::OPEN,
    local_name, local_name ),
    sigc::bind(sigc::ptr_fun(&App::open_img_in_external), i->second) );
    ui_info += strprintf("<menuitem action='%s' />", action_name.c_str());
    }
    else
    {
    String local_name = String(_("Open file")) + " '" + i->first + "'";
    action_group->add(

    This function is called from

    handle<studio::Instance>::cast_static(get_canvas_interface()->get_instance())->
    add_special_layer_actions_to_group(action_group_, ui_info, layer_list);
    }

  20. ankit-kumar-dwivedi commented on Apr 3, 2019

    @ankit-kumar-dwivedi
    Member

    EDIT: I got my answer. This comment can be ignored
    @morevnaproject and is there a separate function that is called when I right click a yellow switch group?
    As I was trying to find where the same is implemented for .pgo files as you mentioned earlier

    There is already similar case, which can help to understand how to implement this.

    Synfig has support for Papagayo lipsync files - PGO. Here is how it works - https://www.youtube.com/watch?v=-Y0Ox0cnlL4

    This feature is interesting for us, because it adds "Open file ..." action to group menu, IF some of group's parameters references a filename:

    screenshot_006

    See gather_uri() functions responsible for this in https://github.com/synfig/synfig/blob/master/synfig-studio/src/gui/instance.cpp#L1597

  21. ankit-kumar-dwivedi commented on Apr 4, 2019

    @ankit-kumar-dwivedi
    Member

    @morevnaproject I used the group layer and accessed the canvas using
    layer->get_canvas() but when I tried using the function
    std::set<etl::handle<Layer> > get_layers_in_group(const String&group);
    In return I am getting an empty set.
    so i changed the following

    void
    Instance::gather_uri(std::set<synfig::String> &x, const synfig::Layer::Handle &layer) const
    {
    if (!layer || !layer->get_canvas()) return;
    FileSystem::Handle file_system = layer->get_canvas()->get_file_system();
    if (!file_system) return;
    ParamVocab vocab = layer->get_param_vocab();
    for(ParamVocab::const_iterator i = vocab.begin(); i != vocab.end(); ++i)
    {
    if (i->get_hint() == "filename")
    {
    ValueBase v = layer->get_param(i->get_name());
    if (v.can_get(String()))
    {
    String filename = CanvasFileNaming::make_full_filename(layer->get_canvas()->get_file_name(), v.get(String()));
    String uri = file_system->get_real_uri(filename);
    if (!uri.empty()) x.insert(uri);
    }
    }
    Layer::DynamicParamList::const_iterator j = layer->dynamic_param_list().find(i->get_name());
    if (j != layer->dynamic_param_list().end() && j->second)
    gather_uri(x, j->second);
    }
    //if (etl::handle<Layer_PasteCanvas> paste = etl::handle<Layer_PasteCanvas>::cast_dynamic(layer))
    // gather_uri(x, paste->get_param("canvas").get(Canvas::Handle()));
    }
    and I am getting 0 after I wrote the following at line 1634.

    int layerset = layer->get_canvas()->get_group_count();
    std::cout<<std::endl<<"group count is : "<<layerset<<"\n";
    
    

    I wish to know the number of layers inside the group layer which is passed to the gather_uri() function please let me know if am looking into wrong direction [^_^]
    As this is the last step for achieving this feature

  22. morevnaproject commented on Apr 5, 2019

    @morevnaproject
    Member

    @ankit-kumar-dwivedi I am afraid get_group_count() is not the right function to use, as it serves for different purpose ^__^ -

    //! Gets the number of groups in this canvas
    int get_group_count()const;

    You need to look for other function of Canvas class. ^__^

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions