Skip to content

Commit

Permalink
clone-git-repo@anaximeno: Version 1.4.0 (#535)
Browse files Browse the repository at this point in the history
* Remove expander from the progress bar during the cloning
* Update text and translation
* Show message dialog if cloned folder could not be opened
  • Loading branch information
anaximeno authored Oct 4, 2024
1 parent c81d780 commit 21992c5
Show file tree
Hide file tree
Showing 18 changed files with 545 additions and 319 deletions.
42 changes: 30 additions & 12 deletions clone-git-repo@anaximeno/files/clone-git-repo@anaximeno/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ def __init__(self, directory: str, assume_protocol: str = "http") -> None:
self._directory = directory
self._assume_protocol = assume_protocol
self._win_icon_path = aui.get_action_icon_path(text.UUID)
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
self._clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
self._process = None
self._formatted_address = ""
self._folder_path = ""
self._buff = ""
self._cancelled = False

def get_address_from_clipboard(self) -> str:
clipcontent: str = self.clipboard.wait_for_text()
addresscontent: str = ""
clipcontent = self._clipboard.wait_for_text()
addresscontent = ""

if clipcontent:
clipaddress = self._clean_address(clipcontent)
Expand Down Expand Up @@ -151,9 +151,9 @@ def _format_address(self, address: str) -> str:
address = f"file://{Path(address).resolve()}"

if address.startswith("git@"):
pass # Don't prepend anything
pass # Don't prepend/append anything
elif address.startswith("file://"):
pass # Don't prepend anything
pass # Don't prepend/append anything
elif address.startswith("://"):
address = f"{self._assume_protocol}{address}"
elif not "://" in address:
Expand All @@ -176,9 +176,8 @@ def clone_git_repo(self, address: str, local_path: str) -> bool:
message=text.CLONING_FOR % address,
window_icon_path=self._win_icon_path,
timeout_callback=self._handle_progress,
timeout_ms=35,
on_cancel_callback=self._handle_cancel,
expander_label=text.MORE_INFO,
timeout_ms=35,
)

window.run()
Expand All @@ -200,7 +199,7 @@ def run(self) -> None:
folder_name = self.prompt_user_for_cloned_folder_name(folder_name)

if not folder_name:
exit(1) # On user cancel
exit(1) # On user cancel
elif folder_name == "":
self.prompt_user_folder_name_invalid(folder_name)
exit(1)
Expand Down Expand Up @@ -233,8 +232,6 @@ def _handle_progress(self, user_data, window: aui.ProgressbarDialogWindow) -> bo
self._buff += self._process.stderr.read(8).decode("utf-8")
split_content = self._buff.split("\n")
window.progressbar.set_text(_r(split_content[-1]))
expand_text = "\n".join(_r(line) for line in split_content[-10:])
window.set_expanded_text(expand_text)
window.progressbar.pulse()
except UnicodeDecodeError as e:
log("Exception:", e)
Expand Down Expand Up @@ -277,14 +274,35 @@ def prompt_remove_residual_folder_on_clone_canceled(self, folder: str) -> None:

def prompt_successful_cloning(self, folder_path):
log(f"Info: repo {self._formatted_address!r} was successfully cloned")
window = aui.InfoDialogWindow(
open_cloned_folder_button = aui.ActionableButton(
text.OPEN_CLONED_FOLDER, lambda: self.on_opening_cloned_folder(folder_path)
)
window = aui.ActionableDialogWindow(
title=text.ACTION_TITLE,
message=text.SUCCESSFUL_CLONING,
window_icon_path=self._win_icon_path,
message=text.SUCCESSFUL_CLONING % f"<b>{folder_path}</b>",
buttons=[open_cloned_folder_button],
)
window.run()
window.destroy()

def on_opening_cloned_folder(self, folder_path):
try:
subprocess.Popen(
["xdg-open", folder_path],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
except Exception as e:
log(f"Error: Couldn't open the cloned folder: {e}")
window = aui.InfoDialogWindow(
title=text.ACTION_TITLE,
window_icon_path=self._win_icon_path,
message=text.UNSUCCESSFUL_OPEN_CLONED_FOLDER,
)
window.run()
window.destroy()

def prompt_unsuccessful_cloning(self, repository_address):
log(f"Error: repo {repository_address!r} wasn't cloned successfully")
buffer_clean = "\n".join(_r(line) for line in self._buff.split("\n"))
Expand Down
143 changes: 117 additions & 26 deletions clone-git-repo@anaximeno/files/clone-git-repo@anaximeno/aui.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,28 @@
"""Action UI - Basic GTK Based UI Toolkit for Nemo Actions.
@Author: Anaxímeno Brito <[email protected]>
@Url: https://github.com/anaximeno/aui
@Version: 0.5-patch1
@License: BSD 3-Clause License
@Version: 0.6
@License: MIT License
Copyright (c) 2024, Anaxímeno Brito
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

import os
Expand Down Expand Up @@ -503,3 +496,101 @@ def run(self) -> str | None:
if btn.gtk_button.get_active():
return btn.id
return None


class ActionableButton:
_id_counter = 0

def __init__(self, text: str, on_click_action: Callable) -> None:
self._id = self._get_id()
self._on_click_action = on_click_action
self._text = text

@classmethod
def _get_id(cls):
cls._id_counter += 1
return cls._id_counter

@property
def id(self) -> str:
return self._id

@property
def text(self) -> str:
return self._text

@property
def on_click_action(self) -> Callable:
return self._on_click_action

def trigger_on_click_action(self, *args, **kwargs) -> None:
self._on_click_action(*args, **kwargs)


class _ActionableDialog(Gtk.Dialog):
def __init__(
self,
*args,
title: str = None,
message: str,
buttons: Iterable[ActionableButton],
width: int,
height: int,
**kwargs,
) -> None:
super().__init__(*args, title=title, **kwargs)
self._box = Gtk.VBox()
self._label = Gtk.Label()
self._label.set_margin_top(10)
self._label.set_margin_bottom(10)
self._label.set_margin_start(10)
self._label.set_margin_end(10)
self._label.set_halign(Gtk.Align.CENTER)
self._label.set_valign(Gtk.Align.CENTER)
self._label.set_markup(message)
self._box.pack_start(self._label, True, True, 0)
self._content_area = self.get_content_area()
self._content_area.add(self._box)
self._buttons = buttons

for button in self._buttons:
self.add_button(button.text, button.id)

self.set_default_size(width, height)
self.show_all()


class ActionableDialogWindow(DialogWindow):
def __init__(
self,
*args,
title: str,
message: str,
buttons: Iterable[ActionableButton],
width: int = 360,
height: int = 120,
window_icon_path: str = None,
**kwargs,
) -> None:
super().__init__(
*args,
title=title,
icon_path=window_icon_path,
**kwargs,
)
self.buttons = buttons
self.dialog = _ActionableDialog(
flags=0,
transient_for=self,
message=message,
buttons=buttons,
width=width,
height=height,
)

def run(self) -> None:
response = super().run()
for button in self.buttons:
if response == button.id:
button.trigger_on_click_action()
break
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"uuid": "clone-git-repo@anaximeno",
"name": "Clone git repo",
"author": "anaximeno",
"version": "1.3.1"
"version": "1.4.0"
}
46 changes: 27 additions & 19 deletions clone-git-repo@anaximeno/files/clone-git-repo@anaximeno/po/ca.po
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# SOME DESCRIPTIVE TITLE.
# CLONE GIT REPO
# This file is put in the public domain.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
# anaximeno, 2024
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: clone-git-repo@anaximeno 1.2.1\n"
"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-actions/"
"issues\n"
"POT-Creation-Date: 2024-06-08 21:03-0100\n"
"POT-Creation-Date: 2024-10-04 01:20-0100\n"
"PO-Revision-Date: 2024-07-24 00:45+0200\n"
"Last-Translator: Odyssey <[email protected]>\n"
"Language-Team: \n"
Expand All @@ -18,31 +18,31 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.4.2\n"

#: text.py:14
#. text.py:14
msgid "Clone a repository"
msgstr "Clona un repositori"

#: text.py:16
#. text.py:16
msgid "git urls"
msgstr "urls de git"

#: text.py:18
#. text.py:18
msgid "Enter the name for the cloned folder:"
msgstr "Introdueix el nom per la carpeta clonada:"

#: text.py:21
#. text.py:21
msgid ""
"The entered name is invalid.\n"
"Please choose a name that follows folder naming rules."
msgstr ""
"El nom introduït és invàlid.\n"
"Si us plau, tria un nom que segueixi les convencions de nom de carpetes."

#: text.py:28
#. text.py:28
msgid "Repository Address:"
msgstr "Adreça del repositori:"

#: text.py:32
#. text.py:32
#, python-format
msgid ""
"The given Git address has an unrecognized format.\n"
Expand All @@ -51,22 +51,30 @@ msgstr ""
"L'adreça git facilitada té un format desconegut.\n"
"Si us plau, revisa els formats suportats a %s i prova-ho de nou."

#: text.py:38
#. text.py:38
#, python-format
msgid "Cloning %s"
msgstr "Clonant %s"

#: text.py:40
#, python-format
msgid "Repository successfully cloned to %s"
msgstr "El repositori s'ha clonat correctament a %s"
#. text.py:40
msgid "Repository successfully cloned!"
msgstr "El repositori s'ha clonat correctamen!"

#. text.py:42
msgid "Open"
msgstr ""

#. text.py:44
#, fuzzy
msgid "Couldn't open the cloned folder!"
msgstr "Introdueix el nom per la carpeta clonada:"

#: text.py:42
#. text.py:46
#, python-format
msgid "Error cloning repository %s !"
msgstr "Error clonant el repositori %s!"

#: text.py:45
#. text.py:49
#, python-format
msgid ""
"A folder named %s already exists in this location.\n"
Expand All @@ -75,15 +83,15 @@ msgstr ""
"Ja hi ha una carpeta anomenada %s a aquesta ruta.\n"
"Si us plau, tria un nom diferent o elimina la carpeta ja existent."

#: text.py:49
#. text.py:53
msgid "Cloning info"
msgstr "Informació de la clonació"

#: text.py:51
#. text.py:55
msgid "More info"
msgstr "Més informació"

#: text.py:54
#. text.py:58
msgid ""
"The clone operation was canceled, leaving behind a residual folder. Should "
"this folder be sent to the trash? Please note that due to the cancellation, "
Expand Down
Loading

0 comments on commit 21992c5

Please sign in to comment.