Skip to content

Commit

Permalink
[gui] Make sure parent dirs exist on Windows before creating the pg_s…
Browse files Browse the repository at this point in the history
…ervice file
  • Loading branch information
gacarrillor committed Jan 9, 2025
1 parent 25df9f6 commit 8f0003f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pg_service_parser/core/pg_service_parser_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from pg_service_parser.libs import pgserviceparser


def conf_path() -> Path:
return pgserviceparser.conf_path()
def conf_path(create_if_missing: Optional[bool] = False) -> Path:
return pgserviceparser.conf_path(create_if_missing)


def service_names(conf_file_path: Optional[Path] = None) -> List[str]:
Expand Down
5 changes: 2 additions & 3 deletions pg_service_parser/gui/dlg_pg_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from pathlib import Path

from qgis.core import QgsApplication
from qgis.gui import QgsMessageBar
from qgis.PyQt.QtCore import QItemSelection, QModelIndex, Qt, pyqtSlot
Expand Down Expand Up @@ -114,7 +112,8 @@ def __create_file_clicked(self):
dlg = NewNameDialog(EnumNewName.SERVICE, self)
dlg.exec()
if dlg.result() == QDialog.DialogCode.Accepted:
Path.touch(self.__conf_file_path)
self.__conf_file_path = conf_path(create_if_missing=True)

add_new_service(dlg.new_name)

# Set flag to get a template after some initialization
Expand Down
5 changes: 4 additions & 1 deletion pg_service_parser/pg_service_parser_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def initGui(self):
self.build_menus()

def build_menus(self):
_conf_path = conf_path()
if not _conf_path.exists():
return

self.menu.clear()

button_menu = QMenu()
Expand All @@ -69,7 +73,6 @@ def build_menus(self):
self.menu.addAction(self.default_action)

if len(self.shortcuts_model.shortcuts):
_conf_path = conf_path()
_services = service_names(_conf_path)
self.button.setPopupMode(QToolButton.MenuButtonPopup)
button_menu.addSeparator()
Expand Down

0 comments on commit 8f0003f

Please sign in to comment.