Class: VimMate::FilesMenu
- Inherits:
-
Object
- Object
- VimMate::FilesMenu
- Defined in:
- lib/vim_mate/files_menu.rb
Overview
The pop-up menu used in the file tree
Instance Method Summary collapse
-
#menu_delete ⇒ Object
Open a dialog and ask the user if he really wants to delete the target file or directory.
-
#menu_new_folder ⇒ Object
Open a dialog to enter a new folder name to create.
-
#menu_refresh ⇒ Object
Signals that the file tree must be refreshed.
-
#menu_rename ⇒ Object
Open a dialog to enter a new name for a file or directory.
Instance Method Details
#menu_delete ⇒ Object
Open a dialog and ask the user if he really wants to delete the target file or directory. Note that for safety, directories can only be removed if they are empty.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/vim_mate/files_menu.rb', line 74 def name = File.basename(@last_path) dialog = Gtk::MessageDialog.new(@parent_window.gtk_window, Gtk::MessageDialog::Flags::MODAL, Gtk::MessageDialog::Type::QUESTION, Gtk::MessageDialog::ButtonsType::YES_NO, if File.directory? @last_path "Delete directory #{name} ?" else "Delete file #{name} ?" end) dialog.set_icon_list(Icons.window_icons) if dialog.run == Gtk::Dialog::RESPONSE_YES begin if File.directory? @last_path FileUtils.rmdir(@last_path) else FileUtils.rm(@last_path) end rescue $stderr.puts "Cannot remove #{@last_path}" end end dialog.destroy end |
#menu_new_folder ⇒ Object
Open a dialog to enter a new folder name to create
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vim_mate/files_menu.rb', line 32 def dialog = Gtk::FileChooserDialog.new("New folder", @parent_window.gtk_window, Gtk::FileChooser::ACTION_CREATE_FOLDER, nil, [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL], [Gtk::Stock::SAVE, Gtk::Dialog::RESPONSE_ACCEPT]) dialog.set_icon_list(Icons.window_icons) dialog.current_folder = if File.directory? @last_path @last_path else File.dirname(@last_path) end dialog.run dialog.destroy end |
#menu_refresh ⇒ Object
Signals that the file tree must be refreshed
102 103 104 105 106 |
# File 'lib/vim_mate/files_menu.rb', line 102 def @refresh_signals.each do |signal| signal.call end end |
#menu_rename ⇒ Object
Open a dialog to enter a new name for a file or directory
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/vim_mate/files_menu.rb', line 51 def dialog = Gtk::FileChooserDialog.new("Rename #{File.basename(@last_path)}", @parent_window.gtk_window, Gtk::FileChooser::ACTION_SAVE, nil, [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL], [Gtk::Stock::SAVE, Gtk::Dialog::RESPONSE_ACCEPT]) dialog.set_icon_list(Icons.window_icons) dialog.current_folder = File.dirname(@last_path) if dialog.run == Gtk::Dialog::RESPONSE_ACCEPT begin File.rename(@last_path, dialog.filename) rescue SystemCallError $stderr.puts "Cannot rename from #{@last_path} to #{dialog.filename}" end end dialog.destroy end |