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

Where; documentation for python API #29

Open
brunoais opened this issue Feb 27, 2018 · 14 comments
Open

Where; documentation for python API #29

brunoais opened this issue Feb 27, 2018 · 14 comments

Comments

@brunoais
Copy link

Where can I find the documentation of the python API?

I want to make an extension in python to:
When:

  • Double click used on a file
    Instead of (default):
  • Open the file with default program
    Do:
  • Test if Ctrl and Shift are currently pressed
    -- (if so) Execute gksudo -u root + {start command}
    -- (else) Execute default

caja already has a right click command to "start as administrator" (root) but I'd like a step further and have a keyboard shortcut.

@info-cppsp
Copy link

in the docs/reference folder? please have a look at the examples as well.
you can also use python to describe methods with doc
https://docs.python.org/3/tutorial/controlflow.html#documentation-strings

@brunoais
Copy link
Author

brunoais commented Mar 6, 2018

@info-cppsp I've looked there. Unfortunately, none of those explain how to bind keyboard modifiers and a mouse action to some code.

@info-cppsp
Copy link

  1. where is it defined, what a double click on file does?
    caja/libcaja-private/caja-file.c has a function gboolean caja_file_is_launchable (CajaFile *file)
    caja-mime-actions.c get_activation_action()
    activate_files() - this seems to be the function
    better: caja_mime_activate_file() or caja_mime_activate_files()
    these are called from caja/src/file-manager/fm-directory-view.c
    fm_directory_view_activate_file() fm_directory_view_activate_files()

now all this is deep inside caja. I don't think there is a way to use extensions to override this.

>>> dir(Caja)
['Column', 'ColumnClass', 'ColumnDetails', 'ColumnProvider', 'ColumnProviderIface', 'File', 'FileInfo', 'FileInfoIface', 'InfoProvider', 'InfoProviderIface', 'LocationWidgetProvider', 'LocationWidgetProviderIface', 'Menu', 'MenuClass', 'MenuItem', 'MenuItemClass', 'MenuItemDetails', 'MenuPrivate', 'MenuProvider', 'MenuProviderIface', 'OperationHandle', 'OperationResult', 'PropertyPage', 'PropertyPageClass', 'PropertyPageDetails', 'PropertyPageProvider', 'PropertyPageProviderIface', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__file__', '__format__', '__ge__', '__getattr__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__loader__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__package__', '__path__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__spec__', '__str__', '__subclasshook__', '__weakref__', '_namespace', '_version', 'file_info_create', 'file_info_create_for_uri', 'file_info_list_copy', 'file_info_list_free', 'file_info_lookup', 'file_info_lookup_for_uri', 'info_provider_update_complete_invoke', 'module_initialize', 'module_list_types', 'module_shutdown']

What looks useful here is the menu.
see the open-terminal.py in the examples.
You could probably add a new context menu that launches a program for you as an administrator, based on the file's extension.
(like you could write that .txt files should be opened with gksudo -u root pluma).
However I have read that because of privilege escalation you may not be able to use sudo or alike commands in os.system('%s &' % terminal) calls. I don't remember anymore, please check.

Maybe have a look at caja-extensions/gksu - that is the open as admin menu
Maybe you have access to the default menus in caja from python in which case you could override the default context menu 'Open'. Still, that would be a right click and a left, not a double click...

@brunoais
Copy link
Author

brunoais commented Mar 6, 2018

The context menu option to start with gksu already exists. I just wanted to add a keyboard shortcut at the time of the double click for opening, so it is opened with gksu as if I had used the context option to open as super user.

@info-cppsp
Copy link

to add shortcut:
caja/src/file-manager/fm-directory-view.c fm_directory_view_class_init()
at the end of this function there are signal bindings for deleting files.
One could add a shortcut here - and add it for the other views as well.

yes, I get what you are trying to do, but I still don't think it is possible with extensions...

@brunoais
Copy link
Author

brunoais commented Mar 6, 2018 via email

@info-cppsp
Copy link

http://wiki.mate-desktop.org/applications:caja
This may help.

@monsta @lukefromdc
Could you help with this issue please?

@lukefromdc
Copy link
Member

All my experience is with C and I really don't know much about Python

@info-cppsp
Copy link

that's, ok, the actual question is: can the default double-click action (on a file) in caja be redefined?
so that it would open the file as administrator, with the default application, if Ctrl and Shift are currently pressed.
can this be done with an extension?

@lukefromdc
Copy link
Member

Right click on a file, then click "properties" in the menu that opens, then select "open with" and you will get a list of applications with radio buttons. Whichever one is the active radio button will be the one that double-clicking files of that type opens them with

@brunoais
Copy link
Author

brunoais commented Mar 6, 2018

@lukefromdc I want a different action for when Ctrl+Shift combo is pressed than when both are not pressed

@lukefromdc
Copy link
Member

I do not know how to do something like that, maybe someone else here does. @monsta?

@monsta
Copy link
Contributor

monsta commented Mar 16, 2018

You can add a list view column, a property page tab, and a context menu item. I recall there also was an ability to add a toolbar button, but it got lost at some point. I think that's all.

Note that there's a preference setting (in Caja, not here) to open folders with single click instead of double one, so I'd be careful with changing anything that could be related.

@brunoais
Copy link
Author

In that case.... Nothing I can do except going to caja and add code for such feature, right?

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

No branches or pull requests

4 participants